Fix: bug #13896 overview: Problme avec les commandes fournisseurs
This commit is contained in:
parent
b7ef050ecd
commit
8184049a5c
@ -43,9 +43,11 @@ if ($user->societe_id > 0)
|
||||
$socidp = $user->societe_id;
|
||||
}
|
||||
|
||||
$mesg='';
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Actions
|
||||
*/
|
||||
if ($_POST["action"] == 'classin')
|
||||
{
|
||||
@ -97,8 +99,16 @@ if ($_POST["action"] == 'addligne' && $user->rights->fournisseur->commande->cree
|
||||
0,
|
||||
$_POST["remise_percent"]);
|
||||
}
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
|
||||
if ($result >= 0)
|
||||
{
|
||||
Header("Location: fiche.php?id=".$_GET["id"]);
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mesg='<div class="error">'.$comf->error.'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST["action"] == 'updateligne' && $user->rights->commande->creer)
|
||||
@ -212,7 +222,6 @@ if ($_GET["action"] == 'create')
|
||||
else
|
||||
{
|
||||
$mesg=$fourn->error;
|
||||
print "x $mesg x";
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,11 +236,18 @@ $html = new Form($db);
|
||||
/* Mode vue et edition */
|
||||
/* */
|
||||
/* *************************************************************************** */
|
||||
|
||||
|
||||
if ($_GET["id"] > 0)
|
||||
{
|
||||
$commande = new CommandeFournisseur($db);
|
||||
if ( $commande->fetch($_GET["id"]) == 0)
|
||||
<<<<<<< fiche.php
|
||||
if ($mesg) print $mesg;
|
||||
|
||||
$commande = new CommandeFournisseur($db);
|
||||
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->fetch($commande->soc_id);
|
||||
@ -302,17 +318,18 @@ 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");
|
||||
print '<br />';
|
||||
}
|
||||
|
||||
/*
|
||||
* Confirmation de l'envoi de la commande
|
||||
*
|
||||
*/
|
||||
if ($_GET["action"] == 'commande')
|
||||
{
|
||||
if ($_GET["action"] == 'commande')
|
||||
{
|
||||
$date_com = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
|
||||
$html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"],
|
||||
"Envoi de la commande","Etes-vous sûr de vouloir confirmer cette commande en date du ".strftime("%d/%m/%Y",$date_com)." ?","confirm_commande");
|
||||
print '<br />';
|
||||
}
|
||||
print '<br />';
|
||||
}
|
||||
|
||||
/*
|
||||
* Commande
|
||||
@ -370,10 +387,13 @@ if ($_GET["id"] > 0)
|
||||
|
||||
print "</table>";
|
||||
|
||||
if ($mesg) print $mesg;
|
||||
else print '<br>';
|
||||
|
||||
/*
|
||||
* 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.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
|
||||
@ -403,7 +423,7 @@ if ($_GET["id"] > 0)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
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)
|
||||
{
|
||||
print '<td>';
|
||||
|
||||
@ -62,66 +62,65 @@ class CommandeFournisseur
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lit une commande
|
||||
*
|
||||
*/
|
||||
function fetch ($id)
|
||||
/**
|
||||
* Lit une commande
|
||||
*/
|
||||
function fetch ($id)
|
||||
{
|
||||
$sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva";
|
||||
$sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande ";
|
||||
$sql .= ", c.note";
|
||||
|
||||
$sql .= ", cm.libelle as methode_commande";
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
|
||||
|
||||
$sql .= " WHERE c.rowid = ".$id;
|
||||
$resql = $this->db->query($sql) ;
|
||||
|
||||
if ( $resql )
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->ref;
|
||||
$this->soc_id = $obj->fk_soc;
|
||||
$this->fourn_id = $obj->fk_soc;
|
||||
$this->statut = $obj->fk_statut;
|
||||
$this->user_author_id = $obj->fk_user_author;
|
||||
$this->total_ht = $obj->total_ht;
|
||||
$this->total_tva = $obj->tva;
|
||||
$this->total_ttc = $obj->total_ttc;
|
||||
$this->date_commande = $obj->date_commande; // date à laquelle la commande a été transmise
|
||||
$this->remise_percent = $obj->remise_percent;
|
||||
$this->methode_commande_id = $obj->fk_methode_commande;
|
||||
$this->methode_commande = $obj->methode_commande;
|
||||
|
||||
$this->source = $obj->source;
|
||||
$this->facturee = $obj->facture;
|
||||
$this->projet_id = $obj->fk_projet;
|
||||
$this->note = stripslashes($obj->note);
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$this->brouillon = 1;
|
||||
}
|
||||
|
||||
$result = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("CommandeFournisseur::Fetch Error $sql");
|
||||
dolibarr_syslog("CommandeFournisseur::Fetch Error ".$this->db->error());
|
||||
$result = -1;
|
||||
}
|
||||
|
||||
return $result ;
|
||||
$sql = "SELECT c.rowid, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.tva";
|
||||
$sql .= ", ".$this->db->pdate("c.date_commande")." as date_commande, c.fk_projet, c.remise_percent, c.source, c.fk_methode_commande ";
|
||||
$sql .= ", c.note";
|
||||
|
||||
$sql .= ", cm.libelle as methode_commande";
|
||||
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_methode_commande_fournisseur as cm ON cm.rowid = c.fk_methode_commande";
|
||||
|
||||
$sql .= " WHERE c.rowid = ".$id;
|
||||
|
||||
$resql = $this->db->query($sql) ;
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
|
||||
$this->id = $obj->rowid;
|
||||
$this->ref = $obj->ref;
|
||||
$this->soc_id = $obj->fk_soc;
|
||||
$this->fourn_id = $obj->fk_soc;
|
||||
$this->statut = $obj->fk_statut;
|
||||
$this->user_author_id = $obj->fk_user_author;
|
||||
$this->total_ht = $obj->total_ht;
|
||||
$this->total_tva = $obj->tva;
|
||||
$this->total_ttc = $obj->total_ttc;
|
||||
$this->date_commande = $obj->date_commande; // date à laquelle la commande a été transmise
|
||||
$this->remise_percent = $obj->remise_percent;
|
||||
$this->methode_commande_id = $obj->fk_methode_commande;
|
||||
$this->methode_commande = $obj->methode_commande;
|
||||
|
||||
$this->source = $obj->source;
|
||||
$this->facturee = $obj->facture;
|
||||
$this->projet_id = $obj->fk_projet;
|
||||
$this->note = stripslashes($obj->note);
|
||||
|
||||
$this->db->free($resql);
|
||||
|
||||
if ($this->statut == 0)
|
||||
{
|
||||
$this->brouillon = 1;
|
||||
}
|
||||
|
||||
$result = 0;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dolibarr_syslog("CommandeFournisseur::Fetch Error $sql");
|
||||
dolibarr_syslog("CommandeFournisseur::Fetch Error ".$this->db->error());
|
||||
$result = -1;
|
||||
}
|
||||
|
||||
return $result ;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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)
|
||||
{
|
||||
$qty = ereg_replace(",",".",$qty);
|
||||
$pu = ereg_replace(",",".",$pu);
|
||||
$desc=trim($desc);
|
||||
|
||||
global $langs;
|
||||
|
||||
$qty = price2num($qty);
|
||||
$pu = price2num($pu);
|
||||
$desc = trim($desc);
|
||||
$remise_percent = price2num($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)
|
||||
{
|
||||
$this->db->begin();
|
||||
|
||||
if (strlen(trim($qty))==0)
|
||||
{
|
||||
$qty=1;
|
||||
}
|
||||
|
||||
if ($fk_product > 0)
|
||||
{
|
||||
$prod = new Product($this->db, $fk_product);
|
||||
if ($prod->fetch($fk_product) > 0)
|
||||
{
|
||||
$prod->get_buyprice($this->fourn_id,$qty);
|
||||
|
||||
$desc = $prod->libelle;
|
||||
$txtva = $prod->tva_tx;
|
||||
$pu = $prod->buyprice;
|
||||
$ref = $prod->ref;
|
||||
$result=$prod->get_buyprice($this->fourn_id,$qty);
|
||||
if ($result)
|
||||
{
|
||||
$desc = $prod->libelle;
|
||||
$txtva = $prod->tva_tx;
|
||||
$pu = $prod->fourn_pu;
|
||||
$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;
|
||||
$price = round(ereg_replace(",",".",$pu), 2);
|
||||
$price = price2num($pu);
|
||||
$subprice = $price;
|
||||
if (trim(strlen($remise_percent)) > 0)
|
||||
if ($remise_percent > 0)
|
||||
{
|
||||
$remise = round(($pu * $remise_percent / 100), 2);
|
||||
$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 .= " 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) )
|
||||
{
|
||||
$this->update_price();
|
||||
|
||||
@ -620,7 +620,7 @@ class Form
|
||||
{
|
||||
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 .= " , ".MAIN_DB_PREFIX."product_fournisseur_price as pf ";
|
||||
$sql.= " WHERE p.rowid = pf.fk_product AND pf.fk_soc = ".$socid;
|
||||
@ -641,11 +641,11 @@ class Form
|
||||
$objp = $this->db->fetch_object($result);
|
||||
$opt = '<option value="'.$objp->rowid.'">['.$objp->ref.'] ';
|
||||
$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)
|
||||
{
|
||||
$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;
|
||||
$opt .= "</option>\n";
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -193,62 +192,60 @@ class Product
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Mise à jour du produit en base
|
||||
* \param id id du produit
|
||||
* \param user utilisateur qui effectue l'insertion
|
||||
* \return int 1 si ok, -1 si ref deja existante, -2 autre erreur
|
||||
*/
|
||||
|
||||
function update($id, $user)
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("main");
|
||||
$langs->load("products");
|
||||
|
||||
if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT';
|
||||
|
||||
$this->ref = trim(sanitize_string($this->ref));
|
||||
$this->libelle = trim($this->libelle);
|
||||
$this->description = trim($this->description);
|
||||
$this->note = trim($this->note);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
|
||||
$sql .= " SET label = '" . addslashes($this->libelle) ."'";
|
||||
if ($this->ref) $sql .= ",ref = '" . $this->ref ."'";
|
||||
$sql .= ",tva_tx = " . $this->tva_tx ;
|
||||
$sql .= ",envente = " . $this->envente ;
|
||||
$sql .= ",seuil_stock_alerte = " . $this->seuil_stock_alerte ;
|
||||
$sql .= ",description = '" . addslashes($this->description) ."'";
|
||||
$sql .= ",note = '" . addslashes($this->note) ."'";
|
||||
$sql .= ",duration = '" . $this->duration_value . $this->duration_unit ."'";
|
||||
$sql .= " WHERE rowid = " . $id;
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
/**
|
||||
* \brief Mise à jour du produit en base
|
||||
* \param id id du produit
|
||||
* \param user utilisateur qui effectue l'insertion
|
||||
* \return int 1 si ok, -1 si ref deja existante, -2 autre erreur
|
||||
*/
|
||||
function update($id, $user)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
||||
global $langs;
|
||||
$langs->load("main");
|
||||
$langs->load("products");
|
||||
|
||||
if (! $this->libelle) $this->libelle = 'LIBELLE MANQUANT';
|
||||
|
||||
$this->ref = trim(sanitize_string($this->ref));
|
||||
$this->libelle = trim($this->libelle);
|
||||
$this->description = trim($this->description);
|
||||
$this->note = trim($this->note);
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product ";
|
||||
$sql .= " SET label = '" . addslashes($this->libelle) ."'";
|
||||
if ($this->ref) $sql .= ",ref = '" . $this->ref ."'";
|
||||
$sql .= ",tva_tx = " . $this->tva_tx ;
|
||||
$sql .= ",envente = " . $this->envente ;
|
||||
$sql .= ",seuil_stock_alerte = " . $this->seuil_stock_alerte ;
|
||||
$sql .= ",description = '" . addslashes($this->description) ."'";
|
||||
$sql .= ",note = '" . addslashes($this->note) ."'";
|
||||
$sql .= ",duration = '" . $this->duration_value . $this->duration_unit ."'";
|
||||
$sql .= " WHERE rowid = " . $id;
|
||||
|
||||
if ( $this->db->query($sql) )
|
||||
{
|
||||
$this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref);
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
|
||||
return -2;
|
||||
if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
|
||||
{
|
||||
$this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Ajoute un changement de prix en base dans l'historique des prix
|
||||
* \param user utilisateur qui modifie le prix
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Ajoute un changement de prix en base dans l'historique des prix
|
||||
* \param user utilisateur qui modifie le prix
|
||||
*/
|
||||
function _log_price($user)
|
||||
{
|
||||
// On supprimme ligne existante au cas ou
|
||||
@ -278,28 +275,43 @@ class Product
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Lit le prix d'achat pour un fournisseur
|
||||
* \param fourn_id Id du fournisseur
|
||||
* \param qty Quantite pour lequel le prix est valide
|
||||
* \return int Renvoi prix
|
||||
*/
|
||||
function get_buyprice($fourn_id, $qty)
|
||||
/**
|
||||
* \brief Lit le prix pratiqué par un fournisseur
|
||||
* \param fourn_id Id du fournisseur
|
||||
* \param qty Quantite pour lequel le prix est valide
|
||||
* \return int <0 si ko, 0 si ok mais rien trouvé, 1 si ok et trouvé
|
||||
*/
|
||||
function get_buyprice($fourn_id, $qty)
|
||||
{
|
||||
$result = 0;
|
||||
$sql = "SELECT pf.price";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf ";
|
||||
$sql = "SELECT pf.price as price, pf.quantity as quantity";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf";
|
||||
$sql.= " WHERE pf.fk_soc = ".$fourn_id;
|
||||
$sql.= " AND pf.fk_product =" .$this->id;
|
||||
$sql.= " AND quantity <= ".$qty;
|
||||
$sql.= " ORDER BY quantity DESC";
|
||||
$sql.= " LIMIT 1";
|
||||
|
||||
dolibarr_syslog("Product::get_buyprice $fourn_id,$qty sql=$sql");
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$row = $this->db->fetch_row($resql);
|
||||
$this->buyprice = $row[0];
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user