E-INVOICE: add code quantity

This commit is contained in:
sparkyx 2025-09-11 11:56:41 +02:00
parent 3209def90f
commit d776c7bf98
6 changed files with 39 additions and 2 deletions

View file

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

View file

@ -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'];

View file

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

View file

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

View file

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

View file

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