Merge branch '14.0' of git@github.com:Dolibarr/dolibarr.git into develop

Conflicts:
	htdocs/product/fournisseurs.php
This commit is contained in:
Laurent Destailleur 2022-06-23 12:26:26 +02:00
commit b2603c9b53
2 changed files with 34 additions and 30 deletions

View File

@ -32,6 +32,7 @@
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/productfournisseurprice.class.php';
/**
@ -256,9 +257,10 @@ class ProductFournisseur extends Product
* @param string $desc_fourn Custom description for product_fourn_price
* @param string $barcode Barcode
* @param int $fk_barcode_type Barcode type
* @param array $options Extrafields of product fourn price
* @return int <0 if KO, >=0 if OK
*/
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 = '')
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;
@ -407,7 +409,21 @@ class ProductFournisseur extends Product
$sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
}
$sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
//print $sql;exit;
if (!$error) {
if (!empty($options) && is_array($options)) {
$productfournisseurprice = new ProductFournisseurPrice($this->db);
$res = $productfournisseurprice->fetch($this->product_fourn_price_id);
if ($res > 0) {
foreach ($options as $key=>$value) {
$productfournisseurprice->array_options[$key] = $value;
}
$res = $productfournisseurprice->update($user);
if ($res < 0) $error++;
}
}
}
// TODO Add price_base_type and price_ttc
dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
@ -493,6 +509,20 @@ class ProductFournisseur extends Product
$error++;
}
if (!$error) {
if (!empty($options) && is_array($options)) {
$productfournisseurprice = new ProductFournisseurPrice($this->db);
$res = $productfournisseurprice->fetch($this->product_fourn_price_id);
if ($res > 0) {
foreach ($options as $key=>$value) {
$productfournisseurprice->array_options[$key] = $value;
}
$res = $productfournisseurprice->update($user);
if ($res < 0) $error++;
}
}
}
if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
// Add record into log table
// $this->product_fourn_price_id must be set

View File

@ -285,34 +285,8 @@ if (empty($reshook)) {
if (GETPOSTISSET('ref_fourn_price_id')) {
$object->fetch_product_fournisseur_price(GETPOST('ref_fourn_price_id', 'int'));
}
$extralabels = $extrafields->fetch_name_optionals_label("product_fournisseur_price");
$extrafield_values = $extrafields->getOptionalsFromPost("product_fournisseur_price");
if (!empty($extrafield_values)) {
$resql = $db->query("SELECT fk_object FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields WHERE fk_object = ".((int) $object->product_fourn_price_id));
// Insert a new extrafields row, if none exists
if ($db->num_rows($resql) != 1) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields (fk_object, ";
foreach ($extrafield_values as $key => $value) {
$sql .= str_replace('options_', '', $key).', ';
}
$sql = substr($sql, 0, strlen($sql) - 2).") VALUES (".((int) $object->product_fourn_price_id).", ";
foreach ($extrafield_values as $key => $value) {
$sql .= "'".$db->escape($value)."', ";
}
$sql = substr($sql, 0, strlen($sql) - 2).')';
} else {
// update the existing one
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields SET ";
foreach ($extrafield_values as $key => $value) {
$sql .= str_replace('options_', '', $key)." = '".$db->escape($value)."', ";
}
$sql = substr($sql, 0, strlen($sql) - 2).' WHERE fk_object = '.((int) $object->product_fourn_price_id);
}
// Execute the sql command from above
$db->query($sql);
}
$newprice = price2num(GETPOST("price", "alpha"));
@ -330,9 +304,9 @@ if (empty($reshook)) {
$multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha'));
$multicurrency_code = GETPOST("multicurrency_code", 'alpha');
$ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, GETPOST("multicurrency_price_base_type"), $multicurrency_tx, $multicurrency_code, $supplier_description, $barcode, $fk_barcode_type);
$ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', $multicurrency_price, GETPOST("multicurrency_price_base_type"), $multicurrency_tx, $multicurrency_code, $supplier_description, $barcode, $fk_barcode_type, $extrafield_values);
} else {
$ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type);
$ret = $object->update_buyprice($quantity, $newprice, $user, GETPOST("price_base_type"), $supplier, GETPOST("oselDispo"), $ref_fourn, $tva_tx, GETPOST("charges"), $remise_percent, 0, $npr, $delivery_time_days, $supplier_reputation, array(), '', 0, 'HT', 1, '', $supplier_description, $barcode, $fk_barcode_type, $extrafield_values);
}
if ($ret < 0) {
$error++;