dolibarr  16.0.5
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 <https://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 $sref = GETPOST('sref', 'alphanohtml');
37 $sRefSupplier = GETPOST('srefsupplier');
38 $snom = GETPOST('snom', 'alphanohtml');
39 $type = GETPOST('type', 'alphanohtml');
40 $optioncss = GETPOST('optioncss', 'alpha');
41 
42 // Load variable for pagination
43 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
44 $sortfield = GETPOST('sortfield', 'aZ09comma');
45 $sortorder = GETPOST('sortorder', 'aZ09comma');
46 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
47 if (empty($page) || $page == -1) {
48  $page = 0;
49 } // If $page is not defined, or '' or -1
50 $offset = $limit * $page;
51 $pageprev = $page - 1;
52 $pagenext = $page + 1;
53 if (!$sortfield) {
54  $sortfield = "p.ref"; // Set here default search field
55 }
56 if (!$sortorder) {
57  $sortorder = "ASC";
58 }
59 
60 $fourn_id = GETPOST('fourn_id', 'intcomma');
61 if ($user->socid) {
62  $fourn_id = $user->socid;
63 }
64 
65 $catid = GETPOST('catid', 'intcomma');
66 
67 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
68 $hookmanager->initHooks(array('supplierpricelist'));
69 $extrafields = new ExtraFields($db);
70 
71 if (empty($user->rights->produit->lire) && empty($user->rights->service->lire)) {
73 }
74 
75 $permissiontoadd = ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'));
76 
77 
78 /*
79  * Actions
80  */
81 
82 if (GETPOST('cancel', 'alpha')) {
83  $action = 'list'; $massaction = '';
84 }
85 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
86  $massaction = '';
87 }
88 
89 $parameters = array();
90 
91 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
92 if ($reshook < 0) {
93  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
94 }
95 
96 if (empty($reshook)) {
97  // Selection of new fields
98  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
99 
100  // Purge search criteria
101  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
102  $sref = '';
103  $sRefSupplier = '';
104  $snom = '';
105  $search_field1 = '';
106  $search_field2 = '';
107  $search_date_creation = '';
108  $search_date_update = '';
109  $toselect = array();
110  $search_array_options = array();
111  }
112 }
113 
114 /*
115  * View
116  */
117 
118 $form = new Form($db);
119 $productstatic = new Product($db);
120 $companystatic = new Societe($db);
121 
122 $title = $langs->trans('Supplier')." - ".$langs->trans('ProductsAndServices');
123 
124 if ($fourn_id) {
125  $supplier = new Fournisseur($db);
126  $supplier->fetch($fourn_id);
127 }
128 
129 
130 
131 $arrayofmassactions = array(
132  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
133  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
134  'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
135 );
136 if ($user->rights->mymodule->supprimer) {
137  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
138 }
139 if (in_array($massaction, array('presend', 'predelete'))) {
140  $arrayofmassactions = array();
141 }
142 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
143 
144 
145 $sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type, p.entity, p.tosell, p.tobuy, p.barcode, p.fk_barcode_type,";
146 $sql .= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
147 $sql .= " s.rowid as socid, s.nom as name";
148 // Add fields to SELECT from hooks
149 $parameters = array();
150 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action);
151 if ($reshook < 0) {
152  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
153 }
154 $sql .= $hookmanager->resPrint;
155 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
156 if ($catid) {
157  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
158 }
159 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product AND p.entity = ppf.entity";
160 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid AND s.entity IN (".getEntity('societe').")";
161 $sql .= " WHERE p.entity IN (".getEntity('product').")";
162 if ($sRefSupplier) {
163  $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
164 }
165 if (GETPOST('type')) {
166  $sql .= " AND p.fk_product_type = ".GETPOST('type', 'int');
167 }
168 if ($sref) {
169  $sql .= natural_search('p.ref', $sref);
170 }
171 if ($snom) {
172  $sql .= natural_search('p.label', $snom);
173 }
174 if ($catid) {
175  $sql .= " AND cp.fk_categorie = ".((int) $catid);
176 }
177 if ($fourn_id > 0) {
178  $sql .= " AND ppf.fk_soc = ".((int) $fourn_id);
179 }
180 
181 // Add WHERE filters from hooks
182 $parameters = array();
183 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
184 if ($reshook < 0) {
185  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
186 }
187 $sql .= $hookmanager->resPrint;
188 
189 $sql .= $db->order($sortfield, $sortorder);
190 
191 // Count total nb of records without orderby and limit
192 $nbtotalofrecords = '';
193 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
194  $result = $db->query($sql);
195  $nbtotalofrecords = $db->num_rows($result);
196  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
197  $page = 0;
198  $offset = 0;
199  }
200 }
201 
202 $sql .= $db->plimit($limit + 1, $offset);
203 
204 dol_syslog("fourn/product/list.php:", LOG_DEBUG);
205 $resql = $db->query($sql);
206 if ($resql) {
207  $num = $db->num_rows($resql);
208 
209  $i = 0;
210 
211  if ($num == 1 && (GETPOST("mode") == 'search')) {
212  $objp = $db->fetch_object($resql);
213  header("Location: ".DOL_URL_ROOT."/product/card.php?id=".$objp->rowid);
214  exit;
215  }
216 
217  if (!empty($supplier->id)) {
218  $texte = $langs->trans("ListOfSupplierProductForSupplier", $supplier->name);
219  } else {
220  $texte = $langs->trans("List");
221  }
222 
223  llxHeader("", "", $texte);
224 
225  $param = "&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type) ? "&amp;type=".$type : "").(empty($sRefSupplier) ? "" : "&amp;srefsupplier=".$sRefSupplier);
226  if ($optioncss != '') {
227  $param .= '&optioncss='.$optioncss;
228  }
229 
230  $newcardbutton = '';
231  $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/list.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
232 
233  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton);
234 
235  if (!empty($catid)) {
236  print "<div id='ways'>";
237  $c = new Categorie($db);
238  $ways = $c->print_all_ways(' &gt; ', 'fourn/product/list.php');
239  print " &gt; ".$ways[0]."<br>\n";
240  print "</div><br>";
241  }
242 
243  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
244  if ($optioncss != '') {
245  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
246  }
247  print '<input type="hidden" name="token" value="'.newToken().'">';
248  if ($fourn_id > 0) {
249  print '<input type="hidden" name="fourn_id" value="'.$fourn_id.'">';
250  }
251  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
252  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
253  print '<input type="hidden" name="page" value="'.$page.'">';
254  print '<input type="hidden" name="type" value="'.$type.'">';
255 
256  $topicmail = "Information";
257  $modelmail = "product";
258  $objecttmp = new Product($db);
259  $trackid = 'prod'.$object->id;
260  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
261 
262  print '<div class="div-table-responsive-no-min">';
263  print '<table class="liste centpercent">';
264 
265  // Fields title search
266  print '<tr class="liste_titre">';
267  print '<td class="liste_titre">';
268  print '<input class="flat maxwidth100" type="text" name="sref" value="'.$sref.'">';
269  print '</td>';
270  print '<td class="liste_titre">';
271  print '<input class="flat maxwidth100" type="text" name="srefsupplier" value="'.$sRefSupplier.'">';
272  print '</td>';
273  print '<td class="liste_titre">';
274  print '<input class="flat maxwidth100" type="text" name="snom" value="'.$snom.'">';
275  print '</td>';
276  print '<td></td>';
277  print '<td></td>';
278  print '<td></td>';
279  print '<td></td>';
280  // add filters from hooks
281  $parameters = array();
282  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action);
283  if ($reshook < 0) {
284  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
285  }
286  print $hookmanager->resPrint;
287  print '<td class="liste_titre maxwidthsearch">';
288  $searchpicto = $form->showFilterButtons();
289  print $searchpicto;
290  print '</td>';
291  print '</tr>';
292 
293  // Line for title
294  print '<tr class="liste_titre">';
295  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", $param, "", "", $sortfield, $sortorder);
296  print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "ppf.ref_fourn", $param, "", "", $sortfield, $sortorder);
297  print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", $param, "", "", $sortfield, $sortorder);
298  print_liste_field_titre("Supplier", $_SERVER["PHP_SELF"], "ppf.fk_soc", $param, "", "", $sortfield, $sortorder);
299  print_liste_field_titre("BuyingPrice", $_SERVER["PHP_SELF"], "ppf.price", $param, "", '', $sortfield, $sortorder, 'right ');
300  print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "ppf.quantity", $param, "", '', $sortfield, $sortorder, 'right ');
301  print_liste_field_titre("UnitPrice", $_SERVER["PHP_SELF"], "ppf.unitprice", $param, "", '', $sortfield, $sortorder, 'right ');
302  // add header cells from hooks
303  $parameters = array();
304  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action);
305  if ($reshook < 0) {
306  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
307  }
308  print $hookmanager->resPrint;
309  print_liste_field_titre('', $_SERVER["PHP_SELF"]);
310  print "</tr>\n";
311 
312  while ($i < min($num, $limit)) {
313  $objp = $db->fetch_object($resql);
314 
315  $productstatic->id = $objp->rowid;
316  $productstatic->ref = $objp->ref;
317  $productstatic->type = $objp->fk_product_type;
318  $productstatic->entity = $objp->entity;
319  $productstatic->status = $objp->tosell;
320  $productstatic->status_buy = $objp->tobuy;
321  $productstatic->barcode = $objp->barcode;
322  $productstatic->barcode_type = $objp->fk_barcode_type;
323 
324  print '<tr class="oddeven">';
325 
326  print '<td>';
327  print $productstatic->getNomUrl(1, 'supplier');
328  print '</td>';
329 
330  print '<td>'.$objp->ref_fourn.'</td>';
331 
332  print '<td>'.$objp->label.'</td>'."\n";
333 
334  $companystatic->name = $objp->name;
335  $companystatic->id = $objp->socid;
336  print '<td>';
337  if ($companystatic->id > 0) {
338  print $companystatic->getNomUrl(1, 'supplier');
339  }
340  print '</td>';
341 
342  print '<td class="right">'.(isset($objp->price) ? price($objp->price) : '').'</td>';
343 
344  print '<td class="right">'.$objp->qty.'</td>';
345 
346  print '<td class="right">'.(isset($objp->unitprice) ? price($objp->unitprice) : '').'</td>';
347 
348  // add additional columns from hooks
349  $parameters = array();
350  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action);
351  if ($reshook < 0) {
352  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
353  }
354  print $hookmanager->resPrint;
355 
356  print '<td class="right"></td>';
357 
358  print "</tr>\n";
359  $i++;
360  }
361  $db->free($resql);
362 
363  // If no record found
364  if ($num == 0) {
365  $colspan = 8;
366  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
367  }
368 
369  print "</table></div>";
370 
371  print '</form>';
372 } else {
373  dol_print_error($db);
374 }
375 
376 // End of page
377 llxFooter();
378 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Categorie
Class to manage categories.
Definition: categorie.class.php:47
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3880
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
Fournisseur
Class to manage suppliers.
Definition: fournisseur.class.php:34
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:10605
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5257
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
natural_search
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...
Definition: functions.lib.php:9420
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
price
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.
Definition: functions.lib.php:5541
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59