diff --git a/app/Jobs/Invoice/CreateEInvoice.php b/app/Jobs/Invoice/CreateEInvoice.php index ff4e87d7e872..dc2fdfba1d39 100644 --- a/app/Jobs/Invoice/CreateEInvoice.php +++ b/app/Jobs/Invoice/CreateEInvoice.php @@ -51,9 +51,9 @@ class CreateEInvoice implements ShouldQueue /* Set customized translations _NOW_ */ $t->replace(Ninja::transformTranslations($this->invoice->client->getMergedSettings())); - + $e_invoice_type = $this->invoice->client->getSetting('e_invoice_type'); - + switch ($e_invoice_type) { case "EN16931": case "XInvoice_2_2": @@ -63,13 +63,13 @@ class CreateEInvoice implements ShouldQueue case "XInvoice-Extended": case "XInvoice-BasicWL": case "XInvoice-Basic": - return (new ZugferdEInvoice($this->invoice, $this->alterPDF, $this->custom_pdf_path))->run(); + return (new ZugferdEInvoice($this->invoice))->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, $this->alterPDF, $this->custom_pdf_path))->run(); + return (new ZugferdEInvoice($this->invoice))->run(); } diff --git a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php index 823662f73c90..687f8431e80f 100644 --- a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php +++ b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php @@ -23,7 +23,7 @@ use horstoeko\zugferd\codelists\ZugferdDutyTaxFeeCategories; class ZugferdEInvoice extends AbstractService { - public function __construct(public Invoice $invoice, private bool $alterPDF, private string $custom_pdf_path = "", private array $tax_map = []) + public function __construct(public Invoice $invoice, private array $tax_map = []) { } @@ -175,22 +175,6 @@ 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->alterPDF) { - if ($this->custom_pdf_path != "") { - $pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, $this->custom_pdf_path); - $pdfBuilder->generateDocument(); - $pdfBuilder->saveDocument($this->custom_pdf_path); - } else { - $filepath_pdf = $client->invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName(); - $file = Storage::disk($disk)->exists($filepath_pdf); - if ($file) { - $pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf)); - $pdfBuilder->generateDocument(); - $pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf)); - } - } - } - return $client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"); } diff --git a/app/Services/Invoice/GetInvoiceXInvoice.php b/app/Services/Invoice/GetInvoiceEInvoice.php similarity index 96% rename from app/Services/Invoice/GetInvoiceXInvoice.php rename to app/Services/Invoice/GetInvoiceEInvoice.php index c3f312382058..6b6dac9f544f 100644 --- a/app/Services/Invoice/GetInvoiceXInvoice.php +++ b/app/Services/Invoice/GetInvoiceEInvoice.php @@ -17,7 +17,7 @@ use App\Models\Invoice; use App\Services\AbstractService; use Illuminate\Support\Facades\Storage; -class GetInvoiceXInvoice extends AbstractService +class GetInvoiceEInvoice extends AbstractService { public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) { diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index fa4fb4036187..8558c0128ec6 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -48,7 +48,7 @@ class InvoiceService return $this; } - + /** * applyPaymentAmount * @@ -194,9 +194,13 @@ class InvoiceService public function getEInvoice($contact = null) { - return (new GetInvoiceXInvoice($this->invoice, $contact))->run(); + return (new GetInvoiceEInvoice($this->invoice, $contact))->run(); } + public function mergeEInvoice($contact = null): void + { + (new MergeEInvoice($this->invoice, $contact))->run(); + } public function sendEmail($contact = null) { $send_email = new SendEmail($this->invoice, null, $contact); diff --git a/app/Services/Invoice/MergeEInvoice.php b/app/Services/Invoice/MergeEInvoice.php new file mode 100644 index 000000000000..d05d61abaf86 --- /dev/null +++ b/app/Services/Invoice/MergeEInvoice.php @@ -0,0 +1,61 @@ +invoice->client->getSetting('e_invoice_type'); + switch ($e_invoice_type) { + case "EN16931": + case "XInvoice_2_2": + case "XInvoice_2_1": + case "XInvoice_2_0": + case "XInvoice_1_0": + case "XInvoice-Extended": + case "XInvoice-BasicWL": + case "XInvoice-Basic": + $this->embedEInvoiceZuGFerD(); + //case "Facturae_3.2": + //case "Facturae_3.2.1": + //case "Facturae_3.2.2": + // + default: + $this->embedEInvoiceZuGFerD(); + break; + } + } + + /** + * @throws \Exception + */ + 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"); + $document = ZugferdDocumentReader::readAndGuessFromFile($e_invoice_path); + $disk = config('filesystems.default'); + + 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->generateDocument(); + $pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf)); + } +}