Skip to content

Commit

Permalink
Merge branch 'develop' of [email protected]:Dolibarr/dolibarr.git into d…
Browse files Browse the repository at this point in the history
…evelop
  • Loading branch information
eldy committed Jan 29, 2025
2 parents 1c7a3a0 + 1af487b commit 2483c4e
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 2 deletions.
26 changes: 26 additions & 0 deletions htdocs/comm/propal/class/propal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,20 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txloca

$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)) {

Check warning on line 718 in htdocs/comm/propal/class/propal.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

propal.class.php: PhanTypeMismatchArgumentNullableInternal: Argument 2 ($num2) is $product-&gt;packaging of type ?float but \fmod() takes float (expected type to be non-nullable)
$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 = '';
Expand Down Expand Up @@ -974,6 +988,18 @@ public function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocalt
$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;
Expand Down
11 changes: 11 additions & 0 deletions htdocs/comm/propal/class/propaleligne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ class PropaleLigne extends CommonObjectLine
*/
public $multicurrency_total_ttc;

/**
* @var float
*/
public $packaging;

/**
* Class line Constructor
Expand Down Expand Up @@ -370,6 +374,9 @@ public function fetch($rowid)
$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);
Expand Down Expand Up @@ -418,6 +425,10 @@ public function fetch($rowid)
$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);

Expand Down
30 changes: 30 additions & 0 deletions htdocs/commande/class/commande.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,20 @@ public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocalt

$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)) {

Check warning on line 1643 in htdocs/commande/class/commande.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

commande.class.php: PhanTypeMismatchArgumentNullableInternal: Argument 2 ($num2) is $product-&gt;packaging of type ?float but \fmod() takes float (expected type to be non-nullable)
$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 = '';
Expand Down Expand Up @@ -2192,6 +2206,10 @@ public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
$line->volume = $objp->volume;
$line->volume_units = $objp->volume_units;

if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$line->packaging = $objp->packaging;
}

$line->date_start = $this->db->jdate($objp->date_start);
$line->date_end = $this->db->jdate($objp->date_end);

Expand Down Expand Up @@ -3163,6 +3181,18 @@ public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $t
$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) && fmod($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;
Expand Down
11 changes: 11 additions & 0 deletions htdocs/commande/class/orderline.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class OrderLine extends CommonOrderLine
*/
public $skip_update_total;

/**
* @var float
*/
public $packaging;

/**
* Constructor
Expand All @@ -171,6 +175,9 @@ public function fetch($rowid)
$sql .= ' cd.fk_multicurrency, cd.multicurrency_code, cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc, p.tobatch as product_tobatch,';
$sql .= ' cd.date_start, cd.date_end, cd.vat_src_code';
if (getDolGlobalInt('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$sql .= ', p.packaging';
}
$sql .= ' FROM '.MAIN_DB_PREFIX.'commandedet as cd';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
$sql .= ' WHERE cd.rowid = '.((int) $rowid);
Expand Down Expand Up @@ -225,6 +232,10 @@ public function fetch($rowid)
$this->product_tobatch = $objp->product_tobatch;
$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);

Expand Down
26 changes: 26 additions & 0 deletions htdocs/compta/facture/class/facture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3999,6 +3999,20 @@ public function addline(

$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)) {

Check warning on line 4008 in htdocs/compta/facture/class/facture.class.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

facture.class.php: PhanTypeMismatchArgumentNullableInternal: Argument 2 ($num2) is $product-&gt;packaging of type ?float but \fmod() takes float (expected type to be non-nullable)
$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 = '';
Expand Down Expand Up @@ -4303,6 +4317,18 @@ public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_star
$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) && fmod($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;
Expand Down
12 changes: 12 additions & 0 deletions htdocs/compta/facture/class/factureligne.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ class FactureLigne extends CommonInvoiceLine
*/
public $fk_prev_id;

/**
* @var float
*/
public $packaging;


/**
* Constructor
Expand Down Expand Up @@ -211,6 +216,9 @@ public function fetch($rowid)
$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);
Expand Down Expand Up @@ -277,6 +285,10 @@ public function fetch($rowid)
$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);
Expand Down
13 changes: 13 additions & 0 deletions htdocs/core/modules/modProduct.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,12 @@ public function __construct($db)
));
}

if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array(
'p.packaging' => 'PackagingForThisProductSell',
));
}

if (isModEnabled("supplier_order") || isModEnabled("supplier_invoice") || isModEnabled('margin')) {
$this->import_fields_array[$r] = array_merge($this->import_fields_array[$r], array('p.cost_price' => 'CostPrice'));
}
Expand Down Expand Up @@ -755,6 +761,13 @@ public function __construct($db)
)
));
}

if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$import_sample = array_merge($import_sample, array(
'p.packaging' => "2",
));
}

$this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
$this->import_updatekeys_array[$r] = array('p.ref' => 'Ref');
if (isModEnabled('barcode')) {
Expand Down
3 changes: 3 additions & 0 deletions htdocs/langs/en_US/products.lang
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ ProductSupplierDescription=Vendor description for the product
UseProductSupplierPackaging=Use the "packaging" feature to round the quantities to some given multiples (when adding/updating line in a vendor documents, recalculate quantities and purchase prices according to the higher multiple set on the purchase prices of a product)
PackagingForThisProduct=Packaging of quantities
PackagingForThisProductDesc=You will automatically purchase a multiple of this quantity.
UseProductCustomerPackaging=Use the "packaging" feature to round the quantities to some given multiples (when adding/updating line in a customer documents, recalculate quantities and sale prices according to the higher multiple set on the sale prices of a product)
PackagingForThisProductSell=Packaging of quantities (sale)
PackagingForThisProductSellDesc=You will automatically sell a multiple of this quantity.
QtyRecalculatedWithPackaging=The quantity of the line were recalculated according to supplier packaging

#Attributes
Expand Down
3 changes: 3 additions & 0 deletions htdocs/langs/fr_FR/products.lang
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ ProductSupplierDescription=Description du fournisseur du produit
UseProductSupplierPackaging=Utilisez la fonction "conditionnement" pour arrondir les quantités à certains multiples donnés (lors de l'ajout/de la mise à jour d'une ligne, dans les documents d'un fournisseur, recalculez les quantités et les prix d'achat en fonction du multiple supérieur défini sur les prix d'achat d'un produit)
PackagingForThisProduct=Conditionnement des quantités
PackagingForThisProductDesc=Vous achèterez automatiquement un multiple de cette quantité.
UseProductCustomerPackaging=Utilisez la fonction "conditionnement" pour arrondir les quantités à certains multiples donnés (lors de l'ajout/de la mise à jour d'une ligne, dans les documents d'un client, recalculez les quantités et les prix de vente en fonction du multiple supérieur défini sur les prix de vente d'un produit)
PackagingForThisProductSell=Conditionnement des quantités (vente)
PackagingForThisProductSellDesc=Vous vendrez automatiquement un multiple de cette quantité.
QtyRecalculatedWithPackaging=La quantité de la ligne a été recalculée en fonction de l'emballage du fournisseur

#Attributes
Expand Down
16 changes: 16 additions & 0 deletions htdocs/product/admin/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
$value = GETPOST('PRODUCT_USE_SUPPLIER_PACKAGING', 'alpha');
$res = dolibarr_set_const($db, "PRODUCT_USE_SUPPLIER_PACKAGING", $value, 'chaine', 0, '', $conf->entity);
}

if (GETPOSTISSET('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$value = GETPOST('PRODUCT_USE_CUSTOMER_PACKAGING', 'alpha');
$res = dolibarr_set_const($db, "PRODUCT_USE_CUSTOMER_PACKAGING", $value, 'chaine', 0, '', $conf->entity);
}
}


Expand Down Expand Up @@ -642,6 +647,17 @@
print '</tr>';
}

// Use packaging during your sales
if (isModEnabled("order") || isModEnabled("invoice")) {
print '<tr class="oddeven">';
print '<td>'.$form->textwithpicto($langs->trans("UseProductCustomerPackaging"), $langs->trans("PackagingForThisProductSellDesc")).'</td>';
print '<td align="right">';
print ajax_constantonoff("PRODUCT_USE_CUSTOMER_PACKAGING", array(), $conf->entity, 0, 0, 0, 0);
//print $form->selectyesno("activate_useProdSupplierPackaging", (!empty($conf->global->PRODUCT_USE_CUSTOMER_PACKAGING) ? $conf->global->PRODUCT_USE_CUSTOMER_PACKAGING : 0), 1);
print '</td>';
print '</tr>';
}

print '</table>';
print '</div>';

Expand Down
11 changes: 10 additions & 1 deletion htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,6 @@ public function update($id, $user, $notrigger = 0, $action = 'update', $updatety
$this->accountancy_code_sell_intra = trim($this->accountancy_code_sell_intra);
$this->accountancy_code_sell_export = trim($this->accountancy_code_sell_export);


$this->db->begin();

$result = 0;
Expand Down Expand Up @@ -1597,6 +1596,9 @@ public function update($id, $user, $notrigger = 0, $action = 'update', $updatety
$sql .= ", fk_price_expression = ".($this->fk_price_expression != 0 ? (int) $this->fk_price_expression : 'NULL');
$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : 'NULL');
$sql .= ", mandatory_period = ".($this->mandatory_period);
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING') && !empty($this->packaging)) {
$sql .= ", packaging = " . (float) $this->packaging;
}
// stock field is not here because it is a denormalized value from product_stock.
$sql .= " WHERE rowid = ".((int) $id);

Expand Down Expand Up @@ -2897,6 +2899,9 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_
} else {
$sql .= " ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export, ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export,";
}
if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$sql .= " p.packaging,";
}

// For MultiCompany
// PMP per entity & Stocks Sharings stock_reel includes only stocks shared with this entity
Expand Down Expand Up @@ -3076,6 +3081,10 @@ public function fetch($id = 0, $ref = '', $ref_ext = '', $barcode = '', $ignore_

$this->mandatory_period = $obj->mandatory_period;

if (getDolGlobalString('PRODUCT_USE_CUSTOMER_PACKAGING')) {
$this->packaging = $obj->packaging;
}

$this->db->free($resql);

// fetch optionals attributes and labels
Expand Down
Loading

0 comments on commit 2483c4e

Please sign in to comment.