* Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * * 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 . */ /** * \file htdocs/product/reassort.php * \ingroup produit * \brief Page to list stocks */ require("../main.inc.php"); require_once(DOL_DOCUMENT_ROOT.'/product/class/product.class.php'); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php"); $langs->load("products"); $langs->load("stocks"); // Security check if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service'); $sref=isset($_GET["sref"])?$_GET["sref"]:$_POST["sref"]; $snom=isset($_GET["snom"])?$_GET["snom"]:$_POST["snom"]; $sall=isset($_GET["sall"])?$_GET["sall"]:$_POST["sall"]; $type=isset($_GET["type"])?$_GET["type"]:$_POST["type"]; $sref=trim($sref); $snom=trim($snom); $sall=trim($sall); $type=trim($type); $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; if (! $sortfield) $sortfield="stock_physique"; if (! $sortorder) $sortorder="ASC"; $page = $_GET["page"]; $limit = $conf->liste_limit; $offset = $limit * $page ; $catid=GETPOST('catid'); $toolowstock=GETPOST('toolowstock'); // Load sale and categ filters $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 /* * View */ $htmlother=new FormOther($db); $title=$langs->trans("ProductsAndServices"); $sql = 'SELECT 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 as statut, p.tobuy, p.seuil_stock_alerte,'; $sql.= ' SUM(s.reel) as stock_physique'; $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"; $sql.= ') LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; if ($search_categ) $sql.= " AND p.rowid = cp.fk_product"; // Join for the needed table to filter by categ if ($sall) { $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($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 ($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($_GET["tosell"]) && dol_strlen($_GET["tosell"]) > 0) { $sql.= " AND p.tosell = ".$_GET["tosell"]; } if (isset($_GET["tobuy"]) && dol_strlen($_GET["tobuy"]) > 0) { $sql.= " AND p.tobuy = ".$_GET["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); } $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 ($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); $i = 0; 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["tobuy"]) || isset($_POST["tobuy"])) { $tobuy = (isset($_GET["tobuy"])?$_GET["tobuy"]:$_POST["tobuy"]); } $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").')'; 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 ($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 ''; // 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"; // 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 ''; print ''; print ''; print ''; $product_static=new Product($db); $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); // 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"; $result = $db->query($sql); if ($result) { $objtp = $db->fetch_object($result); if ($objtp->label != '') $objp->label = $objtp->label; } } $var=!$var; print ''; print ''; if ($conf->service->enabled && $type == 1) { print ''; } //print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; $i++; } print "
'; print $moreforfilter; 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.''; 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).''.$product_static->LibStatut($objp->tobuy,5,1).'
"; 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, ''); } } $db->free($resql); } else { dol_print_error($db); } $db->close(); llxFooter(); ?>