mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-01-06 17:13:03 +01:00
Merge branch '14.0' of https://github.com/Dolibarr/dolibarr into 14.0_FIX_productfournprice_saveextrafieldsvalues
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
* \brief File of class to manage suppliers orders
|
||||
*/
|
||||
|
||||
include_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
||||
if (!empty($conf->productbatch->enabled)) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php';
|
||||
@@ -431,6 +431,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
* Lines
|
||||
*/
|
||||
$result = $this->fetch_lines();
|
||||
|
||||
if ($result < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
@@ -453,7 +454,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
{
|
||||
global $conf;
|
||||
// phpcs:enable
|
||||
//$result=$this->fetch_lines();
|
||||
|
||||
$this->lines = array();
|
||||
|
||||
$sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
|
||||
@@ -464,22 +465,12 @@ class CommandeFournisseur extends CommonOrder
|
||||
$sql .= " l.fk_unit,";
|
||||
$sql .= " l.date_start, l.date_end,";
|
||||
$sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql .= ", pfp.rowid as fk_pfp, pfp.packaging, MAX(pfp.quantity) as max_qty";
|
||||
}
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid';
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.entity IN (".getEntity('product_fournisseur_price').") AND l.fk_product = pfp.fk_product and l.ref = pfp.ref_fourn AND l.qty >= pfp.quantity AND pfp.fk_soc = ".((int) $this->socid);
|
||||
}
|
||||
$sql .= " WHERE l.fk_commande = ".$this->id;
|
||||
$sql .= " WHERE l.fk_commande = ".((int) $this->id);
|
||||
if ($only_product) {
|
||||
$sql .= ' AND p.fk_product_type = 0';
|
||||
}
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql.= " GROUP BY l.rowid";
|
||||
$sql.= " HAVING (max_qty = MAX(pfp.quantity) OR max_qty IS NULL)";
|
||||
}
|
||||
$sql .= " ORDER BY l.rang, l.rowid";
|
||||
//print $sql;
|
||||
|
||||
@@ -527,11 +518,34 @@ class CommandeFournisseur extends CommonOrder
|
||||
$line->ref_supplier = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since
|
||||
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$line->fk_fournprice = $objp->fk_pfp;
|
||||
$line->packaging = $objp->packaging;
|
||||
// TODO We should not fetch this properties into the fetch_lines. This is NOT properties of a line.
|
||||
// Move this into another method and call it when required.
|
||||
|
||||
// Take better packaging for $objp->qty (first supplier ref quantity <= $objp->qty)
|
||||
$sqlsearchpackage = 'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sqlsearchpackage .= ' WHERE entity IN ('.getEntity('product_fournisseur_price').")";
|
||||
$sqlsearchpackage .= " AND fk_product = ".((int) $objp->fk_product);
|
||||
$sqlsearchpackage .= " AND ref_fourn = '".$this->db->escape($objp->ref_supplier)."'";
|
||||
$sqlsearchpackage .= " AND quantity <= ".((float) $objp->qty); // required to be qualified
|
||||
$sqlsearchpackage .= " AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).")"; // required to be qualified
|
||||
$sqlsearchpackage .= " AND fk_soc = ".((int) $this->socid);
|
||||
$sqlsearchpackage .= " ORDER BY packaging ASC"; // Take the smaller package first
|
||||
$sqlsearchpackage .= " LIMIT 1";
|
||||
|
||||
$resqlsearchpackage = $this->db->query($sqlsearchpackage);
|
||||
if ($resqlsearchpackage) {
|
||||
$objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
|
||||
if ($objsearchpackage) {
|
||||
$line->fk_fournprice = $objsearchpackage->rowid;
|
||||
$line->packaging = $objsearchpackage->packaging;
|
||||
}
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
$line->date_start = $this->db->jdate($objp->date_start);
|
||||
$line->date_start = $this->db->jdate($objp->date_start);
|
||||
$line->date_end = $this->db->jdate($objp->date_end);
|
||||
$line->fk_unit = $objp->fk_unit;
|
||||
|
||||
@@ -1807,6 +1821,7 @@ class CommandeFournisseur extends CommonOrder
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
$prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
|
||||
|
||||
if ($qty < $prod->packaging) {
|
||||
$qty = $prod->packaging;
|
||||
} else {
|
||||
@@ -3515,25 +3530,18 @@ class CommandeFournisseurLigne extends CommonOrderLine
|
||||
global $conf;
|
||||
|
||||
$sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
|
||||
$sql .= ' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref,';
|
||||
$sql .= ' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
|
||||
$sql .= ' cd.remise, cd.remise_percent, cd.subprice,';
|
||||
$sql .= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
|
||||
$sql .= ' cd.total_localtax1, cd.total_localtax2,';
|
||||
$sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
|
||||
$sql .= ' cd.date_start, cd.date_end, cd.fk_unit,';
|
||||
$sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc';
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql .= ", pfp.rowid as fk_pfp, pfp.packaging, MAX(pfp.quantity) as max_qty";
|
||||
}
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
|
||||
$sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
|
||||
$sql .= ' c.fk_soc as socid';
|
||||
$sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseur as c, '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
|
||||
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid';
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.entity IN (".getEntity('product_fournisseur_price').") AND cd.fk_product = pfp.fk_product and cd.ref = pfp.ref_fourn AND cd.qty >= pfp.quantity";
|
||||
}
|
||||
$sql .= ' WHERE cd.rowid = '.((int) $rowid);
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql .= " GROUP BY cd.rowid HAVING (max_qty = MAX(pfp.quantity) OR max_qty IS NULL)";
|
||||
}
|
||||
$sql .= ' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
@@ -3544,8 +3552,8 @@ class CommandeFournisseurLigne extends CommonOrderLine
|
||||
$this->fk_commande = $objp->fk_commande;
|
||||
$this->desc = $objp->description;
|
||||
$this->qty = $objp->qty;
|
||||
$this->ref_fourn = $objp->ref;
|
||||
$this->ref_supplier = $objp->ref;
|
||||
$this->ref_fourn = $objp->ref_supplier;
|
||||
$this->ref_supplier = $objp->ref_supplier;
|
||||
$this->subprice = $objp->subprice;
|
||||
$this->tva_tx = $objp->tva_tx;
|
||||
$this->localtax1_tx = $objp->localtax1_tx;
|
||||
@@ -3569,9 +3577,33 @@ class CommandeFournisseurLigne extends CommonOrderLine
|
||||
$this->product_ref = $objp->product_ref;
|
||||
$this->product_label = $objp->product_label;
|
||||
$this->product_desc = $objp->product_desc;
|
||||
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$this->packaging = $objp->packaging;
|
||||
$this->fk_fournprice = $objp->fk_pfp;
|
||||
// TODO We should not fetch this properties into the fetch_lines. This is NOT properties of a line.
|
||||
// Move this into another method and call it when required.
|
||||
|
||||
// Take better packaging for $objp->qty (first supplier ref quantity <= $objp->qty)
|
||||
$sqlsearchpackage = 'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sqlsearchpackage .= ' WHERE entity IN ('.getEntity('product_fournisseur_price').")";
|
||||
$sqlsearchpackage .= " AND fk_product = ".((int) $objp->fk_product);
|
||||
$sqlsearchpackage .= " AND ref_fourn = '".$this->db->escape($objp->ref_supplier)."'";
|
||||
$sqlsearchpackage .= " AND quantity <= ".((float) $objp->qty); // required to be qualified
|
||||
$sqlsearchpackage .= " AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).")"; // required to be qualified
|
||||
$sqlsearchpackage .= " AND fk_soc = ".((int) $objp->socid);
|
||||
$sqlsearchpackage .= " ORDER BY packaging ASC"; // Take the smaller package first
|
||||
$sqlsearchpackage .= " LIMIT 1";
|
||||
|
||||
$resqlsearchpackage = $this->db->query($sqlsearchpackage);
|
||||
if ($resqlsearchpackage) {
|
||||
$objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
|
||||
if ($objsearchpackage) {
|
||||
$this->fk_fournprice = $objsearchpackage->rowid;
|
||||
$this->packaging = $objsearchpackage->packaging;
|
||||
}
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
$this->date_start = $this->db->jdate($objp->date_start);
|
||||
|
||||
@@ -262,7 +262,6 @@ class ProductFournisseur extends Product
|
||||
*/
|
||||
public function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges = 0, $remise_percent = 0, $remise = 0, $newnpr = 0, $delivery_time_days = 0, $supplier_reputation = '', $localtaxes_array = array(), $newdefaultvatcode = '', $multicurrency_buyprice = 0, $multicurrency_price_base_type = 'HT', $multicurrency_tx = 1, $multicurrency_code = '', $desc_fourn = '', $barcode = '', $fk_barcode_type = '', $options = array())
|
||||
{
|
||||
|
||||
// phpcs:enable
|
||||
global $conf, $langs;
|
||||
//global $mysoc;
|
||||
@@ -320,7 +319,9 @@ class ProductFournisseur extends Product
|
||||
$qty = price2num($qty, 'MS');
|
||||
$unitBuyPrice = price2num($buyprice / $qty, 'MU');
|
||||
|
||||
$packaging = price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging), 'MS');
|
||||
// We can have a puchase ref that need to buy 100 min for a given price and with a packaging of 50.
|
||||
//$packaging = price2num(((empty($this->packaging) || $this->packaging < $qty) ? $qty : $this->packaging), 'MS');
|
||||
$packaging = price2num((empty($this->packaging) ? $qty : $this->packaging), 'MS');
|
||||
|
||||
$error = 0;
|
||||
$now = dol_now();
|
||||
@@ -625,13 +626,7 @@ class ProductFournisseur extends Product
|
||||
$this->supplier_barcode = $obj->barcode;
|
||||
$this->supplier_fk_barcode_type = $obj->fk_barcode_type;
|
||||
}
|
||||
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$this->packaging = $obj->packaging;
|
||||
if ($this->packaging < $this->fourn_qty) {
|
||||
$this->packaging = $this->fourn_qty;
|
||||
}
|
||||
}
|
||||
$this->packaging = $obj->packaging;
|
||||
|
||||
if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) {
|
||||
$priceparser = new PriceParser($this->db);
|
||||
@@ -679,10 +674,7 @@ class ProductFournisseur extends Product
|
||||
$sql .= " pfp.rowid as product_fourn_pri_id, pfp.entity, pfp.ref_fourn, pfp.desc_fourn, pfp.fk_product as product_fourn_id, pfp.fk_supplier_price_expression,";
|
||||
$sql .= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation,";
|
||||
$sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,";
|
||||
$sql .= " pfp.barcode, pfp.fk_barcode_type";
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$sql .= ", pfp.packaging";
|
||||
}
|
||||
$sql .= " pfp.barcode, pfp.fk_barcode_type, pfp.packaging";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")";
|
||||
$sql .= " AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid";
|
||||
@@ -736,12 +728,7 @@ class ProductFournisseur extends Product
|
||||
$prodfourn->fourn_multicurrency_id = $record["fk_multicurrency"];
|
||||
$prodfourn->fourn_multicurrency_code = $record["multicurrency_code"];
|
||||
|
||||
if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
|
||||
$prodfourn->packaging = $record["packaging"];
|
||||
if ($prodfourn->packaging < $prodfourn->fourn_qty) {
|
||||
$prodfourn->packaging = $prodfourn->fourn_qty;
|
||||
}
|
||||
}
|
||||
$prodfourn->packaging = $record["packaging"];
|
||||
|
||||
if (!empty($conf->barcode->enabled)) {
|
||||
$prodfourn->supplier_barcode = $record["barcode"];
|
||||
|
||||
Reference in New Issue
Block a user