From 9921eb8496b80941fddcacb25f12e4a7d178195d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Apr 2015 19:41:19 +0200 Subject: [PATCH] Fix error when upgating price --- htdocs/product/admin/product.php | 4 ++++ htdocs/product/class/product.class.php | 11 +++++++---- htdocs/product/price.php | 20 ++++++++++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/htdocs/product/admin/product.php b/htdocs/product/admin/product.php index 2d0c1cca468..c3de8edd468 100644 --- a/htdocs/product/admin/product.php +++ b/htdocs/product/admin/product.php @@ -54,6 +54,10 @@ if ($conf->global->MAIN_FEATURES_LEVEL >= 2) $select_pricing_rules['PRODUIT_CUSTOMER_PRICES_BY_QTY&PRODUIT_MULTIPRICES'] = $langs->trans('MultiPricesAbility') . '+' . $langs->trans('PriceByQuantity'); } +// Clean param +if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5; + + /* * Actions diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 16b5a4b1e4e..397f06ce156 100755 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1146,6 +1146,9 @@ class Product extends CommonObject $now=dol_now(); + // Clean parameters + if (empty($this->price_by_qty)) $this->price_by_qty=0; + // Add new price $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price(price_level,date_price,fk_product,fk_user_author,price,price_ttc,price_base_type,tosell,tva_tx,recuperableonly,"; $sql.= " localtax1_tx, localtax2_tx, price_min,price_min_ttc,price_by_qty,entity,fk_price_expression) "; @@ -1153,7 +1156,7 @@ class Product extends CommonObject $sql.= " ".$this->localtax1_tx.",".$this->localtax2_tx.",".$this->price_min.",".$this->price_min_ttc.",".$this->price_by_qty.",".$conf->entity.",".($this->fk_price_expression > 0?$this->fk_price_expression:'null'); $sql.= ")"; - dol_syslog(get_class($this)."_log_price", LOG_DEBUG); + dol_syslog(get_class($this)."::_log_price", LOG_DEBUG); $resql=$this->db->query($sql); if(! $resql) { @@ -1180,7 +1183,7 @@ class Product extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price"; $sql.= " WHERE rowid=".$rowid; - dol_syslog(get_class($this)."log_price_delete", LOG_DEBUG); + dol_syslog(get_class($this)."::log_price_delete", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -1315,7 +1318,7 @@ class Product extends CommonObject $id=$this->id; - dol_syslog(get_class($this)."update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr); + dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr); // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; @@ -1393,7 +1396,7 @@ class Product extends CommonObject $sql.= " recuperableonly='".$newnpr."'"; $sql.= " WHERE rowid = ".$id; - dol_syslog(get_class($this)."update_price", LOG_DEBUG); + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/product/price.php b/htdocs/product/price.php index da61ccc45b8..3e7ba24d3dd 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -51,12 +51,14 @@ $eid = GETPOST('eid', 'int'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); -if ($user->societe_id) - $socid = $user->societe_id; +if ($user->societe_id) $socid = $user->societe_id; $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); $object = new Product($db); +// Clean param +if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5; + $error=0; @@ -119,7 +121,8 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit- $newprice = $newprice_min; //Set price same as min, the user will not see the } - if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) { + if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) + { if ($object->fk_price_expression != 0) { //Check the expression validity by parsing it $priceparser = new PriceParser($db); @@ -130,7 +133,8 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit- setEventMessage($priceparser->translatedError(), 'errors'); } } - if (empty($error) && ! empty($conf->dynamicprices->enabled)) { + if (empty($error) && ! empty($conf->dynamicprices->enabled)) + { $ret=$object->setPriceExpression($object->fk_price_expression); if ($ret < 0) { @@ -139,7 +143,8 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit- setEventMessage($object->error, 'errors'); } } - if (empty($error)) { + if (empty($error)) + { $action = ''; setEventMessage($langs->trans("RecordSaved")); } @@ -147,7 +152,10 @@ if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit- $action = 'edit_price'; setEventMessage($object->error, 'errors'); } -} else if ($action == 'delete' && $user->rights->produit->supprimer) { +} + +if ($action == 'delete' && $user->rights->produit->supprimer) +{ $result = $object->log_price_delete($user, $_GET ["lineid"]); if ($result < 0) { setEventMessage($object->error, 'errors');