Skip to content

Commit

Permalink
Fix: Multiprices were not update by mass vat update tool
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Jun 13, 2013
1 parent d3a500d commit 5f60a7c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
42 changes: 38 additions & 4 deletions htdocs/product/admin/product_tools.php
Expand Up @@ -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<br>\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<br>\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++;
Expand Down
6 changes: 4 additions & 2 deletions htdocs/product/class/product.class.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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."'";
Expand All @@ -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"];
Expand Down

0 comments on commit 5f60a7c

Please sign in to comment.