Fix: We need to change the vatrate when changing the price
This commit is contained in:
parent
b99c8621bf
commit
64c4df446a
@ -1903,13 +1903,13 @@ function print_fleche_navigation($page,$file,$options='',$nextpage,$betweenarrow
|
||||
* \param info_bits Miscellanous information on vat
|
||||
* \return string Chaine avec montant formaté (19,6 ou 19,6% ou 8.5% *)
|
||||
*/
|
||||
function vatrate($rate,$foundpercent=false,$info_bits=0)
|
||||
function vatrate($rate,$addpercent=false,$info_bits=0)
|
||||
{
|
||||
// Test for compatibility
|
||||
if (eregi('%',$rate))
|
||||
{
|
||||
$rate=eregi_replace('%','',$rate);
|
||||
$foundpercent=true;
|
||||
$addpercent=true;
|
||||
}
|
||||
if (eregi('\*',$rate) || eregi(MAIN_LABEL_MENTION_NPR,$rate))
|
||||
{
|
||||
@ -1917,7 +1917,7 @@ function vatrate($rate,$foundpercent=false,$info_bits=0)
|
||||
$info_bits |= 1;
|
||||
}
|
||||
|
||||
$ret=price($rate,0,'',0,0).($foundpercent?'%':'');
|
||||
$ret=price($rate,0,'',0,0).($addpercent?'%':'');
|
||||
if ($info_bits & 1) $ret.=' '.MAIN_LABEL_MENTION_NPR;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class Product extends CommonObject
|
||||
|
||||
//! Identifiant unique
|
||||
var $id ;
|
||||
//! R<EFBFBD>f<EFBFBD>rence
|
||||
//! Ref
|
||||
var $ref;
|
||||
var $libelle;
|
||||
var $description;
|
||||
@ -761,40 +761,45 @@ class Product extends CommonObject
|
||||
|
||||
|
||||
/**
|
||||
\brief Modifie le prix d'un produit/service
|
||||
\param id Id du produit/service <EFBFBD> modifier
|
||||
\param newprice Nouveau prix
|
||||
\param newpricebase HT ou TTC
|
||||
\param user Objet utilisateur qui modifie le prix
|
||||
* \brief Modifie le prix d'un produit/service
|
||||
* \param id Id du produit/service a modifier
|
||||
* \param newprice Nouveau prix
|
||||
* \param newpricebase HT ou TTC
|
||||
* \param user Objet utilisateur qui modifie le prix
|
||||
* \param newvat New VAT Rate
|
||||
* \return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function update_price($id, $newprice, $newpricebase, $user)
|
||||
function update_price($id, $newprice, $newpricebase, $user, $newvat='')
|
||||
{
|
||||
//multiprix
|
||||
global $conf,$langs;
|
||||
dolibarr_syslog("Product::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase);
|
||||
|
||||
if ($newvat == '') $newvat=$this->tva_tx;
|
||||
|
||||
if ($newprice)
|
||||
{
|
||||
if ($newpricebase == 'TTC')
|
||||
{
|
||||
$price_ttc = price2num($newprice,'MU');
|
||||
$price = price2num($newprice) / (1 + ($this->tva_tx / 100));
|
||||
$price = price2num($newprice) / (1 + ($newvat / 100));
|
||||
$price = price2num($price,'MU');
|
||||
}
|
||||
else
|
||||
{
|
||||
$price = price2num($newprice,'MU');
|
||||
$price_ttc = price2num($newprice) * (1 + ($this->tva_tx / 100));
|
||||
$price_ttc = price2num($newprice) * (1 + ($newvat / 100));
|
||||
$price_ttc = price2num($price_ttc,'MU');
|
||||
}
|
||||
|
||||
// Ne pas mettre de quote sur le num<75>riques decimaux.
|
||||
// Ceci provoque des sotckage avec arrondis en base au lieu des valeurs exactes.
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
|
||||
$sql .= " SET price=".$price."";
|
||||
$sql .= " , price_base_type='".$newpricebase."'";
|
||||
$sql .= " , price_ttc=".$price_ttc."";
|
||||
$sql .= " WHERE rowid = " . $id;
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product SET";
|
||||
$sql.= " price_base_type='".$newpricebase."',";
|
||||
$sql.= " price=".$price.",";
|
||||
$sql.= " price_ttc=".$price_ttc.",";
|
||||
$sql.= " tva_tx='".price2num($newvat)."'";
|
||||
$sql.= " WHERE rowid = " . $id;
|
||||
|
||||
dolibarr_syslog("Product::update_price sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
@ -803,7 +808,8 @@ class Product extends CommonObject
|
||||
$this->price = $price;
|
||||
$this->price_ttc = $price_ttc;
|
||||
$this->price_base_type = $newpricebase;
|
||||
|
||||
$this->tva_tx = $newvat;
|
||||
|
||||
$this->_log_price($user);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -136,9 +136,6 @@ if ($_POST["action"] == 'update' &&
|
||||
{
|
||||
$product->ref = $_POST["ref"];
|
||||
$product->libelle = $_POST["libelle"];
|
||||
if ( isset( $_POST["price"] ) )
|
||||
$product->price = $_POST["price"];
|
||||
$product->tva_tx = $_POST["tva_tx"];
|
||||
$product->description = $_POST["desc"];
|
||||
$product->note = $_POST["note"];
|
||||
$product->status = $_POST["statut"];
|
||||
@ -572,34 +569,6 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
|
||||
// Label
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>';
|
||||
|
||||
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
|
||||
print '<td><input name="price" size="10" value="'.$product->price.'">';
|
||||
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
|
||||
print '</td></tr>';
|
||||
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
|
||||
print '<td><input name="price_'.$i.'" size="10" value="'.$product->multiprices["$i"].'">';
|
||||
print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
// PRIX
|
||||
else
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("SellingPrice").'</td>';
|
||||
print '<td><input name="price" size="10" value="'.$product->price.'">';
|
||||
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// VAT
|
||||
print '<tr><td>'.$langs->trans("VATRate").'</td><td>';
|
||||
print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,'');
|
||||
print '</td></tr>';
|
||||
|
||||
// Status
|
||||
print '<tr><td>'.$langs->trans("Status").'</td><td>';
|
||||
$statutarray=array('1' => $langs->trans("OnSell"), '0' => $langs->trans("NotOnSell"));
|
||||
@ -672,9 +641,47 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
|
||||
print '</textarea>';
|
||||
}
|
||||
print "</td></tr>";
|
||||
|
||||
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
if($conf->global->PRODUIT_MULTIPRICES == 1)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("SellingPrice").' 1</td>';
|
||||
print '<td><input name="price" size="10" value="'.$product->price.'">';
|
||||
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
|
||||
print '</td></tr>';
|
||||
for($i=2;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
|
||||
print '<td><input name="price_'.$i.'" size="10" value="'.$product->multiprices["$i"].'">';
|
||||
print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
|
||||
print '</td></tr>';
|
||||
}
|
||||
}
|
||||
// PRIX
|
||||
else
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("SellingPrice").'</td>';
|
||||
print '<td><input name="price" size="10" value="'.$product->price.'">';
|
||||
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// VAT
|
||||
print '<tr><td width="20%">'.$langs->trans("VATRate").'</td><td>';
|
||||
print $html->select_tva("tva_tx",$conf->defaulttx,$mysoc,'');
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<table class="border" width="100%">';
|
||||
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
|
||||
print '</table>';
|
||||
|
||||
print '</form>';
|
||||
}
|
||||
else
|
||||
@ -846,14 +853,14 @@ if ($_GET["id"] || $_GET["ref"])
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// TVA
|
||||
print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.vatrate($product->tva_tx,true).'</td></tr>';
|
||||
|
||||
// Statut
|
||||
print '<tr><td>'.$langs->trans("Status").'</td><td>';
|
||||
print $product->getLibStatut(2);
|
||||
print '</td></tr>';
|
||||
|
||||
// TVA
|
||||
print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.price2num($product->tva_tx,'MU').'%</td></tr>';
|
||||
|
||||
// Description
|
||||
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>'.nl2br($product->description).'</td></tr>';
|
||||
|
||||
@ -930,10 +937,6 @@ if ($_GET["id"] || $_GET["ref"])
|
||||
print '<tr><td width="15%">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" size="40" maxlength="32" value="'.$product->ref.'"></td></tr>';
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>';
|
||||
|
||||
print '<tr><td>'.$langs->trans("VATRate").'</td><td colspan="2">';
|
||||
print $html->select_tva("tva_tx", $product->tva_tx, $mysoc, '', $product->tva_tx);
|
||||
print '</td></tr>';
|
||||
|
||||
// Status
|
||||
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
|
||||
print '<select class="flat" name="statut">';
|
||||
|
||||
@ -367,7 +367,7 @@ if ($result)
|
||||
}
|
||||
|
||||
print '<td align="center">'.$langs->trans($objp->price_base_type)."</td>";
|
||||
print '<td align="right">'.vatrate($objp->tva_tx)."</td>";
|
||||
print '<td align="right">'.vatrate($objp->tva_tx,true)."</td>";
|
||||
print '<td align="right">'.price($objp->price)."</td>";
|
||||
print '<td align="right">'.price($objp->price_ttc)."</td>";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user