diff --git a/app/Jobs/Invoice/CreateXInvoice.php b/app/Jobs/Invoice/CreateXInvoice.php index 2fbff1c177..45f8e6bd7b 100644 --- a/app/Jobs/Invoice/CreateXInvoice.php +++ b/app/Jobs/Invoice/CreateXInvoice.php @@ -61,6 +61,7 @@ class CreateXInvoice implements ShouldQueue case "XInvoice-Basic": $profile = ZugferdProfiles::PROFILE_BASIC; break; + } $xrechnung = ZugferdDocumentBuilder::CreateNew($profile); @@ -72,7 +73,6 @@ class CreateXInvoice implements ShouldQueue ->setDocumentSellerContact($invoice->user->first_name." ".$invoice->user->last_name, "", $invoice->user->phone, "", $invoice->user->email) ->setDocumentBuyer($client->name, $client->number) ->setDocumentBuyerAddress($client->address1, "", "", $client->postal_code, $client->city, $client->country->iso_3166_2) - ->setDocumentBuyerReference($client->routing_id) ->setDocumentBuyerContact($client->primary_contact()->first()->first_name . " " . $client->primary_contact()->first()->last_name, "", $client->primary_contact()->first()->phone, "", $client->primary_contact()->first()->email) ->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state) ->addDocumentPaymentTerm(ctrans("texts.xinvoice_payable", ['payeddue' => date_create($invoice->date)->diff(date_create($invoice->due_date))->format("%d"), 'paydate' => $invoice->due_date])); @@ -85,6 +85,9 @@ class CreateXInvoice implements ShouldQueue if (empty($client->routing_id)){ $xrechnung->setDocumentBuyerReference(ctrans("texts.xinvoice_no_buyers_reference")); } + else { + $xrechnung->setDocumentBuyerReference($client->routing_id); + } $xrechnung->addDocumentPaymentMean(68, ctrans("texts.xinvoice_online_payment")); if (str_contains($company->getSetting('vat_number'), "/")) { diff --git a/tests/Unit/EInvoiceTest.php b/tests/Unit/EInvoiceTest.php index f8424ffa2c..7f6a3ecb4b 100644 --- a/tests/Unit/EInvoiceTest.php +++ b/tests/Unit/EInvoiceTest.php @@ -39,6 +39,7 @@ class EInvoiceTest extends TestCase public function testEInvoiceGenerates() { + $this->company->e_invoice_type = "EN16931"; $this->invoice->client->routing_id = 'DE123456789'; $this->invoice->client->save(); $xinvoice = (new CreateXInvoice($this->invoice, false))->handle(); @@ -46,30 +47,31 @@ class EInvoiceTest extends TestCase $this->assertTrue(Storage::exists($xinvoice)); } - // /** - // * @throws Exception - // */ - // public function testValidityofXMLFile() - // { - // $this->invoice->client->routing_id = 'DE123456789'; - // $this->invoice->client->save(); + /** + * @throws Exception + */ + public function testValidityofXMLFile() + { + $this->company->e_invoice_type = "EN16931"; + $this->invoice->client->routing_id = 'DE123456789'; + $this->invoice->client->save(); - // $xinvoice = (new CreateXInvoice($this->invoice, false))->handle(); - // nlog(Storage::path($xinvoice)); - // $document = ZugferdDocumentReader::readAndGuessFromFile(Storage::path($xinvoice)); - // $document->getDocumentInformation($documentno); - // $this->assertEquals($this->invoice->number, $documentno); - // } + $xinvoice = (new CreateXInvoice($this->invoice, false))->handle(); + nlog(Storage::path($xinvoice)); + $document = ZugferdDocumentReader::readAndGuessFromFile(Storage::path($xinvoice)); + $document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest); + $this->assertEquals($this->invoice->number, $documentno); + } - // /** - // * @throws Exception - // */ - // public function checkEmbededPDFFile() - // { - // $pdf = (new CreateEntityPdf($this->invoice->invitations()->first()))->handle(); - // (new CreateXInvoice($this->invoice, true, $pdf))->handle(); - // $document = ZugferdDocumentReader::readAndGuessFromFile($pdf); - // $document->getDocumentInformation($documentno); - // $this->assertEquals($this->invoice->number, $documentno); - // } + /** + * @throws Exception + */ + public function checkEmbededPDFFile() + { + $pdf = (new CreateEntityPdf($this->invoice->invitations()->first()))->handle(); + (new CreateXInvoice($this->invoice, true, $pdf))->handle(); + $document = ZugferdDocumentReader::readAndGuessFromFile($pdf); + $document->getDocumentInformation($documentno, $documenttypecode, $documentdate, $documentcurrency, $taxcurrency, $taxname, $documentlangeuage, $rest); + $this->assertEquals($this->invoice->number, $documentno); + } }