dolibarr  16.0.5
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
6  * Copyright (C) 2013-2019 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
8  * Copyright (C) 2013 Jean Heimburger <jean@tiaris.info>
9  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
10  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11  * Copyright (C) 2013 Adolfo segura <adolfo.segura@gmail.com>
12  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
13  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
14  * Copyright (C) 2020-2021 Open-DSI <support@open-dsi.fr>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
36 require '../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
45 if (!empty($conf->categorie->enabled)) {
46  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
47 }
48 
49 // Load translation files required by the page
50 $langs->loadLangs(array('products', 'stocks', 'suppliers', 'companies', 'margins'));
51 if (!empty($conf->productbatch->enabled)) {
52  $langs->load("productbatch");
53 }
54 
55 $action = GETPOST('action', 'aZ09');
56 $massaction = GETPOST('massaction', 'alpha');
57 $show_files = GETPOST('show_files', 'int');
58 $confirm = GETPOST('confirm', 'alpha');
59 $toselect = GETPOST('toselect', 'array');
60 
61 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
62 $search_id = GETPOST("search_id", 'alpha');
63 $search_ref = GETPOST("search_ref", 'alpha');
64 $search_ref_supplier = GETPOST("search_ref_supplier", 'alpha');
65 $search_barcode = GETPOST("search_barcode", 'alpha');
66 $search_label = GETPOST("search_label", 'alpha');
67 $search_type = GETPOST("search_type", 'int');
68 $search_vatrate = GETPOST("search_vatrate", 'alpha');
69 $searchCategoryProductOperator = 0;
70 if (GETPOSTISSET('formfilteraction')) {
71  $searchCategoryProductOperator = GETPOST('search_category_product_operator', 'int');
72 } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
73  $searchCategoryProductOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
74 }
75 $searchCategoryProductList = GETPOST('search_category_product_list', 'array');
76 $search_tosell = GETPOST("search_tosell", 'int');
77 $search_tobuy = GETPOST("search_tobuy", 'int');
78 $search_country = GETPOST("search_country", 'int');
79 $search_state = GETPOST("state_id", 'int');
80 $fourn_id = GETPOST("fourn_id", 'int');
81 $catid = GETPOST('catid', 'int');
82 $search_tobatch = GETPOST("search_tobatch", 'int');
83 $search_accountancy_code_sell = GETPOST("search_accountancy_code_sell", 'alpha');
84 $search_accountancy_code_sell_intra = GETPOST("search_accountancy_code_sell_intra", 'alpha');
85 $search_accountancy_code_sell_export = GETPOST("search_accountancy_code_sell_export", 'alpha');
86 $search_accountancy_code_buy = GETPOST("search_accountancy_code_buy", 'alpha');
87 $search_accountancy_code_buy_intra = GETPOST("search_accountancy_code_buy_intra", 'alpha');
88 $search_accountancy_code_buy_export = GETPOST("search_accountancy_code_buy_export", 'alpha');
89 $search_finished = GETPOST("search_finished", 'int');
90 $optioncss = GETPOST('optioncss', 'alpha');
91 $type = GETPOST("type", "int");
92 
93 //Show/hide child products
94 if (!empty($conf->variants->enabled) && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
95  $show_childproducts = GETPOST('search_show_childproducts');
96 } else {
97  $show_childproducts = '';
98 }
99 
100 $diroutputmassaction = $conf->product->dir_output.'/temp/massgeneration/'.$user->id;
101 
102 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
103 $sortfield = GETPOST('sortfield', 'aZ09comma');
104 $sortorder = GETPOST('sortorder', 'aZ09comma');
105 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
106 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
107  $page = 0;
108 } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
109 $offset = $limit * $page;
110 $pageprev = $page - 1;
111 $pagenext = $page + 1;
112 if (!$sortfield) {
113  $sortfield = "p.ref";
114 }
115 if (!$sortorder) {
116  $sortorder = "ASC";
117 }
118 
119 // Initialize context for list
120 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'productservicelist';
121 if ((string) $type == '1') {
122  $contextpage = 'servicelist'; if ($search_type == '') {
123  $search_type = '1';
124  }
125 }
126 if ((string) $type == '0') {
127  $contextpage = 'productlist'; if ($search_type == '') {
128  $search_type = '0';
129  }
130 }
131 
132 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array of hooks
133 $object = new Product($db);
134 $hookmanager->initHooks(array('productservicelist'));
135 $extrafields = new ExtraFields($db);
136 $form = new Form($db);
137 $formcompany = new FormCompany($db);
138 $formproduct = new FormProduct($db);
139 
140 // fetch optionals attributes and labels
141 $extrafields->fetch_name_optionals_label($object->table_element);
142 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
143 
144 if (empty($action)) {
145  $action = 'list';
146 }
147 
148 // Get object canvas (By default, this is not defined, so standard usage of dolibarr)
149 $canvas = GETPOST("canvas");
150 $objcanvas = null;
151 if (!empty($canvas)) {
152  require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php';
153  $objcanvas = new Canvas($db, $action);
154  $objcanvas->getCanvas('product', 'list', $canvas);
155 }
156 
157 // Define virtualdiffersfromphysical
158 $virtualdiffersfromphysical = 0;
159 if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
160  || !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
161  || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)
162  || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION)
163  || !empty($conf->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE)
164  || !empty($conf->mrp->enabled)) {
165  $virtualdiffersfromphysical = 1; // According to increase/decrease stock options, virtual and physical stock may differs.
166 }
167 
168 // List of fields to search into when doing a "search in all"
169 $fieldstosearchall = array(
170  'p.ref'=>"Ref",
171  'p.label'=>"ProductLabel",
172  'p.description'=>"Description",
173  "p.note"=>"Note",
174  'pfp.ref_fourn'=>"RefSupplier",
175 
176 );
177 // multilang
178 if (!empty($conf->global->MAIN_MULTILANGS)) {
179  $fieldstosearchall['pl.label'] = 'ProductLabelTranslated';
180  $fieldstosearchall['pl.description'] = 'ProductDescriptionTranslated';
181  $fieldstosearchall['pl.note'] = 'ProductNoteTranslated';
182 }
183 if (!empty($conf->barcode->enabled)) {
184  $fieldstosearchall['p.barcode'] = 'Gencod';
185  $fieldstosearchall['pfp.barcode'] = 'GencodBuyPrice';
186 }
187 // Personalized search criterias. Example: $conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS = 'p.ref=ProductRef;p.label=ProductLabel;p.description=Description;p.note=Note;'
188 if (!empty($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS)) {
189  $fieldstosearchall = dolExplodeIntoArray($conf->global->PRODUCT_QUICKSEARCH_ON_FIELDS);
190 }
191 
192 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
193  $titlesellprice = $langs->trans("SellingPrice");
194  if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
195  $titlesellprice = $form->textwithpicto($langs->trans("SellingPrice"), $langs->trans("DefaultPriceRealPriceMayDependOnCustomer"));
196  }
197 }
198 
199 $isInEEC = isInEEC($mysoc);
200 
201 $alias_product_perentity = empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED) ? "p" : "ppe";
202 
203 // Definition of array of fields for columns
204 $arrayfields = array(
205  'p.rowid'=>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'noteditable'=>1, 'notnull'=> 1, 'index'=>1, 'position'=>1, 'comment'=>'Id', 'css'=>'left'),
206  'p.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>10),
207  //'pfp.ref_fourn'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1, 'enabled'=>(! empty($conf->barcode->enabled))),
208  'thumbnail'=>array('label'=>'Photo', 'checked'=>0, 'position'=>10),
209  'p.label'=>array('label'=>"Label", 'checked'=>1, 'position'=>10),
210  'p.fk_product_type'=>array('label'=>"Type", 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && !empty($conf->service->enabled)), 'position'=>11),
211  'p.barcode'=>array('label'=>"Gencod", 'checked'=>1, 'enabled'=>(!empty($conf->barcode->enabled)), 'position'=>12),
212  'p.duration'=>array('label'=>"Duration", 'checked'=>($contextpage != 'productlist'), 'enabled'=>(!empty($conf->service->enabled) && (string) $type == '1'), 'position'=>13),
213  'p.finished'=>array('label'=>"Nature", 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && $type != '1'), 'position'=>19),
214  'p.weight'=>array('label'=>'Weight', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && $type != '1'), 'position'=>20),
215  'p.weight_units'=>array('label'=>'WeightUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && $type != '1'), 'position'=>21),
216  'p.length'=>array('label'=>'Length', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>22),
217  'p.length_units'=>array('label'=>'LengthUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>23),
218  'p.width'=>array('label'=>'Width', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>24),
219  'p.width_units'=>array('label'=>'WidthUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>25),
220  'p.height'=>array('label'=>'Height', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>26),
221  'p.height_units'=>array('label'=>'HeightUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SIZE) && $type != '1'), 'position'=>27),
222  'p.surface'=>array('label'=>'Surface', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SURFACE) && $type != '1'), 'position'=>28),
223  'p.surface_units'=>array('label'=>'SurfaceUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_SURFACE) && $type != '1'), 'position'=>29),
224  'p.volume'=>array('label'=>'Volume', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_VOLUME) && $type != '1'), 'position'=>30),
225  'p.volume_units'=>array('label'=>'VolumeUnits', 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && empty($conf->global->PRODUCT_DISABLE_VOLUME) && $type != '1'), 'position'=>31),
226  'cu.label'=>array('label'=>"DefaultUnitToShow", 'checked'=>0, 'enabled'=>(!empty($conf->product->enabled) && !empty($conf->global->PRODUCT_USE_UNITS)), 'position'=>32),
227  'p.sellprice'=>array('label'=>"SellingPrice", 'checked'=>1, 'enabled'=>empty($conf->global->PRODUIT_MULTIPRICES), 'position'=>40),
228  'p.tva_tx'=>array('label'=>"VATRate", 'checked'=>0, 'enabled'=>empty($conf->global->PRODUIT_MULTIPRICES), 'position'=>41),
229  'p.minbuyprice'=>array('label'=>"BuyingPriceMinShort", 'checked'=>1, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>42),
230  'p.numbuyprice'=>array('label'=>"BuyingPriceNumShort", 'checked'=>0, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>43),
231  'p.pmp'=>array('label'=>"PMPValueShort", 'checked'=>0, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>44),
232  'p.cost_price'=>array('label'=>"CostPrice", 'checked'=>0, 'enabled'=>(!empty($user->rights->fournisseur->lire)), 'position'=>45),
233  'p.seuil_stock_alerte'=>array('label'=>"StockLimit", 'checked'=>0, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && ($contextpage != 'servicelist' || !empty($conf->global->STOCK_SUPPORTS_SERVICES))), 'position'=>50),
234  'p.desiredstock'=>array('label'=>"DesiredStock", 'checked'=>1, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && ($contextpage != 'servicelist' || !empty($conf->global->STOCK_SUPPORTS_SERVICES))), 'position'=>51),
235  'p.stock'=>array('label'=>"PhysicalStock", 'checked'=>1, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && ($contextpage != 'servicelist' || !empty($conf->global->STOCK_SUPPORTS_SERVICES))), 'position'=>52),
236  'stock_virtual'=>array('label'=>"VirtualStock", 'checked'=>1, 'enabled'=>(!empty($conf->stock->enabled) && $user->rights->stock->lire && ($contextpage != 'servicelist' || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $virtualdiffersfromphysical), 'position'=>53),
237  'p.tobatch'=>array('label'=>"ManageLotSerial", 'checked'=>0, 'enabled'=>(!empty($conf->productbatch->enabled)), 'position'=>60),
238  'p.fk_country'=>array('label'=>"Country", 'checked'=>0, 'position'=>100),
239  'p.fk_state'=>array('label'=>"State", 'checked'=>0, 'position'=>101),
240  $alias_product_perentity . '.accountancy_code_sell'=>array('label'=>"ProductAccountancySellCode", 'checked'=>0, 'enabled'=>empty($conf->global->PRODUCT_DISABLE_ACCOUNTING), 'position'=>400),
241  $alias_product_perentity . '.accountancy_code_sell_intra'=>array('label'=>"ProductAccountancySellIntraCode", 'checked'=>0, 'enabled'=>$isInEEC && empty($conf->global->PRODUCT_DISABLE_ACCOUNTING), 'position'=>401),
242  $alias_product_perentity . '.accountancy_code_sell_export'=>array('label'=>"ProductAccountancySellExportCode", 'checked'=>0, 'enabled'=>empty($conf->global->PRODUCT_DISABLE_ACCOUNTING), 'position'=>402),
243  $alias_product_perentity . '.accountancy_code_buy'=>array('label'=>"ProductAccountancyBuyCode", 'checked'=>0, 'enabled'=>empty($conf->global->PRODUCT_DISABLE_ACCOUNTING), 'position'=>403),
244  $alias_product_perentity . '.accountancy_code_buy_intra'=>array('label'=>"ProductAccountancyBuyIntraCode", 'checked'=>0, 'enabled'=>$isInEEC && empty($conf->global->PRODUCT_DISABLE_ACCOUNTING), 'position'=>404),
245  $alias_product_perentity . '.accountancy_code_buy_export'=>array('label'=>"ProductAccountancyBuyExportCode", 'checked'=>0, 'enabled'=>empty($conf->global->PRODUCT_DISABLE_ACCOUNTING), 'position'=>405),
246  'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
247  'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
248  'p.tosell'=>array('label'=>$langs->transnoentitiesnoconv("Status").' ('.$langs->transnoentitiesnoconv("Sell").')', 'checked'=>1, 'position'=>1000),
249  'p.tobuy'=>array('label'=>$langs->transnoentitiesnoconv("Status").' ('.$langs->transnoentitiesnoconv("Buy").')', 'checked'=>1, 'position'=>1000)
250 );
251 /*foreach ($object->fields as $key => $val) {
252  // If $val['visible']==0, then we never show the field
253  if (!empty($val['visible'])) {
254  $visible = dol_eval($val['visible'], 1, 1, '1');
255  $arrayfields['p.'.$key] = array(
256  'label'=>$val['label'],
257  'checked'=>(($visible < 0) ? 0 : 1),
258  'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
259  'position'=>$val['position']
260  );
261  }
262 }*/
263 
264 
265 // MultiPrices
266 if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
267  for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
268  $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
269  if (!empty($conf->global->$keyforlabel)) {
270  $labelp = $i.' - '.$langs->transnoentitiesnoconv($conf->global->$keyforlabel);
271  } else {
272  $labelp = $langs->transnoentitiesnoconv("SellingPrice")." ".$i;
273  }
274  $arrayfields['p.sellprice'.$i] = array('label'=>$labelp, 'checked'=>($i == 1 ? 1 : 0), 'enabled'=>$conf->global->PRODUIT_MULTIPRICES, 'position'=>floatval('40.'.sprintf('%03s', $i)));
275  $arraypricelevel[$i] = array($i);
276  }
277 }
278 
279 //var_dump($arraypricelevel);
280 // Extra fields
281 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
282 
283 $object->fields = dol_sort_array($object->fields, 'position');
284 $arrayfields = dol_sort_array($arrayfields, 'position');
285 
286 // Security check
287 if ($search_type == '0') {
288  $result = restrictedArea($user, 'produit', '', '', '', '', '', 0);
289 } elseif ($search_type == '1') {
290  $result = restrictedArea($user, 'service', '', '', '', '', '', 0);
291 } else {
292  $result = restrictedArea($user, 'produit|service', '', '', '', '', '', 0);
293 }
294 
295 
296 /*
297  * Actions
298  */
299 
300 if (GETPOST('cancel', 'alpha')) {
301  $action = 'list'; $massaction = '';
302 }
303 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
304  $massaction = '';
305 }
306 
307 $parameters = array();
308 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
309 if ($reshook < 0) {
310  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
311 }
312 
313 $rightskey = 'produit';
314 if ($type == Product::TYPE_SERVICE) {
315  $rightskey = 'service';
316 }
317 
318 if (empty($reshook)) {
319  // Selection of new fields
320  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
321 
322  // Purge search criteria
323  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
324  $sall = "";
325  $search_id = '';
326  $search_ref = "";
327  $search_ref_supplier = "";
328  $search_label = "";
329  $search_barcode = "";
330  $searchCategoryProductOperator = 0;
331  $searchCategoryProductList = array();
332  $search_tosell = "";
333  $search_tobuy = "";
334  $search_tobatch = '';
335  $search_country = "";
336  $search_state = "";
337  $search_vatrate = "";
338  $search_finished = '';
339  //$search_type=''; // There is 2 types of list: a list of product and a list of services. No list with both. So when we clear search criteria, we must keep the filter on type.
340 
341  $show_childproducts = '';
342  $search_accountancy_code_sell = '';
343  $search_accountancy_code_sell_intra = '';
344  $search_accountancy_code_sell_export = '';
345  $search_accountancy_code_buy = '';
346  $search_accountancy_code_buy_intra = '';
347  $search_accountancy_code_buy_export = '';
348  $search_array_options = array();
349  }
350 
351  // Mass actions
352  $objectclass = 'Product';
353  if ((string) $search_type == '1') {
354  $objectlabel = 'Services';
355  }
356  if ((string) $search_type == '0') {
357  $objectlabel = 'Products';
358  }
359 
360  $permissiontoread = $user->rights->{$rightskey}->lire;
361  $permissiontodelete = $user->rights->{$rightskey}->supprimer;
362  $permissiontoadd = $user->rights->{$rightskey}->creer;
363  $uploaddir = $conf->product->dir_output;
364  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
365 
366  if (!$error && $massaction == 'switchonsalestatus' && $permissiontoadd) {
367  $product = new Product($db);
368  foreach ($toselect as $toselectid) {
369  $result = $product->fetch($toselectid);
370  if ($result > 0 && $product->id > 0) {
371  $product->setStatut($product->status ? 0 : 1, null, 'product', 'PRODUCT_MODIFY', 'tosell');
372  }
373  }
374  }
375  if (!$error && $massaction == 'switchonpurchasestatus' && $permissiontoadd) {
376  $product = new Product($db);
377  foreach ($toselect as $toselectid) {
378  $result = $product->fetch($toselectid);
379  if ($result > 0 && $product->id > 0) {
380  $product->setStatut($product->status_buy ? 0 : 1, null, 'product', 'PRODUCT_MODIFY', 'tobuy');
381  }
382  }
383  }
384 }
385 
386 
387 /*
388  * View
389  */
390 
391 $title = $langs->trans("ProductsAndServices");
392 
393 if ($search_type != '' && $search_type != '-1') {
394  if ($search_type == 1) {
395  $texte = $langs->trans("Services");
396  } else {
397  $texte = $langs->trans("Products");
398  }
399 } else {
400  $texte = $langs->trans("ProductsAndServices");
401 }
402 
403 $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.fk_product_type, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type, p.entity,';
404 $sql .= ' p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,';
405 $sql .= ' p.tobatch,';
406 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
407  $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
408 } else {
409  $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
410 }
411 $sql .= ' p.datec as date_creation, p.tms as date_update, p.pmp, p.stock, p.cost_price,';
412 $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, fk_country, fk_state,';
413 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
414  $sql .= ' p.fk_unit, cu.label as cu_label,';
415 }
416 $sql .= ' MIN(pfp.unitprice) as minsellprice';
417 if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
418  $sql .= ', pac.rowid prod_comb_id';
419 }
420 // Add fields from extrafields
421 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
422  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
423  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
424  }
425 }
426 // Add fields from hooks
427 $parameters = array();
428 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
429 $sql .= $hookmanager->resPrint;
430 
431 $sqlfields = $sql; // $sql fields to remove for count total
432 
433 $sql .= ' FROM '.MAIN_DB_PREFIX.'product as p';
434 if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
435  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity);
436 }
437 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
438  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_extrafields as ef on (p.rowid = ef.fk_object)";
439 }
440 if (!empty($searchCategoryProductList) || !empty($catid)) {
441  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; // We'll need this table joined to the select in order to filter by categ
442 }
443 $linktopfp = " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
444 $sql .= $linktopfp;
445 // multilang
446 if (!empty($conf->global->MAIN_MULTILANGS)) {
447  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang = '".$db->escape($langs->getDefaultLang())."'";
448 }
449 
450 if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
451  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid";
452 }
453 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
454  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_units cu ON cu.rowid = p.fk_unit";
455 }
456 
457 
458 $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
459 if ($sall) {
460  // Clean $fieldstosearchall
461  $newfieldstosearchall = $fieldstosearchall;
462  unset($newfieldstosearchall['pfp.ref_fourn']);
463  unset($newfieldstosearchall['pfp.barcode']);
464 
465  $sql .= ' AND (';
466  $sql .= natural_search(array_keys($newfieldstosearchall), $sall, 0, 1);
467  // Search also into a supplier reference 'pfp.ref_fourn'="RefSupplier"
468  $sql .= ' OR EXISTS (SELECT rowid FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp WHERE pfp.fk_product = p.rowid';
469  $sql .= ' AND ('.natural_search('pfp.ref_fourn', $sall, 0, 1);
470  if (isModEnabled('barcode')) {
471  // Search also into a supplier barcode 'pfp.barcode'='GencodBuyPrice';
472  $sql .= ' OR '.natural_search('pfp.barcode', $sall, 0, 1);
473  }
474  $sql .= ')))';
475 }
476 // if the type is not 1, we show all products (type = 0,2,3)
477 if (dol_strlen($search_type) && $search_type != '-1') {
478  if ($search_type == 1) {
479  $sql .= " AND p.fk_product_type = 1";
480  } else {
481  $sql .= " AND p.fk_product_type <> 1";
482  }
483 }
484 
485 if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
486  $sql .= " AND pac.rowid IS NULL";
487 }
488 
489 if ($search_id) {
490  $sql .= natural_search('p.rowid', $search_id, 1);
491 }
492 if ($search_ref) {
493  $sql .= natural_search('p.ref', $search_ref);
494 }
495 if ($search_label) {
496  $sql .= natural_search('p.label', $search_label);
497 }
498 if ($search_barcode) {
499  $sql .= natural_search('p.barcode', $search_barcode);
500 }
501 if (isset($search_tosell) && dol_strlen($search_tosell) > 0 && $search_tosell != -1) {
502  $sql .= " AND p.tosell = ".((int) $search_tosell);
503 }
504 if (isset($search_tobuy) && dol_strlen($search_tobuy) > 0 && $search_tobuy != -1) {
505  $sql .= " AND p.tobuy = ".((int) $search_tobuy);
506 }
507 if (isset($search_tobatch) && dol_strlen($search_tobatch) > 0 && $search_tobatch != -1) {
508  $sql .= " AND p.tobatch = ".((int) $search_tobatch);
509 }
510 if ($search_vatrate) {
511  $sql .= natural_search('p.tva_tx', $search_vatrate, 1);
512 }
513 if (dol_strlen($canvas) > 0) {
514  $sql .= " AND p.canvas = '".$db->escape($canvas)."'";
515 }
516 if ($catid > 0) {
517  $sql .= " AND cp.fk_categorie = ".((int) $catid);
518 }
519 if ($catid == -2) {
520  $sql .= " AND cp.fk_categorie IS NULL";
521 }
522 $searchCategoryProductSqlList = array();
523 if ($searchCategoryProductOperator == 1) {
524  foreach ($searchCategoryProductList as $searchCategoryProduct) {
525  if (intval($searchCategoryProduct) == -2) {
526  $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL";
527  } elseif (intval($searchCategoryProduct) > 0) {
528  $searchCategoryProductSqlList[] = "cp.fk_categorie = ".$db->escape($searchCategoryProduct);
529  }
530  }
531  if (!empty($searchCategoryProductSqlList)) {
532  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
533  }
534 } else {
535  foreach ($searchCategoryProductList as $searchCategoryProduct) {
536  if (intval($searchCategoryProduct) == -2) {
537  $searchCategoryProductSqlList[] = "cp.fk_categorie IS NULL";
538  } elseif (intval($searchCategoryProduct) > 0) {
539  $searchCategoryProductSqlList[] = "p.rowid IN (SELECT fk_product FROM ".MAIN_DB_PREFIX."categorie_product WHERE fk_categorie = ".((int) $searchCategoryProduct).")";
540  }
541  }
542  if (!empty($searchCategoryProductSqlList)) {
543  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
544  }
545 }
546 if ($fourn_id > 0) {
547  $sql .= " AND pfp.fk_soc = ".((int) $fourn_id);
548 }
549 if ($search_country) {
550  $sql .= " AND p.fk_country = ".((int) $search_country);
551 }
552 if ($search_state) {
553  $sql .= " AND p.fk_state = ".((int) $search_state);
554 }
555 if ($search_finished >= 0 && $search_finished !== '') {
556  $sql .= " AND p.finished = ".((int) $search_finished);
557 }
558 if ($search_accountancy_code_sell) {
559  $sql .= natural_search($alias_product_perentity . '.accountancy_code_sell', clean_account($search_accountancy_code_sell));
560 }
561 if ($search_accountancy_code_sell_intra) {
562  $sql .= natural_search($alias_product_perentity . '.accountancy_code_sell_intra', clean_account($search_accountancy_code_sell_intra));
563 }
564 if ($search_accountancy_code_sell_export) {
565  $sql .= natural_search($alias_product_perentity . '.accountancy_code_sell_export', clean_account($search_accountancy_code_sell_export));
566 }
567 if ($search_accountancy_code_buy) {
568  $sql .= natural_search($alias_product_perentity . '.accountancy_code_buy', clean_account($search_accountancy_code_buy));
569 }
570 if ($search_accountancy_code_buy_intra) {
571  $sql .= natural_search($alias_product_perentity . '.accountancy_code_buy_intra', clean_account($search_accountancy_code_buy_intra));
572 }
573 if ($search_accountancy_code_buy_export) {
574  $sql .= natural_search($alias_product_perentity . '.accountancy_code_buy_export', clean_account($search_accountancy_code_buy_export));
575 }
576 
577 // Add where from extra fields
578 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
579 // Add where from hooks
580 $parameters = array();
581 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
582 $sql .= $hookmanager->resPrint;
583 $sql .= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.tva_tx, p.price_ttc, p.price_base_type,";
584 $sql .= " p.fk_product_type, p.duration, p.finished, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock,";
585 $sql .= ' p.datec, p.tms, p.entity, p.tobatch, p.pmp, p.cost_price, p.stock,';
586 if (empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) {
587  $sql .= " p.accountancy_code_sell, p.accountancy_code_sell_intra, p.accountancy_code_sell_export, p.accountancy_code_buy, p.accountancy_code_buy_intra, p.accountancy_code_buy_export,";
588 } else {
589  $sql .= " ppe.accountancy_code_sell, ppe.accountancy_code_sell_intra, ppe.accountancy_code_sell_export, ppe.accountancy_code_buy, ppe.accountancy_code_buy_intra, ppe.accountancy_code_buy_export,";
590 }
591 $sql .= ' p.weight, p.weight_units, p.length, p.length_units, p.width, p.width_units, p.height, p.height_units, p.surface, p.surface_units, p.volume, p.volume_units, p.fk_country, p.fk_state';
592 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
593  $sql .= ', p.fk_unit, cu.label';
594 }
595 
596 if (!empty($conf->variants->enabled) && (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD) && !$show_childproducts)) {
597  $sql .= ', pac.rowid';
598 }
599 // Add fields from extrafields
600 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
601  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
602  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
603  }
604 }
605 // Add fields from hooks
606 $parameters = array();
607 $reshook = $hookmanager->executeHooks('printFieldSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
608 $sql .= $hookmanager->resPrint;
609 //if (GETPOST("toolowstock")) $sql.= " HAVING SUM(s.reel) < p.seuil_stock_alerte"; // Not used yet
610 $sql .= $db->order($sortfield, $sortorder);
611 
612 $nbtotalofrecords = '';
613 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
614  /* The fast and low memory method to get and count full list converts the sql into a sql count */
615  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
616  $sqlforcount = preg_replace('/'.preg_quote($linktopfp, '/').'/', '', $sqlforcount);
617  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
618 
619  $resql = $db->query($sqlforcount);
620  if ($resql) {
621  $objforcount = $db->fetch_object($resql);
622  $nbtotalofrecords = $objforcount->nbtotalofrecords;
623  } else {
624  dol_print_error($db);
625  }
626 
627  /*
628  $result = $db->query($sql);
629  $nbtotalofrecords = $db->num_rows($result);
630  */
631 
632  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
633  $page = 0;
634  $offset = 0;
635  }
636 }
637 
638 $sql .= $db->plimit($limit + 1, $offset);
639 
640 $resql = $db->query($sql);
641 
642 if ($resql) {
643  $num = $db->num_rows($resql);
644 
645  $arrayofselected = is_array($toselect) ? $toselect : array();
646 
647  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
648  $obj = $db->fetch_object($resql);
649  $id = $obj->rowid;
650  header("Location: ".DOL_URL_ROOT.'/product/card.php?id='.$id);
651  exit;
652  }
653 
654  $helpurl = '';
655  if ($search_type != '') {
656  if ($search_type == 0) {
657  $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
658  } elseif ($search_type == 1) {
659  $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
660  }
661  }
662 
663  $paramsCat = '';
664  foreach ($searchCategoryProductList as $searchCategoryProduct) {
665  $paramsCat .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
666  }
667 
668  //llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, 'classforhorizontalscrolloftabs');
669  llxHeader('', $title, $helpurl, '', 0, 0, array(), array(), $paramsCat, '');
670 
671  // Displays product removal confirmation
672  if (GETPOST('delprod')) {
673  setEventMessages($langs->trans("ProductDeleted", GETPOST('delprod')), null, 'mesgs');
674  }
675 
676  $param = '';
677  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
678  $param .= '&contextpage='.urlencode($contextpage);
679  }
680  if ($limit > 0 && $limit != $conf->liste_limit) {
681  $param .= '&limit='.urlencode($limit);
682  }
683  if ($sall) {
684  $param .= "&sall=".urlencode($sall);
685  }
686  if ($searchCategoryProductOperator == 1) {
687  $param .= "&search_category_product_operator=".urlencode($searchCategoryProductOperator);
688  }
689  foreach ($searchCategoryProductList as $searchCategoryProduct) {
690  $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
691  }
692  if ($search_ref) {
693  $param = "&search_ref=".urlencode($search_ref);
694  }
695  if ($search_ref_supplier) {
696  $param = "&search_ref_supplier=".urlencode($search_ref_supplier);
697  }
698  if ($search_barcode) {
699  $param .= ($search_barcode ? "&search_barcode=".urlencode($search_barcode) : "");
700  }
701  if ($search_label) {
702  $param .= "&search_label=".urlencode($search_label);
703  }
704  if ($search_tosell != '') {
705  $param .= "&search_tosell=".urlencode($search_tosell);
706  }
707  if ($search_tobuy != '') {
708  $param .= "&search_tobuy=".urlencode($search_tobuy);
709  }
710  if ($search_tobatch) {
711  $param = "&search_tobatch=".urlencode($search_tobatch);
712  }
713  if ($search_country != '') {
714  $param .= "&search_country=".urlencode($search_country);
715  }
716  if ($search_state != '') {
717  $param .= "&search_state=".urlencode($search_state);
718  }
719  if ($search_vatrate) {
720  $param = "&search_vatrate=".urlencode($search_vatrate);
721  }
722  if ($fourn_id > 0) {
723  $param .= "&fourn_id=".urlencode($fourn_id);
724  }
725  //if ($seach_categ) $param.=($search_categ?"&search_categ=".urlencode($search_categ):"");
726  if ($show_childproducts) {
727  $param .= ($show_childproducts ? "&search_show_childproducts=".urlencode($show_childproducts) : "");
728  }
729  if ($type != '') {
730  $param .= '&type='.urlencode($type);
731  }
732  if ($search_type != '') {
733  $param .= '&search_type='.urlencode($search_type);
734  }
735  if ($optioncss != '') {
736  $param .= '&optioncss='.urlencode($optioncss);
737  }
738  if ($search_accountancy_code_sell) {
739  $param = "&search_accountancy_code_sell=".urlencode($search_accountancy_code_sell);
740  }
741  if ($search_accountancy_code_sell_intra) {
742  $param = "&search_accountancy_code_sell_intra=".urlencode($search_accountancy_code_sell_intra);
743  }
744  if ($search_accountancy_code_sell_export) {
745  $param = "&search_accountancy_code_sell_export=".urlencode($search_accountancy_code_sell_export);
746  }
747  if ($search_accountancy_code_buy) {
748  $param = "&search_accountancy_code_buy=".urlencode($search_accountancy_code_buy);
749  }
750  if ($search_accountancy_code_buy_intra) {
751  $param = "&search_accountancy_code_buy_intra=".urlencode($search_accountancy_code_buy_intra);
752  }
753  if ($search_accountancy_code_buy_export) {
754  $param = "&search_accountancy_code_buy_export=".urlencode($search_accountancy_code_buy_export);
755  }
756  if ($search_finished) {
757  $param = "&search_finished=".urlencode($search_finished);
758  }
759  // Add $param from extra fields
760  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
761 
762  // List of mass actions available
763  $arrayofmassactions = array(
764  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
765  'edit_extrafields'=>img_picto('', 'edit', 'class="pictofixedwidth"').$langs->trans("ModifyValueExtrafields"),
766  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
767  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
768  );
769 
770  if ($user->rights->{$rightskey}->supprimer) {
771  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
772  }
773  if ($user->rights->{$rightskey}->creer) {
774  $arrayofmassactions['switchonsalestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnSaleStatus");
775  $arrayofmassactions['switchonpurchasestatus'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SwitchOnPurchaseStatus");
776  }
777  if (isModEnabled('category') && $user->rights->{$rightskey}->creer) {
778  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
779  }
780  if (in_array($massaction, array('presend', 'predelete','preaffecttag', 'edit_extrafields'))) {
781  $arrayofmassactions = array();
782  }
783  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
784 
785  $newcardbutton = '';
786  if ($type === "") {
787  $perm = ($user->rights->produit->creer || $user->rights->service->creer);
788  } elseif ($type == Product::TYPE_SERVICE) {
789  $perm = $user->rights->service->creer;
790  } elseif ($type == Product::TYPE_PRODUCT) {
791  $perm = $user->rights->produit->creer;
792  }
793  $oldtype = $type;
794  $params = array();
795  if ($type === "") {
796  $params['forcenohideoftext'] = 1;
797  }
798  if ($type === "") {
799  $newcardbutton .= dolGetButtonTitle($langs->trans('NewProduct'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type=0', '', $perm, $params);
800  $type = Product::TYPE_SERVICE;
801  }
802  $label = 'NewProduct';
803  if ($type == Product::TYPE_SERVICE) {
804  $label = 'NewService';
805  }
806  $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/card.php?action=create&type='.$type, '', $perm, $params);
807 
808  $type = $oldtype;
809 
810  print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" name="formulaire">';
811  if ($optioncss != '') {
812  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
813  }
814  print '<input type="hidden" name="token" value="'.newToken().'">';
815  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
816  print '<input type="hidden" name="action" value="list">';
817  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
818  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
819  //print '<input type="hidden" name="page" value="'.$page.'">';
820  print '<input type="hidden" name="type" value="'.$type.'">';
821  if (empty($arrayfields['p.fk_product_type']['checked'])) {
822  print '<input type="hidden" name="search_type" value="'.dol_escape_htmltag($search_type).'">';
823  }
824 
825  $picto = 'product';
826  if ($type == 1) {
827  $picto = 'service';
828  }
829 
830  print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
831 
832  $topicmail = "Information";
833  $modelmail = "product";
834  $objecttmp = new Product($db);
835  $trackid = 'prod'.$object->id;
836  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
837 
838  if (!empty($catid)) {
839  print "<div id='ways'>";
840  $c = new Categorie($db);
841  $ways = $c->print_all_ways(' &gt; ', 'product/list.php');
842  print " &gt; ".$ways[0]."<br>\n";
843  print "</div><br>";
844  }
845 
846  if ($sall) {
847  $setupstring = '';
848  foreach ($fieldstosearchall as $key => $val) {
849  $fieldstosearchall[$key] = $langs->trans($val);
850  $setupstring .= $key."=".$val.";";
851  }
852  print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
853  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>'."\n";
854  }
855 
856  // Filter on categories
857  $moreforfilter = '';
858  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
859  $moreforfilter .= '<div class="divsearchfield">';
860  $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedwidth"');
861  $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', '', 64, 0, 1);
862  $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -';
863  $moreforfilter .= Form::multiselectarray('search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0, 'minwidth300');
864  $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_product_operator" name="search_category_product_operator" value="1"'.($searchCategoryProductOperator == 1 ? ' checked="checked"' : '').'/><label class="none valignmiddle" for="search_category_product_operator">'.$langs->trans('UseOrOperatorForCategories').'</label>';
865  $moreforfilter .= '</div>';
866  }
867 
868  //Show/hide child products. Hidden by default
869  if (!empty($conf->variants->enabled) && !empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
870  $moreforfilter .= '<div class="divsearchfield">';
871  $moreforfilter .= '<input type="checkbox" id="search_show_childproducts" name="search_show_childproducts"'.($show_childproducts ? 'checked="checked"' : '').'>';
872  $moreforfilter .= ' <label for="search_show_childproducts">'.$langs->trans('ShowChildProducts').'</label>';
873  $moreforfilter .= '</div>';
874  }
875 
876  $parameters = array();
877  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
878  if (empty($reshook)) {
879  $moreforfilter .= $hookmanager->resPrint;
880  } else {
881  $moreforfilter = $hookmanager->resPrint;
882  }
883 
884  if ($moreforfilter) {
885  print '<div class="liste_titre liste_titre_bydiv centpercent">';
886  print $moreforfilter;
887  print '</div>';
888  }
889 
890  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
891 
892  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
893  if ($massactionbutton) {
894  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
895  }
896 
897  print '<div class="div-table-responsive">';
898  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
899 
900  // Lines with input filters
901  print '<tr class="liste_titre_filter">';
902  if (!empty($arrayfields['p.rowid']['checked'])) {
903  print '<td class="liste_titre left">';
904  print '<input class="flat" type="text" name="search_id" size="4" value="'.dol_escape_htmltag($search_id).'">';
905  print '</td>';
906  }
907  if (!empty($arrayfields['p.ref']['checked'])) {
908  print '<td class="liste_titre left">';
909  print '<input class="flat" type="text" name="search_ref" size="8" value="'.dol_escape_htmltag($search_ref).'">';
910  print '</td>';
911  }
912  if (!empty($arrayfields['pfp.ref_fourn']['checked'])) {
913  print '<td class="liste_titre left">';
914  print '<input class="flat" type="text" name="search_ref_supplier" size="8" value="'.dol_escape_htmltag($search_ref_supplier).'">';
915  print '</td>';
916  }
917  // Thumbnail
918  if (!empty($arrayfields['thumbnail']['checked'])) {
919  print '<td class="liste_titre center">';
920  print '</td>';
921  }
922  if (!empty($arrayfields['p.label']['checked'])) {
923  print '<td class="liste_titre left">';
924  print '<input class="flat" type="text" name="search_label" size="12" value="'.dol_escape_htmltag($search_label).'">';
925  print '</td>';
926  }
927  // Type
928  if (!empty($arrayfields['p.fk_product_type']['checked'])) {
929  print '<td class="liste_titre center">';
930  $array = array('-1'=>'&nbsp;', '0'=>$langs->trans('Product'), '1'=>$langs->trans('Service'));
931  print $form->selectarray('search_type', $array, $search_type);
932  print '</td>';
933  }
934  // Barcode
935  if (!empty($arrayfields['p.barcode']['checked'])) {
936  print '<td class="liste_titre">';
937  print '<input class="flat" type="text" name="search_barcode" size="6" value="'.dol_escape_htmltag($search_barcode).'">';
938  print '</td>';
939  }
940  // Duration
941  if (!empty($arrayfields['p.duration']['checked'])) {
942  print '<td class="liste_titre">';
943  print '</td>';
944  }
945 
946  // Finished
947  if (!empty($arrayfields['p.finished']['checked'])) {
948  print '<td class="liste_titre">';
949  print $formproduct->selectProductNature('search_finished', $search_finished);
950  print '</td>';
951  }
952  // Weight
953  if (!empty($arrayfields['p.weight']['checked'])) {
954  print '<td class="liste_titre">';
955  print '</td>';
956  }
957  // Weight units
958  if (!empty($arrayfields['p.weight_units']['checked'])) {
959  print '<td class="liste_titre">';
960  print '</td>';
961  }
962  // Length
963  if (!empty($arrayfields['p.length']['checked'])) {
964  print '<td class="liste_titre">';
965  print '</td>';
966  }
967  // Length units
968  if (!empty($arrayfields['p.length_units']['checked'])) {
969  print '<td class="liste_titre">';
970  print '</td>';
971  }
972  // Width
973  if (!empty($arrayfields['p.width']['checked'])) {
974  print '<td class="liste_titre">';
975  print '</td>';
976  }
977  // Width units
978  if (!empty($arrayfields['p.width_units']['checked'])) {
979  print '<td class="liste_titre">';
980  print '</td>';
981  }
982  // Height
983  if (!empty($arrayfields['p.height']['checked'])) {
984  print '<td class="liste_titre">';
985  print '</td>';
986  }
987  // Height units
988  if (!empty($arrayfields['p.height_units']['checked'])) {
989  print '<td class="liste_titre">';
990  print '</td>';
991  }
992  // Surface
993  if (!empty($arrayfields['p.surface']['checked'])) {
994  print '<td class="liste_titre">';
995  print '</td>';
996  }
997  // Surface units
998  if (!empty($arrayfields['p.surface_units']['checked'])) {
999  print '<td class="liste_titre">';
1000  print '</td>';
1001  }
1002  // Volume
1003  if (!empty($arrayfields['p.volume']['checked'])) {
1004  print '<td class="liste_titre">';
1005  print '</td>';
1006  }
1007  // Volume units
1008  if (!empty($arrayfields['p.volume_units']['checked'])) {
1009  print '<td class="liste_titre">';
1010  print '</td>';
1011  }
1012 
1013  // Unit
1014  if (!empty($arrayfields['cu.label']['checked'])) {
1015  print '<td class="liste_titre">';
1016  print '</td>';
1017  }
1018 
1019  // Sell price
1020  if (!empty($arrayfields['p.sellprice']['checked'])) {
1021  print '<td class="liste_titre right">';
1022  print '</td>';
1023  }
1024 
1025  // Multiprice
1026  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
1027  foreach ($arraypricelevel as $key => $value) {
1028  if (!empty($arrayfields['p.sellprice'.$key]['checked'])) {
1029  print '<td class="liste_titre right">';
1030  print '</td>';
1031  }
1032  }
1033  }
1034 
1035  // Minimum buying Price
1036  if (!empty($arrayfields['p.minbuyprice']['checked'])) {
1037  print '<td class="liste_titre">';
1038  print '&nbsp;';
1039  print '</td>';
1040  }
1041  // Number buying Price
1042  if (!empty($arrayfields['p.numbuyprice']['checked'])) {
1043  print '<td class="liste_titre">';
1044  print '&nbsp;';
1045  print '</td>';
1046  }
1047  // Sell price
1048  if (!empty($arrayfields['p.tva_tx']['checked'])) {
1049  print '<td class="liste_titre right">';
1050  print '<input class="right flat maxwidth50" placeholder="%" type="text" name="search_vatrate" size="1" value="'.dol_escape_htmltag($search_vatrate).'">';
1051  print '</td>';
1052  }
1053  // WAP
1054  if (!empty($arrayfields['p.pmp']['checked'])) {
1055  print '<td class="liste_titre">';
1056  print '&nbsp;';
1057  print '</td>';
1058  }
1059  // cost_price
1060  if (!empty($arrayfields['p.cost_price']['checked'])) {
1061  print '<td class="liste_titre">';
1062  print '&nbsp;';
1063  print '</td>';
1064  }
1065  // Limit for alert
1066  if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) {
1067  print '<td class="liste_titre">';
1068  print '&nbsp;';
1069  print '</td>';
1070  }
1071  // Desired stock
1072  if (!empty($arrayfields['p.desiredstock']['checked'])) {
1073  print '<td class="liste_titre">';
1074  print '&nbsp;';
1075  print '</td>';
1076  }
1077  // Stock
1078  if (!empty($arrayfields['p.stock']['checked'])) {
1079  print '<td class="liste_titre">&nbsp;</td>';
1080  }
1081  // Stock
1082  if (!empty($arrayfields['stock_virtual']['checked'])) {
1083  print '<td class="liste_titre">&nbsp;</td>';
1084  }
1085  // To batch
1086  if (!empty($arrayfields['p.tobatch']['checked'])) {
1087  print '<td class="liste_titre center">';
1088  $statutarray = array(
1089  '-1' => '',
1090  '0' => $langs->trans("ProductStatusNotOnBatchShort"),
1091  '1' => $langs->trans("ProductStatusOnBatchShort"),
1092  '2' => $langs->trans("ProductStatusOnSerialShort")
1093  );
1094  print $form->selectarray('search_tobatch', $statutarray, $search_tobatch);
1095  print '</td>';
1096  }
1097  // Country
1098  if (!empty($arrayfields['p.fk_country']['checked'])) {
1099  print '<td class="liste_titre center">';
1100  print $form->select_country($search_country, 'search_country', '', 0);
1101  print '</td>';
1102  }
1103  // State
1104  if (!empty($arrayfields['p.fk_state']['checked'])) {
1105  print '<td class="liste_titre center">';
1106  print $formcompany->select_state($search_state, $search_country);
1107  print '</td>';
1108  }
1109  // Accountancy code sell
1110  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) {
1111  print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell" value="'.dol_escape_htmltag($search_accountancy_code_sell).'"></td>';
1112  }
1113  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) {
1114  print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell_intra" value="'.dol_escape_htmltag($search_accountancy_code_sell_intra).'"></td>';
1115  }
1116  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) {
1117  print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_sell_export" value="'.dol_escape_htmltag($search_accountancy_code_sell_export).'"></td>';
1118  }
1119  // Accountancy code buy
1120  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) {
1121  print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy" value="'.dol_escape_htmltag($search_accountancy_code_buy).'"></td>';
1122  }
1123  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) {
1124  print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy_intra" value="'.dol_escape_htmltag($search_accountancy_code_buy_intra).'"></td>';
1125  }
1126  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) {
1127  print '<td class="liste_titre"><input class="flat maxwidth75" type="text" name="search_accountancy_code_buy_export" value="'.dol_escape_htmltag($search_accountancy_code_buy_export).'"></td>';
1128  }
1129  // Extra fields
1130  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1131  // Fields from hook
1132  $parameters = array('arrayfields'=>$arrayfields);
1133  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1134  print $hookmanager->resPrint;
1135  // Date creation
1136  if (!empty($arrayfields['p.datec']['checked'])) {
1137  print '<td class="liste_titre">';
1138  print '</td>';
1139  }
1140  // Date modification
1141  if (!empty($arrayfields['p.tms']['checked'])) {
1142  print '<td class="liste_titre">';
1143  print '</td>';
1144  }
1145  if (!empty($arrayfields['p.tosell']['checked'])) {
1146  print '<td class="liste_titre center">';
1147  print $form->selectarray('search_tosell', array('0'=>$langs->trans('ProductStatusNotOnSellShort'), '1'=>$langs->trans('ProductStatusOnSellShort')), $search_tosell, 1);
1148  print '</td >';
1149  }
1150  if (!empty($arrayfields['p.tobuy']['checked'])) {
1151  print '<td class="liste_titre center">';
1152  print $form->selectarray('search_tobuy', array('0'=>$langs->trans('ProductStatusNotOnBuyShort'), '1'=>$langs->trans('ProductStatusOnBuyShort')), $search_tobuy, 1);
1153  print '</td>';
1154  }
1155  print '<td class="liste_titre center maxwidthsearch">';
1156  $searchpicto = $form->showFilterButtons();
1157  print $searchpicto;
1158  print '</td>';
1159 
1160  print '</tr>';
1161 
1162  print '<tr class="liste_titre">';
1163  if (!empty($arrayfields['p.rowid']['checked'])) {
1164  print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
1165  }
1166  if (!empty($arrayfields['p.ref']['checked'])) {
1167  print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, "", $sortfield, $sortorder);
1168  }
1169  if (!empty($arrayfields['pfp.ref_fourn']['checked'])) {
1170  print_liste_field_titre($arrayfields['pfp.ref_fourn']['label'], $_SERVER["PHP_SELF"], "pfp.ref_fourn", "", $param, "", $sortfield, $sortorder);
1171  }
1172  if (!empty($arrayfields['thumbnail']['checked'])) {
1173  print_liste_field_titre($arrayfields['thumbnail']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
1174  }
1175  if (!empty($arrayfields['p.label']['checked'])) {
1176  print_liste_field_titre($arrayfields['p.label']['label'], $_SERVER["PHP_SELF"], "p.label", "", $param, "", $sortfield, $sortorder);
1177  }
1178  if (!empty($arrayfields['p.fk_product_type']['checked'])) {
1179  print_liste_field_titre($arrayfields['p.fk_product_type']['label'], $_SERVER["PHP_SELF"], "p.fk_product_type", "", $param, "", $sortfield, $sortorder, 'center ');
1180  }
1181  if (!empty($arrayfields['p.barcode']['checked'])) {
1182  print_liste_field_titre($arrayfields['p.barcode']['label'], $_SERVER["PHP_SELF"], "p.barcode", "", $param, "", $sortfield, $sortorder);
1183  }
1184  if (!empty($arrayfields['p.duration']['checked'])) {
1185  print_liste_field_titre($arrayfields['p.duration']['label'], $_SERVER["PHP_SELF"], "p.duration", "", $param, '', $sortfield, $sortorder, 'center ');
1186  }
1187  if (!empty($arrayfields['p.finished']['checked'])) {
1188  print_liste_field_titre($arrayfields['p.finished']['label'], $_SERVER["PHP_SELF"], "p.finished", "", $param, '', $sortfield, $sortorder, 'center ');
1189  }
1190 
1191  if (!empty($arrayfields['p.weight']['checked'])) {
1192  print_liste_field_titre($arrayfields['p.weight']['label'], $_SERVER['PHP_SELF'], 'p.weight', '', $param, '', $sortfield, $sortorder, 'center ');
1193  }
1194  if (!empty($arrayfields['p.weight_units']['checked'])) {
1195  print_liste_field_titre($arrayfields['p.weight_units']['label'], $_SERVER['PHP_SELF'], 'p.weight_units', '', $param, '', $sortfield, $sortorder, 'center ');
1196  }
1197  if (!empty($arrayfields['p.length']['checked'])) {
1198  print_liste_field_titre($arrayfields['p.length']['label'], $_SERVER['PHP_SELF'], 'p.length', '', $param, '', $sortfield, $sortorder, 'center ');
1199  }
1200  if (!empty($arrayfields['p.length_units']['checked'])) {
1201  print_liste_field_titre($arrayfields['p.length_units']['label'], $_SERVER['PHP_SELF'], 'p.length_units', '', $param, '', $sortfield, $sortorder, 'center ');
1202  }
1203  if (!empty($arrayfields['p.width']['checked'])) {
1204  print_liste_field_titre($arrayfields['p.width']['label'], $_SERVER['PHP_SELF'], 'p.width', '', $param, '', $sortfield, $sortorder, 'center ');
1205  }
1206  if (!empty($arrayfields['p.width_units']['checked'])) {
1207  print_liste_field_titre($arrayfields['p.width_units']['label'], $_SERVER['PHP_SELF'], 'p.width_units', '', $param, '', $sortfield, $sortorder, 'center ');
1208  }
1209  if (!empty($arrayfields['p.height']['checked'])) {
1210  print_liste_field_titre($arrayfields['p.height']['label'], $_SERVER['PHP_SELF'], 'p.height', '', $param, '', $sortfield, $sortorder, 'center ');
1211  }
1212  if (!empty($arrayfields['p.height_units']['checked'])) {
1213  print_liste_field_titre($arrayfields['p.height_units']['label'], $_SERVER['PHP_SELF'], 'p.height_units', '', $param, '', $sortfield, $sortorder, 'center ');
1214  }
1215  if (!empty($arrayfields['p.surface']['checked'])) {
1216  print_liste_field_titre($arrayfields['p.surface']['label'], $_SERVER['PHP_SELF'], "p.surface", '', $param, '', $sortfield, $sortorder, 'center ');
1217  }
1218  if (!empty($arrayfields['p.surface_units']['checked'])) {
1219  print_liste_field_titre($arrayfields['p.surface_units']['label'], $_SERVER['PHP_SELF'], 'p.surface_units', '', $param, '', $sortfield, $sortorder, 'center ');
1220  }
1221  if (!empty($arrayfields['p.volume']['checked'])) {
1222  print_liste_field_titre($arrayfields['p.volume']['label'], $_SERVER['PHP_SELF'], 'p.volume', '', $param, '', $sortfield, $sortorder, 'center ');
1223  }
1224  if (!empty($arrayfields['p.volume_units']['checked'])) {
1225  print_liste_field_titre($arrayfields['p.volume_units']['label'], $_SERVER['PHP_SELF'], 'p.volume_units', '', $param, '', $sortfield, $sortorder, 'center ');
1226  }
1227  if (!empty($arrayfields['cu.label']['checked'])) {
1228  print_liste_field_titre($arrayfields['cu.label']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center ');
1229  }
1230  if (!empty($arrayfields['p.sellprice']['checked'])) {
1231  print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1232  }
1233 
1234  // Multiprices
1235  if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
1236  foreach ($arraypricelevel as $key => $value) {
1237  if (!empty($arrayfields['p.sellprice'.$key]['checked'])) {
1238  print_liste_field_titre($arrayfields['p.sellprice'.$key]['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1239  }
1240  }
1241  }
1242 
1243  if (!empty($arrayfields['p.minbuyprice']['checked'])) {
1244  print_liste_field_titre($arrayfields['p.minbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1245  }
1246  if (!empty($arrayfields['p.numbuyprice']['checked'])) {
1247  print_liste_field_titre($arrayfields['p.numbuyprice']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1248  }
1249  if (!empty($arrayfields['p.tva_tx']['checked'])) {
1250  print_liste_field_titre($arrayfields['p.tva_tx']['label'], $_SERVER["PHP_SELF"], 'p.tva_tx', "", $param, '', $sortfield, $sortorder, 'right ');
1251  }
1252  if (!empty($arrayfields['p.pmp']['checked'])) {
1253  print_liste_field_titre($arrayfields['p.pmp']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1254  }
1255  if (!empty($arrayfields['p.cost_price']['checked'])) {
1256  print_liste_field_titre($arrayfields['p.cost_price']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1257  }
1258  if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) {
1259  print_liste_field_titre($arrayfields['p.seuil_stock_alerte']['label'], $_SERVER["PHP_SELF"], "p.seuil_stock_alerte", "", $param, '', $sortfield, $sortorder, 'right ');
1260  }
1261  if (!empty($arrayfields['p.desiredstock']['checked'])) {
1262  print_liste_field_titre($arrayfields['p.desiredstock']['label'], $_SERVER["PHP_SELF"], "p.desiredstock", "", $param, '', $sortfield, $sortorder, 'right ');
1263  }
1264  if (!empty($arrayfields['p.stock']['checked'])) {
1265  print_liste_field_titre($arrayfields['p.stock']['label'], $_SERVER["PHP_SELF"], "p.stock", "", $param, '', $sortfield, $sortorder, 'right ');
1266  }
1267  if (!empty($arrayfields['stock_virtual']['checked'])) {
1268  print_liste_field_titre($arrayfields['stock_virtual']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder, 'right ');
1269  }
1270  if (!empty($arrayfields['p.tobatch']['checked'])) {
1271  print_liste_field_titre($arrayfields['p.tobatch']['label'], $_SERVER["PHP_SELF"], "p.tobatch", "", $param, '', $sortfield, $sortorder, 'center ');
1272  }
1273  if (!empty($arrayfields['p.fk_country']['checked'])) {
1274  print_liste_field_titre($arrayfields['p.fk_country']['label'], $_SERVER["PHP_SELF"], "p.fk_country", "", $param, '', $sortfield, $sortorder);
1275  }
1276  if (!empty($arrayfields['p.fk_state']['checked'])) {
1277  print_liste_field_titre($arrayfields['p.fk_state']['label'], $_SERVER["PHP_SELF"], "p.fk_state", "", $param, '', $sortfield, $sortorder);
1278  }
1279  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) {
1280  print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell", "", $param, '', $sortfield, $sortorder);
1281  }
1282  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) {
1283  print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_intra", "", $param, '', $sortfield, $sortorder);
1284  }
1285  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) {
1286  print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_sell_export", "", $param, '', $sortfield, $sortorder);
1287  }
1288  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) {
1289  print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy", "", $param, '', $sortfield, $sortorder);
1290  }
1291  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) {
1292  print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_intra", "", $param, '', $sortfield, $sortorder);
1293  }
1294  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) {
1295  print_liste_field_titre($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['label'], $_SERVER["PHP_SELF"], $alias_product_perentity . ".accountancy_code_buy_export", "", $param, '', $sortfield, $sortorder);
1296  }
1297  // Extra fields
1298  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1299  // Hook fields
1300  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1301  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1302  print $hookmanager->resPrint;
1303  if (!empty($arrayfields['p.datec']['checked'])) {
1304  print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1305  }
1306  if (!empty($arrayfields['p.tms']['checked'])) {
1307  print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1308  }
1309  if (!empty($arrayfields['p.tosell']['checked'])) {
1310  print_liste_field_titre($arrayfields['p.tosell']['label'], $_SERVER["PHP_SELF"], "p.tosell", "", $param, '', $sortfield, $sortorder, 'center ');
1311  }
1312  if (!empty($arrayfields['p.tobuy']['checked'])) {
1313  print_liste_field_titre($arrayfields['p.tobuy']['label'], $_SERVER["PHP_SELF"], "p.tobuy", "", $param, '', $sortfield, $sortorder, 'center ');
1314  }
1315  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1316  print "</tr>\n";
1317 
1318 
1319  $product_static = new Product($db);
1320  $product_fourn = new ProductFournisseur($db);
1321 
1322  $i = 0;
1323  $totalarray = array();
1324  $totalarray['nbfield'] = 0;
1325  while ($i < min($num, $limit)) {
1326  $obj = $db->fetch_object($resql);
1327 
1328  // Multilangs
1329  if (!empty($conf->global->MAIN_MULTILANGS)) { // If multilang is enabled
1330  $sql = "SELECT label";
1331  $sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
1332  $sql .= " WHERE fk_product = ".((int) $obj->rowid);
1333  $sql .= " AND lang = '".$db->escape($langs->getDefaultLang())."'";
1334  $sql .= " LIMIT 1";
1335 
1336  $result = $db->query($sql);
1337  if ($result) {
1338  $objtp = $db->fetch_object($result);
1339  if (!empty($objtp->label)) {
1340  $obj->label = $objtp->label;
1341  }
1342  }
1343  }
1344 
1345  $product_static->id = $obj->rowid;
1346  $product_static->ref = $obj->ref;
1347  $product_static->ref_fourn = empty($obj->ref_supplier) ? '' : $obj->ref_supplier; // deprecated
1348  $product_static->ref_supplier = empty($obj->ref_supplier) ? '' : $obj->ref_supplier;
1349  $product_static->label = $obj->label;
1350  $product_static->finished = $obj->finished;
1351  $product_static->type = $obj->fk_product_type;
1352  $product_static->status_buy = $obj->tobuy;
1353  $product_static->status = $obj->tosell;
1354  $product_static->status_batch = $obj->tobatch;
1355  $product_static->entity = $obj->entity;
1356  $product_static->pmp = $obj->pmp;
1357  $product_static->accountancy_code_sell = $obj->accountancy_code_sell;
1358  $product_static->accountancy_code_sell_export = $obj->accountancy_code_sell_export;
1359  $product_static->accountancy_code_sell_intra = $obj->accountancy_code_sell_intra;
1360  $product_static->accountancy_code_buy = $obj->accountancy_code_buy;
1361  $product_static->accountancy_code_buy_intra = $obj->accountancy_code_buy_intra;
1362  $product_static->accountancy_code_buy_export = $obj->accountancy_code_buy_export;
1363  $product_static->length = $obj->length;
1364  $product_static->length_units = $obj->length_units;
1365  $product_static->width = $obj->width;
1366  $product_static->width_units = $obj->width_units;
1367  $product_static->height = $obj->height;
1368  $product_static->height_units = $obj->height_units;
1369  $product_static->weight = $obj->weight;
1370  $product_static->weight_units = $obj->weight_units;
1371  $product_static->volume = $obj->volume;
1372  $product_static->volume_units = $obj->volume_units;
1373  $product_static->surface = $obj->surface;
1374  $product_static->surface_units = $obj->surface_units;
1375  if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1376  $product_static->fk_unit = $obj->fk_unit;
1377  }
1378 
1379  // STOCK_DISABLE_OPTIM_LOAD can be set to force load_stock whatever is permissions on stock.
1380  if ((!empty($conf->stock->enabled) && $user->rights->stock->lire && $search_type != 1) || !empty($conf->global->STOCK_DISABLE_OPTIM_LOAD)) { // To optimize call of load_stock
1381  if ($obj->fk_product_type != 1 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Not a service
1382  $option = 'nobatch';
1383  if (empty($arrayfields['stock_virtual']['checked'])) {
1384  $option .= ',novirtual';
1385  }
1386  $product_static->load_stock($option); // Load stock_reel + stock_warehouse. This can also call load_virtual_stock()
1387  }
1388  }
1389 
1390  print '<tr class="oddeven">';
1391 
1392  // Ref
1393  if (!empty($arrayfields['p.rowid']['checked'])) {
1394  print '<td class="nowraponall">';
1395  print $product_static->id;
1396  print "</td>\n";
1397  if (!$i) {
1398  $totalarray['nbfield']++;
1399  }
1400  }
1401 
1402  // Ref
1403  if (!empty($arrayfields['p.ref']['checked'])) {
1404  print '<td class="tdoverflowmax200">';
1405  print $product_static->getNomUrl(1);
1406  print "</td>\n";
1407  if (!$i) {
1408  $totalarray['nbfield']++;
1409  }
1410  }
1411 
1412  // Ref supplier
1413  if (!empty($arrayfields['pfp.ref_fourn']['checked'])) {
1414  print '<td class="tdoverflowmax200">';
1415  print $product_static->getNomUrl(1);
1416  print "</td>\n";
1417  if (!$i) {
1418  $totalarray['nbfield']++;
1419  }
1420  }
1421 
1422  // Thumbnail
1423  if (!empty($arrayfields['thumbnail']['checked'])) {
1424  $product_thumbnail_html = '';
1425  if (!empty($product_static->entity)) {
1426  $product_thumbnail = $product_static->show_photos('product', $conf->product->multidir_output[$product_static->entity], 1, 1, 0, 0, 0, 80);
1427  if ($product_static->nbphoto > 0) {
1428  $product_thumbnail_html = $product_thumbnail;
1429  }
1430  }
1431 
1432  print '<td class="center">' . $product_thumbnail_html . '</td>';
1433  if (!$i) {
1434  $totalarray['nbfield']++;
1435  }
1436  }
1437 
1438  // Label
1439  if (!empty($arrayfields['p.label']['checked'])) {
1440  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->label).'">'.$obj->label.'</td>';
1441  if (!$i) {
1442  $totalarray['nbfield']++;
1443  }
1444  }
1445 
1446  // Type
1447  if (!empty($arrayfields['p.fk_product_type']['checked'])) {
1448  print '<td class="center">';
1449  $s = '';
1450  if ($obj->fk_product_type == 0) {
1451  $s .= img_picto($langs->trans("Product"), 'product', 'class="paddingleftonly paddingrightonly colorgrey"');
1452  } else {
1453  $s .= img_picto($langs->trans("Service"), 'service', 'class="paddingleftonly paddingrightonly colorgrey"');
1454  }
1455  print $s;
1456  print '</td>';
1457  if (!$i) {
1458  $totalarray['nbfield']++;
1459  }
1460  }
1461 
1462  // Barcode
1463  if (!empty($arrayfields['p.barcode']['checked'])) {
1464  print '<td>'.$obj->barcode.'</td>';
1465  if (!$i) {
1466  $totalarray['nbfield']++;
1467  }
1468  }
1469 
1470  // Duration
1471  if (!empty($arrayfields['p.duration']['checked'])) {
1472  print '<td class="center nowraponall">';
1473 
1474  if (preg_match('/([^a-z]+)[a-z]$/i', $obj->duration)) {
1475  $duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1);
1476  $duration_unit = substr($obj->duration, -1);
1477 
1478  if ((float) $duration_value > 1) {
1479  $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
1480  } elseif ((float) $duration_value > 0) {
1481  $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
1482  }
1483  print $duration_value;
1484  print ((!empty($duration_unit) && isset($dur[$duration_unit]) && $duration_value != '') ? ' '.$langs->trans($dur[$duration_unit]) : '');
1485  } elseif (!preg_match('/^[a-z]$/i', $obj->duration)) { // If duration is a simple char (like 's' of 'm'), we do not show value
1486  print $obj->duration;
1487  }
1488 
1489  print '</td>';
1490  if (!$i) {
1491  $totalarray['nbfield']++;
1492  }
1493  }
1494 
1495  // Finished
1496  if (!empty($arrayfields['p.finished']['checked'])) {
1497  print '<td class="center">';
1498  print $product_static->getLibFinished();
1499  print '</td>';
1500  if (!$i) {
1501  $totalarray['nbfield']++;
1502  }
1503  }
1504 
1505  // Weight
1506  if (!empty($arrayfields['p.weight']['checked'])) {
1507  print '<td class="center">';
1508  print $obj->weight;
1509  print '</td>';
1510  if (!$i) {
1511  $totalarray['nbfield']++;
1512  }
1513  }
1514  // Weight units
1515  if (!empty($arrayfields['p.weight_units']['checked'])) {
1516  print '<td class="center">';
1517  if ($product_static->weight != '') {
1518  print measuringUnitString(0, 'weight', $product_static->weight_units);
1519  }
1520  print '</td>';
1521  if (!$i) {
1522  $totalarray['nbfield']++;
1523  }
1524  }
1525  // Length
1526  if (!empty($arrayfields['p.length']['checked'])) {
1527  print '<td class="center">';
1528  print $obj->length;
1529  print '</td>';
1530  if (!$i) {
1531  $totalarray['nbfield']++;
1532  }
1533  }
1534  // Length units
1535  if (!empty($arrayfields['p.length_units']['checked'])) {
1536  print '<td class="center">';
1537  if ($product_static->length != '') {
1538  print measuringUnitString(0, 'size', $product_static->length_units);
1539  }
1540  print '</td>';
1541  if (!$i) {
1542  $totalarray['nbfield']++;
1543  }
1544  }
1545  // Width
1546  if (!empty($arrayfields['p.width']['checked'])) {
1547  print '<td align="center">';
1548  print $obj->width;
1549  print '</td>';
1550  if (!$i) {
1551  $totalarray['nbfield']++;
1552  }
1553  }
1554  // Width units
1555  if (!empty($arrayfields['p.width_units']['checked'])) {
1556  print '<td class="center">';
1557  if ($product_static->width != '') {
1558  print measuringUnitString(0, 'size', $product_static->width_units);
1559  }
1560  print '</td>';
1561  if (!$i) {
1562  $totalarray['nbfield']++;
1563  }
1564  }
1565  // Height
1566  if (!empty($arrayfields['p.height']['checked'])) {
1567  print '<td align="center">';
1568  print $obj->height;
1569  print '</td>';
1570  if (!$i) {
1571  $totalarray['nbfield']++;
1572  }
1573  }
1574  // Height units
1575  if (!empty($arrayfields['p.height_units']['checked'])) {
1576  print '<td class="center">';
1577  if ($product_static->height != '') {
1578  print measuringUnitString(0, 'size', $product_static->height_units);
1579  }
1580  print '</td>';
1581  if (!$i) {
1582  $totalarray['nbfield']++;
1583  }
1584  }
1585  // Surface
1586  if (!empty($arrayfields['p.surface']['checked'])) {
1587  print '<td class="center">';
1588  print $obj->surface;
1589  print '</td>';
1590  if (!$i) {
1591  $totalarray['nbfield']++;
1592  }
1593  }
1594  // Surface units
1595  if (!empty($arrayfields['p.surface_units']['checked'])) {
1596  print '<td class="center">';
1597  if ($product_static->surface != '') {
1598  print measuringUnitString(0, 'surface', $product_static->surface_units);
1599  }
1600  print '</td>';
1601  if (!$i) {
1602  $totalarray['nbfield']++;
1603  }
1604  }
1605  // Volume
1606  if (!empty($arrayfields['p.volume']['checked'])) {
1607  print '<td class="center">';
1608  print $obj->volume;
1609  print '</td>';
1610  if (!$i) {
1611  $totalarray['nbfield']++;
1612  }
1613  }
1614  // Volume units
1615  if (!empty($arrayfields['p.volume_units']['checked'])) {
1616  print '<td class="center">';
1617  if ($product_static->volume != '') {
1618  print measuringUnitString(0, 'volume', $product_static->volume_units);
1619  }
1620  print '</td>';
1621  if (!$i) {
1622  $totalarray['nbfield']++;
1623  }
1624  }
1625  // Unit
1626  if (!empty($arrayfields['cu.label']['checked'])) {
1627  print '<td align="center">';
1628  if (!empty($obj->cu_label)) {
1629  print $langs->trans($obj->cu_label);
1630  }
1631  print '</td>';
1632  if (!$i) {
1633  $totalarray['nbfield']++;
1634  }
1635  }
1636 
1637  // Sell price
1638  if (!empty($arrayfields['p.sellprice']['checked'])) {
1639  print '<td class="right nowraponall">';
1640  if ($obj->tosell) {
1641  if ($obj->price_base_type == 'TTC') {
1642  print '<span class="amount">'.price($obj->price_ttc).' '.$langs->trans("TTC").'</span>';
1643  } else {
1644  print '<span class="amount">'.price($obj->price).' '.$langs->trans("HT").'</span>';
1645  }
1646  }
1647  print '</td>';
1648  if (!$i) {
1649  $totalarray['nbfield']++;
1650  }
1651  }
1652 
1653 
1654  // Multiprices
1655  if (! empty($conf->global->PRODUIT_MULTIPRICES)) {
1656  if (! isset($productpricescache)) {
1657  $productpricescache=array();
1658  }
1659  if (! isset($productpricescache[$obj->rowid])) {
1660  $productpricescache[$obj->rowid] = array();
1661  }
1662 
1663  if ($obj->tosell) {
1664  // Make 1 request for all price levels (without filter on price_level) and saved result into an cache array
1665  // then reuse the cache array if we need prices for other price levels
1666  $sqlp = "SELECT p.rowid, p.fk_product, p.price, p.price_ttc, p.price_level, p.date_price, p.price_base_type";
1667  $sqlp .= " FROM ".MAIN_DB_PREFIX."product_price as p";
1668  $sqlp .= " WHERE fk_product = ".((int) $obj->rowid);
1669  $sqlp .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
1670  $resultp = $db->query($sqlp);
1671  if ($resultp) {
1672  $nump = $db->num_rows($resultp);
1673  $j = 0;
1674  while ($j < $nump) {
1675  $objp = $db->fetch_object($resultp);
1676 
1677  if (empty($productpricescache[$obj->rowid][$objp->price_level])) {
1678  $productpricescache[$obj->rowid][$objp->price_level]['price'] = $objp->price;
1679  $productpricescache[$obj->rowid][$objp->price_level]['price_ttc'] = $objp->price_ttc;
1680  $productpricescache[$obj->rowid][$objp->price_level]['price_base_type'] = $objp->price_base_type;
1681  }
1682 
1683  $j++;
1684  }
1685 
1686  $db->free($resultp);
1687  } else {
1688  dol_print_error($db);
1689  }
1690  }
1691 
1692  foreach ($arraypricelevel as $key => $value) {
1693  if (!empty($arrayfields['p.sellprice'.$key]['checked'])) {
1694  print '<td class="right nowraponall">';
1695  if (!empty($productpricescache[$obj->rowid])) {
1696  if ($productpricescache[$obj->rowid][$key]['price_base_type'] == 'TTC') {
1697  print '<span class="amount">'.price($productpricescache[$obj->rowid][$key]['price_ttc']).' '.$langs->trans("TTC").'</span>';
1698  } else {
1699  print '<span class="amount">'.price($productpricescache[$obj->rowid][$key]['price']).' '.$langs->trans("HT").'</span>';
1700  }
1701  }
1702  print '</td>';
1703  if (!$i) {
1704  $totalarray['nbfield']++;
1705  }
1706  }
1707  }
1708  }
1709 
1710  // Better buy price
1711  if (!empty($arrayfields['p.minbuyprice']['checked'])) {
1712  print '<td class="right nowraponall">';
1713  if ($obj->tobuy && $obj->minsellprice != '') {
1714  //print price($obj->minsellprice).' '.$langs->trans("HT");
1715  if ($product_fourn->find_min_price_product_fournisseur($obj->rowid) > 0) {
1716  if ($product_fourn->product_fourn_price_id > 0) {
1717  if ((!empty($conf->fournisseur->enabled) && !empty($user->rights->fournisseur->lire) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (!empty($conf->supplier_order->enabled) && !empty($user->rights->supplier_order->lire)) || (!empty($conf->supplier_invoice->enabled) && !empty($user->rights->supplier_invoice->lire))) {
1718  $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1);
1719  print '<span class="amount">'.$form->textwithpicto(price($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent / 100) - $product_fourn->fourn_remise).' '.$langs->trans("HT"), $htmltext).'</span>';
1720  } else {
1721  print '<span class="amount">'.price($product_fourn->fourn_unitprice).' '.$langs->trans("HT").'</span>';
1722  }
1723  }
1724  }
1725  }
1726  print '</td>';
1727  if (!$i) {
1728  $totalarray['nbfield']++;
1729  }
1730  }
1731 
1732  // Number of buy prices
1733  if (!empty($arrayfields['p.numbuyprice']['checked'])) {
1734  print '<td class="right">';
1735  if ($obj->tobuy) {
1736  if (count($productFournList = $product_fourn->list_product_fournisseur_price($obj->rowid)) > 0) {
1737  $htmltext = $product_fourn->display_price_product_fournisseur(1, 1, 0, 1, $productFournList);
1738  print $form->textwithpicto(count($productFournList), $htmltext);
1739  }
1740  }
1741  print '</td>';
1742  }
1743 
1744  // VAT or Sell Tax Rate
1745  if (!empty($arrayfields['p.tva_tx']['checked'])) {
1746  print '<td class="right">';
1747  print vatrate($obj->tva_tx, true);
1748  print '</td>';
1749  if (!$i) {
1750  $totalarray['nbfield']++;
1751  }
1752  }
1753 
1754  // WAP
1755  if (!empty($arrayfields['p.pmp']['checked'])) {
1756  print '<td class="nowrap right">';
1757  print '<span class="amount">'.price($product_static->pmp, 1, $langs)."</span>";
1758  print '</td>';
1759  }
1760  // Cost price
1761  if (!empty($arrayfields['p.cost_price']['checked'])) {
1762  print '<td class="nowrap right">';
1763  //print $obj->cost_price;
1764  print '<span class="amount">'.price($obj->cost_price).' '.$langs->trans("HT").'</span>';
1765  print '</td>';
1766  }
1767 
1768  // Limit alert
1769  if (!empty($arrayfields['p.seuil_stock_alerte']['checked'])) {
1770  print '<td class="right">';
1771  if ($obj->fk_product_type != 1) {
1772  print $obj->seuil_stock_alerte;
1773  }
1774  print '</td>';
1775  if (!$i) {
1776  $totalarray['nbfield']++;
1777  }
1778  }
1779  // Desired stock
1780  if (!empty($arrayfields['p.desiredstock']['checked'])) {
1781  print '<td class="right">';
1782  if ($obj->fk_product_type != 1) {
1783  print $obj->desiredstock;
1784  }
1785  print '</td>';
1786  if (!$i) {
1787  $totalarray['nbfield']++;
1788  }
1789  }
1790  // Stock real
1791  if (!empty($arrayfields['p.stock']['checked'])) {
1792  print '<td class="right">';
1793  if ($obj->fk_product_type != 1) {
1794  if ($obj->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $obj->seuil_stock_alerte) {
1795  print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' ';
1796  }
1797  print price(price2num($product_static->stock_reel, 'MS'), 0, $langs, 1, 0);
1798  }
1799  print '</td>';
1800  if (!$i) {
1801  $totalarray['nbfield']++;
1802  }
1803  }
1804  // Stock virtual
1805  if (!empty($arrayfields['stock_virtual']['checked'])) {
1806  print '<td class="right">';
1807  if ($obj->fk_product_type != 1) {
1808  if ($obj->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $obj->seuil_stock_alerte) {
1809  print img_warning($langs->trans("StockLowerThanLimit", $obj->seuil_stock_alerte)).' ';
1810  }
1811  print price(price2num($product_static->stock_theorique, 'MS'), 0, $langs, 1, 0);
1812  }
1813  print '</td>';
1814  if (!$i) {
1815  $totalarray['nbfield']++;
1816  }
1817  }
1818  // Lot/Serial
1819  if (!empty($arrayfields['p.tobatch']['checked'])) {
1820  print '<td class="center">';
1821  print $product_static->getLibStatut(1, 2);
1822  print '</td>';
1823  if (!$i) {
1824  $totalarray['nbfield']++;
1825  }
1826  }
1827  // Country
1828  if (!empty($arrayfields['p.fk_country']['checked'])) {
1829  print '<td>'.getCountry($obj->fk_country, 0, $db).'</td>';
1830  if (!$i) {
1831  $totalarray['nbfield']++;
1832  }
1833  }
1834  // State
1835  if (!empty($arrayfields['p.fk_state']['checked'])) {
1836  print '<td>';
1837  if (!empty($obj->fk_state)) {
1838  print getState($obj->fk_state, 0, $db);
1839  }
1840  print '</td>';
1841  if (!$i) {
1842  $totalarray['nbfield']++;
1843  }
1844  }
1845  // Accountancy code sell
1846  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell']['checked'])) {
1847  print '<td>'.length_accountg($obj->accountancy_code_sell).'</td>';
1848  if (!$i) {
1849  $totalarray['nbfield']++;
1850  }
1851  }
1852  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_intra']['checked'])) {
1853  print '<td>'.length_accountg($obj->accountancy_code_sell_intra).'</td>';
1854  if (!$i) {
1855  $totalarray['nbfield']++;
1856  }
1857  }
1858  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_sell_export']['checked'])) {
1859  print '<td>'.length_accountg($obj->accountancy_code_sell_export).'</td>';
1860  if (!$i) {
1861  $totalarray['nbfield']++;
1862  }
1863  }
1864  // Accountancy code buy
1865  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy']['checked'])) {
1866  print '<td>'.length_accountg($obj->accountancy_code_buy).'</td>';
1867  if (!$i) {
1868  $totalarray['nbfield']++;
1869  }
1870  }
1871  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_intra']['checked'])) {
1872  print '<td>'.length_accountg($obj->accountancy_code_buy_intra).'</td>';
1873  if (!$i) {
1874  $totalarray['nbfield']++;
1875  }
1876  }
1877  if (!empty($arrayfields[$alias_product_perentity . '.accountancy_code_buy_export']['checked'])) {
1878  print '<td>'.length_accountg($obj->accountancy_code_buy_export).'</td>';
1879  if (!$i) {
1880  $totalarray['nbfield']++;
1881  }
1882  }
1883  // Extra fields
1884  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1885  // Fields from hook
1886  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1887  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1888  print $hookmanager->resPrint;
1889  // Date creation
1890  if (!empty($arrayfields['p.datec']['checked'])) {
1891  print '<td class="center nowraponall">';
1892  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1893  print '</td>';
1894  if (!$i) {
1895  $totalarray['nbfield']++;
1896  }
1897  }
1898  // Date modification
1899  if (!empty($arrayfields['p.tms']['checked'])) {
1900  print '<td class="center nowraponall">';
1901  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1902  print '</td>';
1903  if (!$i) {
1904  $totalarray['nbfield']++;
1905  }
1906  }
1907 
1908  // Status (to sell)
1909  if (!empty($arrayfields['p.tosell']['checked'])) {
1910  print '<td class="center nowrap">';
1911  if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
1912  print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
1913  } else {
1914  print $product_static->LibStatut($obj->tosell, 5, 0);
1915  }
1916  print '</td>';
1917  if (!$i) {
1918  $totalarray['nbfield']++;
1919  }
1920  }
1921  // Status (to buy)
1922  if (!empty($arrayfields['p.tobuy']['checked'])) {
1923  print '<td class="center nowrap">';
1924  if (!empty($conf->use_javascript_ajax) && $user->rights->produit->creer && !empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) {
1925  print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
1926  } else {
1927  print $product_static->LibStatut($obj->tobuy, 5, 1);
1928  }
1929  print '</td>';
1930  if (!$i) {
1931  $totalarray['nbfield']++;
1932  }
1933  }
1934 
1935  // Action
1936  print '<td class="nowrap center">';
1937  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1938  $selected = 0;
1939  if (in_array($obj->rowid, $arrayofselected)) {
1940  $selected = 1;
1941  }
1942  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1943  }
1944  print '</td>';
1945  if (!$i) {
1946  $totalarray['nbfield']++;
1947  }
1948 
1949  print "</tr>\n";
1950  $i++;
1951  }
1952 
1953  $db->free($resql);
1954 
1955  // If no record found
1956  if ($num == 0) {
1957  $colspan = 1;
1958  foreach ($arrayfields as $key => $val) {
1959  if (!empty($val['checked'])) {
1960  $colspan++;
1961  }
1962  }
1963  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1964  }
1965 
1966  print "</table>";
1967  print "</div>";
1968  print '</form>';
1969 } else {
1970  dol_print_error($db);
1971 }
1972 
1973 // End of page
1974 llxFooter();
1975 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
ProductFournisseur
Class to manage predefined suppliers products.
Definition: fournisseur.product.class.php:41
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
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
img_warning
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
Definition: functions.lib.php:4521
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
ajax_object_onoff
ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array(), $morecss='')
On/off button to change status of an object This is called when MAIN_DIRECT_STATUS_UPDATE is set and ...
Definition: ajax.lib.php:652
Categorie
Class to manage categories.
Definition: categorie.class.php:47
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
measuringUnitString
measuringUnitString($unit, $measuring_style='', $scale='', $use_short_label=0, $outputlangs=null)
Return translation label of a unit key.
Definition: product.lib.php:619
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
dolExplodeIntoArray
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
Definition: functions.lib.php:9354
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
getState
getState($id, $withcode='', $dbtouse=0, $withregion=0, $outputlangs='', $entconv=1)
Return state translated from an id.
Definition: company.lib.php:569
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
clean_account
clean_account($account)
Return accounting account without zero on the right.
Definition: accounting.lib.php:81
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
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
Canvas
Class to manage canvas.
Definition: canvas.class.php:29
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
Form\multiselectarray
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Definition: html.form.class.php:8256
FormProduct
Class with static methods for building HTML components related to products Only components common to ...
Definition: html.formproduct.class.php:30
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
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
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:504
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
Product\TYPE_PRODUCT
const TYPE_PRODUCT
Regular product.
Definition: product.class.php:500
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
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5492
isInEEC
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
Definition: company.lib.php:753