diff --git a/app/Services/EDocument/Standards/ZugferdEDocument.php b/app/Services/EDocument/Standards/ZugferdEDocument.php index 706aac5754..1a5eac1222 100644 --- a/app/Services/EDocument/Standards/ZugferdEDocument.php +++ b/app/Services/EDocument/Standards/ZugferdEDocument.php @@ -42,6 +42,8 @@ class ZugferdEDocument extends AbstractService private ?string $exemption_reason_code = null; + private ?string $temp_file_path = null; + /** * __construct * @@ -90,7 +92,8 @@ class ZugferdEDocument extends AbstractService ->setPaymentTerms() // 3. Then payment terms ->setLineItems() // 4. Then line items ->setCustomSurcharges() // 4a. Surcharges - ->setDocumentSummation(); // 5. Finally document summation + ->setDocumentSummation() // 5. Finally document summation + ->setAdditionalReferencedDocument(); // 6. Additional referenced document return $this; @@ -125,6 +128,27 @@ class ZugferdEDocument extends AbstractService return $this; } + private function setAdditionalReferencedDocument(): self + { + if($this->document->client->getSetting('merge_e_invoice_to_pdf')) { + return $this; + } + + $invitation = $this->document->invitations()->first(); + $pdf = (new \App\Jobs\Entity\CreateRawPdf($invitation))->handle(); + $file_name = $this->document->numberFormatter().'.pdf'; + + $this->temp_file_path = \App\Utils\TempFile::filePath($pdf, $file_name); + + $this->xdocument->addDocumentInvoiceSupportingDocumentWithFile( + $this->document->number, + $this->temp_file_path, + $file_name, + ); + + return $this; + } + /** * setDocumentTaxes * @@ -249,7 +273,14 @@ class ZugferdEDocument extends AbstractService public function getXml(): string { - return $this->xdocument->getContent(); + $xml = $this->xdocument->getContent(); + + //used if we are embedding the document within the PDF + if($this->temp_file_path){ + unlink($this->temp_file_path); + } + + return $xml; } private function bootFlags(): self