dolibarr 18.0.6
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'; $massaction = '';
91}
92if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
93 $massaction = '';
94}
95
96$parameters = array();
97
98$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
99if ($reshook < 0) {
100 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
101}
102
103if (empty($reshook)) {
104 // Selection of new fields
105 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
106
107 // Purge search criteria
108 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
109 $sref = '';
110 $sRefSupplier = '';
111 $snom = '';
112 $search_field1 = '';
113 $search_field2 = '';
114 $search_date_creation = '';
115 $search_date_update = '';
116 $toselect = array();
117 $search_array_options = array();
118 }
119}
120
121
122/*
123 * View
124 */
125
126$form = new Form($db);
127$productstatic = new Product($db);
128$companystatic = new Societe($db);
129
130$title = $langs->trans('Supplier')." - ".$langs->trans('ProductsAndServices');
131
132if ($fourn_id) {
133 $supplier = new Fournisseur($db);
134 $supplier->fetch($fourn_id);
135}
136
137
138
139$arrayofmassactions = array(
140 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
141 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
142 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
143);
144if ($user->hasRight('mymodule', 'supprimer')) {
145 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
146}
147if (in_array($massaction, array('presend', 'predelete'))) {
148 $arrayofmassactions = array();
149}
150$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
151
152
153$sql = "SELECT p.rowid, p.label, p.ref, p.fk_product_type, p.entity, p.tosell, p.tobuy, p.barcode, p.fk_barcode_type,";
154$sql .= " ppf.fk_soc, ppf.ref_fourn, ppf.price as price, ppf.quantity as qty, ppf.unitprice,";
155$sql .= " s.rowid as socid, s.nom as name";
156// Add fields to SELECT from hooks
157$parameters = array();
158$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action);
159if ($reshook < 0) {
160 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
161}
162$sql .= $hookmanager->resPrint;
163
164$sqlfields = $sql; // $sql fields to remove for count total
165
166$sql .= " FROM ".MAIN_DB_PREFIX."product as p";
167if ($catid) {
168 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON cp.fk_product = p.rowid";
169}
170$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as ppf ON p.rowid = ppf.fk_product AND p.entity = ppf.entity";
171$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON ppf.fk_soc = s.rowid AND s.entity IN (".getEntity('societe').")";
172$sql .= " WHERE p.entity IN (".getEntity('product').")";
173if ($sRefSupplier) {
174 $sql .= natural_search('ppf.ref_fourn', $sRefSupplier);
175}
176if (GETPOST('type')) {
177 $sql .= " AND p.fk_product_type = ".GETPOST('type', 'int');
178}
179if ($sref) {
180 $sql .= natural_search('p.ref', $sref);
181}
182if ($snom) {
183 $sql .= natural_search('p.label', $snom);
184}
185if ($catid) {
186 $sql .= " AND cp.fk_categorie = ".((int) $catid);
187}
188if ($fourn_id > 0) {
189 $sql .= " AND ppf.fk_soc = ".((int) $fourn_id);
190}
191
192// Add WHERE filters from hooks
193$parameters = array();
194$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);
195if ($reshook < 0) {
196 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
197}
198$sql .= $hookmanager->resPrint;
199
200// Count total nb of records
201$nbtotalofrecords = '';
202if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
203 /* The fast and low memory method to get and count full list converts the sql into a sql count */
204 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
205 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
206 $resql = $db->query($sqlforcount);
207 if ($resql) {
208 $objforcount = $db->fetch_object($resql);
209 $nbtotalofrecords = $objforcount->nbtotalofrecords;
210 } else {
211 dol_print_error($db);
212 }
213
214 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
215 $page = 0;
216 $offset = 0;
217 }
218 $db->free($resql);
219}
220
221// Complete request and execute it with limit
222$sql .= $db->order($sortfield, $sortorder);
223if ($limit) {
224 $sql .= $db->plimit($limit + 1, $offset);
225}
226
227dol_syslog("fourn/product/list.php:", LOG_DEBUG);
228$resql = $db->query($sql);
229if ($resql) {
230 $num = $db->num_rows($resql);
231
232 $i = 0;
233
234 if ($num == 1 && (GETPOST("mode") == 'search')) {
235 $objp = $db->fetch_object($resql);
236 header("Location: ".DOL_URL_ROOT."/product/card.php?id=".$objp->rowid);
237 exit;
238 }
239
240 if (!empty($supplier->id)) {
241 $texte = $langs->trans("ListOfSupplierProductForSupplier", $supplier->name);
242 } else {
243 $texte = $langs->trans("List");
244 }
245
246 llxHeader("", "", $texte);
247
248 $param = "&sref=".$sref."&snom=".$snom."&fourn_id=".$fourn_id.(isset($type) ? "&amp;type=".$type : "").(empty($sRefSupplier) ? "" : "&amp;srefsupplier=".$sRefSupplier);
249 if ($optioncss != '') {
250 $param .= '&optioncss='.$optioncss;
251 }
252
253 $newcardbutton = '';
254 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/list.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
255
256 print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'generic', 0, $newcardbutton);
257
258 if (!empty($catid)) {
259 print "<div id='ways'>";
260 $c = new Categorie($db);
261 $ways = $c->print_all_ways(' &gt; ', 'fourn/product/list.php');
262 print " &gt; ".$ways[0]."<br>\n";
263 print "</div><br>";
264 }
265
266 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
267 if ($optioncss != '') {
268 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
269 }
270 print '<input type="hidden" name="token" value="'.newToken().'">';
271 if ($fourn_id > 0) {
272 print '<input type="hidden" name="fourn_id" value="'.$fourn_id.'">';
273 }
274 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
275 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
276 print '<input type="hidden" name="page" value="'.$page.'">';
277 print '<input type="hidden" name="type" value="'.$type.'">';
278
279 $topicmail = "Information";
280 $modelmail = "product";
281 $objecttmp = new Product($db);
282 $trackid = 'prod'.$object->id;
283 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
284
285 print '<div class="div-table-responsive-no-min">';
286 print '<table class="liste centpercent">';
287
288 // Fields title search
289 print '<tr class="liste_titre">';
290 print '<td class="liste_titre">';
291 print '<input class="flat maxwidth100" type="text" name="sref" value="'.$sref.'">';
292 print '</td>';
293 print '<td class="liste_titre">';
294 print '<input class="flat maxwidth100" type="text" name="srefsupplier" value="'.$sRefSupplier.'">';
295 print '</td>';
296 print '<td class="liste_titre">';
297 print '<input class="flat maxwidth100" type="text" name="snom" value="'.$snom.'">';
298 print '</td>';
299 print '<td></td>';
300 print '<td></td>';
301 print '<td></td>';
302 print '<td></td>';
303 // add filters from hooks
304 $parameters = array();
305 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action);
306 if ($reshook < 0) {
307 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
308 }
309 print $hookmanager->resPrint;
310 print '<td class="liste_titre maxwidthsearch">';
311 $searchpicto = $form->showFilterButtons();
312 print $searchpicto;
313 print '</td>';
314 print '</tr>';
315
316 // Line for title
317 print '<tr class="liste_titre">';
318 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "p.ref", $param, "", "", $sortfield, $sortorder);
319 print_liste_field_titre("RefSupplierShort", $_SERVER["PHP_SELF"], "ppf.ref_fourn", $param, "", "", $sortfield, $sortorder);
320 print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "p.label", $param, "", "", $sortfield, $sortorder);
321 print_liste_field_titre("Supplier", $_SERVER["PHP_SELF"], "ppf.fk_soc", $param, "", "", $sortfield, $sortorder);
322 print_liste_field_titre("BuyingPrice", $_SERVER["PHP_SELF"], "ppf.price", $param, "", '', $sortfield, $sortorder, 'right ');
323 print_liste_field_titre("QtyMin", $_SERVER["PHP_SELF"], "ppf.quantity", $param, "", '', $sortfield, $sortorder, 'right ');
324 print_liste_field_titre("UnitPrice", $_SERVER["PHP_SELF"], "ppf.unitprice", $param, "", '', $sortfield, $sortorder, 'right ');
325 // add header cells from hooks
326 $parameters = array();
327 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action);
328 if ($reshook < 0) {
329 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
330 }
331 print $hookmanager->resPrint;
332 print_liste_field_titre('', $_SERVER["PHP_SELF"]);
333 print "</tr>\n";
334
335 while ($i < min($num, $limit)) {
336 $objp = $db->fetch_object($resql);
337
338 $productstatic->id = $objp->rowid;
339 $productstatic->ref = $objp->ref;
340 $productstatic->type = $objp->fk_product_type;
341 $productstatic->entity = $objp->entity;
342 $productstatic->status = $objp->tosell;
343 $productstatic->status_buy = $objp->tobuy;
344 $productstatic->barcode = $objp->barcode;
345 $productstatic->barcode_type = $objp->fk_barcode_type;
346
347 print '<tr class="oddeven">';
348
349 print '<td>';
350 print $productstatic->getNomUrl(1, 'supplier');
351 print '</td>';
352
353 print '<td>'.$objp->ref_fourn.'</td>';
354
355 print '<td>'.$objp->label.'</td>'."\n";
356
357 $companystatic->name = $objp->name;
358 $companystatic->id = $objp->socid;
359 print '<td>';
360 if ($companystatic->id > 0) {
361 print $companystatic->getNomUrl(1, 'supplier');
362 }
363 print '</td>';
364
365 print '<td class="right">'.(isset($objp->price) ? price($objp->price) : '').'</td>';
366
367 print '<td class="right">'.$objp->qty.'</td>';
368
369 print '<td class="right">'.(isset($objp->unitprice) ? price($objp->unitprice) : '').'</td>';
370
371 // add additional columns from hooks
372 $parameters = array();
373 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objp, $action);
374 if ($reshook < 0) {
375 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
376 }
377 print $hookmanager->resPrint;
378
379 print '<td class="right"></td>';
380
381 print "</tr>\n";
382 $i++;
383 }
384 $db->free($resql);
385
386 // If no record found
387 if ($num == 0) {
388 $colspan = 8;
389 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
390 }
391
392 print "</table></div>";
393
394 print '</form>';
395} else {
396 dol_print_error($db);
397}
398
399// End of page
400llxFooter();
401$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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 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.