diff --git a/html/js/acc_ledger.js b/html/js/acc_ledger.js index 8f6abcd9f..f23e31f10 100644 --- a/html/js/acc_ledger.js +++ b/html/js/acc_ledger.js @@ -2218,3 +2218,31 @@ Supplement_Document.save_file=function(form_dom_id) remove_waiting_box(); return false; } +Supplement_Document.refresh_list=function (nDossier,sDiv,nJR_id) +{ + try + { + var queryString = { + gDossier:nDossier, + div:sDiv, + jr_id:nJR_id, + op:"ledger", + act:"refresh_file" + }; + var action = new Ajax.Request( + "ajax_misc.php", + { + method: 'GET', + parameters: queryString, + onSuccess: function (req) { + $("supplement_div_list"+sDiv).update(req.responseText); + + } + } + ); + } catch (e) + { + console.error(e.message); + } + +} diff --git a/include/XMLDocument/xml_reader.class.php b/include/XMLDocument/xml_reader.class.php index b0d5623f2..f4d458c2a 100644 --- a/include/XMLDocument/xml_reader.class.php +++ b/include/XMLDocument/xml_reader.class.php @@ -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); + } diff --git a/include/XMLDocument/xmlcreditnote_reader.class.php b/include/XMLDocument/xmlcreditnote_reader.class.php index 0dd7052c0..747df8fb6 100644 --- a/include/XMLDocument/xmlcreditnote_reader.class.php +++ b/include/XMLDocument/xmlcreditnote_reader.class.php @@ -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 diff --git a/include/XMLDocument/xmlinvoice_reader.class.php b/include/XMLDocument/xmlinvoice_reader.class.php index 64cef8549..fd1d346bb 100644 --- a/include/XMLDocument/xmlinvoice_reader.class.php +++ b/include/XMLDocument/xmlinvoice_reader.class.php @@ -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 diff --git a/include/ajax/ajax_ledger.php b/include/ajax/ajax_ledger.php index 515c4dd99..fa2fae901 100644 --- a/include/ajax/ajax_ledger.php +++ b/include/ajax/ajax_ledger.php @@ -654,6 +654,13 @@ EOF; $cn->commit(); return; + case 'refresh_file': + //------------------------------------------------ + // refresh list of suppemental files + //------------------------------------------------ + Acc_Document::display_supplementary_doc($cn, $http->get("div"), $http->get("jr_id")); + + return; } $html = escape_xml($html); if (!headers_sent()) { diff --git a/include/class/acc_document.class.php b/include/class/acc_document.class.php index 111df5d5d..a0a405847 100644 --- a/include/class/acc_document.class.php +++ b/include/class/acc_document.class.php @@ -314,7 +314,7 @@ class Acc_Document extends Document { jr_id=$2", [$oid,$this->d_id]); - $xmlreader= XMLInvoice_Reader::build_from_file($a_file['filename']); + $xmlreader= \Noalyss\XMLDocument\XML_Reader::build_from_file($a_file['filename']); //@var $embedded_file (array) keys = filecontent: binary data //,mimecode mimetype and filename (string) @@ -395,5 +395,42 @@ class Acc_Document extends Document { .''; return $r; } - + static function display_supplementary_doc($cn,$div,$jr_id) + { + $gDossier=\Dossier::id(); + $q=new Jrn_Sup_Document_SQL($cn); + $a_row=$q->collect_objects(" where jr_id=$1 order by js_cbc_id", [$jr_id]); + + if ( count($a_row) > 0) + { + foreach ($a_row as $item) { + $export="export.php?"; + $script="Supplement_Document.delete_document('$gDossier','$div','{$item->js_id}','$jr_id')"; + $rowid=sprintf("row_js_%s_%s",$div,$item->js_id); + // @var $download (url) to send file + $download="export.php?". http_build_query( + [ + "act"=>"RAW:suppl-document" + ,"js_id"=>$item->js_id + ,"gDossier"=>$gDossier + ]); + ?> +