Fix: bug #13896 overview: Problème avec les commandes fournisseurs

This commit is contained in:
Laurent Destailleur 2005-12-25 01:46:38 +00:00
parent b7ef050ecd
commit 8184049a5c
4 changed files with 195 additions and 152 deletions

View File

@ -43,9 +43,11 @@ if ($user->societe_id > 0)
$socidp = $user->societe_id; $socidp = $user->societe_id;
} }
$mesg='';
/* /*
* * Actions
*/ */
if ($_POST["action"] == 'classin') if ($_POST["action"] == 'classin')
{ {
@ -97,9 +99,17 @@ if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->cree
0, 0,
$_POST["remise_percent"]); $_POST["remise_percent"]);
} }
if ($result >= 0)
{
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit; exit;
} }
else
{
$mesg='<div class="error">'.$comf->error.'</div>';
}
}
if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer) if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer)
{ {
@ -212,7 +222,6 @@ if ($_GET["action"] == 'create')
else else
{ {
$mesg=$fourn->error; $mesg=$fourn->error;
print "x $mesg x";
} }
} }
@ -230,8 +239,15 @@ $html = new Form($db);
if ($_GET["id"] > 0) if ($_GET["id"] > 0)
{ {
<<<<<<< fiche.php
if ($mesg) print $mesg;
$commande = new CommandeFournisseur($db); $commande = new CommandeFournisseur($db);
if ( $commande->fetch($_GET["id"]) == 0) if ( $commande->fetch($_GET["id"]) == 0)
=======
$commande = new CommandeFournisseur($db);
if ( $commande->fetch($_GET["id"]) == 0)
>>>>>>> 1.29.2.1
{ {
$soc = new Societe($db); $soc = new Societe($db);
$soc->fetch($commande->soc_id); $soc->fetch($commande->soc_id);
@ -302,6 +318,7 @@ if ($_GET["id"] > 0)
$html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel"); $html->form_confirm("fiche.php?id=$commande->id",$langs->trans("Cancel"),"Etes-vous sûr de vouloir annuler cette commande ?","confirm_cancel");
print '<br />'; print '<br />';
} }
/* /*
* Confirmation de l'envoi de la commande * Confirmation de l'envoi de la commande
* *
@ -370,10 +387,13 @@ if ($_GET["id"] > 0)
print "</table>"; print "</table>";
if ($mesg) print $mesg;
else print '<br>';
/* /*
* Lignes de commandes * Lignes de commandes
*/ */
print '<br><table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
$sql = "SELECT l.ref, l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice"; $sql = "SELECT l.ref, l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
@ -403,7 +423,7 @@ if ($_GET["id"] > 0)
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td><a href="'.DOL_URL_ROOT.'/fourn/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</td>'; print '<td><a href="'.DOL_URL_ROOT.'/fourn/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a></td>';
if ($objp->fk_product > 0) if ($objp->fk_product > 0)
{ {
print '<td>'; print '<td>';

View File

@ -64,7 +64,6 @@ class CommandeFournisseur
/** /**
* Lit une commande * Lit une commande
*
*/ */
function fetch ($id) function fetch ($id)
{ {
@ -78,8 +77,8 @@ class CommandeFournisseur
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
$sql .= " WHERE c.rowid = ".$id; $sql .= " WHERE c.rowid = ".$id;
$resql = $this->db->query($sql) ;
$resql = $this->db->query($sql) ;
if ($resql) if ($resql)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@ -467,47 +466,59 @@ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm
*/ */
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0) function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{ {
$qty = ereg_replace(",",".",$qty); global $langs;
$pu = ereg_replace(",",".",$pu);
$qty = price2num($qty);
$pu = price2num($pu);
$desc = trim($desc); $desc = trim($desc);
$remise_percent = price2num($remise_percent);
dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent"); dolibarr_syslog("Fournisseur_Commande.class.php::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
if ($qty < 1 && ! $fk_product)
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Product"));
return -1;
}
if ($this->brouillon) if ($this->brouillon)
{ {
$this->db->begin(); $this->db->begin();
if (strlen(trim($qty))==0)
{
$qty=1;
}
if ($fk_product > 0) if ($fk_product > 0)
{ {
$prod = new Product($this->db, $fk_product); $prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0) if ($prod->fetch($fk_product) > 0)
{ {
$prod->get_buyprice($this->fourn_id,$qty); $result=$prod->get_buyprice($this->fourn_id,$qty);
if ($result)
{
$desc = $prod->libelle; $desc = $prod->libelle;
$txtva = $prod->tva_tx; $txtva = $prod->tva_tx;
$pu = $prod->buyprice; $pu = $prod->fourn_pu;
$ref = $prod->ref; $ref = $prod->ref;
} }
else
{
$this->error="Aucun tarif trouvé pour cette quantité. Quantité saisie insuffisante ?";
$this->db->rollback();
dolibarr_syslog($this->error);
return -1;
}
}
} }
$remise = 0; $remise = 0;
$price = round(ereg_replace(",",".",$pu), 2); $price = price2num($pu);
$subprice = $price; $subprice = $price;
if (trim(strlen($remise_percent)) > 0) if ($remise_percent > 0)
{ {
$remise = round(($pu * $remise_percent / 100), 2); $remise = round(($pu * $remise_percent / 100), 2);
$price = $pu - $remise; $price = $pu - $remise;
} }
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet (fk_commande,label,description,fk_product, price, qty, tva_tx, remise_percent, subprice, remise, ref)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet (fk_commande,label,description,fk_product, price, qty, tva_tx, remise_percent, subprice, remise, ref)";
$sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',$fk_product,".ereg_replace(",",".",$price).", '$qty', $txtva, $remise_percent,'".ereg_replace(",",".",$subprice)."','".ereg_replace(",",".", $remise)."','".$ref."') ;"; $sql .= " VALUES ($this->id, '" . addslashes($desc) . "','" . addslashes($desc) . "',".$fk_product.",".price2num($price).", '$qty', $txtva, $remise_percent,'".price2num($subprice)."','".price2num($remise)."','".$ref."') ;";
if ( $this->db->query( $sql) ) if ( $this->db->query( $sql) )
{ {
$this->update_price(); $this->update_price();

View File

@ -620,7 +620,7 @@ class Form
{ {
global $langs,$conf; global $langs,$conf;
$sql = "SELECT p.rowid, p.label, p.ref, p.price, pf.quantity, p.duration"; $sql = "SELECT p.rowid, p.label, p.ref, p.price as price, pf.price as fprice, pf.quantity, p.duration";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p "; $sql.= " FROM ".MAIN_DB_PREFIX."product as p ";
$sql .= " , ".MAIN_DB_PREFIX."product_fournisseur_price as pf "; $sql .= " , ".MAIN_DB_PREFIX."product_fournisseur_price as pf ";
$sql.= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$socid; $sql.= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$socid;
@ -641,11 +641,11 @@ class Form
$objp = $this->db->fetch_object($result); $objp = $this->db->fetch_object($result);
$opt = '<option value="'.$objp->rowid.'">['.$objp->ref.'] '; $opt = '<option value="'.$objp->rowid.'">['.$objp->ref.'] ';
$opt.= dolibarr_trunc($objp->label,40).' - '; $opt.= dolibarr_trunc($objp->label,40).' - ';
$opt.= $objp->price." ".$langs->trans("Currency".$conf->monnaie)." / ".$objp->quantity." ".$langs->trans("Units"); $opt.= $objp->fprice." ".$langs->trans("Currency".$conf->monnaie)." / ".$objp->quantity." ".$langs->trans("Units");
if ($objp->quantity > 1) if ($objp->quantity > 1)
{ {
$opt.=" - "; $opt.=" - ";
$opt.= round($objp->price/$objp->quantity,4)." ".$langs->trans("Currency".$conf->monnaie)." / ".$langs->trans("Unit"); $opt.= round($objp->fprice/$objp->quantity,4)." ".$langs->trans("Currency".$conf->monnaie)." / ".$langs->trans("Unit");
} }
if ($objp->duration) $opt .= " - ".$objp->duration; if ($objp->duration) $opt .= " - ".$objp->duration;
$opt .= "</option>\n"; $opt .= "</option>\n";

View File

@ -18,7 +18,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -199,7 +198,6 @@ class Product
* \param user utilisateur qui effectue l'insertion * \param user utilisateur qui effectue l'insertion
* \return int 1 si ok, -1 si ref deja existante, -2 autre erreur * \return int 1 si ok, -1 si ref deja existante, -2 autre erreur
*/ */
function update($id, $user) function update($id, $user)
{ {
global $langs; global $langs;
@ -248,7 +246,6 @@ class Product
* \brief Ajoute un changement de prix en base dans l'historique des prix * \brief Ajoute un changement de prix en base dans l'historique des prix
* \param user utilisateur qui modifie le prix * \param user utilisateur qui modifie le prix
*/ */
function _log_price($user) function _log_price($user)
{ {
// On supprimme ligne existante au cas ou // On supprimme ligne existante au cas ou
@ -279,15 +276,15 @@ class Product
/** /**
* \brief Lit le prix d'achat pour un fournisseur * \brief Lit le prix pratiqué par un fournisseur
* \param fourn_id Id du fournisseur * \param fourn_id Id du fournisseur
* \param qty Quantite pour lequel le prix est valide * \param qty Quantite pour lequel le prix est valide
* \return int Renvoi prix * \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
*/ */
function get_buyprice($fourn_id, $qty) function get_buyprice($fourn_id, $qty)
{ {
$result = 0; $result = 0;
$sql = "SELECT pf.price"; $sql = "SELECT pf.price as price, pf.quantity as quantity";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf"; $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf";
$sql.= " WHERE pf.fk_soc = ".$fourn_id; $sql.= " WHERE pf.fk_soc = ".$fourn_id;
$sql.= " AND pf.fk_product =" .$this->id; $sql.= " AND pf.fk_product =" .$this->id;
@ -295,11 +292,26 @@ class Product
$sql.= " ORDER BY quantity DESC"; $sql.= " ORDER BY quantity DESC";
$sql.= " LIMIT 1"; $sql.= " LIMIT 1";
dolibarr_syslog("Product::get_buyprice $fourn_id,$qty sql=$sql");
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql)
{ {
$row = $this->db->fetch_row($resql); $obj = $this->db->fetch_object($resql);
$this->buyprice = $row[0]; if ($obj && $obj->quantity > 0)
{
$this->buyprice = $obj->price; // \deprecated
$this->fourn_pu = $obj->price / $obj->quantity; // Prix unitaire du produit pour le fournisseur $fourn_id
return 1;
}
else
{
return 0;
}
}
else
{
return -1;
} }
return $result; return $result;
} }