Fix: Fix a serious database default. Table llx_product_fournisseur was
linked with llx_product_fournisseur_price with a link 1-1 so was useless. I removed it. This reduce a lot of sophisticated code and will make import of prices easier. This also increase speed.
This commit is contained in:
parent
98ab396837
commit
47bb2171e0
@ -1207,16 +1207,14 @@ class Form
|
|||||||
$langs->load('stocks');
|
$langs->load('stocks');
|
||||||
|
|
||||||
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
|
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
|
||||||
$sql.= " pf.ref_fourn,";
|
$sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
|
||||||
$sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
|
|
||||||
$sql.= " s.nom";
|
$sql.= " s.nom";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
|
$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.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pf.fk_soc = s.rowid";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
|
|
||||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||||
$sql.= " AND p.tobuy = 1";
|
$sql.= " AND p.tobuy = 1";
|
||||||
if ($socid) $sql.= " AND pf.fk_soc = ".$socid;
|
if ($socid) $sql.= " AND pfp.fk_soc = ".$socid;
|
||||||
if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
|
if (strval($filtertype) != '') $sql.=" AND p.fk_product_type=".$filtertype;
|
||||||
if (! empty($filtre)) $sql.=" ".$filtre;
|
if (! empty($filtre)) $sql.=" ".$filtre;
|
||||||
// Add criteria on ref/label
|
// Add criteria on ref/label
|
||||||
@ -1224,14 +1222,14 @@ class Form
|
|||||||
{
|
{
|
||||||
if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
|
if (! empty($conf->global->PRODUCT_DONOTSEARCH_ANYWHERE))
|
||||||
{
|
{
|
||||||
$sql.=" AND (pf.ref_fourn LIKE '".$filterkey."%' OR p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%')";
|
$sql.=" AND (pfp.ref_fourn LIKE '".$filterkey."%' OR p.ref LIKE '".$filterkey."%' OR p.label LIKE '".$filterkey."%')";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql.=" AND (pf.ref_fourn LIKE '%".$filterkey."%' OR p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%')";
|
$sql.=" AND (pfp.ref_fourn LIKE '%".$filterkey."%' OR p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%')";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sql.= " ORDER BY pf.ref_fourn DESC";
|
$sql.= " ORDER BY pfp.ref_fourn DESC";
|
||||||
|
|
||||||
// Build output string
|
// Build output string
|
||||||
$outselect='';
|
$outselect='';
|
||||||
@ -1354,17 +1352,16 @@ class Form
|
|||||||
$langs->load('stocks');
|
$langs->load('stocks');
|
||||||
|
|
||||||
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
|
$sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
|
||||||
$sql.= " pf.ref_fourn,";
|
$sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
|
||||||
$sql.= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
|
|
||||||
$sql.= " s.nom";
|
$sql.= " s.nom";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product as p";
|
$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.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = pf.fk_soc";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pf.rowid = pfp.fk_product_fournisseur";
|
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||||
$sql.= " WHERE p.tobuy = 1";
|
$sql.= " AND p.tobuy = 1";
|
||||||
$sql.= " AND s.fournisseur = 1";
|
$sql.= " AND s.fournisseur = 1";
|
||||||
$sql.= " AND p.rowid = ".$productid;
|
$sql.= " AND p.rowid = ".$productid;
|
||||||
$sql.= " ORDER BY s.nom, pf.ref_fourn DESC";
|
$sql.= " ORDER BY s.nom, pfp.ref_fourn DESC";
|
||||||
|
|
||||||
dol_syslog("Form::select_product_fourn_price sql=".$sql,LOG_DEBUG);
|
dol_syslog("Form::select_product_fourn_price sql=".$sql,LOG_DEBUG);
|
||||||
$result=$this->db->query($sql);
|
$result=$this->db->query($sql);
|
||||||
|
|||||||
@ -78,12 +78,14 @@ class Fournisseur extends Societe
|
|||||||
return $num;
|
return $num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FIXME This returns number of prices, not number of products. Is it what we want ?
|
||||||
|
*/
|
||||||
function NbProduct()
|
function NbProduct()
|
||||||
{
|
{
|
||||||
$sql = "SELECT count(pf.rowid)";
|
$sql = "SELECT count(pfp.rowid)";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as pf,";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= " ".MAIN_DB_PREFIX."product_fournisseur_price as ppf";
|
$sql .= " WHERE pfp.fk_soc = ".$this->id;
|
||||||
$sql .= " WHERE fk_soc = ".$this->id." AND ppf.fk_product_fournisseur = pf.rowid";
|
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ( $resql )
|
if ( $resql )
|
||||||
|
|||||||
@ -1822,7 +1822,7 @@ class CommandeFournisseurLigne extends OrderLine
|
|||||||
var $libelle; // Label produit
|
var $libelle; // Label produit
|
||||||
var $product_desc; // Description produit
|
var $product_desc; // Description produit
|
||||||
|
|
||||||
// From llx_product_fournisseur
|
// From llx_product_fournisseur_price
|
||||||
var $ref_fourn; // Ref supplier
|
var $ref_fourn; // Ref supplier
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -384,10 +384,8 @@ class FactureFournisseur extends Facture
|
|||||||
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
|
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
|
||||||
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type';
|
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type';
|
||||||
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
|
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
|
||||||
//$sql.= ', pf.ref_fourn';
|
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
|
||||||
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
|
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
|
||||||
//$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur as pf ON f.fk_product = pf.fk_product';
|
|
||||||
$sql.= ' WHERE fk_facture_fourn='.$this->id;
|
$sql.= ' WHERE fk_facture_fourn='.$this->id;
|
||||||
|
|
||||||
dol_syslog("FactureFournisseur::fetch_lines sql=".$sql, LOG_DEBUG);
|
dol_syslog("FactureFournisseur::fetch_lines sql=".$sql, LOG_DEBUG);
|
||||||
|
|||||||
@ -72,87 +72,31 @@ class ProductFournisseur extends Product
|
|||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Search all links
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||||
$sql = "SELECT rowid";
|
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
|
||||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql);
|
dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql);
|
||||||
$resql=$this->db->query($sql);
|
$resql2=$this->db->query($sql);
|
||||||
if ($resql)
|
if (! $resql2)
|
||||||
{
|
{
|
||||||
// For each link, delete price line
|
$this->error=$this->db->lasterror();
|
||||||
while ($obj=$this->db->fetch_object($resql))
|
dol_syslog(get_class($this)."::remove_fournisseur ".$this->error, LOG_ERR);
|
||||||
{
|
$ok=0;
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
|
||||||
$sql.= " WHERE fk_product_fournisseur = ".$obj->rowid;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql);
|
|
||||||
$resql2=$this->db->query($sql);
|
|
||||||
if (! $resql2)
|
|
||||||
{
|
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
dol_syslog(get_class($this)."::remove_fournisseur ".$this->error, LOG_ERR);
|
|
||||||
$ok=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now delete all link supplier-product (they have no more childs)
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
|
||||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql);
|
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
if (! $resql)
|
|
||||||
{
|
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
dol_syslog(get_class($this)."::remove_fournisseur ".$this->error, LOG_ERR);
|
|
||||||
$ok=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($ok)
|
|
||||||
{
|
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->db->rollback();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
if ($ok)
|
||||||
$this->db->rollback();
|
|
||||||
dol_print_error($this->db);
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove supplier product
|
|
||||||
*
|
|
||||||
* @param rowid Product id
|
|
||||||
* @return int < 0 if error, > 0 if ok
|
|
||||||
*/
|
|
||||||
function remove_product_fournisseur($rowid)
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
|
||||||
$sql.= " WHERE rowid = ".$rowid;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::remove_product_fournisseur sql=".$sql);
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
{
|
||||||
|
$this->db->commit();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a price for a couple supplier-product
|
* Remove a price for a couple supplier-product
|
||||||
*
|
*
|
||||||
@ -172,54 +116,8 @@ class ProductFournisseur extends Product
|
|||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
// Remove all entries with no childs
|
$this->db->commit();
|
||||||
$sql = "SELECT pf.rowid";
|
return 1;
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.fk_product_fournisseur = pf.rowid";
|
|
||||||
$sql.= " WHERE pfp.rowid IS NULL";
|
|
||||||
$sql.= " AND pf.entity = ".$conf->entity;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::remove_product_fournisseur_price sql=".$sql);
|
|
||||||
$resql = $this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
$ok=1;
|
|
||||||
|
|
||||||
while ($obj=$this->db->fetch_object($resql))
|
|
||||||
{
|
|
||||||
$rowidpf=$obj->rowid;
|
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
|
||||||
$sql.= " WHERE rowid = ".$rowidpf;
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::remove_product_fournisseur_price sql=".$sql);
|
|
||||||
$resql2 = $this->db->query($sql);
|
|
||||||
if (! $resql2)
|
|
||||||
{
|
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
dol_syslog(get_class($this)."::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
|
||||||
$ok=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($ok)
|
|
||||||
{
|
|
||||||
$this->db->commit();
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->db->rollback();
|
|
||||||
return -3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->error=$this->db->lasterror();
|
|
||||||
dol_syslog(get_class($this)."::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
|
||||||
$this->db->rollback();
|
|
||||||
return -2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -234,16 +132,18 @@ class ProductFournisseur extends Product
|
|||||||
/**
|
/**
|
||||||
* Modify the purchase price for a supplier
|
* Modify the purchase price for a supplier
|
||||||
*
|
*
|
||||||
* @param qty Min quantity for which price is valid
|
* @param int $qty Min quantity for which price is valid
|
||||||
* @param buyprice Purchase price for the quantity min
|
* @param float $buyprice Purchase price for the quantity min
|
||||||
* @param user Object user user made changes
|
* @param User $user Object user user made changes
|
||||||
* @param price_base_type HT or TTC
|
* @param string $price_base_type HT or TTC
|
||||||
* @param fourn Supplier
|
* @param Societe $fourn Supplier
|
||||||
* @param availability Product availability
|
* @param int $availability Product availability
|
||||||
|
* @param string $ref_fourn Supplier ref
|
||||||
|
* @return int >0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function update_buyprice($qty, $buyprice, $user, $price_base_type='HT', $fourn, $availability)
|
function update_buyprice($qty, $buyprice, $user, $price_base_type, $fourn, $availability, $ref_fourn)
|
||||||
{
|
{
|
||||||
global $mysoc;
|
global $conf,$mysoc;
|
||||||
|
|
||||||
// Clean parameter
|
// Clean parameter
|
||||||
$buyprice=price2num($buyprice);
|
$buyprice=price2num($buyprice);
|
||||||
@ -259,11 +159,6 @@ class ProductFournisseur extends Product
|
|||||||
{
|
{
|
||||||
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
|
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$sql.= " WHERE fk_product_fournisseur = ".$this->product_fourn_id;
|
|
||||||
$sql.= " AND quantity = ".$qty;
|
|
||||||
}
|
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
@ -279,14 +174,17 @@ class ProductFournisseur extends Product
|
|||||||
|
|
||||||
// Ajoute prix courant du fournisseur pour cette quantite
|
// Ajoute prix courant du fournisseur pour cette quantite
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
|
||||||
$sql.= "datec, fk_product_fournisseur, fk_user, price, quantity, unitprice, fk_availability)";
|
$sql.= "datec, fk_product, fk_soc, ref_fourn, fk_user, price, quantity, unitprice, fk_availability, entity)";
|
||||||
$sql.= " values('".$this->db->idate($now)."',";
|
$sql.= " values('".$this->db->idate($now)."',";
|
||||||
$sql.= " ".$this->product_fourn_id.",";
|
$sql.= " ".$this->id.",";
|
||||||
|
$sql.= " ".$fourn->id.",";
|
||||||
|
$sql.= " '".$this->db->escape($ref_fourn)."',";
|
||||||
$sql.= " ".$user->id.",";
|
$sql.= " ".$user->id.",";
|
||||||
$sql.= " ".price2num($buyprice).",";
|
$sql.= " ".price2num($buyprice).",";
|
||||||
$sql.= " ".$qty.",";
|
$sql.= " ".$qty.",";
|
||||||
$sql.= " ".$unitBuyPrice.",";
|
$sql.= " ".$unitBuyPrice.",";
|
||||||
$sql.= " ".$availability;
|
$sql.= " ".$availability.",";
|
||||||
|
$sql.= $conf->entity;
|
||||||
$sql.=")";
|
$sql.=")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::update_buyprice sql=".$sql);
|
dol_syslog(get_class($this)."::update_buyprice sql=".$sql);
|
||||||
@ -295,7 +193,7 @@ 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(";
|
||||||
@ -313,6 +211,7 @@ class ProductFournisseur extends Product
|
|||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -335,44 +234,6 @@ class ProductFournisseur extends Product
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Changes the purchase price for a supplier of the product in the reference supplier
|
|
||||||
*
|
|
||||||
* @param id_fourn Supplier ID
|
|
||||||
* @param product_fourn_ref Supplier ref product
|
|
||||||
* @param qty Amount for which the price is valid
|
|
||||||
* @param buyprice Purchase price for the quantity
|
|
||||||
* @param user Object user user made changes
|
|
||||||
* @return int <0 if KO, >0 if OK
|
|
||||||
*/
|
|
||||||
function UpdateBuyPriceByFournRef($id_fourn, $product_fourn_ref, $qty, $buyprice, $user, $price_base_type='HT')
|
|
||||||
{
|
|
||||||
global $conf;
|
|
||||||
|
|
||||||
$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."'";
|
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
|
||||||
|
|
||||||
$resql=$this->db->query($sql);
|
|
||||||
if ($resql)
|
|
||||||
{
|
|
||||||
if ($obj = $this->db->fetch_object($resql))
|
|
||||||
{
|
|
||||||
// Met a jour prix pour la qte
|
|
||||||
$this->id = $obj->fk_product;
|
|
||||||
$result = $this->update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load information about a provider
|
* Load information about a provider
|
||||||
*
|
*
|
||||||
@ -387,7 +248,7 @@ class ProductFournisseur extends Product
|
|||||||
if (empty($fournid)) return -1;
|
if (empty($fournid)) return -1;
|
||||||
|
|
||||||
$sql = "SELECT rowid, ref_fourn";
|
$sql = "SELECT rowid, ref_fourn";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||||
$sql.= " WHERE fk_product = ".$this->id;
|
$sql.= " WHERE fk_product = ".$this->id;
|
||||||
$sql.= " AND fk_soc = ".$fournid;
|
$sql.= " AND fk_soc = ".$fournid;
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
@ -398,7 +259,7 @@ class ProductFournisseur extends Product
|
|||||||
{
|
{
|
||||||
$result = $this->db->fetch_array($result);
|
$result = $this->db->fetch_array($result);
|
||||||
$this->ref_fourn = $result["ref_fourn"];
|
$this->ref_fourn = $result["ref_fourn"];
|
||||||
$this->product_fourn_id = $result["rowid"];
|
$this->product_fourn_price_id = $result["rowid"];
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -417,12 +278,10 @@ class ProductFournisseur extends Product
|
|||||||
*/
|
*/
|
||||||
function fetch_product_fournisseur_price($rowid)
|
function fetch_product_fournisseur_price($rowid)
|
||||||
{
|
{
|
||||||
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability,";
|
||||||
$sql.= ", pf.rowid as product_fourn_id, pf.fk_soc, pf.ref_fourn, pf.fk_product";
|
$sql.= " pfp.fk_soc, pfp.ref_fourn, pfp.fk_product";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
|
||||||
$sql.= " WHERE pfp.rowid = ".$rowid;
|
$sql.= " WHERE pfp.rowid = ".$rowid;
|
||||||
$sql.= " AND pf.rowid = pfp.fk_product_fournisseur";
|
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this)."::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
@ -432,7 +291,6 @@ class ProductFournisseur extends Product
|
|||||||
if ($obj)
|
if ($obj)
|
||||||
{
|
{
|
||||||
$this->product_fourn_price_id = $rowid;
|
$this->product_fourn_price_id = $rowid;
|
||||||
$this->product_fourn_id = $obj->product_fourn_id;
|
|
||||||
$this->fourn_ref = $obj->ref_fourn;
|
$this->fourn_ref = $obj->ref_fourn;
|
||||||
$this->fourn_price = $obj->price;
|
$this->fourn_price = $obj->price;
|
||||||
$this->fourn_qty = $obj->quantity;
|
$this->fourn_qty = $obj->quantity;
|
||||||
@ -462,26 +320,24 @@ class ProductFournisseur extends Product
|
|||||||
* @param int $rowid id du produit
|
* @param int $rowid id du produit
|
||||||
* @return array Array of ProductFournisseur
|
* @return array Array of ProductFournisseur
|
||||||
*/
|
*/
|
||||||
function fetch_product_fournisseur($prodid)
|
function list_product_fournisseur_price($prodid)
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
// Suppliers list
|
// Suppliers list
|
||||||
$sql = "SELECT s.nom as supplier_name, ";
|
$sql = "SELECT s.nom as supplier_name, ";
|
||||||
$sql.= " s.rowid as fourn_id,";
|
$sql.= " s.rowid as fourn_id,";
|
||||||
$sql.= " pf.ref_fourn,";
|
$sql.= " pfp.ref_fourn,";
|
||||||
$sql.= " pfp.rowid as product_fourn_pri_id, ";
|
$sql.= " pfp.rowid as product_fourn_pri_id, ";
|
||||||
$sql.= " pf.rowid as product_fourn_id, ";
|
|
||||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||||
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON pf.fk_soc = s.rowid ";
|
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
$sql.= " ON pfp.fk_soc = s.rowid";
|
||||||
$sql.= " ON pf.rowid = pfp.fk_product_fournisseur";
|
|
||||||
$sql.= " WHERE s.entity = ".$conf->entity;
|
$sql.= " WHERE s.entity = ".$conf->entity;
|
||||||
$sql.= " AND pf.fk_product = ".$prodid;
|
$sql.= " AND pfp.fk_product = ".$prodid;
|
||||||
$sql.= " ORDER BY s.nom, pfp.quantity";
|
$sql.= " ORDER BY s.nom, pfp.quantity";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch_product_fournisseur sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this)."::list_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|
||||||
@ -526,7 +382,7 @@ class ProductFournisseur extends Product
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error=$this->db->error();
|
$this->error=$this->db->error();
|
||||||
dol_syslog(get_class($this)."::fetch_product_fournisseur error=".$this->error, LOG_ERR);
|
dol_syslog(get_class($this)."::list_product_fournisseur_price error=".$this->error, LOG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -551,18 +407,15 @@ class ProductFournisseur extends Product
|
|||||||
$this->fourn_name = '';
|
$this->fourn_name = '';
|
||||||
$this->id = '';
|
$this->id = '';
|
||||||
|
|
||||||
$sql = "SELECT s.nom as supplier_name, ";
|
$sql = "SELECT s.nom as supplier_name,";
|
||||||
$sql.= " s.rowid as fourn_id,";
|
$sql.= " s.rowid as fourn_id,";
|
||||||
$sql.= " pf.ref_fourn,";
|
$sql.= " pfp.ref_fourn,";
|
||||||
$sql.= " pfp.rowid as product_fourn_pri_id, ";
|
$sql.= " pfp.rowid as product_fourn_price_id,";
|
||||||
$sql.= " pf.rowid as product_fourn_id, ";
|
|
||||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice";
|
$sql.= " pfp.price, pfp.quantity, pfp.unitprice";
|
||||||
$sql.= " FROM (".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf)";
|
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
|
||||||
$sql.= " ON pf.rowid = pfp.fk_product_fournisseur";
|
|
||||||
$sql.= " WHERE s.entity = ".$conf->entity;
|
$sql.= " WHERE s.entity = ".$conf->entity;
|
||||||
$sql.= " AND pf.fk_product = ".$prodid;
|
$sql.= " AND pfp.fk_product = ".$prodid;
|
||||||
$sql.= " AND pf.fk_soc = s.rowid";
|
$sql.= " AND pfp.fk_soc = s.rowid";
|
||||||
$sql.= " ORDER BY pfp.unitprice";
|
$sql.= " ORDER BY pfp.unitprice";
|
||||||
$sql.= $this->db->plimit(1);
|
$sql.= $this->db->plimit(1);
|
||||||
|
|
||||||
@ -572,8 +425,7 @@ class ProductFournisseur extends Product
|
|||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
$record = $this->db->fetch_array($resql);
|
$record = $this->db->fetch_array($resql);
|
||||||
$this->product_fourn_price_id = $record["product_fourn_pri_id"];
|
$this->product_fourn_price_id = $record["product_fourn_price_id"];
|
||||||
$this->product_fourn_id = $record["product_fourn_id"];
|
|
||||||
$this->fourn_ref = $record["ref_fourn"];
|
$this->fourn_ref = $record["ref_fourn"];
|
||||||
$this->fourn_price = $record["price"];
|
$this->fourn_price = $record["price"];
|
||||||
$this->fourn_qty = $record["quantity"];
|
$this->fourn_qty = $record["quantity"];
|
||||||
|
|||||||
@ -456,7 +456,9 @@ if ($action == 'addline')
|
|||||||
|
|
||||||
if ($_POST['idprodfournprice']) // > 0 or -1
|
if ($_POST['idprodfournprice']) // > 0 or -1
|
||||||
{
|
{
|
||||||
|
$product=new Product($db);
|
||||||
$idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']);
|
$idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']);
|
||||||
|
|
||||||
if ($idprod > 0)
|
if ($idprod > 0)
|
||||||
{
|
{
|
||||||
$result=$product->fetch($idprod);
|
$result=$product->fetch($idprod);
|
||||||
@ -465,8 +467,6 @@ if ($action == 'addline')
|
|||||||
// $label = '['.$product->ref.'] - '. $product->libelle;
|
// $label = '['.$product->ref.'] - '. $product->libelle;
|
||||||
$label = $product->libelle;
|
$label = $product->libelle;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$tvatx=get_default_tva($societe,$mysoc,$product->id);
|
$tvatx=get_default_tva($societe,$mysoc,$product->id);
|
||||||
|
|
||||||
$localtax1tx= get_localtax($tvatx, 1, $societe);
|
$localtax1tx= get_localtax($tvatx, 1, $societe);
|
||||||
|
|||||||
@ -88,17 +88,15 @@ if ($fourn_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type,";
|
$sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type,";
|
||||||
$sql .= " pf.fk_soc, pf.ref_fourn,";
|
$sql .= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
|
||||||
$sql .= " ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
|
|
||||||
$sql .= " s.rowid as socid, s.nom";
|
$sql .= " s.rowid as socid, s.nom";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
|
||||||
if ($catid)
|
if ($catid)
|
||||||
{
|
{
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
|
||||||
}
|
}
|
||||||
$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 ppf ON p.rowid = ppf.fk_product";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = pf.fk_soc";
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
|
||||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON ppf.fk_product_fournisseur = pf.rowid";
|
|
||||||
|
|
||||||
if ($_POST["mode"] == 'search')
|
if ($_POST["mode"] == 'search')
|
||||||
{
|
{
|
||||||
@ -118,7 +116,7 @@ else
|
|||||||
}
|
}
|
||||||
if ($sRefSupplier)
|
if ($sRefSupplier)
|
||||||
{
|
{
|
||||||
$sql .= " AND pf.ref_fourn like '%".$sRefSupplier."%'";
|
$sql .= " AND ppf.ref_fourn like '%".$sRefSupplier."%'";
|
||||||
}
|
}
|
||||||
if ($snom)
|
if ($snom)
|
||||||
{
|
{
|
||||||
@ -128,11 +126,10 @@ else
|
|||||||
{
|
{
|
||||||
$sql .= " AND cp.fk_categorie = ".$catid;
|
$sql .= " AND cp.fk_categorie = ".$catid;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if ($fourn_id > 0)
|
if ($fourn_id > 0)
|
||||||
{
|
{
|
||||||
$sql .= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
|
$sql .= " AND ppf.fk_soc = ".$fourn_id;
|
||||||
}
|
}
|
||||||
$sql .= " ORDER BY ".$sortfield." ".$sortorder;
|
$sql .= " ORDER BY ".$sortfield." ".$sortorder;
|
||||||
$sql .= $db->plimit($limit + 1 ,$offset);
|
$sql .= $db->plimit($limit + 1 ,$offset);
|
||||||
|
|||||||
@ -48,3 +48,19 @@ INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active)
|
|||||||
INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (220, 'CAP5', 'Format Canadian P5', '140', '215', 'mm', 1);
|
INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (220, 'CAP5', 'Format Canadian P5', '140', '215', 'mm', 1);
|
||||||
INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (225, 'CAP6', 'Format Canadian P6', '107', '140', 'mm', 1);
|
INSERT INTO llx_c_paper_format (rowid, code, label, width, height, unit, active) VALUES (225, 'CAP6', 'Format Canadian P6', '107', '140', 'mm', 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD COLUMN fk_product integer after tms;
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD COLUMN fk_soc integer after fk_product;
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD COLUMN ref_fourn varchar(30) after fk_soc;
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD COLUMN entity integer DEFAULT 1 NOT NULL;
|
||||||
|
|
||||||
|
UPDATE llx_product_fournisseur_price as a, llx_product_fournisseur as b SET a.fk_product = b.fk_product, a.fk_soc = b.fk_soc, a.ref_fourn = b.ref_fourn, a.entity = b.entity WHERE a.fk_product_fournisseur = b.rowid AND (a.fk_product IS NULL OR a.fk_soc IS NULL OR a.fk_product = 0 OR a.fk_soc = 0);
|
||||||
|
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD UNIQUE INDEX uk_product_fournisseur_price_ref (ref_fourn, fk_soc, entity);
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fourn_price_fk_product (fk_product, entity);
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fourn_price_fk_soc (fk_soc, entity);
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
|
||||||
|
|
||||||
|
ALTER TABLE llx_product_fournisseur_price DROP FOREIGN KEY fk_product_fournisseur_price_fk_product_fournisseur;
|
||||||
|
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
-- ============================================================================
|
|
||||||
-- Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
-- Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
||||||
-- Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
|
|
||||||
--
|
|
||||||
-- This program is free software; you can redistribute it and/or modify
|
|
||||||
-- it under the terms of the GNU General Public License as published by
|
|
||||||
-- the Free Software Foundation; either version 2 of the License, or
|
|
||||||
-- (at your option) any later version.
|
|
||||||
--
|
|
||||||
-- This program is distributed in the hope that it will be useful,
|
|
||||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
-- GNU General Public License for more details.
|
|
||||||
--
|
|
||||||
-- You should have received a copy of the GNU General Public License
|
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
--
|
|
||||||
-- ============================================================================
|
|
||||||
|
|
||||||
|
|
||||||
ALTER TABLE llx_product_fournisseur ADD UNIQUE INDEX uk_product_fournisseur_ref (ref_fourn, fk_soc, entity);
|
|
||||||
|
|
||||||
ALTER TABLE llx_product_fournisseur ADD INDEX idx_product_fourn_fk_product (fk_product, entity);
|
|
||||||
ALTER TABLE llx_product_fournisseur ADD INDEX idx_product_fourn_fk_soc (fk_soc, entity);
|
|
||||||
|
|
||||||
ALTER TABLE llx_product_fournisseur ADD CONSTRAINT fk_product_fournisseur_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
-- ============================================================================
|
|
||||||
-- Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
|
||||||
-- Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
|
||||||
-- Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
|
|
||||||
--
|
|
||||||
-- This program is free software; you can redistribute it and/or modify
|
|
||||||
-- it under the terms of the GNU General Public License as published by
|
|
||||||
-- the Free Software Foundation; either version 2 of the License, or
|
|
||||||
-- (at your option) any later version.
|
|
||||||
--
|
|
||||||
-- This program is distributed in the hope that it will be useful,
|
|
||||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
-- GNU General Public License for more details.
|
|
||||||
--
|
|
||||||
-- You should have received a copy of the GNU General Public License
|
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
--
|
|
||||||
-- ============================================================================
|
|
||||||
|
|
||||||
create table llx_product_fournisseur
|
|
||||||
(
|
|
||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
datec datetime,
|
|
||||||
tms timestamp,
|
|
||||||
fk_product integer,
|
|
||||||
fk_soc integer,
|
|
||||||
ref_fourn varchar(30),
|
|
||||||
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
|
||||||
fk_user_author integer
|
|
||||||
)ENGINE=innodb;
|
|
||||||
|
|
||||||
--
|
|
||||||
-- List of codes for the field entity
|
|
||||||
--
|
|
||||||
-- 1 : first company product
|
|
||||||
-- 2 : second company product
|
|
||||||
-- 3 : etc...
|
|
||||||
--
|
|
||||||
@ -19,9 +19,16 @@
|
|||||||
|
|
||||||
|
|
||||||
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fournisseur_price_fk_user (fk_user);
|
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fournisseur_price_fk_user (fk_user);
|
||||||
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fournisseur_price_fk_product_fournisseur (fk_product_fournisseur);
|
--ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fournisseur_price_fk_product_fournisseur (fk_product_fournisseur);
|
||||||
|
|
||||||
ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
|
ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
|
||||||
ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_product_fournisseur FOREIGN KEY (fk_product_fournisseur) REFERENCES llx_product_fournisseur (rowid);
|
--ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_product_fournisseur FOREIGN KEY (fk_product_fournisseur) REFERENCES llx_product_fournisseur (rowid);
|
||||||
|
|
||||||
|
-- Added to remove table llx_product_fournisseur
|
||||||
|
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD UNIQUE INDEX uk_product_fournisseur_price_ref (ref_fourn, fk_soc, entity);
|
||||||
|
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fourn_price_fk_product (fk_product, entity);
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD INDEX idx_product_fourn_price_fk_soc (fk_soc, entity);
|
||||||
|
|
||||||
|
ALTER TABLE llx_product_fournisseur_price ADD CONSTRAINT fk_product_fournisseur_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid);
|
||||||
|
|||||||
@ -22,11 +22,14 @@ create table llx_product_fournisseur_price
|
|||||||
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
rowid integer AUTO_INCREMENT PRIMARY KEY,
|
||||||
datec datetime,
|
datec datetime,
|
||||||
tms timestamp,
|
tms timestamp,
|
||||||
fk_product_fournisseur integer NOT NULL,
|
fk_product_fournisseur integer NOT NULL, -- deprecated
|
||||||
|
fk_product integer,
|
||||||
|
fk_soc integer,
|
||||||
|
ref_fourn varchar(30),
|
||||||
fk_availability integer,
|
fk_availability integer,
|
||||||
price double(24,8) DEFAULT 0,
|
price double(24,8) DEFAULT 0,
|
||||||
quantity double,
|
quantity double,
|
||||||
unitprice double(24,8) DEFAULT 0,
|
unitprice double(24,8) DEFAULT 0,
|
||||||
fk_user integer
|
fk_user integer,
|
||||||
|
entity integer DEFAULT 1 NOT NULL, -- multi company id
|
||||||
)ENGINE=innodb;
|
)ENGINE=innodb;
|
||||||
|
|||||||
@ -310,7 +310,7 @@ class ActionsCardService extends Product
|
|||||||
if ($_GET["fourn_id"] > 0)
|
if ($_GET["fourn_id"] > 0)
|
||||||
{
|
{
|
||||||
$fourn_id = $_GET["fourn_id"];
|
$fourn_id = $_GET["fourn_id"];
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
}
|
}
|
||||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||||
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
|
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
|
||||||
@ -335,7 +335,7 @@ class ActionsCardService extends Product
|
|||||||
}
|
}
|
||||||
if ($fourn_id > 0)
|
if ($fourn_id > 0)
|
||||||
{
|
{
|
||||||
$sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id;
|
$sql.= " AND p.rowid = pfp.fk_product AND pfp.fk_soc = ".$fourn_id;
|
||||||
}
|
}
|
||||||
// Insert categ filter
|
// Insert categ filter
|
||||||
if ($search_categ)
|
if ($search_categ)
|
||||||
|
|||||||
@ -37,7 +37,7 @@ class Product extends CommonObject
|
|||||||
public $element='product';
|
public $element='product';
|
||||||
public $table_element='product';
|
public $table_element='product';
|
||||||
public $fk_element='fk_product';
|
public $fk_element='fk_product';
|
||||||
public $childtables=array('propaldet','commandedet','facturedet','contratdet','product_fournisseur');
|
public $childtables=array('propaldet','commandedet','facturedet','contratdet','product_fournisseur_price');
|
||||||
protected $isnolinkedbythird = 1; // No field fk_soc
|
protected $isnolinkedbythird = 1; // No field fk_soc
|
||||||
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
|
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
|
||||||
|
|
||||||
@ -519,11 +519,11 @@ class Product extends CommonObject
|
|||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// Delete supplier prices log
|
// Delete supplier prices log
|
||||||
if (! $error)
|
/*if (! $error)
|
||||||
{
|
{
|
||||||
$sql = 'DELETE pfpl';
|
$sql = 'DELETE pfpl';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price_log as pfpl, '.MAIN_DB_PREFIX.'product_fournisseur as pf';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price_log as pfpl, '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp';
|
||||||
$sql.= ' WHERE pfpl.fk_product_fournisseur = pf.rowid';
|
$sql.= ' WHERE pfpl.fk_product_fournisseur = pfp.rowid';
|
||||||
$sql.= ' AND pf.fk_product = '.$id;
|
$sql.= ' AND pf.fk_product = '.$id;
|
||||||
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
|
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
@ -533,15 +533,14 @@ class Product extends CommonObject
|
|||||||
$this->error = $this->db->lasterror();
|
$this->error = $this->db->lasterror();
|
||||||
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
|
dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Delete supplier prices
|
// Delete supplier prices
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
$sql = 'DELETE pfp';
|
$sql = 'DELETE pfp';
|
||||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp, '.MAIN_DB_PREFIX.'product_fournisseur as pf';
|
$sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp';
|
||||||
$sql.= ' WHERE pfp.fk_product_fournisseur = pf.rowid';
|
$sql.= ' WHERE pfp.fk_product = '.$id;
|
||||||
$sql.= ' AND pf.fk_product = '.$id;
|
|
||||||
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
|
dol_syslog(get_class($this).'::delete sql='.$sql, LOG_DEBUG);
|
||||||
$result = $this->db->query($sql);
|
$result = $this->db->query($sql);
|
||||||
if (! $result)
|
if (! $result)
|
||||||
@ -819,10 +818,9 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$result = 0;
|
$result = 0;
|
||||||
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity,";
|
$sql = "SELECT pfp.rowid, pfp.price as price, pfp.quantity as quantity,";
|
||||||
$sql.= " pf.fk_product, pf.ref_fourn";
|
$sql.= " pfp.fk_product, pfp.ref_fourn, pfp.fk_soc";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= " WHERE pf.rowid = pfp.fk_product_fournisseur";
|
$sql.= " WHERE pfp.rowid = ".$prodfournprice;
|
||||||
$sql.= " AND pfp.rowid = ".$prodfournprice;
|
|
||||||
$sql.= " AND pfp.quantity <= ".$qty;
|
$sql.= " AND pfp.quantity <= ".$qty;
|
||||||
|
|
||||||
dol_syslog("Product::get_buyprice sql=".$sql);
|
dol_syslog("Product::get_buyprice sql=".$sql);
|
||||||
@ -841,13 +839,12 @@ class Product extends CommonObject
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// On refait le meme select sur la ref et l'id du produit
|
// On refait le meme select sur la ref et l'id du produit
|
||||||
$sql = "SELECT pfp.price as price, pfp.quantity as quantity, pf.fk_soc,";
|
$sql = "SELECT pfp.price as price, pfp.quantity as quantity, pfp.fk_soc,";
|
||||||
$sql.= " pf.fk_product, pf.ref_fourn";
|
$sql.= " pfp.fk_product, pfp.ref_fourn";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||||
$sql.= " WHERE pf.rowid = pfp.fk_product_fournisseur";
|
$sql.= " WHERE pfp.ref_fourn = '".$fourn_ref."'";
|
||||||
$sql.= " AND pf.ref_fourn = '".$fourn_ref."'";
|
$sql.= " AND pfp.fk_product = ".$product_id;
|
||||||
$sql.= " AND pf.fk_product = ".$product_id;
|
$sql.= " AND pfp.quantity <= ".$qty;
|
||||||
$sql.= " AND quantity <= ".$qty;
|
|
||||||
$sql.= " ORDER BY pfp.quantity DESC";
|
$sql.= " ORDER BY pfp.quantity DESC";
|
||||||
$sql.= " LIMIT 1";
|
$sql.= " LIMIT 1";
|
||||||
|
|
||||||
@ -1774,8 +1771,10 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
|
$now=dol_now();
|
||||||
|
|
||||||
$sql = "SELECT rowid, fk_product";
|
$sql = "SELECT rowid, fk_product";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||||
$sql.= " WHERE fk_soc = ".$id_fourn;
|
$sql.= " WHERE fk_soc = ".$id_fourn;
|
||||||
$sql.= " AND ref_fourn = '".$ref_fourn."'";
|
$sql.= " AND ref_fourn = '".$ref_fourn."'";
|
||||||
$sql.= " AND entity = ".$conf->entity;
|
$sql.= " AND entity = ".$conf->entity;
|
||||||
@ -1789,15 +1788,15 @@ class Product extends CommonObject
|
|||||||
// The reference supplier does not exist, we create it for this product.
|
// The reference supplier does not exist, we create it for this product.
|
||||||
if (! $obj)
|
if (! $obj)
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur (";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price (";
|
||||||
$sql.= "datec";
|
$sql.= "datec";
|
||||||
$sql.= ", entity";
|
$sql.= ", entity";
|
||||||
$sql.= ", fk_product";
|
$sql.= ", fk_product";
|
||||||
$sql.= ", fk_soc";
|
$sql.= ", fk_soc";
|
||||||
$sql.= ", ref_fourn";
|
$sql.= ", ref_fourn";
|
||||||
$sql.= ", fk_user_author";
|
$sql.= ", fk_user";
|
||||||
$sql.= ") VALUES (";
|
$sql.= ") VALUES (";
|
||||||
$sql.= $this->db->idate(mktime());
|
$sql.= $this->db->idate($now);
|
||||||
$sql.= ", ".$conf->entity;
|
$sql.= ", ".$conf->entity;
|
||||||
$sql.= ", ".$this->id;
|
$sql.= ", ".$this->id;
|
||||||
$sql.= ", ".$id_fourn;
|
$sql.= ", ".$id_fourn;
|
||||||
@ -1808,7 +1807,7 @@ class Product extends CommonObject
|
|||||||
dol_syslog("Product::add_fournisseur sql=".$sql);
|
dol_syslog("Product::add_fournisseur sql=".$sql);
|
||||||
if ($this->db->query($sql))
|
if ($this->db->query($sql))
|
||||||
{
|
{
|
||||||
$this->product_fourn_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur");
|
$this->product_fourn_price_id = $this->db->last_insert_id(MAIN_DB_PREFIX."product_fournisseur_price");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1821,15 +1820,13 @@ class Product extends CommonObject
|
|||||||
// If the supplier ref already exists for this product
|
// If the supplier ref already exists for this product
|
||||||
else if ($obj->fk_product == $this->id)
|
else if ($obj->fk_product == $this->id)
|
||||||
{
|
{
|
||||||
$this->product_fourn_id = $obj->rowid;
|
$this->product_fourn_price_id = $obj->rowid;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// If the supplier ref already exists but for another product
|
// If the supplier ref already exists but for another product
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->product_id_already_linked = $obj->fk_product;
|
$this->product_id_already_linked = $obj->fk_product;
|
||||||
|
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1852,8 +1849,8 @@ class Product extends CommonObject
|
|||||||
|
|
||||||
$list = array();
|
$list = array();
|
||||||
|
|
||||||
$sql = "SELECT fk_soc";
|
$sql = "SELECT p.fk_soc";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as p";
|
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as p";
|
||||||
$sql.= " WHERE p.fk_product = ".$this->id;
|
$sql.= " WHERE p.fk_product = ".$this->id;
|
||||||
$sql.= " AND p.entity = ".$conf->entity;
|
$sql.= " AND p.entity = ".$conf->entity;
|
||||||
|
|
||||||
@ -1925,16 +1922,16 @@ class Product extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Recopie les fournisseurs et prix fournisseurs d'un produit/service sur un autre
|
* Recopie les fournisseurs et prix fournisseurs d'un produit/service sur un autre
|
||||||
*
|
*
|
||||||
* @param fromId Id produit source
|
* @param int $fromId Id produit source
|
||||||
* @param toId Id produit cible
|
* @param int $toId Id produit cible
|
||||||
* @return int < 0 si erreur, > 0 si ok
|
* @return int < 0 si erreur, > 0 si ok
|
||||||
*/
|
*/
|
||||||
function clone_fournisseurs($fromId, $toId)
|
function clone_fournisseurs($fromId, $toId)
|
||||||
{
|
{
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
// les fournisseurs
|
// les fournisseurs
|
||||||
$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur ("
|
/*$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur ("
|
||||||
. " datec, fk_product, fk_soc, ref_fourn, fk_user_author )"
|
. " datec, fk_product, fk_soc, ref_fourn, fk_user_author )"
|
||||||
. " SELECT '".$this->db->idate(mktime())."', ".$toId.", fk_soc, ref_fourn, fk_user_author"
|
. " SELECT '".$this->db->idate(mktime())."', ".$toId.", fk_soc, ref_fourn, fk_user_author"
|
||||||
. " FROM ".MAIN_DB_PREFIX."product_fournisseur"
|
. " FROM ".MAIN_DB_PREFIX."product_fournisseur"
|
||||||
@ -1944,7 +1941,7 @@ class Product extends CommonObject
|
|||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// les prix de fournisseurs.
|
// les prix de fournisseurs.
|
||||||
$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur_price ("
|
$sql = "INSERT ".MAIN_DB_PREFIX."product_fournisseur_price ("
|
||||||
@ -1953,13 +1950,17 @@ class Product extends CommonObject
|
|||||||
. " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"
|
. " FROM ".MAIN_DB_PREFIX."product_fournisseur_price"
|
||||||
. " WHERE fk_product = ".$fromId;
|
. " WHERE fk_product = ".$fromId;
|
||||||
|
|
||||||
if ( ! $this->db->query($sql ) )
|
$resql=$this->db->query($sql);
|
||||||
|
if (! $resql)
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->rollback();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
$this->db->commit();
|
else
|
||||||
return 1;
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -34,6 +34,8 @@ $langs->load("products");
|
|||||||
$langs->load("suppliers");
|
$langs->load("suppliers");
|
||||||
$langs->load("bills");
|
$langs->load("bills");
|
||||||
|
|
||||||
|
$action=GETPOST('action');
|
||||||
|
|
||||||
// If socid provided by ajax company selector
|
// If socid provided by ajax company selector
|
||||||
if (! empty($_REQUEST['search_fourn_id']))
|
if (! empty($_REQUEST['search_fourn_id']))
|
||||||
{
|
{
|
||||||
@ -43,10 +45,7 @@ if (! empty($_REQUEST['search_fourn_id']))
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Security check
|
// Security check
|
||||||
if (isset($_GET["id"]) || isset($_GET["ref"]))
|
$id = GETPOST('id')?GETPOST('id'):GETPOST('ref');
|
||||||
{
|
|
||||||
$id = isset($_GET["id"])?$_GET["id"]:(isset($_GET["ref"])?$_GET["ref"]:'');
|
|
||||||
}
|
|
||||||
$fieldid = isset($_GET["ref"])?'ref':'rowid';
|
$fieldid = isset($_GET["ref"])?'ref':'rowid';
|
||||||
if ($user->societe_id) $socid=$user->societe_id;
|
if ($user->societe_id) $socid=$user->societe_id;
|
||||||
$result=restrictedArea($user,'produit|service&fournisseur',$id,'product','','',$fieldid);
|
$result=restrictedArea($user,'produit|service&fournisseur',$id,'product','','',$fieldid);
|
||||||
@ -75,19 +74,6 @@ if ($_GET["action"] == 'remove_pf')
|
|||||||
$_GET["action"] = '';
|
$_GET["action"] = '';
|
||||||
$mesg = '<div class="ok">'.$langs->trans("PriceRemoved").'.</div>';
|
$mesg = '<div class="ok">'.$langs->trans("PriceRemoved").'.</div>';
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Deprecated. Should not occurs
|
|
||||||
if ($product->remove_fournisseur($_GET["socid"]) > 0)
|
|
||||||
{
|
|
||||||
$_GET["action"] = '';
|
|
||||||
$mesg = '<div class="ok">'.$langs->trans("SupplierRemoved").'.</div>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$_GET["action"] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +131,7 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
|
|||||||
$supplier=new Fournisseur($db);
|
$supplier=new Fournisseur($db);
|
||||||
$result=$supplier->fetch($id_fourn);
|
$result=$supplier->fetch($id_fourn);
|
||||||
|
|
||||||
$ret=$product->update_buyprice($_POST["qty"], $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"]);
|
$ret=$product->update_buyprice($_POST["qty"], $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn);
|
||||||
if ($ret < 0)
|
if ($ret < 0)
|
||||||
{
|
{
|
||||||
$error++;
|
$error++;
|
||||||
@ -169,6 +155,7 @@ if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Canc
|
|||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
$_POST['action']='';
|
$_POST['action']='';
|
||||||
|
$action='';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -259,17 +246,22 @@ if ($_GET["id"] || $_GET["ref"])
|
|||||||
{
|
{
|
||||||
$langs->load("suppliers");
|
$langs->load("suppliers");
|
||||||
|
|
||||||
if ($_GET["rowid"]) {
|
if ($_GET["rowid"])
|
||||||
|
{
|
||||||
$product->fetch_product_fournisseur_price($_GET["rowid"]);
|
$product->fetch_product_fournisseur_price($_GET["rowid"]);
|
||||||
print_fiche_titre($langs->trans("ChangeSupplierPrice"));
|
print_fiche_titre($langs->trans("ChangeSupplierPrice"));
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
print_fiche_titre($langs->trans("AddSupplierPrice"));
|
print_fiche_titre($langs->trans("AddSupplierPrice"));
|
||||||
}
|
}
|
||||||
print '<table class="border" width="100%">';
|
|
||||||
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="token" value="'.$_SESSION['newtoken'].'">';
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||||
print '<input type="hidden" name="action" value="updateprice">';
|
print '<input type="hidden" name="action" value="updateprice">';
|
||||||
|
|
||||||
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="3">';
|
print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="3">';
|
||||||
if ($_GET["rowid"])
|
if ($_GET["rowid"])
|
||||||
{
|
{
|
||||||
@ -330,12 +322,13 @@ if ($_GET["id"] || $_GET["ref"])
|
|||||||
print '</td>';
|
print '</td>';
|
||||||
print '</tr>';
|
print '</tr>';
|
||||||
|
|
||||||
print '<tr><td colspan="4" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">';
|
print '</table>';
|
||||||
|
|
||||||
|
print '<center><input class="button" type="submit" value="'.$langs->trans("Save").'">';
|
||||||
print ' ';
|
print ' ';
|
||||||
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").'"></center>';
|
||||||
|
|
||||||
print '</form>';
|
print '</form>';
|
||||||
print '</table>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
@ -346,14 +339,13 @@ if ($_GET["id"] || $_GET["ref"])
|
|||||||
|
|
||||||
print "\n<div class=\"tabsAction\">\n";
|
print "\n<div class=\"tabsAction\">\n";
|
||||||
|
|
||||||
if ($_GET["action"] != 'add_price') {
|
if ($_GET["action"] != 'add_price' && $action != 'updateprice')
|
||||||
|
{
|
||||||
if ($user->rights->produit->creer || $user->rights->service->creer)
|
if ($user->rights->produit->creer || $user->rights->service->creer)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$product->id.'&action=add_price">';
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$product->id.'&action=add_price">';
|
||||||
print $langs->trans("AddSupplierPrice").'</a>';
|
print $langs->trans("AddSupplierPrice").'</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\n</div>\n";
|
print "\n</div>\n";
|
||||||
@ -371,16 +363,15 @@ if ($_GET["id"] || $_GET["ref"])
|
|||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
|
||||||
print '<td class="liste_titre">'.$langs->trans("SupplierRef").'</td>';
|
print '<td class="liste_titre">'.$langs->trans("SupplierRef").'</td>';
|
||||||
if(!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
|
if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder);
|
||||||
print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,"",$sortfield,$sortorder);
|
|
||||||
print '<td class="liste_titre" align="right">'.$langs->trans("PriceQtyMinHT").'</td>';
|
print '<td class="liste_titre" align="right">'.$langs->trans("PriceQtyMinHT").'</td>';
|
||||||
print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
|
print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
|
||||||
print '<td class="liste_titre"></td>';
|
print '<td class="liste_titre"></td>';
|
||||||
print "</tr>\n";
|
print "</tr>\n";
|
||||||
|
|
||||||
$product_fourn = new ProductFournisseur($db);
|
$product_fourn = new ProductFournisseur($db);
|
||||||
$product_fourn_list = $product_fourn->fetch_product_fournisseur($product->id);
|
$product_fourn_list = $product_fourn->list_product_fournisseur_price($product->id);
|
||||||
|
|
||||||
if (count($product_fourn_list)>0)
|
if (count($product_fourn_list)>0)
|
||||||
{
|
{
|
||||||
@ -406,7 +397,7 @@ if ($_GET["id"] || $_GET["ref"])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Quantity
|
// Quantity
|
||||||
print '<td align="center">';
|
print '<td align="right">';
|
||||||
print $productfourn->fourn_qty;
|
print $productfourn->fourn_qty;
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
|
|||||||
@ -133,8 +133,8 @@ else
|
|||||||
$sql.= ') ';
|
$sql.= ') ';
|
||||||
//if ($fourn_id > 0) // The DISTINCT is used to avoid duplicate from this link
|
//if ($fourn_id > 0) // The DISTINCT is used to avoid duplicate from this link
|
||||||
//{
|
//{
|
||||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON p.rowid = pf.fk_product";
|
//$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 pf.rowid = pfp.fk_product_fournisseur";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
|
||||||
//}
|
//}
|
||||||
$sql.= ' WHERE p.entity IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')';
|
$sql.= ' WHERE p.entity IN (0,'.(! empty($conf->entities['product']) ? $conf->entities['product'] : $conf->entity).')';
|
||||||
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
|
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
|
||||||
@ -156,7 +156,7 @@ else
|
|||||||
if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'";
|
if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'";
|
||||||
if ($catid) $sql.= " AND cp.fk_categorie = ".$catid;
|
if ($catid) $sql.= " AND cp.fk_categorie = ".$catid;
|
||||||
if ($search_categ) $sql.= " AND cp.fk_categorie = ".$search_categ;
|
if ($search_categ) $sql.= " AND cp.fk_categorie = ".$search_categ;
|
||||||
if ($fourn_id > 0) $sql.= " AND pf.fk_soc = ".$fourn_id;
|
if ($fourn_id > 0) $sql.= " AND pfp.fk_soc = ".$fourn_id;
|
||||||
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
|
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,";
|
||||||
$sql.= " p.fk_product_type, p.tms,";
|
$sql.= " p.fk_product_type, p.tms,";
|
||||||
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
|
$sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte";
|
||||||
|
|||||||
@ -96,12 +96,6 @@ $sql.= ' SUM(s.reel) as stock_physique';
|
|||||||
$sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p';
|
$sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p';
|
||||||
// We'll need this table joined to the select in order to filter by categ
|
// We'll need this table joined to the select in order to filter by categ
|
||||||
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
|
if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp";
|
||||||
// We disable this because this create duplicate lines
|
|
||||||
/*if ($_GET["fourn_id"] > 0)
|
|
||||||
{
|
|
||||||
$fourn_id = $_GET["fourn_id"];
|
|
||||||
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
|
||||||
}*/
|
|
||||||
$sql.= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product';
|
$sql.= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product';
|
||||||
$sql.= " WHERE p.entity = ".$conf->entity;
|
$sql.= " WHERE p.entity = ".$conf->entity;
|
||||||
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
|
if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ
|
||||||
@ -112,9 +106,12 @@ if ($sall)
|
|||||||
// if the type is not 1, we show all products (type = 0,2,3)
|
// if the type is not 1, we show all products (type = 0,2,3)
|
||||||
if (dol_strlen($type))
|
if (dol_strlen($type))
|
||||||
{
|
{
|
||||||
if ($type==1) {
|
if ($type==1)
|
||||||
|
{
|
||||||
$sql.= " AND p.fk_product_type = '1'";
|
$sql.= " AND p.fk_product_type = '1'";
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$sql.= " AND p.fk_product_type <> '1'";
|
$sql.= " AND p.fk_product_type <> '1'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user