Suite et casi fin de la gestion des arrondis

This commit is contained in:
Laurent Destailleur 2007-07-08 22:23:03 +00:00
parent 0b665020f5
commit dba3aa6bde
11 changed files with 463 additions and 392 deletions

View File

@ -90,7 +90,7 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->fournisseur->com
*/
if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->creer)
{
if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['idprod']))
if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['idprod']))
{
$commande = new CommandeFournisseur($db);
$ret=$commande->fetch($_POST["id"]);
@ -105,7 +105,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->cree
// Ecrase $pu par celui du produit
// Ecrase $desc par celui du produit
// Ecrase $txtva par celui du produit
// Ecrase $txtva par celui du produit
if ($_POST["idprod"] > 0)
{
$prod = new Product($db, $_POST['idprod']);
@ -113,7 +113,7 @@ if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->cree
$libelle = $prod->libelle;
// La description de la ligne est celle saisie ou
// La description de la ligne est celle saisie ou
// celle du produit si (non saisi + PRODUIT_CHANGE_PROD_DESC défini)
// \todo Ne faut-il pas rendre $conf->global->PRODUIT_CHANGE_PROD_DESC toujours a on
$desc=$_POST['np_desc'];
@ -137,7 +137,8 @@ if ($_POST['action'] == 'addligne' && $user->rights->fournisseur->commande->cree
$_POST['qty'],
$tva_tx,
$_POST['idprod'],
$_POST['remise_percent']
$_POST['remise_percent'],
'HT'
);
if ($result > 0)
@ -535,7 +536,7 @@ else
*/
if ($_GET["action"] == 'commande')
{
$date_com = mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$date_com = dolibarr_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$html->form_confirm("fiche.php?id=".$commande->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"],
$langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dolibarr_print_date($date_com,'day')),"confirm_commande");
print '<br />';
@ -657,7 +658,7 @@ else
print ' - '.$objp->label;
if ($objp->description) print '<br>'.nl2br($objp->description);
print "</td>";
print '<td align="center">'.$objp->tva_tx.'%</td>';
print '<td align="center">'.vatrate($objp->tva_tx).'%</td>';
print '<td align="center">'.$objp->qty.'</td>';
if ($objp->remise_percent > 0)
{

View File

@ -29,7 +29,7 @@
require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php");
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
require_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.product.class.php");
/**
@ -169,7 +169,7 @@ class Fournisseur extends Societe
if ($idc > 0)
{
$prod = new Product($this->db);
$prod = new ProductFournisseur($this->db);
$prod->fetch($fk_product);
$prod->fetch_fourn_data($this->id);

View File

@ -637,100 +637,106 @@ class CommandeFournisseur extends Commande
}
}
/**
* \brief Ajoute une ligne de commande
* \param desc Description
* \param pu Prix unitaire
* \param qty Quantité
* \param txtva Taux tva
* \param fk_product Id produit
* \param remise_percent Remise
* \param int <0 si ko, >0 si ok
*/
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0)
{
global $langs;
$qty = price2num($qty);
$pu = price2num($pu);
$desc = trim($desc);
$remise_percent = price2num($remise_percent);
dolibarr_syslog("Fournisseur.Commande.class::addline $desc, $pu, $qty, $txtva, $fk_product, $remise_percent");
/**
* \brief Ajoute une ligne de commande
* \param desc Description
* \param pu Prix unitaire
* \param qty Quantité
* \param txtva Taux tva
* \param fk_product Id produit
* \param remise_percent Remise
* \param price_base_type HT or TTC
* \param int <0 si ko, >0 si ok
*/
function addline($desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $price_base_type='HT')
{
global $langs;
// Clean parameters
$qty = price2num($qty);
$pu = price2num($pu);
$desc = trim($desc);
$remise_percent = price2num($remise_percent);
dolibarr_syslog("Fournisseur.Commande.class::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 ($fk_product > 0)
{
$prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0)
{
$result=$prod->get_buyprice($this->fourn_id,$qty);
if ($result > 0)
{
$label = $prod->libelle;
$desc = $prod->description;
$txtva = $prod->tva_tx;
$pu = $prod->fourn_pu;
$ref = $prod->ref;
}
if ($result == 0 || $result == -1)
{
$this->error="Aucun tarif trouvé pour cette quantité. Quantité saisie insuffisante ?";
$this->db->rollback();
dolibarr_syslog("Fournisseur.commande.class::addline result=".$result." - ".$this->error);
return -1;
}
if ($result < -1)
{
$this->error=$prod->error;
$this->db->rollback();
dolibarr_syslog("Fournisseur.commande.class::addline result=".$result." - ".$this->error);
return -1;
}
}
else
{
$this->error=$this->db->error();
return -1;
}
}
$remise = 0;
$price = price2num($pu);
$subprice = $price;
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($label) . "','" . addslashes($desc) . "',".$fk_product.",".price2num($price).", '$qty', $txtva, $remise_percent,'".price2num($subprice)."','".price2num($remise)."','".$ref."') ;";
dolibarr_syslog('Fournisseur.commande.class::addline sql='.$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$this->update_price();
if ($qty < 1 && ! $fk_product)
{
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Product"));
return -1;
}
if ($this->brouillon)
{
$this->db->begin();
if ($fk_product > 0)
{
$prod = new Product($this->db, $fk_product);
if ($prod->fetch($fk_product) > 0)
{
$result=$prod->get_buyprice($this->fourn_id,$qty);
if ($result > 0)
{
$label = $prod->libelle;
$desc = $prod->description;
$txtva = $prod->tva_tx;
$pu = $prod->fourn_pu;
$ref = $prod->ref;
}
if ($result == 0 || $result == -1)
{
$this->error="Aucun tarif trouvé pour cette quantité. Quantité saisie insuffisante ?";
$this->db->rollback();
dolibarr_syslog("Fournisseur.commande.class::addline result=".$result." - ".$this->error);
return -1;
}
if ($result < -1)
{
$this->error=$prod->error;
$this->db->rollback();
dolibarr_syslog("Fournisseur.commande.class::addline result=".$result." - ".$this->error);
return -1;
}
}
else
{
$this->error=$this->db->error();
return -1;
}
}
$subprice = price2num($pu,'MU');
// Champ obsolete
$remise = 0;
$price = $subprice;
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($label) . "','" . addslashes($desc) . "',".$fk_product.",".price2num($price,'MU').", '$qty', $txtva, $remise_percent,'".price2num($subprice,'MU')."','".price2num($remise)."','".$ref."') ;";
dolibarr_syslog('Fournisseur.commande.class::addline sql='.$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$this->update_price();
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
}
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
}
/**
* Dispatch un element de la commande dans un stock
*

View File

@ -27,89 +27,281 @@
\version $Revision$
*/
require_once DOL_DOCUMENT_ROOT."/product.class.php";
require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php";
/**
\class Product
\brief Classe permettant la gestion des produits prédéfinis
*/
require_once DOL_DOCUMENT_ROOT."/product.class.php";
require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.product.class.php";
class ProductFournisseur extends Product
{
var $db ;
var $db ;
var $id ;
var $fourn_ref;
var $fourn;
function ProductFournisseur($db)
{
$this->db = $db;
$this->fourn = new Fournisseur($this->db);
}
function fetch ($id, $id_fourn)
{
Product::Fetch($id);
$this->fourn->fetch($id_fourn);
var $id ;
var $fourn_ref;
var $fourn;
$sql = "SELECT ref_fourn";
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
$sql .=" WHERE fk_soc = ".$this->fourn->id;
$sql .= " AND fk_product = ".$this->id;
function ProductFournisseur($db)
{
$this->db = $db;
}
$resql = $this->db->query($sql) ;
if ( $resql )
{
$result = $this->db->fetch_array($resql);
$this->fourn_ref = $result["ref_fourn"];
$this->db->free($resql);
}
else
{
print "Errir";
}
/**
* \brief Délie un fournisseur au produit/service
* \param user utilisateur qui défait le lien
* \param id_fourn id du fournisseur
* \return int < 0 si erreur, > 0 si ok
*/
function remove_fournisseur($id_fourn)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur ";
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
return 0;
}
dolibarr_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/*
*
*
*/
function get_buyprice($qty)
{
Product::get_buyprice($this->fourn->id, $qty);
}
/*
*
*
*/
function update($ref, $qty, $buyprice, $user)
{
$this->fourn_ref = $ref;
function remove_product_fournisseur($rowid)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
$sql.= " WHERE rowid = ".$rowid;
/* Mise à jour du prix */
dolibarr_syslog("ProductFournisseur::remove_product_fournisseur sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
return -1;
}
}
Product::update_buyprice($this->fourn->id, $qty, $buyprice, $user);
/*
* \return int <0 si KO, 0 si non trouve, >0 si efface
*/
function remove_product_fournisseur_price($rowid)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " WHERE rowid = ".$rowid;
/* Mise à jour de la référence */
dolibarr_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
if ($this->db->affected_rows() > 0) return 1;
else return 0;
}
else
{
return -1;
}
}
/*
*
*
*/
function update($ref, $qty, $buyprice, $user)
{
$this->fourn_ref = $ref;
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur ";
$sql .= " SET ref_fourn = '" . $this->fourn_ref ."'";
$sql .= " WHERE fk_product = " . $this->id;
$sql .=" AND fk_soc = ".$this->fourn->id;
/* Mise à jour du prix */
$resql = $this->db->query($sql) ;
}
$this->update_buyprice($this->fourn->id, $qty, $buyprice, $user);
/* Mise à jour de la référence */
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur ";
$sql .= " SET ref_fourn = '" . $this->fourn_ref ."'";
$sql .= " WHERE fk_product = " . $this->id;
$sql .=" AND fk_soc = ".$this->fourn->id;
$resql = $this->db->query($sql) ;
}
/**
* \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 user Objet user de l'utilisateur qui modifie
* \param price_base_type HT or TTC
*/
function update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type='HT')
{
$error=0;
$this->db->begin();
// Supprime prix courant du fournisseur pour cette quantité
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price ";
$sql .= " WHERE ";
$sql .= " fk_product = ".$this->id;
$sql .= " AND fk_soc = ".$id_fourn;
$sql .= " AND quantity = ".$qty;
if ($this->db->query($sql))
{
// Ajoute prix courant du fournisseur pour cette quantité
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql .= " SET datec = now()";
$sql .= " ,fk_product = ".$this->id;
$sql .= " ,fk_soc = ".$id_fourn;
$sql .= " ,fk_user = ".$user->id;
$sql .= " ,price = ".price2num($buyprice);
$sql .= " ,quantity = ".$qty;
$sql .= " ,unitprice = ".price2num($buyprice/$qty,'MU');
dolibarr_syslog("ProductFournisseur::update_buyprice sql=".$sql);
if (! $this->db->query($sql))
{
$error++;
}
if (! $error) {
// Ajoute modif dans table log
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log ";
$sql .= " SET datec = now()";
$sql .= " ,fk_product = ".$this->id;
$sql .= " ,fk_soc = ".$id_fourn;
$sql .= " ,fk_user = ".$user->id;
$sql .= " ,price = ".price2num($buyprice);
$sql .= " ,quantity = ".$qty;
if (! $this->db->query($sql))
{
$error++;
}
}
if (! $error)
{
$this->db->commit();
return 0;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -2;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -1;
}
}
/**
\brief Modifie le prix d'achat pour un fournisseur par la référecne du produit chez le fournisseur
\param id_fourn Id du fournisseur
\param product_fourn_ref Ref du produit chez le fournisseur
\param qty Quantite pour lequel le prix est valide
\param buyprice Prix d'achat pour la quantité
\param user Objet user de l'utilisateur qui modifie
\return int <0 si KO, >0 si OK
*/
function UpdateBuyPriceByFournRef($id_fourn, $product_fourn_ref, $qty, $buyprice, $user, $price_base_type='HT')
{
$result=0;
// Recherche id produit pour cette ref et fournisseur
$sql = "SELECT fk_product";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
$sql.= " WHERE fk_soc ='".$id_fourn."'";
$sql.= " AND ref_fourn='".$product_fourn_ref."'";
if ($this->db->query($sql))
{
if ($obj = $this->db->fetch_object($resql))
{
// Met a jour prix pour la qté
$this->id = $obj->fk_product;
$result = $this->update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type);
}
}
return $result;
}
/**
* \brief Charge les informations relatives à un fournisseur
* \param fournid id du fournisseur
* \return int < 0 si erreur, > 0 si ok
*/
function fetch_fourn_data($fournid)
{
$sql = "SELECT rowid, ref_fourn";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";
$sql.= " WHERE fk_product = ".$this->id;
$sql.= " AND fk_soc = ".$fournid;
dolibarr_syslog("Product::fetch_fourn_data sql=".$sql);
$result = $this->db->query($sql) ;
if ($result)
{
$result = $this->db->fetch_array();
$this->ref_fourn = $result["ref_fourn"];
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Product::fetch_fourn_data error=".$this->error);
return -1;
}
}
/**
* \brief Charge les informations relatives à un prix de fournisseur
* \param rowid id ligne
* \return int < 0 si erreur, > 0 si ok
*/
function fetch_product_fournisseur_price($rowid)
{
$sql = "SELECT rowid, fk_soc, ref_fourn, price, quantity, unitprice";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql.= " WHERE rowid = ".$rowid;
dolibarr_syslog("Product::fetch_product_fournisseur_price sql=".$sql);
$resql = $this->db->query($sql) ;
if ($resql)
{
$obj = $this->db->fetch_object($resql);
$this->fourn_ref = $obj->ref_fourn;
$this->fourn_price = $obj->price;
$this->fourn_qty = $obj->qty;
$this->fourn_unitprice = $obj->unitprice;
return 1;
}
else
{
$this->error=$this->db->error();
dolibarr_syslog("Product::fetch_product_fournisseur_price error=".$this->error);
return -1;
}
}
}
?>

View File

@ -150,7 +150,7 @@ if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel
}
if ($_GET["action"] == 'remove_fourn')
{
$product = new Product($db);
$product = new ProductFournisseur($db);
if( $product->fetch($_GET["id"]) )
{
if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0)

View File

@ -60,8 +60,7 @@ if ($_GET["id"])
{
$product = new ProductFournisseur($db);
$result = $product->fetch($_GET["id"], $_GET["id_fourn"]);
$product->get_buyprice(1);
$product->get_buyprice($_GET["id_fourn"],1);
}
if ( $result == 0)

View File

@ -1114,11 +1114,9 @@ class Form
{
global $langs,$conf;
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration";
//$sql.= ", pf.ref_fourn";
$sql.= ", pfp.price as fprice, pfp.quantity";
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
$sql.= " pfp.price as fprice, pfp.quantity, pfp.unitprice";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
//$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
$sql.= " WHERE p.envente = 1";
if ($socid) $sql.= " AND pfp.fk_soc = ".$socid;
@ -1167,12 +1165,12 @@ class Form
$opt.= dolibarr_trunc($objp->label,18).' - ';
if ($objp->fprice != '')
{
$opt.= $objp->fprice;
$opt.= price($objp->fprice);
$opt.= $langs->trans("Currency".$conf->monnaie)."/".$objp->quantity.$langs->trans("Units");
if ($objp->quantity > 1)
{
$opt.=" - ";
$opt.= round($objp->fprice/$objp->quantity,4).$langs->trans("Currency".$conf->monnaie)."/".$langs->trans("Unit");
$opt.= price($objp->unitprice).$langs->trans("Currency".$conf->monnaie)."/".$langs->trans("Unit");
}
if ($objp->duration) $opt .= " - ".$objp->duration;
}

View File

@ -659,7 +659,7 @@ class Product
function get_buyprice($fourn_id, $qty)
{
$result = 0;
$sql = "SELECT pf.price as price, pf.quantity as quantity";
$sql = "SELECT pf.rowid, 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;
@ -719,112 +719,6 @@ class 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 user Objet user de l'utilisateur qui modifie
* \param price_base_type HT or TTC
*/
function update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type='HT')
{
$error=0;
$this->db->begin();
// Supprime prix courant du fournisseur pour cette quantité
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price ";
$sql .= " WHERE ";
$sql .= " fk_product = ".$this->id;
$sql .= " AND fk_soc = ".$id_fourn;
$sql .= " AND quantity = ".$qty;
if ($this->db->query($sql))
{
// Ajoute prix courant du fournisseur pour cette quantité
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price";
$sql .= " SET datec = now()";
$sql .= " ,fk_product = ".$this->id;
$sql .= " ,fk_soc = ".$id_fourn;
$sql .= " ,fk_user = ".$user->id;
$sql .= " ,price = ".price2num($buyprice);
$sql .= " ,quantity = ".$qty;
if (! $this->db->query($sql))
{
$error++;
}
if (! $error) {
// Ajoute modif dans table log
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log ";
$sql .= " SET datec = now()";
$sql .= " ,fk_product = ".$this->id;
$sql .= " ,fk_soc = ".$id_fourn;
$sql .= " ,fk_user = ".$user->id;
$sql .= " ,price = ".price2num($buyprice);
$sql .= " ,quantity = ".$qty;
if (! $this->db->query($sql))
{
$error++;
}
}
if (! $error)
{
$this->db->commit();
return 0;
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -2;
}
}
else
{
$this->error=$this->db->error()." sql=".$sql;
$this->db->rollback();
return -1;
}
}
/**
\brief Modifie le prix d'achat pour un fournisseur par la référecne du produit chez le fournisseur
\param id_fourn Id du fournisseur
\param product_fourn_ref Ref du produit chez le fournisseur
\param qty Quantite pour lequel le prix est valide
\param buyprice Prix d'achat pour la quantité
\param user Objet user de l'utilisateur qui modifie
\return int <0 si KO, >0 si OK
*/
function UpdateBuyPriceByFournRef($id_fourn, $product_fourn_ref, $qty, $buyprice, $user, $price_base_type='HT')
{
$result=0;
// Recherche id produit pour cette ref et fournisseur
$sql = "SELECT fk_product";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
$sql.= " WHERE fk_soc ='".$id_fourn."'";
$sql.= " AND ref_fourn='".$product_fourn_ref."'";
if ($this->db->query($sql))
{
if ($obj = $this->db->fetch_object($resql))
{
// Met a jour prix pour la qté
$this->id = $obj->fk_product;
$result = $this->update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type);
}
}
return $result;
}
/**
\brief Modifie le prix d'un produit/service
\param id Id du produit/service à modifier
@ -919,7 +813,8 @@ class Product
if ($id) $sql.= " WHERE rowid = '".$id."'";
if ($ref) $sql.= " WHERE ref = '".addslashes($ref)."'";
$result = $this->db->query($sql) ;
dolibarr_syslog("Product::fetch sql=".$sql);
$result = $this->db->query($sql);
if ( $result )
{
$result = $this->db->fetch_array();
@ -1742,28 +1637,6 @@ class Product
}
}
/**
* \brief Délie un fournisseur au produit/service
* \param user utilisateur qui défait le lien
* \param id_fourn id du fournisseur
* \return int < 0 si erreur, > 0 si ok
*/
function remove_fournisseur($user, $id_fourn)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur ";
$sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn;";
if ($this->db->query($sql) )
{
return 1;
}
else
{
dolibarr_print_error($this->db);
return -1;
}
}
/**
* \brief Recopie les prix d'un produit/service sur un autre
* \param fromId Id produit source
@ -2245,30 +2118,6 @@ class Product
}
}
/**
* \brief Charge les informations relatives à un fournisseur
* \param fournid id du fournisseur
* \return int < 0 si erreur, > 0 si ok
*/
function fetch_fourn_data($fournid)
{
$sql = "SELECT rowid, ref_fourn";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";
$sql.= " WHERE fk_product = ".$this->id;
$sql.= " AND fk_soc = ".$fournid;
$result = $this->db->query($sql) ;
if ($result)
{
$result = $this->db->fetch_array();
$this->ref_fourn = $result["ref_fourn"];
return 1;
}
else {
return -1;
}
}
/**
* \brief Déplace fichier uploadé sous le nom $files dans le répertoire sdir

View File

@ -33,7 +33,7 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/product.class.php");
require_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.product.class.php";
$langs->load("products");
$langs->load("suppliers");
@ -57,24 +57,19 @@ if ($conf->use_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['id
* Actions
*/
if ($_GET["action"] == 'remove_fourn')
if ($_GET["action"] == 'remove_pf')
{
$product = new Product($db);
if( $product->fetch($_GET["id"]) )
$product = new ProductFournisseur($db);
if ($product->fetch($_GET["id"]) > 0)
{
if ($_GET["qty"]) { // On supprime une quantité
if ($product->remove_price($user, $_GET["id_fourn"], $_GET["qty"]) > 0)
{
$_GET["action"] = '';
$mesg = '<div class="ok">'.$langs->trans("PriceRemoved").'.</div>';
}
else
{
$_GET["action"] = '';
}
}
else { // On supprime un fournisseur
if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0)
if ($_GET["rowid"] && $product->remove_product_fournisseur_price($_GET["rowid"]) > 0)
{
$_GET["action"] = '';
$mesg = '<div class="ok">'.$langs->trans("PriceRemoved").'.</div>';
}
else
{
if ($product->remove_fournisseur($_GET["socid"]) > 0)
{
$_GET["action"] = '';
$mesg = '<div class="ok">'.$langs->trans("SupplierRemoved").'.</div>';
@ -90,8 +85,9 @@ if ($_GET["action"] == 'remove_fourn')
if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$product = new Product($db);
if( $product->fetch($_GET["id"]) )
$product = new ProductFournisseur($db);
$result=$product->fetch($_REQUEST["id"]);
if ($result)
{
$db->begin();
@ -105,45 +101,47 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
}
if ($_POST["qty"])
{
if ($_POST["price"] >= 0)
{
$ret=$product->update_buyprice($_POST["id_fourn"], $_POST["qty"], $_POST["price"], $user);
if ($ret < 0)
{
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
if ($ret == -2)
{
$mesg='<div class="error">'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'</div>';
}
}
}
else
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'</div>';
}
}
else
{
$error++;
$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 && $_POST["qty"])
{
if ($_POST["price"] >= 0)
{
$ret=$product->update_buyprice($_POST["id_fourn"], $_POST["qty"], $_POST["price"], $user);
if ($ret < 0)
{
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
if ($ret == -2)
{
$mesg='<div class="error">'.$langs->trans("ProductHasAlreadyReferenceInThisSupplier").'</div>';
}
}
}
else
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Price")).'</div>';
}
}
else
{
$error++;
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Qty")).'</div>';
}
if (! $error)
{
$db->commit();
}
else {
else
{
$db->rollback();
}
}
@ -166,9 +164,10 @@ if ($_GET["id"] || $_GET["ref"])
{
if ($_GET["action"] <> 're-edit')
{
$product = new Product($db);
$product = new ProductFournisseur($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
$product->fetch_fourn_data($_GET["socid"]);
llxHeader("","",$langs->trans("CardProduct".$product->type));
}
@ -223,7 +222,7 @@ if ($_GET["id"] || $_GET["ref"])
{
$langs->load("suppliers");
if ($_GET["id_fourn"]) {
if ($_GET["rowid"]) {
print_fiche_titre($langs->trans("ChangeSupplierPrice"));
} else {
print_fiche_titre($langs->trans("AddSupplierPrice"));
@ -232,25 +231,45 @@ if ($_GET["id"] || $_GET["ref"])
print '<form action="fournisseurs.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="updateprice">';
if ($_GET["id_fourn"]) {
print '<input type="hidden" name="id_fourn" value="'.$_GET["id_fourn"].'">';
$product->fetch_fourn_data($_GET["id_fourn"]);
if ($_GET["rowid"])
{
print '<input type="hidden" name="id_fourn" value="'.$_GET["socid"].'">';
print '<input type="hidden" name="ref_fourn" value="'.$product->ref_fourn.'">';
} else {
}
else
{
print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="5">';
$html=new Form($db);
$html->select_societes('','id_fourn','fournisseur=1');
print '</td></tr>';
}
print '<tr><td>'.$langs->trans("Ref").'</td><td>';
print '<input class="flat" name="ref_fourn" size="12" value="">';
print '<tr><td>'.$langs->trans("SupplierRef").'</td><td>';
if ($_GET["rowid"])
{
print $product->ref_fourn;
}
else
{
print '<input class="flat" name="ref_fourn" size="12" value="'.$product->ref_fourn.'">';
}
print '</td>';
print '<td>'.$langs->trans("QtyMin").'</td>';
$quantity = $_GET["qty"] ? $_GET["qty"] : "1";
print '<td><input class="flat" name="qty" size="5" value="'.$quantity.'"></td>';
print '<td>';
if ($_GET["rowid"])
{
print '<input type="hidden" name="qty" value="'.$quantity.'">';
print $quantity;
}
else
{
print '<input class="flat" name="qty" size="5" value="'.$quantity.'">';
}
print '</td>';
print '<td>'.$langs->trans("PriceQtyHT").'</td>';
print '<td><input class="flat" name="price" size="8" value="'.price($_GET["price"]).'"></td></tr>';
$product->fetch_product_fournisseur_price($_GET["rowid"]);
print '<td><input class="flat" name="price" size="8" value="'.price($product->fourn_price).'"></td></tr>';
print '<tr><td colspan="6" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">';
print '&nbsp; &nbsp;';
@ -272,7 +291,7 @@ if ($_GET["id"] || $_GET["ref"])
if ($user->rights->produit->creer)
{
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$product->id.'&amp;action=add_price">';
print $langs->trans("AddSupplier").'</a>';
print $langs->trans("AddSupplierPrice").'</a>';
}
}
@ -281,14 +300,15 @@ if ($_GET["id"] || $_GET["ref"])
print '<br>';
if ($user->rights->fournisseur->lire) {
if ($user->rights->fournisseur->lire)
{
// Titre liste des fournisseurs
print '<table class="noborder" width="100%">';
if ($product->isproduct()) $nblignefour=4;
else $nblignefour=4;
print '<tr class="liste_titre"><td valign="top">';
print $langs->trans("Suppliers").'</td>';
print '<td>'.$langs->trans("Ref").'</td>';
print '<td>'.$langs->trans("SupplierRef").'</td>';
print '<td align="center">'.$langs->trans("QtyMin").'</td>';
print '<td align="right">'.$langs->trans("PriceQtyHT").'</td>';
print '<td align="right">'.$langs->trans("UnitPriceHT").'</td>';
@ -297,7 +317,8 @@ if ($_GET["id"] || $_GET["ref"])
// Liste des fournisseurs
$sql = "SELECT s.nom, s.rowid as socid,";
$sql.= "pf.ref_fourn, pfp.price, pfp.quantity";
$sql.= " pf.ref_fourn,";
$sql.= " pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product";
@ -335,15 +356,15 @@ if ($_GET["id"] || $_GET["ref"])
// Prix unitaire
print '<td align="right">';
print $objp->quantity?price($objp->price / $objp->quantity):"&nbsp;";
print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):"&nbsp;");
print '</td>';
// Modifier-Supprimer
print '<td align="center">';
if ($user->rights->produit->creer) {
print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=add_price&amp;id_fourn='.$objp->socid.'&amp;qty='.$objp->quantity.'&amp;price='.$objp->price.'">'.img_edit()."</a>";
print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=remove_fourn&amp;id_fourn='.$objp->socid.'&amp;qty='.$objp->quantity.'">';
print img_disable($langs->trans("Remove")).'</a>';
if ($user->rights->produit->creer)
{
print '<a href="fournisseurs.php?id='.$product->id.'&amp;socid='.$objp->socid.'&amp;action=add_price&amp;rowid='.$objp->rowid.'">'.img_edit()."</a>";
print '<a href="fournisseurs.php?id='.$product->id.'&amp;socid='.$objp->socid.'&amp;action=remove_pf&amp;rowid='.$objp->rowid.'">'.img_disable($langs->trans("Remove")).'</a>';
}
print '</td>';

View File

@ -742,6 +742,9 @@ drop table if exists `llx_accountingsystem_det`;
update llx_bank set label='(InitialBankBalance)' where fk_type='SOLD' and label in ('Balance','(Balance)','Solde','(Solde)');
alter table llx_product_fournisseur_price add unitprice double(16,8);
alter table llx_product_fournisseur_price add ref_fourn varchar(30) after fk_soc;
update llx_product_fournisseur_price set unitprice = ROUND(price/quantity,8) where unitprice IS NULL;
update llx_fichinter set tms=datec where tms < datec;
update llx_fichinter set tms=date_valid where tms < date_valid;

View File

@ -27,8 +27,10 @@ create table llx_product_fournisseur_price
tms timestamp,
fk_product integer,
fk_soc integer, -- lien sur llx_societe
ref_fourn varchar(30),
price double(16,8),
quantity double,
unitprice double(16,8),
fk_user integer
)type=innodb;