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 "
"; - $c = new Categorie ($db, $catid); - $ways = $c->print_all_ways(' > ','product/reassort.php'); - print " > ".$ways[0]."
\n"; - print "

"; - } + if ($catid) + { + print "
"; + $c = new Categorie($db); + $c->fetch($catid); + $ways = $c->print_all_ways(' > ','product/reassort.php'); + print " > ".$ways[0]."
\n"; + print "

"; + } - print '
'; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print '
'; - // Filter on categories - $moreforfilter=''; - if ($conf->categorie->enabled) - { - $moreforfilter.=$langs->trans('Categories'). ': '; - $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); - $moreforfilter.='       '; - } - $moreforfilter.='     '.$langs->trans("StockTooLow").' '; - if ($moreforfilter) - { - print ''; - print ''; - } + // Filter on categories + $moreforfilter=''; + if ($conf->categorie->enabled) + { + $moreforfilter.=$langs->trans('Categories'). ': '; + $moreforfilter.=$htmlother->select_categories(0,$search_categ,'search_categ'); + $moreforfilter.='       '; + } + $moreforfilter.='     '.$langs->trans("StockTooLow").' '; + if ($moreforfilter) + { + print ''; + print ''; + } - $param="&tosell=$tosell&tobuy=$tobuy".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; + $param="&tosell=$tosell&tobuy=$tobuy".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; - // Lignes des titres - print ""; - print_liste_field_titre($langs->trans("Ref"),"reassort.php", "p.ref",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label",$param,"","",$sortfield,$sortorder); - if ($conf->service->enabled && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); - // TODO Add info of running suppliers/customers orders - //print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); - print ''; - print_liste_field_titre($langs->trans("Sell"),"reassort.php", "p.tosell",$param,"",'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Buy"),"reassort.php", "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder); - print "\n"; - - // Lignes des champs de filtre - print ''; - print ''; - print ''; - if ($conf->service->enabled && $type == 1) - { - print ''; - } - print ''; - print ''; - print ''; + // Lignes des titres + print ""; + print_liste_field_titre($langs->trans("Ref"),"reassort.php", "p.ref",$param,"","",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Label"),"reassort.php", "p.label",$param,"","",$sortfield,$sortorder); + if ($conf->service->enabled && $type == 1) print_liste_field_titre($langs->trans("Duration"),"reassort.php", "p.duration",$param,"",'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("MininumStock"),"reassort.php", "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PhysicalStock"),"reassort.php", "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); + // TODO Add info of running suppliers/customers orders + //print_liste_field_titre($langs->trans("TheoreticalStock"),"reassort.php", "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); print ''; - print ''; - print ''; + print_liste_field_titre($langs->trans("Sell"),"reassort.php", "p.tosell",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Buy"),"reassort.php", "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder); + print "\n"; - $product_static=new Product($db); + // Lignes des champs de filtre + print ''; + print ''; + print ''; + if ($conf->service->enabled && $type == 1) + { + print ''; + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - $var=True; - while ($i < min($num,$limit)) - { - $objp = $db->fetch_object($resql); + $product_static=new Product($db); - // Multilangs - if ($conf->global->MAIN_MULTILANGS) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; + $var=True; + while ($i < min($num,$limit)) + { + $objp = $db->fetch_object($resql); - $result = $db->query($sql); - if ($result) - { - $objtp = $db->fetch_object($result); - if ($objtp->label != '') $objp->label = $objtp->label; - } - } + // Multilangs + if ($conf->global->MAIN_MULTILANGS) // si l'option est active + { + $sql = "SELECT label"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$objp->rowid; + $sql.= " AND lang='". $langs->getDefaultLang() ."'"; + $sql.= " LIMIT 1"; - $var=!$var; - print ''; - print ''; + $result = $db->query($sql); + if ($result) + { + $objtp = $db->fetch_object($result); + if ($objtp->label != '') $objp->label = $objtp->label; + } + } - if ($conf->service->enabled && $type == 1) - { - print ''; - } - //print ''; - print ''; - print ''; + print ''; + + if ($conf->service->enabled && $type == 1) + { + print ''; + } + //print ''; + print ''; + print ''; - print ''; - print ''; + print $objp->stock_physique; + print ''; + print ''; + print ''; print ''; - print "\n"; - $i++; - } + print "\n"; + $i++; + } - print "
'; - print $moreforfilter; - print '
'; + print $moreforfilter; + print '
 
'; - print ''; - print ''; - print ''; - print ''; - print ' '; - print '   
 '; - print ''; - print ''; - print '
'; + print ''; + print ''; + print ''; + print ''; + print ' '; + print '    '; + print ''; + print ''; + print '
'; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->type=$objp->fk_product_type; - print $product_static->getNomUrl(1,'',16); - //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); - print ''.$objp->label.''; - if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); - elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); - elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); - else print $objp->duration; - print ''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''; + $var=!$var; + print '
'; + $product_static->ref=$objp->ref; + $product_static->id=$objp->rowid; + $product_static->type=$objp->fk_product_type; + print $product_static->getNomUrl(1,'',16); + //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); + print ''.$objp->label.''; + if (preg_match('/([0-9]+)y/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationYear"); + elseif (preg_match('/([0-9]+)m/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationMonth"); + elseif (preg_match('/([0-9]+)d/i',$objp->duration,$regs)) print $regs[1].' '.$langs->trans("DurationDay"); + else print $objp->duration; + print ''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''; if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; - print $objp->stock_physique; - print ''.$langs->trans("Movements").''.$product_static->LibStatut($objp->statut,5,0).''.$langs->trans("Movements").''.$product_static->LibStatut($objp->statut,5,0).''.$product_static->LibStatut($objp->tobuy,5,1).'
"; - print '
'; + print ""; + print ''; - if ($num > $conf->liste_limit) - { - if ($sref || $snom || $sall || $_POST["search"]) - { - print_barre_liste('', $page, "reassort.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, ''); - } - else - { - print_barre_liste('', $page, "reassort.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":"")."&tosell=".$tosell."&tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, ''); - } - } + if ($num > $conf->liste_limit) + { + if ($sref || $snom || $sall || $_POST["search"]) + { + print_barre_liste('', $page, "reassort.php", "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, ''); + } + else + { + print_barre_liste('', $page, "reassort.php", "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":"")."&tosell=".$tosell."&tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, ''); + } + } - $db->free($resql); + $db->free($resql); } else { - dol_print_error($db); + dol_print_error($db); }