Fix: default vat

This commit is contained in:
Laurent Destailleur 2010-08-10 01:19:22 +00:00
parent f73b98546d
commit 5b8237ecf2
2 changed files with 25 additions and 17 deletions

View File

@ -272,23 +272,28 @@ class ProductFournisseur extends Product
$sql.= " AND quantity = ".$qty;
}
if ($this->db->query($sql))
$resql=$this->db->query($sql);
if ($resql)
{
if ($price_base_type == 'TTC')
{
$ttx = get_default_tva($fourn,$mysoc,($this->tva_tx?$this->tva_tx:0));
$ttx = get_default_tva($fourn,$mysoc,$this->id);
$buyprice = $buyprice/(1+($ttx/100));
}
$unitBuyPrice = price2num($buyprice/$qty,'MU');
$now=dol_now();
// Ajoute prix courant du fournisseur pour cette quantite
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " SET datec = ".$this->db->idate(mktime());
$sql.= " ,fk_product_fournisseur = ".$this->product_fourn_id;
$sql.= " ,fk_user = ".$user->id;
$sql.= " ,price = ".price2num($buyprice);
$sql.= " ,quantity = ".$qty;
$sql.= " ,unitprice = ".$unitBuyPrice;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
$sql.= "datec, fk_product_fournisseur, fk_user, price, quantity, unitprice)";
$sql.= " values('".$this->db->idate($now)."',";
$sql.= " ".$this->product_fourn_id.",";
$sql.= " ".$user->id.",";
$sql.= " ".price2num($buyprice).",";
$sql.= " ".$qty.",";
$sql.= " ".$unitBuyPrice;
$sql.=")";
dol_syslog("ProductFournisseur::update_buyprice sql=".$sql);
if (! $this->db->query($sql))
@ -299,14 +304,17 @@ class ProductFournisseur extends Product
if (! $error)
{
// Ajoute modif dans table log
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log ";
$sql .= " SET datec = ".$this->db->idate(mktime());
$sql .= " ,fk_product_fournisseur = ".$this->product_fourn_id;
$sql .= " ,fk_user = ".$user->id;
$sql .= " ,price = ".price2num($buyprice);
$sql .= " ,quantity = ".$qty;
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log(";
$sql.= "datec, fk_product_fournisseur,fk_user,price,quantity)";
$sql.= "values('".$this->db->idate($now)."',";
$sql.= " ".$this->product_fourn_id.",";
$sql.= " ".$user->id.",";
$sql.= " ".price2num($buyprice).",";
$sql.= " ".$qty;
$sql.=")";
if (! $this->db->query($sql))
$resql=$this->db->query($sql);
if (! $resql)
{
$error++;
}

View File

@ -295,7 +295,7 @@ if ($_GET["id"] || $_GET["ref"])
print '<td><input class="flat" name="price" size="8" value="'.($_POST["price"]?$_POST["price"]:price($product->fourn_price)).'">';
print '&nbsp;';
print $html->select_PriceBaseType(($_POST["price_base_type"]?$_POST["price_base_type"]:$product->price_base_type), "price_base_type");
print '</td>';
print '</td>';
print '</tr>';
print '<tr><td colspan="4" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">';