Support adding the pdf into the XML

This commit is contained in:
David Bomba 2025-09-02 18:29:10 +10:00
parent 63d5a4ca52
commit 37a4f5ba62
1 changed files with 33 additions and 2 deletions

View File

@ -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