createsDocument = $createsDocument; $this->createsFiles = $createsFiles; $this->createsKeyValuePair = $createsKeyValuePair; } /** * @throws MalformedRequestException */ public function execute(Transaction $invoice_transaction) { $view = 'pages.pdfs.shipping_einvoice'; $companyModule = $invoice_transaction->owner->owner->companyModule; $user = $companyModule->employees()->first(); $brn = $companyModule->company->documents->where('document_type', DocumentType::SSM_REGISTRATION)->first(); $lastDayOfMonth = $invoice_transaction->created_at->copy()->endOfMonth(); $documentDate = $lastDayOfMonth; $documentIdentifierPrefix = 'EI#: '; $autoCountInvoiceId = ''; $autoCountEInvoiceValidationLink = 'CIEF'; $metadata = $invoice_transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first(); if($metadata){ $autoCountInvoiceId = $metadata->value; } $metadata = $invoice_transaction->attributesKVP()->where('key', KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK)->first(); if($metadata){ $autoCountEInvoiceValidationLink = $metadata->value; } $transaction_invoice_pdf = LaravelMpdf::loadView($view, [ 'invoice_transaction' => $invoice_transaction, 'brn' => $brn, 'document_date' => $documentDate, 'document_identifier' => $autoCountInvoiceId, 'document_identifier_prefix' => $documentIdentifierPrefix, 'autocountEInvoiceValidationLink' => $autoCountEInvoiceValidationLink, ]); $document_object = new DocumentObject( DocumentType::SHIPPING_EINVOICE, [chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))], '', ApprovalStatus::COMPLETED, 'shipping_einvoice' ); /** @var Document $document */ $document =$this->createsDocument->execute($invoice_transaction, $document_object); $this->createsFiles->execute($document, $document_object); $keyValuePairObject = new KeyValuePairObject(KVPKey::EINVOICE_ISSUED, 1); $this->createsKeyValuePair->execute($invoice_transaction, $keyValuePairObject); } }