dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2007 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
7  * Copyright (C) 2013 C├ędric Salvador <csalvador@gpcsolutions.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
33 
34 $langs->loadLangs(array("products","suppliers"));
35 
36 if (!$user->rights->produit->lire && !$user->rights->service->lire) accessforbidden();
37 
38 $sref = GETPOST('sref');
39 $sRefSupplier = GETPOST('srefsupplier');
40 $snom = GETPOST('snom');
41 $type = GETPOST('type');
42 $optioncss = GETPOST('optioncss','alpha');
43 
44 // Load variable for pagination
45 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
46 $sortfield = GETPOST('sortfield','alpha');
47 $sortorder = GETPOST('sortorder','alpha');
48 $page = GETPOST('page','int');
49 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (! $sortfield) $sortfield="p.ref"; // Set here default search field
54 if (! $sortorder) $sortorder="ASC";
55 
56 $fourn_id = GETPOST('fourn_id', 'intcomma');
57 if ($user->societe_id) $fourn_id=$user->societe_id;
58 
59 $catid = GETPOST('catid', 'intcomma');
60 
61 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
62 $hookmanager->initHooks(array('supplierpricelist'));
63 $extrafields = new ExtraFields($db);
64 
65 
66 
67 
68 /*
69  * ACTIONS
70  *
71  * Put here all code to do according to value of "action" parameter
72  */
73 
74 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
75 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
76 
77 $parameters=array();
78 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
79 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80 
81 if (empty($reshook))
82 {
83  // Selection of new fields
84  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
85 
86  // Purge search criteria
87  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
88  {
89  $sref = '';
90  $sRefSupplier = '';
91  $snom = '';
92  $search_field1='';
93  $search_field2='';
94  $search_date_creation='';
95  $search_date_update='';
96  $toselect='';
97  $search_array_options=array();
98  }
99 }
100 
101 /*
102  * View
103  */
104 
105 $form = new Form($db);
106 $productstatic = new Product($db);
107 $companystatic = new Societe($db);
108 
109 $title=$langs->trans("ProductsAndServices");
110 
111 if ($fourn_id)
112 {
113  $supplier = new Fournisseur($db);
114  $supplier->fetch($fourn_id);
115 }
116 
117 
118 
119 $arrayofmassactions = array(
120  'presend'=>$langs->trans("SendByMail"),
121  'builddoc'=>$langs->trans("PDFMerge"),
122 );
123 if ($user->rights->mymodule->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
124 if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
125 $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
126 
127 
128 $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type, p.entity,";
129 $sql.= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
130 $sql.= " s.rowid as socid, s.nom as name";
131 $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
132 if ($catid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
133 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product";
134 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid";
135 $sql.= " WHERE p.entity IN (".getEntity('product').")";
136 if ($sRefSupplier)
137 {
138  $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
139 }
140 if (GETPOST('type'))
141 {
142  $sql .= " AND p.fk_product_type = " . GETPOST('type','int');
143 }
144 if ($sref)
145 {
146  $sql .= natural_search('p.ref', $sref);
147 }
148 if ($snom)
149 {
150  $sql .= natural_search('p.label', $snom);
151 }
152 if($catid)
153 {
154  $sql .= " AND cp.fk_categorie = ".$catid;
155 }
156 if ($fourn_id > 0)
157 {
158  $sql .= " AND ppf.fk_soc = ".$fourn_id;
159 }
160 
161 $sql .= $db->order($sortfield,$sortorder);
162 
163 // Count total nb of records without orderby and limit
164 $nbtotalofrecords = '';
165 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
166 {
167  $result = $db->query($sql);
168  $nbtotalofrecords = $db->num_rows($result);
169  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
170  {
171  $page = 0;
172  $offset = 0;
173  }
174 }
175 
176 $sql .= $db->plimit($limit + 1, $offset);
177 
178 dol_syslog("fourn/product/list.php:", LOG_DEBUG);
179 $resql = $db->query($sql);
180 if ($resql)
181 {
182  $num = $db->num_rows($resql);
183 
184  $i = 0;
185 
186  if ($num == 1 && (GETPOST("mode") == 'search'))
187  {
188  $objp = $db->fetch_object($resql);
189  header("Location: ".DOL_URL_ROOT."/product/card.php?id=".$objp->rowid);
190  exit;
191  }
192 
193  if (! empty($supplier->id)) $texte = $langs->trans("ListOfSupplierProductForSupplier",$supplier->name);
194  else $texte = $langs->trans("List");
195 
196  llxHeader("","",$texte);
197 
198 
199  $param="&tobuy=".$tobuy."&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type)?"&amp;type=".$type:"").(empty($sRefSupplier)?"":"&amp;srefsupplier=".$sRefSupplier);
200  if ($optioncss != '') $param.='&optioncss='.$optioncss;
201  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
202 
203 
204  if (! empty($catid))
205  {
206  print "<div id='ways'>";
207  $c = new Categorie($db);
208  $ways = $c->print_all_ways(' &gt; ','fourn/product/list.php');
209  print " &gt; ".$ways[0]."<br>\n";
210  print "</div><br>";
211  }
212 
213  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
214  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
215  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
216  if ($fourn_id > 0) print '<input type="hidden" name="fourn_id" value="'.$fourn_id.'">';
217  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
218  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
219  print '<input type="hidden" name="page" value="'.$page.'">';
220  print '<input type="hidden" name="type" value="'.$type.'">';
221 
222  $topicmail="Information";
223  $modelmail="product";
224  $objecttmp=new Product($db);
225  $trackid='prod'.$object->id;
226  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
227 
228  print '<table class="liste" width="100%">';
229 
230  // Lignes des champs de filtre
231  print '<tr class="liste_titre">';
232  print '<td class="liste_titre">';
233  print '<input class="flat" type="text" name="sref" value="'.$sref.'" size="12">';
234  print '</td>';
235  print '<td class="liste_titre">';
236  print '<input class="flat" type="text" name="srefsupplier" value="'.$sRefSupplier.'" size="12">';
237  print '</td>';
238  print '<td class="liste_titre">';
239  print '<input class="flat" type="text" name="snom" value="'.$snom.'">';
240  print '</td>';
241  print '<td></td>';
242  print '<td></td>';
243  print '<td></td>';
244  print '<td></td>';
245  print '<td class="liste_titre" align="right">';
246  $searchpicto=$form->showFilterButtons();
247  print $searchpicto;
248  print '</td>';
249  print '</tr>';
250 
251  // Lignes des titres
252  print '<tr class="liste_titre">';
253  print_liste_field_titre("Ref",$_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder);
254  print_liste_field_titre("RefSupplierShort",$_SERVER["PHP_SELF"], "ppf.ref_fourn",$param,"","",$sortfield,$sortorder);
255  print_liste_field_titre("Label",$_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder);
256  print_liste_field_titre("Supplier",$_SERVER["PHP_SELF"], "ppf.fk_soc",$param,"","",$sortfield,$sortorder);
257  print_liste_field_titre("BuyingPrice",$_SERVER["PHP_SELF"], "ppf.price",$param,"",'align="right"',$sortfield,$sortorder);
258  print_liste_field_titre("QtyMin",$_SERVER["PHP_SELF"], "ppf.quantity",$param,"",'align="right"',$sortfield,$sortorder);
259  print_liste_field_titre("UnitPrice",$_SERVER["PHP_SELF"], "ppf.unitprice",$param,"",'align="right"',$sortfield,$sortorder);
260  print_liste_field_titre('',$_SERVER["PHP_SELF"]);
261  print "</tr>\n";
262 
263  $oldid = '';
264 
265  while ($i < min($num,$limit))
266  {
267  $objp = $db->fetch_object($resql);
268 
269  print '<tr class="oddeven">';
270 
271  print '<td>';
272  $productstatic->id=$objp->rowid;
273  $productstatic->ref=$objp->ref;
274  $productstatic->type=$objp->fk_product_type;
275  $productstatic->entity=$objp->entity;
276  print $productstatic->getNomUrl(1,'supplier');
277  print '</td>';
278 
279  print '<td>'.$objp->ref_fourn.'</td>';
280 
281  print '<td>'.$objp->label.'</td>'."\n";
282 
283  $companystatic->name=$objp->name;
284  $companystatic->id=$objp->socid;
285  print '<td>';
286  if ($companystatic->id > 0) print $companystatic->getNomUrl(1,'supplier');
287  print '</td>';
288 
289  print '<td align="right">'.(isset($objp->price) ? price($objp->price) : '').'</td>';
290 
291  print '<td align="right">'.$objp->qty.'</td>';
292 
293  print '<td align="right">'.(isset($objp->unitprice) ? price($objp->unitprice) : '').'</td>';
294 
295  print '<td align="right"></td>';
296 
297  print "</tr>\n";
298  $i++;
299  }
300  $db->free($resql);
301 
302  print "</table>";
303 
304  print '</form>';
305 }
306 else
307 {
308  dol_print_error($db);
309 }
310 
311 // End of page
312 llxFooter();
313 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
Class to manage products or services.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage suppliers.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage categories.
llxHeader()
Empty header.
Definition: wrapper.php:44
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.