Product Fourn Price : fix error save extrafields values
This commit is contained in:
parent
d71f117e81
commit
d99adae850
@ -32,6 +32,7 @@
|
|||||||
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
|
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.'/fourn/class/fournisseur.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.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,10 +257,12 @@ class ProductFournisseur extends Product
|
|||||||
* @param string $desc_fourn Custom description for product_fourn_price
|
* @param string $desc_fourn Custom description for product_fourn_price
|
||||||
* @param string $barcode Barcode
|
* @param string $barcode Barcode
|
||||||
* @param int $fk_barcode_type Barcode type
|
* @param int $fk_barcode_type Barcode type
|
||||||
|
* @param array $options Extrafields of product fourn price
|
||||||
* @return int <0 if KO, >=0 if OK
|
* @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
|
// phpcs:enable
|
||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
//global $mysoc;
|
//global $mysoc;
|
||||||
@ -405,6 +408,21 @@ class ProductFournisseur extends Product
|
|||||||
$sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
|
$sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging);
|
||||||
}
|
}
|
||||||
$sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
|
$sql .= " WHERE rowid = ".((int) $this->product_fourn_price_id);
|
||||||
|
|
||||||
|
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
|
// 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);
|
dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG);
|
||||||
@ -490,6 +508,20 @@ class ProductFournisseur extends Product
|
|||||||
$error++;
|
$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)) {
|
if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) {
|
||||||
// Add record into log table
|
// Add record into log table
|
||||||
// $this->product_fourn_price_id must be set
|
// $this->product_fourn_price_id must be set
|
||||||
|
|||||||
@ -286,34 +286,8 @@ if (empty($reshook)) {
|
|||||||
if (GETPOSTISSET('ref_fourn_price_id')) {
|
if (GETPOSTISSET('ref_fourn_price_id')) {
|
||||||
$object->fetch_product_fournisseur_price(GETPOST('ref_fourn_price_id', 'int'));
|
$object->fetch_product_fournisseur_price(GETPOST('ref_fourn_price_id', 'int'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$extralabels = $extrafields->fetch_name_optionals_label("product_fournisseur_price");
|
$extralabels = $extrafields->fetch_name_optionals_label("product_fournisseur_price");
|
||||||
$extrafield_values = $extrafields->getOptionalsFromPost("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 = ".$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 (".$object->product_fourn_price_id.", ";
|
|
||||||
foreach ($extrafield_values as $key => $value) {
|
|
||||||
$sql .= '"'.$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).' = "'.$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"));
|
$newprice = price2num(GETPOST("price", "alpha"));
|
||||||
|
|
||||||
@ -330,9 +304,9 @@ if (empty($reshook)) {
|
|||||||
$multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha'));
|
$multicurrency_price = price2num(GETPOST("multicurrency_price", 'alpha'));
|
||||||
$multicurrency_code = GETPOST("multicurrency_code", '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 {
|
} 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) {
|
if ($ret < 0) {
|
||||||
$error++;
|
$error++;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user