Can input a supplier price with all taxes

This commit is contained in:
Laurent Destailleur 2008-02-11 21:17:22 +00:00
parent 87c85db86b
commit 4abfe7427d
5 changed files with 72 additions and 42 deletions

View File

@ -143,14 +143,18 @@ class ProductFournisseur extends Product
/** /**
* \brief Modifie le prix d'achat pour un fournisseur * \brief Modifie le prix d'achat pour un fournisseur
* \param id_fourn Id du fournisseur * \param qty Quantite min pour lequel le prix est valide
* \param qty Quantite pour lequel le prix est valide * \param buyprice Prix d'achat pour la quantité min
* \param buyprice Prix d'achat pour la quantité
* \param user Objet user de l'utilisateur qui modifie * \param user Objet user de l'utilisateur qui modifie
* \param price_base_type HT or TTC * \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; $error=0;
$this->db->begin(); $this->db->begin();
@ -167,16 +171,21 @@ class ProductFournisseur extends Product
if ($this->db->query($sql)) 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é // Ajoute prix courant du fournisseur pour cette quantité
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql .= " SET datec = now()"; $sql.= " SET datec = now()";
$sql .= " ,fk_product_fournisseur = ".$this->product_fourn_id; $sql.= " ,fk_product_fournisseur = ".$this->product_fourn_id;
$sql .= " ,fk_user = ".$user->id; $sql.= " ,fk_user = ".$user->id;
$sql .= " ,price = ".price2num($buyprice); $sql.= " ,price = ".price2num($buyprice);
$sql .= " ,quantity = ".$qty; $sql.= " ,quantity = ".$qty;
$sql .= " ,unitprice = ".price2num($unitBuyPrice,'MU'); $sql.= " ,unitprice = ".$unitBuyPrice;
dolibarr_syslog("ProductFournisseur::update_buyprice sql=".$sql); dolibarr_syslog("ProductFournisseur::update_buyprice sql=".$sql);
if (! $this->db->query($sql)) if (! $this->db->query($sql))
@ -184,7 +193,8 @@ class ProductFournisseur extends Product
$error++; $error++;
} }
if (! $error) { if (! $error)
{
// Ajoute modif dans table log // Ajoute modif dans table log
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log ";
$sql .= " SET datec = now()"; $sql .= " SET datec = now()";

View File

@ -124,8 +124,11 @@ Restock=Restock
ProductSpecial=Special ProductSpecial=Special
QtyMin=Quantity minimum QtyMin=Quantity minimum
PriceQty=Price for this quantity PriceQty=Price for this quantity
PriceQtyMin=Price quantity min.
PriceQtyHT=Price for this quantity HT PriceQtyHT=Price for this quantity HT
PriceQtyMinHT=Price quantity min. HT
PriceQtyTTC=Price for this quantity TTC PriceQtyTTC=Price for this quantity TTC
PriceQtyMinTTC=Price quantity min. TTC
NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product NoPriceDefinedForThisSupplier=No price/qty defined for this supplier/product
NoSupplierPriceDefinedForThisProduct=No supplier price/qty defined for this product NoSupplierPriceDefinedForThisProduct=No supplier price/qty defined for this product
RecordedProducts=Products recorded RecordedProducts=Products recorded

View File

@ -124,8 +124,11 @@ Restock=R
ProductSpecial=Special ProductSpecial=Special
QtyMin=Quantité minimum QtyMin=Quantité minimum
PriceQty=Prix pour la quantité PriceQty=Prix pour la quantité
PriceQtyMin=Prix quantité min.
PriceQtyHT=Prix pour la quantité HT PriceQtyHT=Prix pour la quantité HT
PriceQtyMinHT=Prix quantité min. HT
PriceQtyTTC=Prix pour la quantité TTC PriceQtyTTC=Prix pour la quantité TTC
PriceQtyMinTTC=Prix quantité min. TTC
NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit NoPriceDefinedForThisSupplier=Aucun prix/qté défini pour ce fournisseur/produit
NoSupplierPriceDefinedForThisProduct=Aucun prix/qté fournisseur défini pour ce produit NoSupplierPriceDefinedForThisProduct=Aucun prix/qté fournisseur défini pour ce produit
RecordedProducts=Produits en vente RecordedProducts=Produits en vente

View File

@ -18,15 +18,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/product.class.php \file htdocs/product.class.php
\ingroup produit \ingroup produit
\brief Fichier de la classe des produits prédéfinis \brief Fichier de la classe des produits prédéfinis
\version $Revision$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php"); require_once(DOL_DOCUMENT_ROOT ."/commonobject.class.php");

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005 Regis Houssin <regis@dolibarr.fr>
* *
@ -17,16 +17,13 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*/ */
/** /**
\file htdocs/product/fournisseurs.php \file htdocs/product/fournisseurs.php
\ingroup product \ingroup product
\brief Page de l'onglet fournisseur de produits \brief Page de l'onglet fournisseur de produits
\version $Revision$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
@ -50,6 +47,7 @@ if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT &&
$_POST['id_fourn'] = $_POST['id_fourn_id']; $_POST['id_fourn'] = $_POST['id_fourn_id'];
} }
/* /*
* Actions * Actions
*/ */
@ -81,16 +79,26 @@ if ($_GET["action"] == 'remove_pf')
if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel")) if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel"))
{ {
$product = new ProductFournisseur($db); $product = new ProductFournisseur($db);
$result=$product->fetch($_REQUEST["id"]); $result=$product->fetch($_REQUEST["id"]);
if ($result) if ($result > 0)
{ {
$db->begin(); $db->begin();
$error=0; $error=0;
if (! $_POST["ref_fourn"])
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
}
if ($_POST["id_fourn"] <= 0)
{
//print "eee".$_POST["id_fourn"];
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Supplier")).'</div>';
}
if ($_POST["ref_fourn"]) if (! $error)
{ {
$ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]); $ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]);
if ($ret < 0) if ($ret < 0)
@ -103,7 +111,10 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
{ {
if ($_POST["price"] >= 0) 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) if ($ret < 0)
{ {
$error++; $error++;
@ -126,12 +137,6 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'</div>'; $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'</div>';
} }
} }
else
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")).'</div>';
}
if (! $error) if (! $error)
{ {
@ -220,7 +225,7 @@ if ($_GET["id"] || $_GET["ref"])
// Formulaire ajout prix // 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"); $langs->load("suppliers");
@ -234,33 +239,39 @@ if ($_GET["id"] || $_GET["ref"])
print '<form action="fournisseurs.php?id='.$product->id.'" method="post">'; print '<form action="fournisseurs.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="updateprice">'; print '<input type="hidden" name="action" value="updateprice">';
print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="3">';
if ($_GET["rowid"]) if ($_GET["rowid"])
{ {
$supplier=new Fournisseur($db);
$supplier->fetch($_GET["socid"]);
print $supplier->getNomUrl(1);
print '<input type="hidden" name="id_fourn" value="'.$_GET["socid"].'">'; print '<input type="hidden" name="id_fourn" value="'.$_GET["socid"].'">';
print '<input type="hidden" name="ref_fourn" value="'.$product->fourn_ref.'">'; print '<input type="hidden" name="ref_fourn" value="'.$product->fourn_ref.'">';
print '<input type="hidden" name="ref_fourn_price_id" value="'.$_GET["rowid"].'">'; print '<input type="hidden" name="ref_fourn_price_id" value="'.$_GET["rowid"].'">';
} }
else else
{ {
print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="5">';
$html=new Form($db); $html=new Form($db);
$html->select_societes('','id_fourn','fournisseur=1'); $html->select_societes($_POST["id_fourn"],'id_fourn','fournisseur=1',1);
print '</td></tr>';
} }
print '</td></tr>';
print '<tr><td>'.$langs->trans("SupplierRef").'</td><td>'; print '<tr><td>'.$langs->trans("SupplierRef").'</td><td colspan="3">';
if ($_GET["rowid"]) if ($_GET["rowid"])
{ {
print $product->fourn_ref; print $product->fourn_ref;
} }
else else
{ {
print '<input class="flat" name="ref_fourn" size="12" value="'.$product->ref_fourn.'">'; print '<input class="flat" name="ref_fourn" size="12" value="'.($_POST["ref_fourn"]?$_POST["ref_fourn"]:$product->ref_fourn).'">';
} }
print '</td>'; print '</td>';
print '</tr>';
print '<tr>';
print '<td>'.$langs->trans("QtyMin").'</td>'; print '<td>'.$langs->trans("QtyMin").'</td>';
$quantity = $_GET["qty"] ? $_GET["qty"] : "1";
print '<td>'; print '<td>';
$quantity = $_REQUEST["qty"] ? $_REQUEST["qty"] : "1";
if ($_GET["rowid"]) if ($_GET["rowid"])
{ {
print '<input type="hidden" name="qty" value="'.$product->fourn_qty.'">'; print '<input type="hidden" name="qty" value="'.$product->fourn_qty.'">';
@ -271,12 +282,17 @@ if ($_GET["id"] || $_GET["ref"])
print '<input class="flat" name="qty" size="5" value="'.$quantity.'">'; print '<input class="flat" name="qty" size="5" value="'.$quantity.'">';
} }
print '</td>'; print '</td>';
print '<td>'.$langs->trans("PriceQtyHT").'</td>'; print '<td>'.$langs->trans("PriceQtyMin").'</td>';
print '<td><input class="flat" name="price" size="8" value="'.price($product->fourn_price).'"></td></tr>'; 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 '</tr>';
print '<tr><td colspan="6" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">'; print '<tr><td colspan="4" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">';
print '&nbsp; &nbsp;'; print '&nbsp; &nbsp;';
print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</form>'; print '</form>';
print '</table>'; print '</table>';
} }
@ -313,7 +329,7 @@ if ($_GET["id"] || $_GET["ref"])
print $langs->trans("Suppliers").'</td>'; print $langs->trans("Suppliers").'</td>';
print '<td>'.$langs->trans("SupplierRef").'</td>'; print '<td>'.$langs->trans("SupplierRef").'</td>';
print '<td align="center">'.$langs->trans("QtyMin").'</td>'; print '<td align="center">'.$langs->trans("QtyMin").'</td>';
print '<td align="right">'.$langs->trans("PriceQtyHT").'</td>'; print '<td align="right">'.$langs->trans("PriceQtyMinHT").'</td>';
print '<td align="right">'.$langs->trans("UnitPriceHT").'</td>'; print '<td align="right">'.$langs->trans("UnitPriceHT").'</td>';
print '<td>&nbsp;</td>'; print '<td>&nbsp;</td>';
print '</tr>'; print '</tr>';