e-invoice : import creditNote and create a PDF
This commit is contained in:
parent
d0ef7a3057
commit
aaf9a16851
8 changed files with 147 additions and 17 deletions
|
|
@ -94,7 +94,27 @@ abstract class XML_Reader
|
|||
* @return \Noalyss\XMLDocument\XMLInvoice_Reader
|
||||
* @throws \Exception if xml not valid
|
||||
*/
|
||||
abstract static function build_from_file($filename);
|
||||
static function build_from_file($filename)
|
||||
{
|
||||
if (!file_exists($filename))
|
||||
{
|
||||
throw new \Exception("XR101: file not found $filename", 101);
|
||||
}
|
||||
$dm = new \DOMDocument();
|
||||
if ($dm->load($filename) == false)
|
||||
{
|
||||
throw new \Exception("XR106: cannot load file", 106);
|
||||
}
|
||||
if ( $dm->getElementsByTagName("CreditNote")->length == 1)
|
||||
{
|
||||
return new XMLCreditNote_Reader($dm);
|
||||
}
|
||||
if ( $dm->getElementsByTagName("Invoice")->length == 1)
|
||||
{
|
||||
return new XMLInvoice_Reader($dm);
|
||||
}
|
||||
throw new \Exception("XR116: unknown XML", 116);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Build an XMLInvoice_Reader object from an XML string
|
||||
|
|
@ -102,7 +122,23 @@ abstract class XML_Reader
|
|||
* @return \Noalyss\XMLDocument\XMLInvoice_Reader
|
||||
* @throws \Exception if xml not valid
|
||||
*/
|
||||
abstract static function build_from_string($string);
|
||||
static function build_from_string($string)
|
||||
{
|
||||
$dm = new \DOMDocument();
|
||||
if ($dm->loadXML($string) == false)
|
||||
{
|
||||
throw new \Exception("XR130: cannot load XML", 130);
|
||||
}
|
||||
if ( $dm->getElementsByTagName("CreditNote")->length == 1)
|
||||
{
|
||||
return new XMLCreditNote_Reader($dm);
|
||||
}
|
||||
if ( $dm->getElementsByTagName("Invoice")->length == 1)
|
||||
{
|
||||
return new XMLInvoice_Reader($dm);
|
||||
}
|
||||
throw new \Exception("XR120: unknown XML", 120);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class XMLCreditNote_Reader extends XML_Reader
|
|||
function get_invoiceLine(): array
|
||||
{
|
||||
$result = [];
|
||||
$node = $this->get_node("//ns3:CreditNoteLine");
|
||||
$node = $this->get_node("//cac:CreditNoteLine");
|
||||
for ($e = 0; $e < $node->length; $e++)
|
||||
{
|
||||
$row = [];
|
||||
|
|
@ -189,7 +189,6 @@ class XMLCreditNote_Reader extends XML_Reader
|
|||
{
|
||||
$row = [];
|
||||
$xml = simplexml_import_dom($node->item($e));
|
||||
\Noalyss\Dbg::echo_var(0, htmlspecialchars($xml->asXML()));
|
||||
// /Invoice/cac:TaxTotal[1]/cac:TaxSubtotal[1]/cbc:TaxableAmount[1]
|
||||
$this->registerNS($xml);
|
||||
|
||||
|
|
@ -197,7 +196,10 @@ class XMLCreditNote_Reader extends XML_Reader
|
|||
$row ['tax'] = $xml->xpath("//cbc:TaxAmount")[$e] . "";
|
||||
$row ['tax_id'] = $xml->xpath("//cac:TaxCategory/cbc:ID")[$e] . "";
|
||||
$row ['tax_percent'] = $xml->xpath("//cac:TaxCategory/cbc:Percent")[$e] . "";
|
||||
$row ['name'] =$xml->xpath("//cac:CreditNoteLine/cac:Item/cbc:Name")[$e]."";
|
||||
if (isset($xml->xpath("//cac:CreditNoteLine/cac:Item/cbc:Name")[$e]))
|
||||
$row ['name'] =$xml->xpath("//cac:CreditNoteLine/cac:Item/cbc:Name")[$e]."";
|
||||
else
|
||||
$row['name']="";
|
||||
/**
|
||||
* @TODODNY
|
||||
* Implémenter les allowances
|
||||
|
|
|
|||
|
|
@ -153,15 +153,19 @@ class XMLInvoice_Reader extends XML_Reader
|
|||
{
|
||||
$row = [];
|
||||
$xml = simplexml_import_dom($node->item($e));
|
||||
\Noalyss\Dbg::echo_var(0, htmlspecialchars($xml->asXML()));
|
||||
// /Invoice/cac:TaxTotal[1]/cac:TaxSubtotal[1]/cbc:TaxableAmount[1]
|
||||
$this->registerNS($xml);
|
||||
|
||||
|
||||
$row ['taxable_amount'] = $xml->xpath("//cbc:TaxableAmount")[$e] . "";
|
||||
$row ['tax'] = $xml->xpath("//cbc:TaxAmount")[$e] . "";
|
||||
$row ['tax_id'] = $xml->xpath("//cac:TaxCategory/cbc:ID")[$e] . "";
|
||||
$row ['tax_percent'] = $xml->xpath("//cac:TaxCategory/cbc:Percent")[$e] . "";
|
||||
$row ['name'] =$xml->xpath("//cac:InvoiceLine/cac:Item/cbc:Name")[$e]."";
|
||||
if (isset($xml->xpath("//cac:InvoiceLine/cac:Item/cbc:Name")[$e]))
|
||||
{
|
||||
$row ['name'] =$xml->xpath("//cac:InvoiceLine/cac:Item/cbc:Name")[$e]."";
|
||||
}else {
|
||||
$row ['name'] ="";
|
||||
}
|
||||
/**
|
||||
* @TODODNY
|
||||
* Implémenter les allowances
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue