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