e-invoice : import creditNote and create a PDF

This commit is contained in:
sparkyx 2025-11-12 11:32:19 +01:00
parent d0ef7a3057
commit aaf9a16851
8 changed files with 147 additions and 17 deletions

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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

View file

@ -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

View file

@ -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()) {

View file

@ -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 {
.'</a>';
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
]);
?>
<div class="row" id="<?=$rowid?>">
<div class="col">
<a href="<?=$download?>" download> <?=$item->js_filename?></a>
</div>O
<div class="col">
<?=$item->js_description?>
</div>
<div class="col">
<?=\Icon_Action::trash(uniqid("sdd"),$script)?>
</div>
</div>
<?php
}// end foreach $a_row
}// end if count
//download ALL files from this operation
}
}

View file

@ -64,7 +64,11 @@ if ( $div != "popup") :
?>
<li class="<?php echo $class?>">
<?php $div_tab_id=$a_value['id'];?>
<a href="javascript:void(0)" onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected' ;show_tabs($F('<?=$div?>tab').split(','),'<?php echo $div_tab_id; ?>');"><?php echo _($a_value['label'])?></a>
<?php if ( $div_tab_id == "supplemental_doc_div".$div):?>
<a href="javascript:void(0)" onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected' ;Supplement_Document.refresh_list('<?=\Dossier::id()?>','<?=$div?>','<?=$obj->jr_id?>');show_tabs($F('<?=$div?>tab').split(','),'<?php echo $div_tab_id; ?>');"><?php echo _($a_value['label'])?></a>
<?php else: ?>
<a href="javascript:void(0)" onclick="unselect_other_tab(this.parentNode.parentNode);this.parentNode.className='tabs_selected' ;show_tabs($F('<?=$div?>tab').split(','),'<?php echo $div_tab_id; ?>');"><?php echo _($a_value['label'])?></a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
@ -301,7 +305,7 @@ require_once NOALYSS_TEMPLATE.'/ledger_detail_file.php';
?>
<?php
//------------------------------------------------
// Receipt
// Receipt supplemental_doc_div
//------------------------------------------------
require_once NOALYSS_TEMPLATE."/ledger_detail_sup_files.php";
?>

View file

@ -34,14 +34,12 @@
/**
* show existing supplemental files for this operation
*/
Acc_Document::display_supplementary_doc($cn,$div,$jr_id);
/*
$q=new Jrn_Sup_Document_SQL($cn);
$a_row=$q->collect_objects(" where jr_id=$1 order by js_cbc_id", [$jr_id]);
$javascript=sprintf("Supplement_Document.input_file('%s','%s','%s')",
$gDossier,
$div,
$jr_id);
if ( count($a_row) > 0)
{
foreach ($a_row as $item) {
@ -79,6 +77,20 @@ if ( count($a_row) > 0)
,'operation_id'=>$jr_id
]);
*
*/
$javascript=sprintf("Supplement_Document.input_file('%s','%s','%s')",
$gDossier,
$div,
$jr_id);
$download="export.php?". http_build_query(
[
"act"=>"RAW:suppl-document"
,"js_id"=>0
,"gDossier"=>$gDossier
,'operation_id'=>$jr_id
]);
?>
<a href="<?=$download?>" download=""><?=_("Télécharger tous les documents")?>
</a>