From 19fcab3b357760d7b60bd434667d193e3e92e927 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 14 Aug 2023 12:08:25 +0200 Subject: [PATCH] Bugfixes --- app/Jobs/Entity/CreateRawPdf.php | 7 +++++-- app/Jobs/Invoice/MergeEInvoice.php | 17 ++++++++++------- app/Services/Invoice/GetInvoiceEInvoice.php | 1 - app/Services/Invoice/GetInvoicePdf.php | 2 +- app/Services/Invoice/MergeEInvoice.php | 16 +++++----------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/app/Jobs/Entity/CreateRawPdf.php b/app/Jobs/Entity/CreateRawPdf.php index faced3f35ace..8c3b4d77f7f0 100644 --- a/app/Jobs/Entity/CreateRawPdf.php +++ b/app/Jobs/Entity/CreateRawPdf.php @@ -203,8 +203,11 @@ class CreateRawPdf implements ShouldQueue if ($pdf) { $maker =null; $state = null; - if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity == "invoice"){ - (new \App\Services\Invoice\MergeEInvoice($this->invitation->invoice))->run(); + if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity_string == "invoice"){ + $filename = tempnam(sys_get_temp_dir(), 'InvoiceNinja').".pdf"; + file_put_contents($filename, $pdf); + (new \App\Services\Invoice\MergeEInvoice($this->invitation->invoice, $filename))->run(); + return file_get_contents($filename); }; return $pdf; } diff --git a/app/Jobs/Invoice/MergeEInvoice.php b/app/Jobs/Invoice/MergeEInvoice.php index fd5952d3ac89..ea1b9b969a9f 100644 --- a/app/Jobs/Invoice/MergeEInvoice.php +++ b/app/Jobs/Invoice/MergeEInvoice.php @@ -11,7 +11,7 @@ use horstoeko\zugferd\ZugferdDocumentReader; class MergeEInvoice implements ShouldQueue { - public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) + public function __construct(public Invoice $invoice, private string $pdf_path = "") { } @@ -46,14 +46,17 @@ class MergeEInvoice implements ShouldQueue */ private function embedEInvoiceZuGFerD(): void { - $filepath_pdf = $this->invoice->client->invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName(); + $filepath_pdf = !empty($this->pdf_path) ? $this->pdf_path : $this->invoice->service()->getInvoicePdf(); $disk = config('filesystems.default'); - $xrechnung = (new CreateEInvoice($this->invoice, true))->handle(); - if (!Storage::disk($disk)->exists($this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()))) { - Storage::makeDirectory($this->invoice->client->e_invoice_filepath($this->invoice->invitations->first())); + $e_rechnung = (new CreateEInvoice($this->invoice, true))->handle(); + if (!empty($this->pdf_path)){ + $realpath_pdf = $filepath_pdf; } - $pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf)); + else { + $realpath_pdf = Storage::disk($disk)->path($filepath_pdf); + } + $pdfBuilder = new ZugferdDocumentPdfBuilder($e_rechnung, $realpath_pdf); $pdfBuilder->generateDocument(); - $pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf)); + $pdfBuilder->saveDocument($realpath_pdf); } } diff --git a/app/Services/Invoice/GetInvoiceEInvoice.php b/app/Services/Invoice/GetInvoiceEInvoice.php index 66a4759fb6b9..0434b6917fd0 100644 --- a/app/Services/Invoice/GetInvoiceEInvoice.php +++ b/app/Services/Invoice/GetInvoiceEInvoice.php @@ -47,7 +47,6 @@ class GetInvoiceEInvoice extends AbstractService (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); } - return $file_path; } } diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 346f707e3b15..8044e8a290d6 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -51,7 +51,7 @@ class GetInvoicePdf extends AbstractService } if ($this->invoice->client->getSetting('enable_e_invoice')){ (new CreateEInvoice($this->invoice))->handle(); - (new MergeEInvoice($this->invoice))->handle(); + (new MergeEInvoice($this->invoice, $file_path))->handle(); } return $file_path; } diff --git a/app/Services/Invoice/MergeEInvoice.php b/app/Services/Invoice/MergeEInvoice.php index c40cb0bafa58..ad80c49cd821 100644 --- a/app/Services/Invoice/MergeEInvoice.php +++ b/app/Services/Invoice/MergeEInvoice.php @@ -11,23 +11,17 @@ class MergeEInvoice /** * @param Invoice $invoice - * @param mixed|null $contact */ - public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) + public function __construct(public Invoice $invoice, public string $pdf_path = "") { } public function run(): void { - $file_path_xml = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()). $this->invoice->getFileName("xml"); - $file_path_pdf = $this->invoice->getFileName(); - // $disk = 'public'; - $disk = config('filesystems.default'); - - $file_xml = Storage::disk($disk)->exists($file_path_xml); - $file_pdf = Storage::disk($disk)->exists($file_path_pdf); - - if ($file_xml && $file_pdf) { + if (!empty($this->pdf_path)) { + (new \App\Jobs\Invoice\MergeEInvoice($this->invoice, $this->pdf_path))->handle(); + } + else { (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); }