diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 9dc9512e264..b03f588d46f 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -55,21 +55,32 @@ $page = $_GET["page"]; $limit = $conf->liste_limit; $offset = $limit * $page ; -if (isset($_POST["button_removefilter_x"])) -{ - $sref=""; - $snom=""; -} - -if (isset($_REQUEST['catid'])) -{ - $catid = $_REQUEST['catid']; -} +$catid=GETPOST('catid'); +$toolowstock=GETPOST('toolowstock'); // Load sale and categ filters -$search_sale = isset($_GET["search_sale"])?$_GET["search_sale"]:$_POST["search_sale"]; -$search_categ = isset($_GET["search_categ"])?$_GET["search_categ"]:$_POST["search_categ"]; +$search_sale = GETPOST("search_sale"); +$search_categ = GETPOST("search_categ"); +if (! empty($_POST["button_removefilter_x"])) +{ + $sref=""; + $snom=""; + $sall=""; + $search_sale=""; + $search_categ=""; + $type=""; + $catid=''; + $toolowstock=''; +} + + + +/* + * Actions + */ + +// None /* @@ -84,30 +95,30 @@ $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price $sql.= ' p.fk_product_type, p.tms as datem,'; $sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte,'; $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 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"; + $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; -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 if (!$user->rights->produit->hidden && !$user->rights->service->hidden) { - $sql.=' AND p.hidden=0'; + $sql.=' AND p.hidden=0'; } else { - if (!$user->rights->produit->hidden) $sql.=' AND (p.hidden=0 OR p.fk_product_type != 0)'; - if (!$user->rights->service->hidden) $sql.=' AND (p.hidden=0 OR p.fk_product_type != 1)'; + if (!$user->rights->produit->hidden) $sql.=' AND (p.hidden=0 OR p.fk_product_type != 0)'; + if (!$user->rights->service->hidden) $sql.=' AND (p.hidden=0 OR p.fk_product_type != 1)'; } if ($sall) { - $sql.= " AND (p.ref like '%".addslashes($sall)."%' OR p.label like '%".addslashes($sall)."%' OR p.description like '%".addslashes($sall)."%' OR p.note like '%".addslashes($sall)."%')"; + $sql.= " AND (p.ref like '%".addslashes($sall)."%' OR p.label like '%".addslashes($sall)."%' OR p.description like '%".addslashes($sall)."%' OR p.note like '%".addslashes($sall)."%')"; } # if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($type)) @@ -123,7 +134,7 @@ if ($sbarcode) $sql.= " AND p.barcode like '%".$sbarcode."%'"; if ($snom) $sql.= " AND p.label like '%".addslashes($snom)."%'"; if (isset($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) { - $sql.= " AND p.tosell = ".$_GET["tosell"]; + $sql.= " AND p.tosell = ".$_GET["tosell"]; } if (isset($_GET["tobuy"]) && dol_strlen($_GET["tobuy"]) > 0) { @@ -135,42 +146,42 @@ if (dol_strlen($canvas) > 0) } if($catid) { - $sql.= " AND cp.fk_categorie = ".$catid; + $sql.= " AND cp.fk_categorie = ".$catid; } if ($fourn_id > 0) { - $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; + $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; } // Insert categ filter if ($search_categ) { - $sql .= " AND cp.fk_categorie = ".addslashes($search_categ); + $sql .= " AND cp.fk_categorie = ".addslashes($search_categ); } $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 ($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) ; if ($resql) { - $num = $db->num_rows($resql); + $num = $db->num_rows($resql); - $i = 0; + $i = 0; - if ($num == 1 && ($sall or $snom or $sref)) - { - $objp = $db->fetch_object($resql); - Header("Location: fiche.php?id=$objp->rowid"); - exit; - } + if ($num == 1 && ($sall or $snom or $sref)) + { + $objp = $db->fetch_object($resql); + Header("Location: fiche.php?id=$objp->rowid"); + exit; + } - if (isset($_GET["tosell"]) || isset($_POST["tosell"])) - { - $tosell = (isset($_GET["tosell"])?$_GET["tosell"]:$_POST["tosell"]); - } + if (isset($_GET["tosell"]) || isset($_POST["tosell"])) + { + $tosell = (isset($_GET["tosell"])?$_GET["tosell"]:$_POST["tosell"]); + } if (isset($_GET["tobuy"]) || isset($_POST["tobuy"])) { $tobuy = (isset($_GET["tobuy"])?$_GET["tobuy"]:$_POST["tobuy"]); @@ -178,181 +189,182 @@ if ($resql) - $helpurl=''; - $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; + $helpurl=''; + $helpurl='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; - if (isset($_GET["type"]) || isset($_POST["type"])) - { - if ($type==1) { $texte = $langs->trans("Services"); } - else { $texte = $langs->trans("Products"); } - } else { - $texte = $langs->trans("ProductsAndServices"); - } - $texte.=' ('.$langs->trans("Stocks").')'; + if (isset($_GET["type"]) || isset($_POST["type"])) + { + if ($type==1) { $texte = $langs->trans("Services"); } + else { $texte = $langs->trans("Products"); } + } else { + $texte = $langs->trans("ProductsAndServices"); + } + $texte.=' ('.$langs->trans("Stocks").')'; - llxHeader("",$title,$helpurl,$texte); + llxHeader("",$title,$helpurl,$texte); - if ($sref || $snom || $sall || $_POST["search"]) - { - print_barre_liste($texte, $page, "reassort.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$_POST["tosell"]."&tobuy=".$_POST["tobuy"], $sortfield, $sortorder,'',$num); - } - else - { - print_barre_liste($texte, $page, "reassort.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); - } + if ($sref || $snom || $sall || $_POST["search"]) + { + print_barre_liste($texte, $page, "reassort.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$_POST["tosell"]."&tobuy=".$_POST["tobuy"], $sortfield, $sortorder,'',$num); + } + else + { + print_barre_liste($texte, $page, "reassort.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + } - if (isset($catid)) - { - print "