* Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2012 Christophe Battarel * Copyright (C) 2013 Cédric Salvador * * 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 3 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/fourn/product/list.php * \ingroup produit * \brief Page liste des produits ou services */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; $langs->load("products"); $langs->load("suppliers"); if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden(); $sref = GETPOST('sref'); $sRefSupplier = GETPOST('srefsupplier'); $snom = GETPOST('snom'); $type = GETPOST('type'); $sortfield = GETPOST('sortfield'); $sortorder = GETPOST('sortorder'); $page = GETPOST('page'); if ($page < 0) { $page = 0 ; } $limit = $conf->liste_limit; $offset = $limit * $page ; if (! $sortfield) $sortfield = 'p.ref'; if (! $sortorder) $sortorder = 'DESC'; if (GETPOST('button_removefilter')) { $sref = ''; $sRefSupplier = ''; $snom = ''; } $fourn_id = GETPOST('fourn_id', 'int'); if (isset($_REQUEST['catid'])) { $catid = $_REQUEST['catid']; } /* * Mode Liste * */ $productstatic = new Product($db); $companystatic = new Societe($db); $title=$langs->trans("ProductsAndServices"); if ($fourn_id) { $supplier = new Fournisseur($db); $supplier->fetch($fourn_id); } $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type,"; $sql.= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,"; $sql.= " s.rowid as socid, s.nom as name"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid"; $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 ppf.fk_soc = s.rowid"; $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; if ($sRefSupplier) { $sql .= natural_search('ppf.ref_fourn', $sRefSupplier); } if (GETPOST('type')) { $sql .= " AND p.fk_product_type = " . GETPOST('type','int'); } if ($sref) { $sql .= natural_search('p.ref', $sref); } if ($snom) { $sql .= natural_search('s.nom', $snom); } if($catid) { $sql .= " AND cp.fk_categorie = ".$catid; } if ($fourn_id > 0) { $sql .= " AND ppf.fk_soc = ".$fourn_id; } // Count total nb of records without orderby and limit $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } $sql .= $db->order($sortfield,$sortorder); $sql .= $db->plimit($limit + 1, $offset); dol_syslog("fourn/product/list.php:", LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); $i = 0; if ($num == 1 && (GETPOST("mode") == 'search')) { $objp = $db->fetch_object($resql); header("Location: ".DOL_URL_ROOT."/product/card.php?id=".$objp->rowid); exit; } if (! empty($supplier->id)) $texte = $langs->trans("ListOfSupplierProductForSupplier",$supplier->name); else $texte = $langs->trans("List"); llxHeader("","",$texte); $param="&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type)?"&type=".$type:"").(empty($sRefSupplier)?"":"&srefsupplier=".$sRefSupplier); print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords); if (isset($catid)) { print "
"; $c = new Categorie($db); $ways = $c->print_all_ways(' > ','fourn/product/list.php'); print " > ".$ways[0]."
\n"; print "

"; } print '
'; print ''; if ($fourn_id > 0) print ''; print ''; print ''; print ''; print ''; // Lignes des titres print ""; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("RefSupplierShort"),$_SERVER["PHP_SELF"], "ppf.ref_fourn",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Supplier"),$_SERVER["PHP_SELF"], "ppf.fk_soc",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("BuyingPrice"),$_SERVER["PHP_SELF"], "ppf.price",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"], "ppf.quantity",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("UnitPrice"),$_SERVER["PHP_SELF"], "ppf.unitprice",$param,"",'align="right"',$sortfield,$sortorder); print "\n"; // Lignes des champs de filtre print ''; print ''; print ''; print ''; print ''; print ''; $oldid = ''; $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); $var=!$var; print ""; print ''; print ''; print ''."\n"; $companystatic->name=$objp->name; $companystatic->id=$objp->socid; print ''; print ''; print ''; print ''; print "\n"; $i++; } $db->free($resql); print "
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print '  '; print ''; print '
'; $productstatic->id=$objp->rowid; $productstatic->ref=$objp->ref; $productstatic->type=$objp->fk_product_type; print $productstatic->getNomUrl(1,'supplier'); print ''.$objp->ref_fourn.''.$objp->label.''; if ($companystatic->id > 0) print $companystatic->getNomUrl(1,'supplier'); print ''.(isset($objp->price) ? price($objp->price) : '').''.$objp->qty.''.(isset($objp->unitprice) ? price($objp->unitprice) : '').'
"; print '
'; } else { dol_print_error($db); } $db->close(); llxFooter();