From 4abfe7427d221a32e28339ec1ba1897a581788bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Feb 2008 21:17:22 +0000 Subject: [PATCH] Can input a supplier price with all taxes --- htdocs/fourn/fournisseur.product.class.php | 34 +++++++---- htdocs/langs/en_US/products.lang | 3 + htdocs/langs/fr_FR/products.lang | 3 + htdocs/product.class.php | 4 +- htdocs/product/fournisseurs.php | 70 +++++++++++++--------- 5 files changed, 72 insertions(+), 42 deletions(-) diff --git a/htdocs/fourn/fournisseur.product.class.php b/htdocs/fourn/fournisseur.product.class.php index b1fb2d0907c..37b6ef9cfc0 100644 --- a/htdocs/fourn/fournisseur.product.class.php +++ b/htdocs/fourn/fournisseur.product.class.php @@ -143,14 +143,18 @@ class ProductFournisseur extends Product /** * \brief Modifie le prix d'achat pour un fournisseur - * \param id_fourn Id du fournisseur - * \param qty Quantite pour lequel le prix est valide - * \param buyprice Prix d'achat pour la quantité + * \param qty Quantite min pour lequel le prix est valide + * \param buyprice Prix d'achat pour la quantité min * \param user Objet user de l'utilisateur qui modifie * \param price_base_type HT or TTC + * \param fourn Supplier */ - function update_buyprice($qty, $buyprice, $user, $price_base_type='HT') + function update_buyprice($qty, $buyprice, $user, $price_base_type='HT', $fourn) { + global $mysoc; + + $buyprice=price2num($buyprice); + $error=0; $this->db->begin(); @@ -167,16 +171,21 @@ class ProductFournisseur extends Product if ($this->db->query($sql)) { - $unitBuyPrice = (price2num($buyprice)/$qty); + if ($price_base_type == 'TTC') + { + $ttx = get_default_tva($fourn,$mysoc,($this->tva_tx?$this->tva_tx:0)); + $buyprice = $buyprice/(1+($ttx/100)); + } + $unitBuyPrice = price2num($buyprice/$qty,'MU'); // Ajoute prix courant du fournisseur pour cette quantité $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price"; - $sql .= " SET datec = now()"; - $sql .= " ,fk_product_fournisseur = ".$this->product_fourn_id; - $sql .= " ,fk_user = ".$user->id; - $sql .= " ,price = ".price2num($buyprice); - $sql .= " ,quantity = ".$qty; - $sql .= " ,unitprice = ".price2num($unitBuyPrice,'MU'); + $sql.= " SET datec = now()"; + $sql.= " ,fk_product_fournisseur = ".$this->product_fourn_id; + $sql.= " ,fk_user = ".$user->id; + $sql.= " ,price = ".price2num($buyprice); + $sql.= " ,quantity = ".$qty; + $sql.= " ,unitprice = ".$unitBuyPrice; dolibarr_syslog("ProductFournisseur::update_buyprice sql=".$sql); if (! $this->db->query($sql)) @@ -184,7 +193,8 @@ class ProductFournisseur extends Product $error++; } - if (! $error) { + if (! $error) + { // Ajoute modif dans table log $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log "; $sql .= " SET datec = now()"; diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index adbb3c620cb..d80130984c8 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -124,8 +124,11 @@ Restock=Restock ProductSpecial=Special QtyMin=Quantity minimum PriceQty=Price for this quantity +PriceQtyMin=Price quantity min. PriceQtyHT=Price for this quantity HT +PriceQtyMinHT=Price quantity min. HT PriceQtyTTC=Price for this quantity TTC +PriceQtyMinTTC=Price quantity min. TTC NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product NoSupplierPriceDefinedForThisProduct=No supplier price/qty defined for this product RecordedProducts=Products recorded diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index e418c69c07b..d5f7b1a1064 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -124,8 +124,11 @@ Restock=R ProductSpecial=Special QtyMin=Quantité minimum PriceQty=Prix pour la quantité +PriceQtyMin=Prix quantité min. PriceQtyHT=Prix pour la quantité HT +PriceQtyMinHT=Prix quantité min. HT PriceQtyTTC=Prix pour la quantité TTC +PriceQtyMinTTC=Prix quantité min. TTC NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit NoSupplierPriceDefinedForThisProduct=Aucun prix/qté fournisseur défini pour ce produit RecordedProducts=Produits en vente diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 4c2ac92f793..86fa6d11880 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -18,15 +18,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \file htdocs/product.class.php \ingroup produit \brief Fichier de la classe des produits prédéfinis - \version $Revision$ + \version $Id$ */ require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index b4863310c6b..a416324f2ac 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005 Regis Houssin * @@ -17,16 +17,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ /** \file htdocs/product/fournisseurs.php \ingroup product \brief Page de l'onglet fournisseur de produits - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); @@ -50,10 +47,11 @@ if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['id_fourn'] = $_POST['id_fourn_id']; } + /* * Actions */ - + if ($_GET["action"] == 'remove_pf') { $product = new ProductFournisseur($db); @@ -81,16 +79,26 @@ if ($_GET["action"] == 'remove_pf') if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel")) { - $product = new ProductFournisseur($db); $result=$product->fetch($_REQUEST["id"]); - if ($result) + if ($result > 0) { $db->begin(); $error=0; + if (! $_POST["ref_fourn"]) + { + $error++; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; + } + if ($_POST["id_fourn"] <= 0) + { + //print "eee".$_POST["id_fourn"]; + $error++; + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")).'
'; + } - if ($_POST["ref_fourn"]) + if (! $error) { $ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]); if ($ret < 0) @@ -103,7 +111,10 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc { if ($_POST["price"] >= 0) { - $ret=$product->update_buyprice($_POST["qty"], $_POST["price"], $user); + $supplier=new Fournisseur($db); + $result=$supplier->fetch($_POST["id_fourn"]); + + $ret=$product->update_buyprice($_POST["qty"], $_POST["price"], $user, $_POST["price_base_type"], $supplier); if ($ret < 0) { $error++; @@ -126,12 +137,6 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'
'; } } - else - { - $error++; - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'
'; - } - if (! $error) { @@ -220,7 +225,7 @@ if ($_GET["id"] || $_GET["ref"]) // Formulaire ajout prix - if ($_GET["action"] == 'add_price' && $user->rights->produit->creer) + if (($_GET["action"] == 'add_price' || $_POST["action"] == 'updateprice') && $user->rights->produit->creer) { $langs->load("suppliers"); @@ -234,33 +239,39 @@ if ($_GET["id"] || $_GET["ref"]) print '
'; print ''; + print ''.$langs->trans("Supplier").''; if ($_GET["rowid"]) { + $supplier=new Fournisseur($db); + $supplier->fetch($_GET["socid"]); + print $supplier->getNomUrl(1); print ''; print ''; print ''; } else { - print ''.$langs->trans("Supplier").''; $html=new Form($db); - $html->select_societes('','id_fourn','fournisseur=1'); - print ''; + $html->select_societes($_POST["id_fourn"],'id_fourn','fournisseur=1',1); } + print ''; - print ''.$langs->trans("SupplierRef").''; + print ''.$langs->trans("SupplierRef").''; if ($_GET["rowid"]) { print $product->fourn_ref; } else { - print ''; + print 'ref_fourn).'">'; } print ''; + print ''; + + print ''; print ''.$langs->trans("QtyMin").''; - $quantity = $_GET["qty"] ? $_GET["qty"] : "1"; print ''; + $quantity = $_REQUEST["qty"] ? $_REQUEST["qty"] : "1"; if ($_GET["rowid"]) { print ''; @@ -271,12 +282,17 @@ if ($_GET["id"] || $_GET["ref"]) print ''; } print ''; - print ''.$langs->trans("PriceQtyHT").''; - print ''; + print ''.$langs->trans("PriceQtyMin").''; + print 'fourn_price)).'">'; + print ' '; + print $html->select_PriceBaseType(($_POST["price_base_type"]?$_POST["price_base_type"]:$product->price_base_type), "price_base_type"); + print ''; + print ''; - print ''; + print ''; print '   '; print ''; + print '
'; print ''; } @@ -313,7 +329,7 @@ if ($_GET["id"] || $_GET["ref"]) print $langs->trans("Suppliers").''; print ''.$langs->trans("SupplierRef").''; print ''.$langs->trans("QtyMin").''; - print ''.$langs->trans("PriceQtyHT").''; + print ''.$langs->trans("PriceQtyMinHT").''; print ''.$langs->trans("UnitPriceHT").''; print ' '; print '';