Fix: Restore compatibility. Try to isolate "charges" feature with

a condition (i did not understand what it means and goal, i'm afraid
other users should not understand too).
This commit is contained in:
Laurent Destailleur 2012-07-25 11:32:48 +02:00
parent 758d613908
commit de621f0567
2 changed files with 77 additions and 61 deletions

View File

@ -137,75 +137,77 @@ class ProductFournisseur extends Product
* @param float $buyprice Purchase price for the quantity min
* @param User $user Object user user made changes
* @param string $price_base_type HT or TTC
* @param string $charges costs affering to product
* @param Societe $fourn Supplier
* @param int $availability Product availability
* @param string $ref_fourn Supplier ref
* @param float $tva_tx VAT rate
* @param string $charges costs affering to product
* @return int >0 if KO, >0 if OK
*/
function update_buyprice($qty, $buyprice, $charges, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx)
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn, $tva_tx, $charges=0)
{
global $conf,$mysoc;
// Clean parameter
$buyprice=price2num($buyprice);
$charges=price2num($charges);
$qty=price2num($qty);
if (empty($qty)) $qty=0;
if (empty($buyprice)) $buyprice=0;
if (empty($charges)) $charges=0;
if (empty($availability)) $availability=0;
$buyprice=price2num($buyprice);
$charges=price2num($charges);
$qty=price2num($qty);
$error=0;
$error=0;
if ($price_base_type == 'TTC')
{
$ttx = get_default_tva($fourn,$mysoc,$this->id);
$buyprice = $buyprice/(1+($ttx/100));
}
$unitBuyPrice = price2num($buyprice/$qty,'MU');
$unitCharges = price2num($charges/$qty,'MU');
if ($price_base_type == 'TTC')
{
$ttx = get_default_tva($fourn,$mysoc,$this->id);
$buyprice = $buyprice/(1+($ttx/100));
}
$unitBuyPrice = price2num($buyprice/$qty,'MU');
$unitCharges = price2num($charges/$qty,'MU');
$now=dol_now();
$now=dol_now();
$this->db->begin();
if ($this->product_fourn_price_id)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " SET fk_user = " . $user->id." ,";
$sql.= " price = ".price2num($buyprice).",";
$sql.= " quantity = ".$qty.",";
$sql.= " charges = ".price2num($charges).",";
$sql.= " unitprice = ".$unitBuyPrice.",";
$sql.= " unitcharges = ".$unitCharges.",";
$sql.= " tva_tx = ".$tva_tx.",";
$sql.= " fk_availability = ".$availability.",";
$sql.= " entity = ".$conf->entity;
$sql .= " WHERE rowid = ".$this->product_fourn_price_id;
$resql = $this->db->query($sql) ;
if ($resql)
{
$this->db->commit();
return 0;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -2;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " SET fk_user = " . $user->id." ,";
$sql.= " price = ".price2num($buyprice).",";
$sql.= " quantity = ".$qty.",";
$sql.= " unitprice = ".$unitBuyPrice.",";
$sql.= " unitcharges = ".$unitCharges.",";
$sql.= " tva_tx = ".$tva_tx.",";
$sql.= " fk_availability = ".$availability.",";
$sql.= " entity = ".$conf->entity.",";
$sql.= " charges = ".($charges != ''?price2num($charges):"null");
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
$resql = $this->db->query($sql);
if ($resql)
{
$this->db->commit();
return 0;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -2;
}
}
else
{
// Supprime prix courant du fournisseur pour cette quantite
// Delete price for this quantity
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
$resql=$this->db->query($sql);
if ($resql)
{
// Ajoute prix courant du fournisseur pour cette quantite
if ($resql)
{
// Add price for this quantity to supplier
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
$sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, unitprice, tva_tx, fk_availability, entity)";
$sql.= " values('".$this->db->idate($now)."',";
@ -220,13 +222,13 @@ class ProductFournisseur extends Product
$sql.= " ".$availability.",";
$sql.= $conf->entity;
$sql.=")";
dol_syslog(get_class($this)."::update_buyprice sql=".$sql);
if (! $this->db->query($sql))
{
$error++;
}
/*if (! $error)
{
// Ajoute modif dans table log
@ -238,7 +240,7 @@ class ProductFournisseur extends Product
$sql.= " ".price2num($buyprice).",";
$sql.= " ".$qty;
$sql.=")";
$resql=$this->db->query($sql);
if (! $resql)
{
@ -246,7 +248,7 @@ class ProductFournisseur extends Product
}
}
*/
if (! $error)
{
$this->db->commit();

View File

@ -155,7 +155,7 @@ if ($action == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel"))
if (isset($_POST['ref_fourn_price_id']))
$product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
$ret=$product->update_buyprice($quantity, $_POST["price"], $_POST["charges"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx);
$ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"]);
if ($ret < 0)
{
$error++;
@ -348,9 +348,15 @@ if ($id || $ref)
print '</td>';
print '</tr>';
print '<td>'.$langs->trans("Charges").'</td>';
print '<td><input class="flat" name="charges" size="8" value="'.($_POST["charges"]?$_POST["charges"]:price($product->fourn_charges)).'">';
print '</td>';
// Charges ????
if (! empty($conf->global->PRODUCT_LOAD))
{
print '<tr>';
print '<td>'.$langs->trans("Charges").'</td>';
print '<td colspan="3"><input class="flat" name="charges" size="8" value="'.($_POST["charges"]?$_POST["charges"]:price($product->fourn_charges)).'">';
print '</td>';
print '</tr>';
}
print '</table>';
@ -397,9 +403,11 @@ if ($id || $ref)
print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder);
print '<td class="liste_titre" align="right">'.$langs->trans("VATRate").'</td>';
print '<td class="liste_titre" align="right">'.$langs->trans("PriceQtyMinHT").'</td>';
print '<td align="right">'.$langs->trans("Charges").'</td>';
// Charges ????
if (! empty($conf->global->PRODUCT_LOAD)) print '<td align="right">'.$langs->trans("Charges").'</td>';
print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
print '<td align="right">'.$langs->trans("UnitCharges").'</td>';
// Charges ????
if (! empty($conf->global->PRODUCT_LOAD)) print '<td align="right">'.$langs->trans("UnitCharges").'</td>';
print '<td class="liste_titre"></td>';
print "</tr>\n";
@ -444,10 +452,13 @@ if ($id || $ref)
print $productfourn->fourn_price?price($productfourn->fourn_price):"";
print '</td>';
// Charges
print '<td align="right">';
print $productfourn->fourn_charges?price($productfourn->fourn_charges):"";
print '</td>';
// Charges ????
if (! empty($conf->global->PRODUCT_LOAD))
{
print '<td align="right">';
print $productfourn->fourn_charges?price($productfourn->fourn_charges):"";
print '</td>';
}
// Unit price
print '<td align="right">';
@ -455,10 +466,13 @@ if ($id || $ref)
//print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):"&nbsp;");
print '</td>';
// Unit Charges
print '<td align="right">';
print $productfourn->fourn_unitcharges?price($productfourn->fourn_unitcharges) : ($productfourn->fourn_qty?price($productfourn->fourn_charges/$productfourn->fourn_qty):"&nbsp;");
print '</td>';
// Unit Charges ???
if (! empty($conf->global->PRODUCT_LOAD))
{
print '<td align="right">';
print $productfourn->fourn_unitcharges?price($productfourn->fourn_unitcharges) : ($productfourn->fourn_qty?price($productfourn->fourn_charges/$productfourn->fourn_qty):"&nbsp;");
print '</td>';
}
// Modify-Remove
print '<td align="center">';