From 5f929f7a6cac1bd20701a05ee0cbb6fd9488c308 Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 7 Aug 2023 22:02:02 +0200 Subject: [PATCH] Try to merge e-invoice in as many cases as possible. --- app/Jobs/Entity/CreateEntityPdf.php | 3 +++ app/Jobs/Invoice/ZipInvoices.php | 1 + app/Services/Invoice/GetInvoiceEInvoice.php | 2 ++ app/Services/Invoice/InvoiceService.php | 1 + tests/Unit/EInvoiceTest.php | 13 +++++++------ 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 58c60b7cb5ee..266437cd777f 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -13,6 +13,7 @@ namespace App\Jobs\Entity; use App\Exceptions\FilePermissionsFailure; use App\Jobs\Invoice\CreateEInvoice; +use App\Jobs\Invoice\MergeEInvoice; use App\Libraries\MultiDB; use App\Models\Credit; use App\Models\CreditInvitation; @@ -214,6 +215,8 @@ class CreateEntityPdf implements ShouldQueue } if ($this->entity_string == "invoice" && $this->client->getSetting('enable_e_invoice')){ (new CreateEInvoice($this->entity))->handle(); + (new MergeEInvoice($this->entity))->handle(); + } $this->invitation = null; // $this->entity = null; diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index d8c15054343f..c257e647ccb8 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -77,6 +77,7 @@ class ZipInvoices implements ShouldQueue (new CreateEntityPdf($invoice->invitations()->first()))->handle(); if ($invoice->client->getSetting('enable_e_invoice')){ (new CreateEInvoice($invoice))->handle(); + (new MergeEInvoice($invoice))->handle(); } }); diff --git a/app/Services/Invoice/GetInvoiceEInvoice.php b/app/Services/Invoice/GetInvoiceEInvoice.php index b3690eef603c..66a4759fb6b9 100644 --- a/app/Services/Invoice/GetInvoiceEInvoice.php +++ b/app/Services/Invoice/GetInvoiceEInvoice.php @@ -44,6 +44,8 @@ class GetInvoiceEInvoice extends AbstractService if (! $file) { $file_path = (new CreateEInvoice($this->invoice))->handle(); + (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); + } return $file_path; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index d8fc0f47d5ea..2e167561f7c6 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -468,6 +468,7 @@ class InvoiceService if ($invitation->invoice->client->getSetting('enable_e_invoice') && $invitation instanceof InvoiceInvitation) { (new CreateEInvoice($invitation->invoice))->handle(); + (new MergeEInvoice($invitation->invoice))->run(); } }); diff --git a/tests/Unit/EInvoiceTest.php b/tests/Unit/EInvoiceTest.php index 2a76d5971891..41349c264b04 100644 --- a/tests/Unit/EInvoiceTest.php +++ b/tests/Unit/EInvoiceTest.php @@ -42,9 +42,10 @@ class EInvoiceTest extends TestCase $this->company->e_invoice_type = "EN16931"; $this->invoice->client->routing_id = 'DE123456789'; $this->invoice->client->save(); - $xinvoice = (new CreateEInvoice($this->invoice))->handle(); - $this->assertNotNull($xinvoice); - $this->assertTrue(Storage::exists($xinvoice)); + $e_invoice = (new CreateEInvoice($this->invoice))->handle(); + (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); + $this->assertNotNull($e_invoice); + $this->assertTrue(Storage::exists($e_invoice)); } /** @@ -56,9 +57,8 @@ class EInvoiceTest extends TestCase $this->invoice->client->routing_id = 'DE123456789'; $this->invoice->client->save(); - $xinvoice = (new CreateEInvoice($this->invoice))->handle(); - nlog(Storage::path($xinvoice)); - $document = ZugferdDocumentReader::readAndGuessFromFile(Storage::path($xinvoice)); + $e_invoice = (new CreateEInvoice($this->invoice))->handle(); + $document = ZugferdDocumentReader::readAndGuessFromFile(Storage::path($e_invoice)); $document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest); $this->assertEquals($this->invoice->number, $documentno); } @@ -70,6 +70,7 @@ class EInvoiceTest extends TestCase { $pdf = (new CreateEntityPdf($this->invoice->invitations()->first()))->handle(); (new CreateEInvoice($this->invoice))->handle(); + (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); $document = ZugferdDocumentReader::readAndGuessFromFile($pdf); $document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest); $this->assertEquals($this->invoice->number, $documentno);