Merge branch '251011-einvoice' into unstable

* 251011-einvoice:
  E-INVOICE : use VAT to identify company, since it between belgian company for the moment, VAT_CODE Mandatory
This commit is contained in:
sparkyx 2025-10-17 13:10:09 +02:00
commit 065c6c0357
5 changed files with 47 additions and 32 deletions

View file

@ -1,5 +1,4 @@
<?php
namespace Noalyss\XMLDocument;
/*
@ -51,7 +50,7 @@ namespace Noalyss\XMLDocument;
- 'COMPANY_LEGAL_REGISTRATION' full name
- 'COMPANY_BANK_IBAN' IBAN bank account
- 'COMPANY_BANK_BIC' BIC bank account
- 'COMPANY_UBL_ID' PEPPOL id
- 'COMPANY_UBL_ID' PEPPOL id ==> normalement c'est BE0999999999
- 'MY_COUNTRY_CODE' country code (normally BE)
- 'MY_NAME' short company name
- 'MY_STREET' address
@ -97,7 +96,7 @@ class Error_Message
, 'city' => _("Ville")
, 'country'=>_("Code pays")
, 'customer_id' => _("Numéro de TVA")
, 'endpoint_id' => _('Identifiant PEPPOL')
, 'endpoint_id' => _('Identifiant PEPPOL') // here 9925:BE....
);

View file

@ -82,10 +82,8 @@ class FacturX extends XMLInvoice
}
/**
* @brief check that mandatory info are saved in the DB for customer
* @param $customer_id (int) card of the customer FICHE.F_ID
* @param $a_error (array) array of errors, empty if nothing found
*/
function check_customer_data($customer_id){
function check_customer_data(){
$a_error=array();
$a_needed=[ATTR_DEF_NAME=>'name'
,ATTR_DEF_ADRESS=>'street'

View file

@ -48,7 +48,6 @@ class InvoiceUBL21 extends XMLInvoice {
, 'COMPANY_LEGAL_REGISTRATION'
, 'COMPANY_BANK_IBAN'
, 'COMPANY_BANK_BIC'
, 'COMPANY_UBL_ID'
, 'MY_COUNTRY_CODE'
, 'MY_NAME'
, 'MY_STREET'
@ -67,7 +66,7 @@ class InvoiceUBL21 extends XMLInvoice {
function display_error()
{
$a_error=$this->verify();
include NOALYSS_TEMPLATE."/invoiceUBL21-display_error.php";
include NOALYSS_TEMPLATE."/xmlinvoice-display_error.php";
}
@ -88,18 +87,15 @@ class InvoiceUBL21 extends XMLInvoice {
}
/**
* @brief check that mandatory info are saved in the DB for customer
* @param $customer_id (int) card of the customer FICHE.F_ID
* @param $a_error (array) array of errors, empty if nothing found
* @todo : country code au lieu de country !!
*/
function check_customer_data($customer_id){
function check_customer_data(){
$a_error=array();
$a_needed=[ATTR_DEF_NAME=>'name'
,ATTR_DEF_ADRESS=>'street'
,ATTR_DEF_POSTCODE=>'postalzone'
,ATTR_DEF_CITY=>'city'
,ATTR_DEF_COUNTRY_CODE=>'country'
,ATTR_DEF_NUMTVA=>'customer_id'
,ATTR_DEF_NUMTVA=>'customer_vat_id'
,ATTR_DEF_PEPPOLID=>'endpoint_id'
];
@ -155,7 +151,7 @@ class InvoiceUBL21 extends XMLInvoice {
$tax=$this->createElement('cac:PartyTaxScheme');
$tax->appendChild($this->createElement('cbc:CompanyID',$this->data["customer"]['customer_id']));
$tax->appendChild($this->createElement('cbc:CompanyID',$this->data["customer"]['customer_vat_id']));
$tax_scheme=$this->createElement('cac:TaxScheme');
$tax_scheme->appendChild($this->createElement('cbc:ID',"VAT"));
@ -164,8 +160,8 @@ class InvoiceUBL21 extends XMLInvoice {
$ple=$this->createElement('cac:PartyLegalEntity');
///@todo customer = name doit être fiche
$ple->appendChild($this->createElement("cbc:RegistrationName", $this->data['customer']['name']??"ERROR"));
///@todo customer_id = numéro de TVA doit être dans fiche
$ple->appendChild($this->createElement("cbc:CompanyID", $this->data['customer']['customer_id']??"ERROR"));
///@todo customer_vat_id = numéro de TVA doit être dans fiche
$ple->appendChild($this->createElement("cbc:CompanyID", $this->data['customer']['customer_vat_id']??"ERROR"));
// assemble supplier
$customer_party->appendChild($tax);
@ -214,7 +210,7 @@ class InvoiceUBL21 extends XMLInvoice {
$supplier=$this->createElement('cac:AccountingSupplierParty');
$supplier_party=$supplier->appendChild($this->createElement('cac:Party'));
$supplier_party->appendChild($this->createElement('cbc:EndpointID',$company['COMPANY_UBL_ID']))->setAttribute('schemeID', 9925);
$supplier_party->appendChild($this->createElement('cbc:EndpointID',$this->data["supplier"]['supplier_vat_id']))->setAttribute('schemeID', 9925);
$party_name=$this->createElement('cac:PartyName');
$party_name->appendChild($this->createElement('cbc:Name', $this->data['supplier']['name']));
$supplier_party->appendChild($party_name);
@ -229,14 +225,14 @@ class InvoiceUBL21 extends XMLInvoice {
// Tax Schem
$tax=$this->createElement('cac:PartyTaxScheme');
$tax->appendChild($this->createElement('cbc:CompanyID',$this->data["supplier"]['supplier_id']));
$tax->appendChild($this->createElement('cbc:CompanyID',$this->data["supplier"]['supplier_vat_id']));
$tax_scheme=$this->createElement('cac:TaxScheme');
$tax_scheme->appendChild($this->createElement('cbc:ID',"VAT"));
$tax->appendChild($tax_scheme);
// LegalEntity
$ple=$this->createElement('cac:PartyLegalEntity');
$ple->appendChild($this->createElement("cbc:RegistrationName", $company['COMPANY_LEGAL_REGISTRATION']??"ERROR"));
$ple->appendChild($this->createElement("cbc:CompanyID", $this->data['supplier']['supplier_id']??"ERROR"));
$ple->appendChild($this->createElement("cbc:CompanyID", $this->data['supplier']['supplier_vat_id']??"ERROR"));
$ple->appendChild($this->createElement("cbc:CompanyLegalForm", $company['COMPANY_LEGAL_ENTITY']??"ERROR"));
$contact=$this->createElement('cac:Contact');
$contact->appendChild($this->createElement("cbc:Name",$company['INVOICE_CONTACT_NAME']??"ERROR"));
@ -300,7 +296,7 @@ class InvoiceUBL21 extends XMLInvoice {
* @TODO DNY
* Pas toujours S !?
*/
//$taxCategory->appendChild($this->createElement("cbc:ID",$subTotal[$i]['vat_code']));
$taxCategory->appendChild($this->createElement("cbc:ID",$subTotal[$i]['vat_code']));
$taxCategory->appendChild($this->createElement("cbc:Percent",sprintf("%.2f",$subTotal[$i]['percent'])));
$taxScheme=$this->createElement("cac:TaxScheme");
$taxScheme->appendChild($this->createElement("cbc:ID", "VAT"));

View file

@ -41,7 +41,7 @@ namespace Noalyss\XMLDocument;
[postalzone] => 1080
[city] => Molenbeek Saint Jean
[country] => BE
[supplier_id] => BE012345678
[supplier_vat_id] => BE012345678
[registration_name] => My Company sprl
)
@ -52,7 +52,7 @@ namespace Noalyss\XMLDocument;
[postalzone] =>
[city] =>
[country] =>
[customer_id] =>
[customer_vat_id] => numéro TVA
[registration_name] => This asbl
)
@ -330,9 +330,8 @@ abstract class XMLInvoice extends \DOMDocument
abstract function check_company_data() ;
/**
* @brief check that mandatory info are saved in the DB for customer
* @param $customer_id (int) card of the customer FICHE.F_ID
*/
abstract function check_customer_data($customer_id) ;
abstract function check_customer_data() ;
/**
* @brief create the invoice in the right format, with PDF if any
* @param $operation_id (int) JRN.JR_ID
@ -395,7 +394,7 @@ abstract class XMLInvoice extends \DOMDocument
/**
* @brief check that all the data are correct
* @returns null : no errors, string separated with comma of error code
* @returns empty arry : no errors, array with error code
* @see get_message_error
*/
public function verify()
@ -408,7 +407,7 @@ abstract class XMLInvoice extends \DOMDocument
// verify that all needed data in PARAMETER are valid
$a_error['company'] = $this->check_company_data();
$a_error['customer'] = $this->check_customer_data($this->data['customer']['card_id']);
$a_error['customer'] = $this->check_customer_data();
return $a_error;
}
@ -422,9 +421,15 @@ abstract class XMLInvoice extends \DOMDocument
* - ,postalzone
* - ,city
* - ,country
* - ,customer_id => VAT Number
* - ,customer_vat_id => VAT Number
* - , registration_name,
* - card_id
* - endpoint_id
* @note :
* endpoint_id:
normally it this the VAT number (BE included) and scheme 9925
or the scheme 00208 VAT number without BE (enterprise number)
*/
function fill_customer($card_id):array
{
@ -440,10 +445,11 @@ abstract class XMLInvoice extends \DOMDocument
$result['country']=$customer->get_attribute(ATTR_DEF_COUNTRY_CODE,0);
// official ID , like VAT
$result['customer_id']=str_replace([" ",".","-","/"],"" ,$customer->get_attribute(ATTR_DEF_NUMTVA,0));
$result['customer_vat_id']=str_replace([" ",".","-","/"],"" ,$customer->get_attribute(ATTR_DEF_NUMTVA,0));
// official name of the company
$result['registration_name']=$customer->get_attribute(ATTR_DEF_NAME,0);
$result['endpoint_id']=$customer->get_attribute(ATTR_DEF_PEPPOLID,0);
// $result['endpoint_id']=$customer->get_attribute(ATTR_DEF_PEPPOLID,0);
$result['endpoint_id']= $result['customer_vat_id'];
return $result;
}
/**
@ -455,7 +461,7 @@ abstract class XMLInvoice extends \DOMDocument
* - ,postalzone
* - ,city
* - ,country
* - supplier_id => VAT Number
* - supplier_vat_id => VAT Number avec BE !
* - registration_name,
*
*/
@ -471,13 +477,18 @@ abstract class XMLInvoice extends \DOMDocument
// official name of the company
$result['registration_name']=$a_parameter['MY_NAME'];
// official ID , like VAT
$result['supplier_id']=str_replace([" ",".","-","/"],"" ,$a_parameter['MY_TVA']);
$result['supplier_vat_id']=str_replace([" ",".","-","/"],"" ,$a_parameter['MY_TVA']);
/**
* @TODO vérifier qu'il contient bien BE
*/
$result['COUNTRY_CODE']=$a_parameter['COUNTRY_CODE']??"";
$result['COMPANY_LEGAL_REGISTRATION']=$a_parameter['COMPANY_LEGAL_REGISTRATION']??"";
$result['COMPANY_LEGAL_ENTITY']=$a_parameter['COMPANY_LEGAL_ENTITY']??"";
$result['INVOICE_CONTACT_NAME']=$a_parameter['INVOICE_CONTACT_NAME']??"";
$result['INVOICE_EMAIL_COMPANY']=$a_parameter['INVOICE_EMAIL_COMPANY']??"";
$result['COMPANY_UBL_ID']=$a_parameter['COMPANY_UBL_ID']??"";
//$result['COMPANY_UBL_ID']=$a_parameter['COMPANY_UBL_ID']??"";
$result['COMPANY_UBL_ID']="9925:".$result['supplier_vat_id'];
return $result;
}
/**

View file

@ -34,6 +34,17 @@ namespace Noalyss\XMLDocument;
* Exception code :
* - 55 : XML Invalid
* - 62 : filename don't exist
* Namespace standard (from XSD)
*
* Array
(
[xml] => http://www.w3.org/XML/1998/namespace
[cbc] => urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2
[cac] => urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2
[xmlns] => urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
)
*
*/
class XMLInvoice_Reader
{