diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index ae2f4c5cfcb..8a7afdbd816 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -22,7 +22,7 @@ * \file htdocs/fourn/class/fournisseur.product.class.php * \ingroup produit * \brief File of class to manage predefined suppliers products - * \version $Id: fournisseur.product.class.php,v 1.11 2011/08/21 00:27:31 eldy Exp $ + * \version $Id: fournisseur.product.class.php,v 1.12 2011/08/21 10:12:18 eldy Exp $ */ require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php"; @@ -76,7 +76,7 @@ class ProductFournisseur extends Product $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur"; $sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn; - dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql); + dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql); $resql=$this->db->query($sql); if ($resql) { @@ -86,12 +86,12 @@ class ProductFournisseur extends Product $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql.= " WHERE fk_product_fournisseur = ".$obj->rowid; - dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql); + dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql); $resql2=$this->db->query($sql); if (! $resql2) { $this->error=$this->db->lasterror(); - dol_syslog("ProductFournisseur::remove_fournisseur ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::remove_fournisseur ".$this->error, LOG_ERR); $ok=0; } } @@ -100,12 +100,12 @@ class ProductFournisseur extends Product $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur"; $sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn; - dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql); + dol_syslog(get_class($this)."::remove_fournisseur sql=".$sql); $resql=$this->db->query($sql); if (! $resql) { $this->error=$this->db->lasterror(); - dol_syslog("ProductFournisseur::remove_fournisseur ".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::remove_fournisseur ".$this->error, LOG_ERR); $ok=0; } @@ -140,7 +140,7 @@ class ProductFournisseur extends Product $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur"; $sql.= " WHERE rowid = ".$rowid; - dol_syslog("ProductFournisseur::remove_product_fournisseur sql=".$sql); + dol_syslog(get_class($this)."::remove_product_fournisseur sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -167,7 +167,7 @@ class ProductFournisseur extends Product $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql.= " WHERE rowid = ".$rowid; - dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql); + dol_syslog(get_class($this)."::remove_product_fournisseur_price sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -178,7 +178,7 @@ class ProductFournisseur extends Product $sql.= " WHERE pfp.rowid IS NULL"; $sql.= " AND pf.entity = ".$conf->entity; - dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql); + dol_syslog(get_class($this)."::remove_product_fournisseur_price sql=".$sql); $resql = $this->db->query($sql); if ($resql) { @@ -191,12 +191,12 @@ class ProductFournisseur extends Product $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur"; $sql.= " WHERE rowid = ".$rowidpf; - dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql); + 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("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::remove_product_fournisseur_price ".$this->error,LOG_ERR); $ok=0; } } @@ -215,7 +215,7 @@ class ProductFournisseur extends Product else { $this->error=$this->db->lasterror(); - dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::remove_product_fournisseur_price ".$this->error,LOG_ERR); $this->db->rollback(); return -2; } @@ -223,7 +223,7 @@ class ProductFournisseur extends Product else { $this->error=$this->db->lasterror(); - dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR); + dol_syslog(get_class($this)."::remove_product_fournisseur_price ".$this->error,LOG_ERR); $this->db->rollback(); return -1; } @@ -288,7 +288,7 @@ class ProductFournisseur extends Product $sql.= " ".$availability; $sql.=")"; - dol_syslog("ProductFournisseur::update_buyprice sql=".$sql); + dol_syslog(get_class($this)."::update_buyprice sql=".$sql); if (! $this->db->query($sql)) { $error++; @@ -391,7 +391,7 @@ class ProductFournisseur extends Product $sql.= " AND fk_soc = ".$fournid; $sql.= " AND entity = ".$conf->entity; - dol_syslog("Product::fetch_fourn_data sql=".$sql); + dol_syslog(get_class($this)."::fetch_fourn_data sql=".$sql); $result = $this->db->query($sql) ; if ($result) { @@ -403,7 +403,7 @@ class ProductFournisseur extends Product else { $this->error=$this->db->error(); - dol_syslog("ProductFournisseur::fetch_fourn_data error=".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch_fourn_data error=".$this->error, LOG_ERR); return -1; } } @@ -423,7 +423,7 @@ class ProductFournisseur extends Product $sql.= " WHERE pfp.rowid = ".$rowid; $sql.= " AND pf.rowid = pfp.fk_product_fournisseur"; - dol_syslog("ProductFournisseur::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) ; if ($resql) { @@ -449,7 +449,7 @@ class ProductFournisseur extends Product else { $this->error=$this->db->error(); - dol_syslog("ProductFournisseur::fetch_product_fournisseur_price error=".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch_product_fournisseur_price error=".$this->error, LOG_ERR); return -1; } } @@ -480,7 +480,7 @@ class ProductFournisseur extends Product $sql.= " AND pf.fk_product = ".$prodid; $sql.= " ORDER BY s.nom, pfp.quantity"; - dol_syslog("ProductFournisseur::fetch_product_fournisseur sql=".$sql, LOG_DEBUG); + dol_syslog(get_class($this)."::fetch_product_fournisseur sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); @@ -525,7 +525,7 @@ class ProductFournisseur extends Product else { $this->error=$this->db->error(); - dol_syslog("ProductFournisseur::fetch_product_fournisseur error=".$this->error, LOG_ERR); + dol_syslog(get_class($this)."::fetch_product_fournisseur error=".$this->error, LOG_ERR); return -1; } } @@ -556,12 +556,12 @@ class ProductFournisseur extends Product $sql.= " pfp.rowid as product_fourn_pri_id, "; $sql.= " pf.rowid as product_fourn_id, "; $sql.= " pfp.price, pfp.quantity, pfp.unitprice"; - $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.= " 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.rowid = pfp.fk_product_fournisseur"; $sql.= " WHERE s.entity = ".$conf->entity; $sql.= " AND pf.fk_product = ".$prodid; + $sql.= " AND pf.fk_soc = s.rowid"; $sql.= " ORDER BY pfp.unitprice"; $sql.= $this->db->plimit(1); diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index c2abfb26b69..bb542b052d6 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -21,7 +21,7 @@ * \file htdocs/product/liste.php * \ingroup produit * \brief Page to list products and services - * \version $Id: liste.php,v 1.155 2011/08/21 00:36:29 eldy Exp $ + * \version $Id: liste.php,v 1.156 2011/08/21 10:12:18 eldy Exp $ */ require("../main.inc.php"); @@ -39,9 +39,10 @@ $snom=GETPOST("snom"); $sall=GETPOST("sall"); $type=GETPOST("type","int"); $search_sale = GETPOST("search_sale"); -$search_categ = GETPOST("search_categ"); +$search_categ = GETPOST("search_categ",'int'); $tosell = GETPOST("tosell"); $tobuy = GETPOST("tobuy"); +$fourn_id = GETPOST("fourn_id",'int'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); @@ -140,15 +141,17 @@ else $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,'; $sql.= ' p.fk_product_type, p.tms as datem,'; -$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte'; -$sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; +$sql.= ' p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte,'; +$sql.= ' MIN(pfp.unitprice) as minsellprice'; +$sql.= ' FROM ('.MAIN_DB_PREFIX.'product as p'; // 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 ($_GET["fourn_id"] > 0) // The DISTINCT is used to avoid duplicate from this link -{ - $fourn_id = $_GET["fourn_id"]; - $sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf"; -} +$sql.= ') '; +//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_price as pfp ON pf.rowid = pfp.fk_product_fournisseur"; +//} $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 ($sall) @@ -158,48 +161,27 @@ if ($sall) # if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($type)) { - if ($type==1) { - $sql.= " AND p.fk_product_type = '1'"; - } else { - $sql.= " AND p.fk_product_type <> '1'"; - } + if ($type == 1) $sql.= " AND p.fk_product_type = '1'"; + else $sql.= " AND p.fk_product_type <> '1'"; } if ($sref) $sql.= " AND p.ref like '%".$sref."%'"; if ($sbarcode) $sql.= " AND p.barcode like '%".$sbarcode."%'"; if ($snom) $sql.= " AND p.label like '%".$db->escape($snom)."%'"; -if (isset($tosell) && dol_strlen($tosell) > 0) -{ - $sql.= " AND p.tosell = ".$db->escape($tosell); -} -if (isset($tobuy) && dol_strlen($tobuy) > 0) -{ - $sql.= " AND p.tobuy = ".$db->escape($tobuy); -} -if (dol_strlen($canvas) > 0) -{ - $sql.= " AND p.canvas = '".$db->escape($canvas)."'"; -} -if($catid) -{ - $sql.= " AND cp.fk_categorie = ".$catid; -} -if ($fourn_id > 0) -{ - $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; -} -// Insert categ filter -if ($search_categ) -{ - $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); -} +if (isset($tosell) && dol_strlen($tosell) > 0) $sql.= " AND p.tosell = ".$db->escape($tosell); +if (isset($tobuy) && dol_strlen($tobuy) > 0) $sql.= " AND p.tobuy = ".$db->escape($tobuy); +if (dol_strlen($canvas) > 0) $sql.= " AND p.canvas = '".$db->escape($canvas)."'"; +if ($catid) $sql.= " AND cp.fk_categorie = ".$catid; +if ($search_categ) $sql.= " AND cp.fk_categorie = ".$search_categ; +if ($fourn_id > 0) $sql.= " AND pf.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.= " p.fk_product_type, p.tms,"; $sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte"; -if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet +//if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1 ,$offset); -$resql = $db->query($sql) ; +dol_syslog("sql=".$sql); +$resql = $db->query($sql) ; if ($resql) { $num = $db->num_rows($resql); @@ -338,12 +320,9 @@ if ($resql) } // Minimum buying Price - if ($conf->fournisseur->enabled && $user->rights->fournisseur->lire && $type != 1) - { - print '