From d776c7bf98c59ef47f7f4eb095c7fd3b5924b2ab Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 11 Sep 2025 11:56:41 +0200 Subject: [PATCH] E-INVOICE: add code quantity --- include/XMLDocument/InvoiceUBL21.php | 2 +- include/XMLDocument/XMLInvoice.php | 8 ++++++++ include/class/card_property.class.php | 14 ++++++++++++++ include/compta_ven.inc.php | 2 +- unit-test/include/class/card_propertyTest.php | 13 +++++++++++++ unit-test/include/class/ficheTest.php | 2 ++ 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/XMLDocument/InvoiceUBL21.php b/include/XMLDocument/InvoiceUBL21.php index 81405b632..892d46bb1 100644 --- a/include/XMLDocument/InvoiceUBL21.php +++ b/include/XMLDocument/InvoiceUBL21.php @@ -444,7 +444,7 @@ class InvoiceUBL21 extends XMLInvoice { /// il faut adapter les fiches $result->appendChild( $this->createElement("cbc:InvoicedQuantity", $row['quantity'])) - ->setAttribute("unitCode", "EA"); + ->setAttribute("unitCode", $row["code_quantity"]); $result->appendChild($this->createElement("cbc:LineExtensionAmount", $row['price'])) ->setAttribute("currencyID",$this->data['currency']); $item=$this->createElement("cac:Item"); diff --git a/include/XMLDocument/XMLInvoice.php b/include/XMLDocument/XMLInvoice.php index 88e6fcaa3..154bef980 100644 --- a/include/XMLDocument/XMLInvoice.php +++ b/include/XMLDocument/XMLInvoice.php @@ -67,6 +67,7 @@ use Noalyss\Utility; [vat] => 2.1000 [vat_id] => 1 [vat_reversed] => 0.0000 + [code_quantity]=> EA ) [1] => Array @@ -77,6 +78,7 @@ use Noalyss\Utility; [vat] => 17.5200 [vat_id] => 1 [vat_reversed] => 0.0000 + [code_quantity]=> EA ) [2] => Array @@ -87,6 +89,7 @@ use Noalyss\Utility; [vat] => 15.1200 [vat_id] => 5 [vat_reversed] => 15.1200 + [code_quantity]=> EA ) ) @@ -210,6 +213,11 @@ abstract class XMLInvoice extends \DOMDocument for ($i=0;$i < $nb_operation;$i++) { $result['operation'][$i]['card_id']=$operation->det->array[$i]['qs_fiche']; $result['operation'][$i]['quantity']=$operation->det->array[$i]['qs_quantite']; + + // get the type of unity, if not found then it will be EA + $x= \Card_Property::get_attribute($this->cn,$operation->det->array[$i]['qs_fiche'], ATTR_DEF_QUANTITY_TYPE); + $result['operation'][$i]['code_quantity']=($x===false||$x=="")?"EA":$x; + // $operation->det->currency_id == 0 default currency of the folder if ($operation->det->currency_id == 0 ) { $result['operation'][$i]['price']=$operation->det->array[$i]['qs_price']; diff --git a/include/class/card_property.class.php b/include/class/card_property.class.php index c40c21d3e..01e364ee5 100644 --- a/include/class/card_property.class.php +++ b/include/class/card_property.class.php @@ -699,4 +699,18 @@ class Card_Property } return null; } + /** + * @brief returns the property value of a card without creating a card + * @param \Database $conx + * @param $card_id (int) FICHE.F_ID + * @param $property_id (int) ad_value + * @return string or false if nothing was found + */ + static function get_attribute(\Database $conx, $card_id,$property_id) + { + $r=$conx->get_value("select ad_value from fiche_detail where + ad_id = $1 and f_id=$2",[$property_id,$card_id]); + if ( $conx->count() == 0) { return false;} + return $r; + } } diff --git a/include/compta_ven.inc.php b/include/compta_ven.inc.php index 7d023085b..0904b35c6 100644 --- a/include/compta_ven.inc.php +++ b/include/compta_ven.inc.php @@ -154,7 +154,7 @@ if ( isset($_POST['record']) ) $xmldocument->build_data($Ledger->jr_id); $code_error = $xmldocument->verify() ; if ( ! empty( $code_error ) ) { - echo "Impossible de générer facture : code error "; + echo "Impossible de générer facture : code error $code_error "; echo $xmldocument->get_message_error($code_error); } $pdf_filename=$acc_document->transform2pdf(); diff --git a/unit-test/include/class/card_propertyTest.php b/unit-test/include/class/card_propertyTest.php index 400629c7f..c44167c38 100644 --- a/unit-test/include/class/card_propertyTest.php +++ b/unit-test/include/class/card_propertyTest.php @@ -289,4 +289,17 @@ class Card_PropertyTest extends TestCase $this->assertTrue(!empty($fiche->get_attribute(ATTR_DEF_ACCOUNT)),' accounting not computed'); } + /** + * @testdox test the function get_attribute + */ + public function testGet_attribute() + { + $g_connection=Dossier::connect(); + $fiche_goods = new \Fiche($g_connection); + $fiche_goods->get_by_qcode("MARCHA"); + $id=$fiche_goods->id; + + $this->assertTrue(\Card_Property::get_attribute($g_connection, $id, ATTR_DEF_QUICKCODE)=="MARCHA","Quick code not retrieved"); + $this->assertTrue(\Card_Property::get_attribute($g_connection, $id, -5)==false,"Inexistant property not detected"); + } } diff --git a/unit-test/include/class/ficheTest.php b/unit-test/include/class/ficheTest.php index 96afd657e..fe257b33e 100644 --- a/unit-test/include/class/ficheTest.php +++ b/unit-test/include/class/ficheTest.php @@ -849,4 +849,6 @@ where $this->g_connection->exec_sql ('update fiche set f_enable=$1 where f_id = $2 or f_id=$3',[1,34,35]); } + + }