diff --git a/htdocs/product/admin/product_tools.php b/htdocs/product/admin/product_tools.php
index 5cb378241dc..6e7e0513576 100644
--- a/htdocs/product/admin/product_tools.php
+++ b/htdocs/product/admin/product_tools.php
@@ -82,32 +82,11 @@ if ($action == 'convert')
$ret=$objectstatic->fetch($obj->rowid);
if ($ret > 0)
{
- $price_base_type = $objectstatic->price_base_type; // Get price_base_type of product/service to keep the same for update
- if ($price_base_type == 'TTC')
- {
- $newprice=price2num($objectstatic->price_ttc,'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->price_min_ttc;
- }
- else
- {
- $newprice=price2num($objectstatic->price,'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->price_min;
- }
- if ($newminprice > $newprice) $newminprice=$newprice;
- $newvat=str_replace('*','',$newvatrate);
- $newnpr=$objectstatic->recuperableonly;
- $newlevel=0;
+ $ret=0; $retm=0; $updatelevel1=false;
- $ret=0; $retm=0;
-
- // 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)
+ $listofmulti=array_reverse($objectstatic->multiprices, true); // To finish with level 1
+ foreach ($listofmulti 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
@@ -127,15 +106,39 @@ if ($action == 'convert')
$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);
+ //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n";
+ $retm=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr);
if ($retm < 0)
{
$error++;
break;
}
+
+ if ($newlevel == 1) $updatelevel1=true;
}
+ // Update single price
+ $price_base_type = $objectstatic->price_base_type; // Get price_base_type of product/service to keep the same for update
+ if ($price_base_type == 'TTC')
+ {
+ $newprice=price2num($objectstatic->price_ttc,'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->price_min_ttc;
+ }
+ else
+ {
+ $newprice=price2num($objectstatic->price,'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->price_min;
+ }
+ if ($newminprice > $newprice) $newminprice=$newprice;
+ $newvat=str_replace('*','',$newvatrate);
+ $newnpr=$objectstatic->recuperableonly;
+ $newlevel=0;
+ if (! empty($price_base_type) && ! $updatelevel1)
+ {
+ //print "$objectstatic->id $newprice, $price_base_type, $newvat, $newminprice, $newlevel, $newnpr
\n";
+ $ret=$objectstatic->updatePrice($newprice, $price_base_type, $user, $newvat, $newminprice, $newlevel, $newnpr);
+ }
+
if ($ret < 0 || $retm < 0) $error++;
else $nbrecordsmodified++;
}