XMLReader : correct VAT order

This commit is contained in:
sparkyx 2026-04-02 11:13:03 +02:00
parent d444937bcc
commit ffce598f2f
2 changed files with 47 additions and 35 deletions

View file

@ -188,28 +188,37 @@ class XMLCreditNote_Reader extends XML_Reader
{ {
$result = []; $result = [];
$node = $this->get_node("//cac:TaxTotal/cac:TaxSubtotal"); $node = $this->get_node("//cac:TaxTotal/cac:TaxSubtotal");
for ($e = 0; $e < $node->length; $e++) for ($e = 0; $e < $node->length; $e++)
{ {
$row = []; $row = [];
$xml = simplexml_import_dom($node->item($e)); $xml = simplexml_import_dom($node->item($e));
// /Invoice/cac:TaxTotal[1]/cac:TaxSubtotal[1]/cbc:TaxableAmount[1]
$this->registerNS($xml); $this->registerNS($xml);
$row ['taxable_amount'] = $xml->xpath("//cbc:TaxableAmount")[$e] . "";
$row ['tax'] = $xml->xpath("//cbc:TaxAmount")[$e] . ""; $row ['taxable_amount'] = $xml->xpath("cbc:TaxableAmount")[0] . "";
$row ['tax_id'] = $xml->xpath("//cac:TaxCategory/cbc:ID")[$e] . ""; $row ['tax'] = $xml->xpath("cbc:TaxAmount")[0] . "";
$row ['tax_percent'] = $xml->xpath("//cac:TaxCategory/cbc:Percent")[$e] . ""; $row['tax_currency']=$xml->xpath("cbc:TaxAmount")[0]->attributes()['currencyID']."";
if (isset($xml->xpath("//cac:CreditNoteLine/cac:Item/cbc:Name")[$e])) $row ['tax_id'] = $xml->xpath("cac:TaxCategory/cbc:ID")[0]. "";
$row ['name'] =$xml->xpath("//cac:CreditNoteLine/cac:Item/cbc:Name")[$e].""; $row ['tax_percent'] =0;
else $r=$xml->xpath("//cac:TaxCategory/cbc:Percent");
$row['name']=""; if ( isset($r[$e]) )
if ( isset ($xml->xpath("//cbc:TaxExemptionReasonCode")[$e]))
{ {
$row['vatex']=$xml->xpath("//cbc:TaxExemptionReasonCode")[$e]; $row ['tax_percent'] = $xml->xpath("cac:TaxCategory/cbc:Percent")[0] . "";
}else { }
$row['vatex']=""; $row ['name'] ="";
if ( $xml->xpath("cac:TaxCategory/cbc:Name") != null)
{
$row['name']=$xml->xpath("cac:TaxCategory/cbc:Name")[0].'';
}
$row['vatex']="";
if ( $xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason") != null)
{
$row['vatex']=$xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason")[0].'';
}
if ( $xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason") != null)
{
$row['vatex'].=$xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason")[0].'';
} }
$result[] = $row; $result[] = $row;
} }

View file

@ -149,40 +149,43 @@ class XMLInvoice_Reader extends XML_Reader
* @brief get the Taxes info from XML * @brief get the Taxes info from XML
* @return array * @return array
*/ */
function get_taxes(): array function get_taxes(): array
{ {
$result = []; $result = [];
$node = $this->get_node("//cac:TaxTotal/cac:TaxSubtotal"); $node = $this->get_node("//cac:TaxTotal/cac:TaxSubtotal");
for ($e = 0; $e < $node->length; $e++) for ($e = 0; $e < $node->length; $e++)
{ {
$row = []; $row = [];
$xml = simplexml_import_dom($node->item($e));
// /Invoice/cac:TaxTotal[1]/cac:TaxSubtotal[1]/cbc:TaxableAmount[1]
$this->registerNS($xml);
$row ['taxable_amount'] = $xml->xpath("//cbc:TaxableAmount")[$e] . ""; $xml = simplexml_import_dom($node->item($e));
$row ['tax'] = $xml->xpath("//cbc:TaxAmount")[$e] . ""; $this->registerNS($xml);
$row ['tax_id'] = $xml->xpath("//cac:TaxCategory/cbc:ID")[$e] . "";
$row ['tax_percent'] =0;
$row ['taxable_amount'] = $xml->xpath("cbc:TaxableAmount")[0] . "";
$row ['tax'] = $xml->xpath("cbc:TaxAmount")[0] . "";
$row['tax_currency']=$xml->xpath("cbc:TaxAmount")[0]->attributes()['currencyID']."";
$row ['tax_id'] = $xml->xpath("cac:TaxCategory/cbc:ID")[0]. "";
$row ['tax_percent'] =0;
$r=$xml->xpath("//cac:TaxCategory/cbc:Percent"); $r=$xml->xpath("//cac:TaxCategory/cbc:Percent");
if ( isset($r[$e]) ) if ( isset($r[$e]) )
{ {
$row ['tax_percent'] = $xml->xpath("//cac:TaxCategory/cbc:Percent")[$e] . ""; $row ['tax_percent'] = $xml->xpath("cac:TaxCategory/cbc:Percent")[0] . "";
} }
if (isset($xml->xpath("//cac:InvoiceLine/cac:Item/cbc:Name")[$e])) $row ['name'] ="";
if ( $xml->xpath("cac:TaxCategory/cbc:Name") != null)
{ {
$row ['name'] =$xml->xpath("//cac:InvoiceLine/cac:Item/cbc:Name")[$e].""; $row['name']=$xml->xpath("cac:TaxCategory/cbc:Name")[0].'';
}else {
$row ['name'] ="";
} }
if ( isset ($xml->xpath("//cbc:TaxExemptionReasonCode")[$e])) $row['vatex']="";
if ( $xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason") != null)
{ {
$row['vatex']=$xml->xpath("//cbc:TaxExemptionReasonCode")[$e]; $row['vatex']=$xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason")[0].'';
}else {
$row['vatex']="";
} }
$result[] = $row; if ( $xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason") != null)
{
$row['vatex'].=$xml->xpath("cac:TaxCategory/cbc:TaxExemptionReason")[0].'';
}
$result[] = $row;
} }
return $result; return $result;
} }