diff --git a/htdocs/product/admin/product_tools.php b/htdocs/product/admin/product_tools.php index 3c17429e9c98c..5cb378241dcdf 100644 --- a/htdocs/product/admin/product_tools.php +++ b/htdocs/product/admin/product_tools.php @@ -98,12 +98,46 @@ $newnpr=$objectstatic->recuperableonly; $newlevel=0; - $ret=$objectstatic->updatePrice($objectstatic->id, $newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); - if ($ret < 0) $error++; - else $nbrecordsmodified++; + $ret=0; $retm=0; - // FIXME Now update all price levels. Call $objectstatic->updatePrice( as many times than exisitng price_level + // Update single price + if (! empty($price_base_type)) + { + print "$newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; + $ret=$objectstatic->updatePrice($objectstatic->id, $newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); + } + // Update multiprice + foreach ($objectstatic->multiprices as $level => $multiprices) + { + $price_base_type = $objectstatic->multiprices_base_type[$level]; // Get price_base_type of product/service to keep the same for update + if (empty($price_base_type)) continue; // Discard not defined price levels + + if ($price_base_type == 'TTC') + { + $newprice=price2num($objectstatic->multiprices_ttc[$level],'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) + $newminprice=$objectstatic->multiprices_min_ttc[$level]; + } + else + { + $newprice=price2num($objectstatic->multiprices[$level],'MU'); // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals) + $newminprice=$objectstatic->multiprices_min[$level]; + } + if ($newminprice > $newprice) $newminprice=$newprice; + $newvat=str_replace('*','',$newvatrate); + $newnpr=$objectstatic->multiprices_recuperableonly[$level]; + $newlevel=$level; + + print "$newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n"; + $retm=$objectstatic->updatePrice($objectstatic->id, $newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr); + if ($retm < 0) + { + $error++; + break; + } + } + if ($ret < 0 || $retm < 0) $error++; + else $nbrecordsmodified++; } $i++; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f009b0df269b7..7973ab0db5758 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -61,6 +61,7 @@ class Product extends CommonObject var $multiprices_ttc=array(); var $multiprices_base_type=array(); var $multiprices_tva_tx=array(); + var $multiprices_recuperableonly=array(); //! Price by quantity arrays var $price_by_qty; var $prices_by_qty=array(); @@ -1203,7 +1204,7 @@ function fetch($id='',$ref='',$ref_ext='') for ($i=1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) { $sql = "SELECT price, price_ttc, price_min, price_min_ttc,"; - $sql.= " price_base_type, tva_tx, tosell, price_by_qty, rowid"; + $sql.= " price_base_type, tva_tx, tosell, price_by_qty, rowid, recuperableonly"; $sql.= " FROM ".MAIN_DB_PREFIX."product_price"; $sql.= " WHERE price_level=".$i; $sql.= " AND fk_product = '".$this->id."'"; @@ -1219,7 +1220,8 @@ function fetch($id='',$ref='',$ref_ext='') $this->multiprices_min[$i]=$result["price_min"]; $this->multiprices_min_ttc[$i]=$result["price_min_ttc"]; $this->multiprices_base_type[$i]=$result["price_base_type"]; - $this->multiprices_tva_tx[$i]=$result["tva_tx"]; + $this->multiprices_tva_tx[$i]=$result["tva_tx"]; + $this->multiprices_recuperableonly[$i]=$result["recuperableonly"]; // Price by quantity $this->prices_by_qty[$i]=$result["price_by_qty"];