ADD: packaging to round the quantities to some given multiples for the invoices

This commit is contained in:
Mélina JOUM
2025-01-21 09:56:43 +01:00
parent 3c2e6140a1
commit 33d2969ab8
2 changed files with 38 additions and 0 deletions

View File

@@ -3994,6 +3994,20 @@ class Facture extends CommonInvoice
$localtaxes_type = getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc);
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$product = new Product($this->db);
$result = $product->fetch($fk_product);
if ($qty < $product->packaging) {
$qty = $product->packaging;
} else {
if (!empty($product->packaging) && (fmod((float) $qty, $product->packaging) > 0.000001)) {
$coeff = intval((float) $qty / $product->packaging) + 1;
$qty = (float) $product->packaging * $coeff;
setEventMessages($langs->trans('QtyRecalculatedWithPackaging'), null, 'mesgs');
}
}
}
// Clean vat code
$reg = array();
$vat_src_code = '';
@@ -4298,6 +4312,18 @@ class Facture extends CommonInvoice
$this->line->rang = $rangmax + 1;
}
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
if ($qty < $this->line->packaging) {
$qty = $this->line->packaging;
} else {
if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
$coeff = intval($qty / $this->line->packaging) + 1;
$qty = $this->line->packaging * $coeff;
setEventMessage($langs->trans('QtyRecalculatedWithPackaging'), 'mesgs');
}
}
}
$this->line->id = $rowid;
$this->line->rowid = $rowid;
$this->line->label = $label;

View File

@@ -180,6 +180,11 @@ class FactureLigne extends CommonInvoiceLine
*/
public $fk_prev_id;
/**
* @var float
*/
public $packaging;
/**
* Constructor
@@ -211,6 +216,9 @@ class FactureLigne extends CommonInvoiceLine
$sql .= ' fd.multicurrency_total_tva,';
$sql .= ' fd.multicurrency_total_ttc,';
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc';
if (getDolGlobalInt('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$sql .= ', p.packaging';
}
$sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON fd.fk_product = p.rowid';
$sql .= ' WHERE fd.rowid = '.((int) $rowid);
@@ -277,6 +285,10 @@ class FactureLigne extends CommonInvoiceLine
$this->multicurrency_total_tva = $objp->multicurrency_total_tva;
$this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
if (getDolGlobalInt('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$this->packaging = $objp->packaging;
}
$this->fetch_optionals();
$this->db->free($result);