From 817dc6f34537b9d3682ca16ded6115f54188d9f3 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 20 Sep 2025 17:08:11 +0200 Subject: [PATCH] e-invoice : add communication , bank and buyer reference --- include/XMLDocument/InvoiceUBL21.php | 10 +++++----- include/XMLDocument/XMLInvoice.php | 7 +++++-- include/class/acc_ledger_sale.class.php | 9 +++++---- include/class/document.class.php | 18 +++++++++++++----- include/compta_ven.inc.php | 9 +++++++-- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/include/XMLDocument/InvoiceUBL21.php b/include/XMLDocument/InvoiceUBL21.php index 7183bbfb3..52f3a9bdc 100644 --- a/include/XMLDocument/InvoiceUBL21.php +++ b/include/XMLDocument/InvoiceUBL21.php @@ -296,16 +296,16 @@ class InvoiceUBL21 extends XMLInvoice { */ function build_paymentInfo() { + $company = $this->load_noalyss_parameter(); $payment=$this->createElement("cac:PaymentMeans"); $payment->appendChild($this->createElement('cbc:PaymentMeansCode',30)); ///@note cbc:PaymentID est la communication lors du paiement - $payment->appendChild($this->createElement('cbc:PaymentID',$this->data["id"])); + $payment->appendChild($this->createElement('cbc:PaymentID',$this->data["info"]['communication'])); $f=$this->createElement ('cac:PayeeFinancialAccount'); ///@todo customer = IBAN doit être dans les paramètres (voir upgrade.sql) - $f->appendChild($this->createElement("cbc:ID", "ERROR:IBAN")); + $f->appendChild($this->createElement("cbc:ID",$company['COMPANY_BANK_IBAN'])); $g=$this->createElement("cac:FinancialInstitutionBranch"); - ///@todo customer = BIC doit être dans les paramètres (voir upgrade.sql) - $g->appendChild($this->createElement("cbc:ID", "ERROR:BIC")); + $g->appendChild($this->createElement("cbc:ID", $company['COMPANY_BANK_BIC'])); $f->appendChild($g); $payment->appendChild($f); @@ -596,7 +596,7 @@ class InvoiceUBL21 extends XMLInvoice { $root->appendChild($this->createElement('cbc:DueDate',$this->data['due_date'])); $root->appendChild($this->createElement('cbc:InvoiceTypeCode',380)); $root->appendChild($this->createElement('cbc:DocumentCurrencyCode',$this->data['currency'])); - $root->appendChild($this->createElement('cbc:BuyerReference',"NOALYSS")); + $root->appendChild($this->createElement('cbc:BuyerReference',$this->data['info']['order'])); /** * insert PDF in the XML */ diff --git a/include/XMLDocument/XMLInvoice.php b/include/XMLDocument/XMLInvoice.php index a1ce9e0ae..ba5a2d392 100644 --- a/include/XMLDocument/XMLInvoice.php +++ b/include/XMLDocument/XMLInvoice.php @@ -59,7 +59,7 @@ namespace Noalyss\XMLDocument; [currency] => 0 [info] => Array [order] = order reference - [comment] = comment added to the invoice + [communication] = communication added to the invoice [operation] => Array ( [0] => Array @@ -218,17 +218,20 @@ abstract class XMLInvoice extends \DOMDocument ,[$jr_id]); $nb_row = count($a_row); $result['info']=[]; + $result['info']['order']='NA'; + $result['info']['communication']=''; for($i=0;$i<$nb_row;$i++) { switch ($a_row[$i]['id_type']) { case 'BON_COMMANDE': $result['info']['order']=$a_row[$i]['ji_value']; break; case 'OTHER': - $result['info']['comment']=$a_row[$i]['ji_value']; + $result['info']['communication']=$a_row[$i]['ji_value']; break; } } + $result['info']['communication']=($result['info']['communication']=="")?$result['id']:""; return $result; } diff --git a/include/class/acc_ledger_sale.class.php b/include/class/acc_ledger_sale.class.php index 2b929d641..fd7c35420 100644 --- a/include/class/acc_ledger_sale.class.php +++ b/include/class/acc_ledger_sale.class.php @@ -1286,7 +1286,8 @@ EOF; return $r; } - /*!\brief the function extra info allows to + /*! + * \brief the function extra info allows to * - add a attachment * - generate an invoice * - insert extra info @@ -1294,7 +1295,7 @@ EOF; */ public function extra_info() { - $r = '
'; + $r = '
'; // check for upload piece $file = new IFile(); $file->table = 0; @@ -1317,8 +1318,8 @@ EOF; } $r.='
'; $obj = new IText(); - $r.=_('Numero de bon de commande : ') . $obj->input('bon_comm') . '
'; - $r.=_('Communication ou autre information : ') . $obj->input('other_info') . '
'; + $r.=_('Numero de bon de commande') . $obj->input('bon_comm') . '
'; + $r.=_('Communication') . $obj->input('other_info') . '
'; $r.='

'; $r.='
'; return $r; diff --git a/include/class/document.class.php b/include/class/document.class.php index ab3f6c1b7..a1df1a70d 100644 --- a/include/class/document.class.php +++ b/include/class/document.class.php @@ -1917,16 +1917,14 @@ class Document } /** * @brief transform the current Document to a PDF, returns the full path of the PDF from the TMP folder + * if the file IS a pdf , then export it and return the path to the file. + * * @todo replace use of unoconv with a PHP lib to convert into PDF * @return string full path to the PDF file */ function transform2pdf() { - if (GENERATE_PDF == 'NO' ) { - \record_log(__FILE__."D1857 PDF not available"); - throw new \Exception("Cannot not transform to PDF",5000); - } - // Extract from public.document + // Extract from public.document $dirname=tempnam($_ENV['TMP'],"document"); if ( $dirname == false ) { @@ -1937,6 +1935,16 @@ class Document if ( mkdir($dirname) == false ) { throw new Exception("D1868.cannot create tmp directory",5000); } + if ( $this->d_mimetype == "application/pdf") { + $destination_file=$dirname."/".$this->d_filename; + $this->export_file($destination_file); + return $dirname."/".$destination_file; + return; + } + if (GENERATE_PDF == 'NO' ) { + \record_log(__FILE__."D1857 PDF not available"); + throw new \Exception("Cannot not transform to PDF",5000); + } $destination_file=$dirname."/".$this->d_filename; $this->export_file($destination_file); diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php index 0672927ce..55419eecf 100644 --- a/include/compta_ven.inc.php +++ b/include/compta_ven.inc.php @@ -158,12 +158,14 @@ if ( isset($_POST['record']) ) /* Save the attachment or generate doc */ if (isset($_FILES['pj'])) { if (noalyss_strlentrim($_FILES['pj']['name']) != 0) - { $cn->save_receipt($seq); + { + $cn->save_receipt($seq); } else /* Generate an invoice and save it into the database */ if (isset($_POST['gen_invoice'])) { + // generate an invoice $file = $Ledger->create_document($internal, $_POST); $receipt= HtmlInput::show_receipt_document($Ledger->jr_id ,h($file)); @@ -178,6 +180,9 @@ if ( isset($_POST['record']) ) /// 2 = create e-invoice requested $flag_invoice=0; + /** + * @todo si Client non belge ou pas de n° de tva alors pas de e-facture + */ if ($g_parameter->MY_INVOICE_FORMAT != 'BASIC' && ! empty($acc_document->d_filename )) { $flag_invoice=2; @@ -189,7 +194,7 @@ if ( isset($_POST['record']) ) $flag_invoice=1; } } - //----------------------7-------------------------- + //------------------------------------------------ // flag_invoice == 2 , generate an e-invoice //------------------------------------------------ if ( $flag_invoice == 2 )