From de621f0567b6058fcea565dec023b735b0ed976b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 25 Jul 2012 11:32:48 +0200 Subject: [PATCH] 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). --- .../fourn/class/fournisseur.product.class.php | 96 ++++++++++--------- htdocs/product/fournisseurs.php | 42 +++++--- 2 files changed, 77 insertions(+), 61 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index c7fa32d7835..aa87425bf6b 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -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(); diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 83178537734..bdff801393c 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -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 ''; print ''; - print ''.$langs->trans("Charges").''; - print 'fourn_charges)).'">'; - print ''; + // Charges ???? + if (! empty($conf->global->PRODUCT_LOAD)) + { + print ''; + print ''.$langs->trans("Charges").''; + print 'fourn_charges)).'">'; + print ''; + print ''; + } print ''; @@ -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 ''.$langs->trans("VATRate").''; print ''.$langs->trans("PriceQtyMinHT").''; - print ''.$langs->trans("Charges").''; + // Charges ???? + if (! empty($conf->global->PRODUCT_LOAD)) print ''.$langs->trans("Charges").''; print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder); - print ''.$langs->trans("UnitCharges").''; + // Charges ???? + if (! empty($conf->global->PRODUCT_LOAD)) print ''.$langs->trans("UnitCharges").''; print ''; print "\n"; @@ -444,10 +452,13 @@ if ($id || $ref) print $productfourn->fourn_price?price($productfourn->fourn_price):""; print ''; - // Charges - print ''; - print $productfourn->fourn_charges?price($productfourn->fourn_charges):""; - print ''; + // Charges ???? + if (! empty($conf->global->PRODUCT_LOAD)) + { + print ''; + print $productfourn->fourn_charges?price($productfourn->fourn_charges):""; + print ''; + } // Unit price print ''; @@ -455,10 +466,13 @@ if ($id || $ref) //print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" "); print ''; - // Unit Charges - print ''; - print $productfourn->fourn_unitcharges?price($productfourn->fourn_unitcharges) : ($productfourn->fourn_qty?price($productfourn->fourn_charges/$productfourn->fourn_qty):" "); - print ''; + // Unit Charges ??? + if (! empty($conf->global->PRODUCT_LOAD)) + { + print ''; + print $productfourn->fourn_unitcharges?price($productfourn->fourn_unitcharges) : ($productfourn->fourn_qty?price($productfourn->fourn_charges/$productfourn->fourn_qty):" "); + print ''; + } // Modify-Remove print '';