From 3209def90f541eaf7300b282f693dca81d96451d Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 11 Sep 2025 11:12:54 +0200 Subject: [PATCH] E-INVOICE : add AdditionalDocument --- include/XMLDocument/InvoiceUBL21.php | 23 ++++++++++++++++++++--- include/compta_ven.inc.php | 4 +++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/XMLDocument/InvoiceUBL21.php b/include/XMLDocument/InvoiceUBL21.php index 751618a9e..81405b632 100644 --- a/include/XMLDocument/InvoiceUBL21.php +++ b/include/XMLDocument/InvoiceUBL21.php @@ -501,15 +501,32 @@ class InvoiceUBL21 extends XMLInvoice { { if ( $this->pdf_filename == "") return null; /** $pdf_filename = 'chemin/vers/votre/fichier.pdf';*/ + static $i=0; + $i++; if ( $this->pdf_filename == null ) { return null; } // Lire le fichier PDF $pdfContent = file_get_contents( $this->pdf_filename ); - // Encoder le PDF en base64 - $base64Pdf = base64_encode($pdfContent); - $result=$this->createElement("AdditionalDocumentReference",$base64Pdf); + $result=$this->createElement("cac:AdditionalDocumentReference"); + $id=$this->createElement("cbc:ID",$i); + $documentType=$this->createElement("cbc:DocumentType",'application/pdf'); + $document_description=$this->createElement("cbc:DocumentDescription",'INVOICE PDF'); + + // PDF in base64 + $base64Pdf = base64_encode($pdfContent); + $embeddedDocument=$this->createElement("cbc:EmbeddedDocumentBinaryObject",$base64Pdf); + $embeddedDocument->setAttribute("mimeCode", "application/pdf"); + $embeddedDocument->setAttribute("filename", "facture.pdf"); + $attachment=$this->createElement("cac:Attachment"); + $attachment->appendChild($embeddedDocument); + + $result->appendChild($id); + $result->appendChild($documentType); + $result->appendChild($document_description); + $result->appendChild($attachment); + return $result; } /** diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php index bec99f3f5..7d023085b 100644 --- a/include/compta_ven.inc.php +++ b/include/compta_ven.inc.php @@ -168,8 +168,10 @@ if ( isset($_POST['record']) ) // make the XML + PDF $xml=$xmldocument->make_xml($Ledger->jr_id); if (DEBUGNOALYSS > 1) { - $uniq= tempnam($_ENV['TMP'], "e-invoice"); + $mt=date ('ymd-Hi'); + $uniq= $_ENV['TMP']. DIRECTORY_SEPARATOR."$mt-e-invoice.xml"; file_put_contents($uniq, $xml); + chmod ($uniq,774); echo \Noalyss\Dbg::echo_file("file save $uniq"); } // save XML string into the DB