From 33dd437d96063ed205892633951eac83a9dd974c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 16 Aug 2023 15:38:08 +1000 Subject: [PATCH] Minor fixes for return types for e-invoices --- app/DataMapper/InvoiceItem.php | 5 +++ app/Jobs/Invoice/CreateEInvoice.php | 2 +- app/Jobs/Invoice/MergeEInvoice.php | 36 ++++++++++--------- .../Invoice/EInvoice/ZugferdEInvoice.php | 5 ++- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 49571d668f..cdb1953c9b 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -61,8 +61,13 @@ class InvoiceItem public $tax_id = ''; + public $task_id = ''; + + public $expense_id = ''; public static $casts = [ + 'task_id' => 'string', + 'expense_id' => 'string', 'tax_id' => 'string', 'type_id' => 'string', 'quantity' => 'float', diff --git a/app/Jobs/Invoice/CreateEInvoice.php b/app/Jobs/Invoice/CreateEInvoice.php index 017c8fcac4..3988c688b4 100644 --- a/app/Jobs/Invoice/CreateEInvoice.php +++ b/app/Jobs/Invoice/CreateEInvoice.php @@ -38,7 +38,7 @@ class CreateEInvoice implements ShouldQueue * Execute the job. * * - * @return string + * @return string|ZugferdDocumentBuilder */ public function handle(): string|ZugferdDocumentBuilder { diff --git a/app/Jobs/Invoice/MergeEInvoice.php b/app/Jobs/Invoice/MergeEInvoice.php index 1a33db8be1..cae7d11068 100644 --- a/app/Jobs/Invoice/MergeEInvoice.php +++ b/app/Jobs/Invoice/MergeEInvoice.php @@ -46,23 +46,25 @@ class MergeEInvoice implements ShouldQueue */ private function embedEInvoiceZuGFerD(): void { - $filepath_pdf = !empty($this->pdf_path) ? $this->pdf_path : $this->invoice->service()->getInvoicePdf(); - $disk = config('filesystems.default'); - $e_rechnung = (new CreateEInvoice($this->invoice, true))->handle(); - if (!empty($this->pdf_path)){ - $realpath_pdf = $filepath_pdf; - } - else { - $realpath_pdf = Storage::disk($disk)->path($filepath_pdf); - } - if (file_exists($realpath_pdf)){ - $pdfBuilder = new ZugferdDocumentPdfBuilder($e_rechnung, $realpath_pdf); - $pdfBuilder->generateDocument(); - $pdfBuilder->saveDocument($realpath_pdf); - } - else{ - nlog("E_Invoice Merge failed - file to merge not found"); - } + try { + $filepath_pdf = !empty($this->pdf_path) ? $this->pdf_path : $this->invoice->service()->getInvoicePdf(); + $disk = config('filesystems.default'); + $e_rechnung = (new CreateEInvoice($this->invoice, true))->handle(); + if (!empty($this->pdf_path)) { + $realpath_pdf = $filepath_pdf; + } else { + $realpath_pdf = Storage::disk($disk)->path($filepath_pdf); + } + if (file_exists($realpath_pdf)) { + $pdfBuilder = new ZugferdDocumentPdfBuilder($e_rechnung, $realpath_pdf); + $pdfBuilder->generateDocument(); + $pdfBuilder->saveDocument($realpath_pdf); + } else { + nlog("E_Invoice Merge failed - file to merge not found"); + } + } catch (\Exception $e) { + nlog("E_Invoice Merge failed - " . $e->getMessage()); + } } } diff --git a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php index 37d6ce32fe..3baf14128f 100644 --- a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php +++ b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php @@ -178,7 +178,10 @@ class ZugferdEInvoice extends AbstractService if ($this->returnObject){ return $xrechnung; } - return $client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"); + + throw new \Exception("Invalid e invoice object"); + + // return $client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"); } private function getTaxType($name): string