ADD: packaging to round the quantities to some given multiples for the commercials proposals

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

View file

@ -709,6 +709,20 @@ class Propal extends CommonObject
$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 = '';
@ -974,6 +988,18 @@ class Propal extends CommonObject
$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->label = $label;
$this->line->desc = $desc;

View file

@ -343,6 +343,10 @@ class PropaleLigne extends CommonObjectLine
*/
public $multicurrency_total_ttc;
/**
* @var float
*/
public $packaging;
/**
* Class line Constructor
@ -370,6 +374,9 @@ class PropaleLigne extends CommonObjectLine
$sql .= ' pd.fk_multicurrency, pd.multicurrency_code, pd.multicurrency_subprice, pd.multicurrency_total_ht, pd.multicurrency_total_tva, pd.multicurrency_total_ttc,';
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
$sql .= ' pd.date_start, pd.date_end, pd.product_type';
if (getDolGlobalInt('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$sql .= ', p.packaging';
}
$sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pd';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pd.fk_product = p.rowid';
$sql .= ' WHERE pd.rowid = '.((int) $rowid);
@ -418,6 +425,10 @@ class PropaleLigne extends CommonObjectLine
$this->product_desc = $objp->product_desc;
$this->fk_unit = $objp->fk_unit;
if (getDolGlobalInt('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$this->packaging = $objp->packaging;
}
$this->date_start = $this->db->jdate($objp->date_start);
$this->date_end = $this->db->jdate($objp->date_end);