From a4a23606abcaaa342f206e8c0df13374214542ac Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Mon, 14 Aug 2023 10:22:54 +0200 Subject: [PATCH] Workaround for wrong conversion --- app/Jobs/Invoice/CreateEInvoice.php | 9 +++++---- app/Jobs/Invoice/MergeEInvoice.php | 11 ++--------- app/Services/Invoice/EInvoice/ZugferdEInvoice.php | 8 +++++--- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/app/Jobs/Invoice/CreateEInvoice.php b/app/Jobs/Invoice/CreateEInvoice.php index e97444705fe3..017c8fcac448 100644 --- a/app/Jobs/Invoice/CreateEInvoice.php +++ b/app/Jobs/Invoice/CreateEInvoice.php @@ -14,6 +14,7 @@ namespace App\Jobs\Invoice; use App\Utils\Ninja; use App\Models\Invoice; +use horstoeko\zugferd\ZugferdDocumentBuilder; use Illuminate\Bus\Queueable; use Illuminate\Support\Facades\App; use Illuminate\Queue\SerializesModels; @@ -29,7 +30,7 @@ class CreateEInvoice implements ShouldQueue public $deleteWhenMissingModels = true; - public function __construct(private Invoice $invoice) + public function __construct(private Invoice $invoice, private bool $returnObject = false) { } @@ -39,7 +40,7 @@ class CreateEInvoice implements ShouldQueue * * @return string */ - public function handle(): string + public function handle(): string|ZugferdDocumentBuilder { /* Forget the singleton*/ App::forgetInstance('translator'); @@ -63,13 +64,13 @@ class CreateEInvoice implements ShouldQueue case "XInvoice-Extended": case "XInvoice-BasicWL": case "XInvoice-Basic": - return (new ZugferdEInvoice($this->invoice))->run(); + return (new ZugferdEInvoice($this->invoice, $this->returnObject))->run(); case "Facturae_3.2": case "Facturae_3.2.1": case "Facturae_3.2.2": return (new FacturaEInvoice($this->invoice, str_replace("Facturae_", "", $e_invoice_type)))->run(); default: - return (new ZugferdEInvoice($this->invoice))->run(); + return (new ZugferdEInvoice($this->invoice, $this->returnObject))->run(); } diff --git a/app/Jobs/Invoice/MergeEInvoice.php b/app/Jobs/Invoice/MergeEInvoice.php index 9536f15c37d0..fd5952d3ac89 100644 --- a/app/Jobs/Invoice/MergeEInvoice.php +++ b/app/Jobs/Invoice/MergeEInvoice.php @@ -47,19 +47,12 @@ class MergeEInvoice implements ShouldQueue private function embedEInvoiceZuGFerD(): void { $filepath_pdf = $this->invoice->client->invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName(); - $e_invoice_path = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"); $disk = config('filesystems.default'); - $file = Storage::disk($disk)->exists($e_invoice_path); - if (! $file){ - (new CreateEInvoice($this->invoice))->handle(); - } - $document = ZugferdDocumentReader::readAndGuessFromFile(Storage::disk($disk)->path($e_invoice_path)); - - + $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())); } - $pdfBuilder = new ZugferdDocumentPdfBuilder($document, Storage::disk($disk)->path($filepath_pdf)); + $pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf)); $pdfBuilder->generateDocument(); $pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf)); } diff --git a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php index e40d3ed6dbc4..37d6ce32fe65 100644 --- a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php +++ b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php @@ -23,11 +23,11 @@ use horstoeko\zugferd\codelists\ZugferdDutyTaxFeeCategories; class ZugferdEInvoice extends AbstractService { - public function __construct(public Invoice $invoice, private array $tax_map = []) + public function __construct(public Invoice $invoice, private readonly bool $returnObject = false, private array $tax_map = []) { } - public function run() + public function run(): string|ZugferdDocumentBuilder { $company = $this->invoice->company; @@ -175,7 +175,9 @@ class ZugferdEInvoice extends AbstractService $xrechnung->writeFile(Storage::disk($disk)->path($client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"))); // The validity can be checked using https://portal3.gefeg.com/invoice/validation or https://e-rechnung.bayern.de/app/#/upload - + if ($this->returnObject){ + return $xrechnung; + } return $client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"); }