diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 179385b1aba..4964b9d9929 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -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; diff --git a/htdocs/compta/facture/class/factureligne.class.php b/htdocs/compta/facture/class/factureligne.class.php index e4e2b1a3ae2..c96f07c056b 100644 --- a/htdocs/compta/facture/class/factureligne.class.php +++ b/htdocs/compta/facture/class/factureligne.class.php @@ -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);