dolibarr  x.y.z
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-2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
8  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
9  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
10  * Copyright (C) 2018-2022 Charlene Benke <charlene@patas-monkey.com>
11  * Copyright (C) 2019 Nicolas Zabouri <info@inovea-conseil.com>
12  * Copyright (C) 2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
35 // Load Dolibarr environment
36 require '../../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
48 
49 // Load translation files required by the page
50 $langs->loadLangs(array("orders", "sendings", 'deliveries', 'companies', 'compta', 'bills', 'projects', 'suppliers', 'products'));
51 
52 // Get Parameters
53 $action = GETPOST('action', 'aZ09');
54 $massaction = GETPOST('massaction', 'alpha');
55 $show_files = GETPOST('show_files', 'int');
56 $confirm = GETPOST('confirm', 'alpha');
57 $toselect = GETPOST('toselect', 'array');
58 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'supplierorderlist';
59 
60 // Search Criteria
61 $search_date_order_startday = GETPOST('search_date_order_startday', 'int');
62 $search_date_order_startmonth = GETPOST('search_date_order_startmonth', 'int');
63 $search_date_order_startyear = GETPOST('search_date_order_startyear', 'int');
64 $search_date_order_endday = GETPOST('search_date_order_endday', 'int');
65 $search_date_order_endmonth = GETPOST('search_date_order_endmonth', 'int');
66 $search_date_order_endyear = GETPOST('search_date_order_endyear', 'int');
67 $search_date_order_start = dol_mktime(0, 0, 0, $search_date_order_startmonth, $search_date_order_startday, $search_date_order_startyear); // Use tzserver
68 $search_date_order_end = dol_mktime(23, 59, 59, $search_date_order_endmonth, $search_date_order_endday, $search_date_order_endyear);
69 
70 $search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
71 $search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
72 $search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
73 $search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
74 $search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
75 $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
76 $search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear); // Use tzserver
77 $search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
78 
79 $search_date_valid_startday = GETPOST('search_date_valid_startday', 'int');
80 $search_date_valid_startmonth = GETPOST('search_date_valid_startmonth', 'int');
81 $search_date_valid_startyear = GETPOST('search_date_valid_startyear', 'int');
82 $search_date_valid_endday = GETPOST('search_date_valid_endday', 'int');
83 $search_date_valid_endmonth = GETPOST('search_date_valid_endmonth', 'int');
84 $search_date_valid_endyear = GETPOST('search_date_valid_endyear', 'int');
85 $search_date_valid_start = dol_mktime(0, 0, 0, $search_date_valid_startmonth, $search_date_valid_startday, $search_date_valid_startyear); // Use tzserver
86 $search_date_valid_end = dol_mktime(23, 59, 59, $search_date_valid_endmonth, $search_date_valid_endday, $search_date_valid_endyear);
87 
88 $search_date_approve_startday = GETPOST('search_date_approve_startday', 'int');
89 $search_date_approve_startmonth = GETPOST('search_date_approve_startmonth', 'int');
90 $search_date_approve_startyear = GETPOST('search_date_approve_startyear', 'int');
91 $search_date_approve_endday = GETPOST('search_date_approve_endday', 'int');
92 $search_date_approve_endmonth = GETPOST('search_date_approve_endmonth', 'int');
93 $search_date_approve_endyear = GETPOST('search_date_approve_endyear', 'int');
94 $search_date_approve_start = dol_mktime(0, 0, 0, $search_date_approve_startmonth, $search_date_approve_startday, $search_date_approve_startyear); // Use tzserver
95 $search_date_approve_end = dol_mktime(23, 59, 59, $search_date_approve_endmonth, $search_date_approve_endday, $search_date_approve_endyear);
96 
97 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
98 
99 $search_product_category = GETPOST('search_product_category', 'int');
100 $search_ref = GETPOST('search_ref', 'alpha');
101 $search_refsupp = GETPOST('search_refsupp', 'alpha');
102 $search_company = GETPOST('search_company', 'alpha');
103 $search_company_alias = GETPOST('search_company_alias', 'alpha');
104 $search_town = GETPOST('search_town', 'alpha');
105 $search_zip = GETPOST('search_zip', 'alpha');
106 $search_state = GETPOST("search_state", 'alpha');
107 $search_country = GETPOST("search_country", 'int');
108 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
109 $search_user = GETPOST('search_user', 'int');
110 $search_request_author = GETPOST('search_request_author', 'alpha');
111 $search_ht = GETPOST('search_ht', 'alpha');
112 $search_ttc = GETPOST('search_ttc', 'alpha');
113 $optioncss = GETPOST('optioncss', 'alpha');
114 $socid = GETPOST('socid', 'int');
115 $search_sale = GETPOST('search_sale', 'int');
116 $search_total_ht = GETPOST('search_total_ht', 'alpha');
117 $search_total_tva = GETPOST('search_total_tva', 'alpha');
118 $search_total_ttc = GETPOST('search_total_ttc', 'alpha');
119 $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
120 $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
121 $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
122 $search_multicurrency_montant_tva = GETPOST('search_multicurrency_montant_tva', 'alpha');
123 $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
124 $optioncss = GETPOST('optioncss', 'alpha');
125 $search_billed = GETPOST('search_billed', 'int');
126 $search_project_ref = GETPOST('search_project_ref', 'alpha');
127 $search_btn = GETPOST('button_search', 'alpha');
128 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
129 
130 if (GETPOSTISARRAY('search_status')) {
131  $search_status = join(',', GETPOST('search_status', 'array:intcomma'));
132 } else {
133  $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : GETPOST('statut', 'intcomma'));
134 }
135 
136 // Security check
137 $orderid = GETPOST('orderid', 'int');
138 if ($user->socid) {
139  $socid = $user->socid;
140 }
141 $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
142 
143 $diroutputmassaction = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id;
144 
145 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
146 $sortfield = GETPOST('sortfield', 'aZ09comma');
147 $sortorder = GETPOST('sortorder', 'aZ09comma');
148 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
149 if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
150  $page = 0;
151 } // If $page is not defined, or '' or -1
152 $offset = $limit * $page;
153 $pageprev = $page - 1;
154 $pagenext = $page + 1;
155 if (!$sortfield) {
156  $sortfield = 'cf.ref';
157 }
158 if (!$sortorder) {
159  $sortorder = 'DESC';
160 }
161 
162 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
163 $object = new CommandeFournisseur($db);
164 $hookmanager->initHooks(array('supplierorderlist'));
165 $extrafields = new ExtraFields($db);
166 
167 // fetch optionals attributes and labels
168 $extrafields->fetch_name_optionals_label($object->table_element);
169 
170 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
171 
172 // List of fields to search into when doing a "search in all"
173 $fieldstosearchall = array();
174 foreach ($object->fields as $key => $val) {
175  if (!empty($val['searchall'])) {
176  $fieldstosearchall['cf.'.$key] = $val['label'];
177  }
178 }
179 $fieldstosearchall['pd.description'] = 'Description';
180 $fieldstosearchall['s.nom'] = "ThirdParty";
181 $fieldstosearchall['s.name_alias'] = "AliasNameShort";
182 $fieldstosearchall['s.zip'] = "Zip";
183 $fieldstosearchall['s.town'] = "Town";
184 if (empty($user->socid)) {
185  $fieldstosearchall["cf.note_private"] = "NotePrivate";
186 }
187 
188 $checkedtypetiers = 0;
189 
190 // Definition of array of fields for columns
191 $arrayfields = array(
192  's.name_alias'=>array('label'=>"AliasNameShort", 'position'=>47, 'checked'=>0),
193  's.town'=>array('label'=>"Town", 'enabled'=>1, 'position'=>47, 'checked'=>1),
194  's.zip'=>array('label'=>"Zip", 'enabled'=>1, 'position'=>47, 'checked'=>1),
195  'state.nom'=>array('label'=>"StateShort", 'enabled'=>1, 'position'=>48),
196  'country.code_iso'=>array('label'=>"Country", 'enabled'=>1, 'position'=>49),
197  'typent.code'=>array('label'=>"ThirdPartyType", 'enabled'=>$checkedtypetiers, 'position'=>50),
198  'u.login'=>array('label'=>"AuthorRequest", 'enabled'=>1, 'position'=>51),
199  'cf.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES')), 'position'=>100),
200  'cf.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'position'=>110),
201 );
202 foreach ($object->fields as $key => $val) {
203  // If $val['visible']==0, then we never show the field
204  if (!empty($val['visible'])) {
205  $visible = (int) dol_eval($val['visible'], 1);
206  $arrayfields['cf.'.$key] = array(
207  'label'=>$val['label'],
208  'checked'=>(($visible < 0) ? 0 : 1),
209  'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
210  'position'=>$val['position'],
211  'help'=> isset($val['help']) ? $val['help'] : ''
212  );
213  }
214 }
215 // Extra fields
216 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
217 
218 $object->fields = dol_sort_array($object->fields, 'position');
219 $arrayfields = dol_sort_array($arrayfields, 'position');
220 
221 $error = 0;
222 
223 $permissiontoread = ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire);
224 $permissiontoadd = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer);
225 $permissiontodelete = ($user->rights->fournisseur->commande->supprimer || $user->rights->supplier_order->supprimer);
226 $permissiontovalidate = $permissiontoadd;
227 $permissiontoapprove = ($user->rights->fournisseur->commande->approuver || $user->rights->supplier_order->approuver);
228 
229 
230 /*
231  * Actions
232  */
233 
234 if (GETPOST('cancel', 'alpha')) {
235  $action = 'list'; $massaction = '';
236 }
237 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createsupplierbills') {
238  $massaction = '';
239 }
240 
241 $parameters = array('socid'=>$socid);
242 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
243 if ($reshook < 0) {
244  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
245 }
246 
247 if (empty($reshook)) {
248  // Selection of new fields
249  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
250 
251  // Purge search criteria
252  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
253  $search_categ = '';
254  $search_user = '';
255  $search_sale = '';
256  $search_product_category = '';
257  $search_ref = '';
258  $search_refsupp = '';
259  $search_company = '';
260  $search_company_alias = '';
261  $search_town = '';
262  $search_zip = "";
263  $search_state = "";
264  $search_type = '';
265  $search_country = '';
266  $search_type_thirdparty = '';
267  $search_request_author = '';
268  $search_total_ht = '';
269  $search_total_tva = '';
270  $search_total_ttc = '';
271  $search_multicurrency_code = '';
272  $search_multicurrency_tx = '';
273  $search_multicurrency_montant_ht = '';
274  $search_multicurrency_montant_tva = '';
275  $search_multicurrency_montant_ttc = '';
276  $search_project_ref = '';
277  $search_status = '';
278  $search_date_order_startday = '';
279  $search_date_order_startmonth = '';
280  $search_date_order_startyear = '';
281  $search_date_order_endday = '';
282  $search_date_order_endmonth = '';
283  $search_date_order_endyear = '';
284  $search_date_order_start = '';
285  $search_date_order_end = '';
286  $search_date_delivery_startday = '';
287  $search_date_delivery_startmonth = '';
288  $search_date_delivery_startyear = '';
289  $search_date_delivery_endday = '';
290  $search_date_delivery_endmonth = '';
291  $search_date_delivery_endyear = '';
292  $search_date_delivery_start = '';
293  $search_date_delivery_end = '';
294  $search_date_valid_startday = '';
295  $search_date_valid_startmonth = '';
296  $search_date_valid_startyear = '';
297  $search_date_valid_endday = '';
298  $search_date_valid_endmonth = '';
299  $search_date_valid_endyear = '';
300  $search_date_valid_start = '';
301  $search_date_valid_end = '';
302  $search_date_approve_startday = '';
303  $search_date_approve_startmonth = '';
304  $search_date_approve_startyear = '';
305  $search_date_approve_endday = '';
306  $search_date_approve_endmonth = '';
307  $search_date_approve_endyear = '';
308  $search_date_approve_start = '';
309  $search_date_approve_end = '';
310  $billed = '';
311  $search_billed = '';
312  $toselect = array();
313  $search_array_options = array();
314  }
315  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
316  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
317  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
318  }
319 
320  // Mass actions
321  $objectclass = 'CommandeFournisseur';
322  $objectlabel = 'SupplierOrders';
323  $uploaddir = $conf->fournisseur->commande->dir_output;
324  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
325 
326  if ($action == 'validate' && $permissiontovalidate) {
327  if (GETPOST('confirm') == 'yes') {
328  $objecttmp = new CommandeFournisseur($db);
329  $db->begin();
330  $error = 0;
331 
332  foreach ($toselect as $checked) {
333  if ($objecttmp->fetch($checked)) {
334  if ($objecttmp->statut == 0) {
335  $objecttmp->date_commande = dol_now();
336  $result = $objecttmp->valid($user);
337  if ($result >= 0) {
338  // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
339  if (empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $permissiontoapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $objecttmp->hasProductsOrServices(1))) {
340  $result = $objecttmp->approve($user);
341  setEventMessages($langs->trans("SupplierOrderValidatedAndApproved"), array($objecttmp->ref));
342  } else {
343  setEventMessages($langs->trans("SupplierOrderValidated"), array($objecttmp->ref));
344  }
345  } else {
346  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
347  $error++;
348  }
349  }
350  }
351  }
352 
353  if (!$error) $db->commit();
354  else $db->rollback();
355  }
356  }
357 
358  // Mass action to generate vendor bills
359  if ($massaction == 'confirm_createsupplierbills') {
360  $orders = GETPOST('toselect', 'array');
361  $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
362  $validate_invoices = GETPOST('validate_invoices', 'int');
363 
364  $TFact = array();
365  $TFactThird = array();
366 
367  $nb_bills_created = 0;
368  $lastid = 0;
369  $lastref = '';
370 
371  $db->begin();
372 
373  $default_ref_supplier=dol_print_date(dol_now(), '%Y%m%d%H%M%S');
374 
375  foreach ($orders as $id_order) {
376  $cmd = new CommandeFournisseur($db);
377  if ($cmd->fetch($id_order) <= 0) {
378  continue;
379  }
380 
381  $objecttmp = new FactureFournisseur($db);
382  if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
383  $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
384  } else {
385  $objecttmp->socid = $cmd->socid;
386  $objecttmp->type = $objecttmp::TYPE_STANDARD;
387  $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
388  $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
389  $objecttmp->fk_project = $cmd->fk_project;
390  $objecttmp->multicurrency_code = $cmd->multicurrency_code;
391  $objecttmp->ref_supplier = !empty($cmd->ref_supplier) ? $cmd->ref_supplier : $default_ref_supplier;
392  $default_ref_supplier+=1;
393 
394  $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
395  if (empty($datefacture)) {
396  $datefacture = dol_now();
397  }
398 
399  $objecttmp->date = $datefacture;
400  $objecttmp->origin = 'order_supplier';
401  $objecttmp->origin_id = $id_order;
402 
403  $res = $objecttmp->create($user);
404 
405  if ($res > 0) {
406  $nb_bills_created++;
407  $lastref = $objecttmp->ref;
408  $lastid = $objecttmp->id;
409  }
410  }
411 
412  if ($objecttmp->id > 0) {
413  $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
414  $sql .= "fk_source";
415  $sql .= ", sourcetype";
416  $sql .= ", fk_target";
417  $sql .= ", targettype";
418  $sql .= ") VALUES (";
419  $sql .= $id_order;
420  $sql .= ", '".$db->escape($objecttmp->origin)."'";
421  $sql .= ", ".((int) $objecttmp->id);
422  $sql .= ", '".$db->escape($objecttmp->element)."'";
423  $sql .= ")";
424 
425  if (!$db->query($sql)) {
426  $erorr++;
427  }
428 
429  if (!$error) {
430  $lines = $cmd->lines;
431  if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
432  $cmd->fetch_lines();
433  $lines = $cmd->lines;
434  }
435 
436  $fk_parent_line = 0;
437  $num = count($lines);
438 
439  for ($i = 0; $i < $num; $i++) {
440  $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
441  if ($lines[$i]->subprice < 0) {
442  // Negative line, we create a discount line
443  $discount = new DiscountAbsolute($db);
444  $discount->fk_soc = $objecttmp->socid;
445  $discount->amount_ht = abs($lines[$i]->total_ht);
446  $discount->amount_tva = abs($lines[$i]->total_tva);
447  $discount->amount_ttc = abs($lines[$i]->total_ttc);
448  $discount->tva_tx = $lines[$i]->tva_tx;
449  $discount->fk_user = $user->id;
450  $discount->description = $desc;
451  $discountid = $discount->create($user);
452  if ($discountid > 0) {
453  $result = $objecttmp->insert_discount($discountid);
454  //$result=$discount->link_to_invoice($lineid,$id);
455  } else {
456  setEventMessages($discount->error, $discount->errors, 'errors');
457  $error++;
458  break;
459  }
460  } else {
461  // Positive line
462  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
463  // Date start
464  $date_start = false;
465  if ($lines[$i]->date_debut_prevue) {
466  $date_start = $lines[$i]->date_debut_prevue;
467  }
468  if ($lines[$i]->date_debut_reel) {
469  $date_start = $lines[$i]->date_debut_reel;
470  }
471  if ($lines[$i]->date_start) {
472  $date_start = $lines[$i]->date_start;
473  }
474  //Date end
475  $date_end = false;
476  if ($lines[$i]->date_fin_prevue) {
477  $date_end = $lines[$i]->date_fin_prevue;
478  }
479  if ($lines[$i]->date_fin_reel) {
480  $date_end = $lines[$i]->date_fin_reel;
481  }
482  if ($lines[$i]->date_end) {
483  $date_end = $lines[$i]->date_end;
484  }
485  // Reset fk_parent_line for no child products and special product
486  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
487  $fk_parent_line = 0;
488  }
489  $result = $objecttmp->addline(
490  $desc,
491  $lines[$i]->subprice,
492  $lines[$i]->tva_tx,
493  $lines[$i]->localtax1_tx,
494  $lines[$i]->localtax2_tx,
495  $lines[$i]->qty,
496  $lines[$i]->fk_product,
497  $lines[$i]->remise_percent,
498  $date_start,
499  $date_end,
500  0,
501  $lines[$i]->info_bits,
502  'HT',
503  $product_type,
504  $lines[$i]->rang,
505  false,
506  $lines[$i]->array_options,
507  $lines[$i]->fk_unit,
508  $objecttmp->origin_id,
509  $lines[$i]->pa_ht,
510  $lines[$i]->ref_supplier,
511  $lines[$i]->special_code,
512  $fk_parent_line
513  );
514  if ($result > 0) {
515  $lineid = $result;
516  } else {
517  $lineid = 0;
518  $error++;
519  break;
520  }
521  // Defined the new fk_parent_line
522  if ($result > 0 && $lines[$i]->product_type == 9) {
523  $fk_parent_line = $result;
524  }
525  }
526  }
527  }
528  }
529 
530  $cmd->classifyBilled($user); // TODO Move this in workflow like done for sales orders
531 
532  if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
533  $TFactThird[$cmd->socid] = $objecttmp;
534  } else {
535  $TFact[$objecttmp->id] = $objecttmp;
536  }
537  }
538 
539  // Build doc with all invoices
540  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
541  $toselect = array();
542 
543  if (!$error && $validate_invoices) {
544  $massaction = $action = 'builddoc';
545 
546  foreach ($TAllFact as &$objecttmp) {
547  $objecttmp->validate($user);
548  if ($result <= 0) {
549  $error++;
550  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
551  break;
552  }
553 
554  $id = $objecttmp->id; // For builddoc action
555 
556  // Fac builddoc
557  $donotredirect = 1;
558  $upload_dir = $conf->fournisseur->facture->dir_output;
559  $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
560  //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
561  }
562 
563  $massaction = $action = 'confirm_createsupplierbills';
564  }
565 
566  if (!$error) {
567  $db->commit();
568 
569  if ($nb_bills_created == 1) {
570  $texttoshow = $langs->trans('BillXCreated', '{s1}');
571  $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
572  setEventMessages($texttoshow, null, 'mesgs');
573  } else {
574  setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
575  }
576 
577  // Make a redirect to avoid to bill twice if we make a refresh or back
578  $param = '';
579  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
580  $param .= '&contextpage='.urlencode($contextpage);
581  }
582  if ($limit > 0 && $limit != $conf->liste_limit) {
583  $param .= '&limit='.urlencode($limit);
584  }
585  if ($sall) {
586  $param .= '&sall='.urlencode($sall);
587  }
588  if ($socid > 0) {
589  $param .= '&socid='.urlencode($socid);
590  }
591  if ($search_status != '') {
592  $param .= '&search_status='.urlencode($search_status);
593  }
594  if ($search_date_order_startday) {
595  $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
596  }
597  if ($search_date_order_startmonth) {
598  $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
599  }
600  if ($search_date_order_startyear) {
601  $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
602  }
603  if ($search_date_order_endday) {
604  $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
605  }
606  if ($search_date_order_endmonth) {
607  $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
608  }
609  if ($search_date_order_endyear) {
610  $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
611  }
612  if ($search_date_delivery_startday) {
613  $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
614  }
615  if ($search_date_delivery_startmonth) {
616  $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
617  }
618  if ($search_date_delivery_startyear) {
619  $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
620  }
621  if ($search_date_delivery_endday) {
622  $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
623  }
624  if ($search_date_delivery_endmonth) {
625  $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
626  }
627  if ($search_date_delivery_endyear) {
628  $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
629  }
630  if ($search_date_valid_startday) {
631  $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
632  }
633  if ($search_date_valid_startmonth) {
634  $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
635  }
636  if ($search_date_valid_startyear) {
637  $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
638  }
639  if ($search_date_valid_endday) {
640  $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
641  }
642  if ($search_date_valid_endmonth) {
643  $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
644  }
645  if ($search_date_valid_endyear) {
646  $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
647  }
648  if ($search_date_approve_startday) {
649  $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
650  }
651  if ($search_date_approve_startmonth) {
652  $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
653  }
654  if ($search_date_approve_startyear) {
655  $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
656  }
657  if ($search_date_approve_endday) {
658  $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
659  }
660  if ($search_date_approve_endmonth) {
661  $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
662  }
663  if ($search_date_approve_endyear) {
664  $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
665  }
666  if ($search_ref) {
667  $param .= '&search_ref='.urlencode($search_ref);
668  }
669  if ($search_company) {
670  $param .= '&search_company='.urlencode($search_company);
671  }
672  if ($search_company_alias) {
673  $param .= '&search_company_alias='.urlencode($search_company_alias);
674  }
675  //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
676  if ($search_user > 0) {
677  $param .= '&search_user='.urlencode($search_user);
678  }
679  if ($search_sale > 0) {
680  $param .= '&search_sale='.urlencode($search_sale);
681  }
682  if ($search_total_ht != '') {
683  $param .= '&search_total_ht='.urlencode($search_total_ht);
684  }
685  if ($search_total_tva != '') {
686  $param .= '&search_total_tva='.urlencode($search_total_tva);
687  }
688  if ($search_total_ttc != '') {
689  $param .= '&search_total_ttc='.urlencode($search_total_ttc);
690  }
691  if ($search_project_ref >= 0) {
692  $param .= "&search_project_ref=".urlencode($search_project_ref);
693  }
694  if ($show_files) {
695  $param .= '&show_files='.urlencode($show_files);
696  }
697  if ($optioncss != '') {
698  $param .= '&optioncss='.urlencode($optioncss);
699  }
700  if ($billed != '') {
701  $param .= '&billed='.urlencode($billed);
702  }
703 
704  header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
705  exit;
706  } else {
707  $db->rollback();
708  $action = 'create';
709  $_GET["origin"] = $_POST["origin"];
710  $_GET["originid"] = $_POST["originid"];
711  setEventMessages("Error", null, 'errors');
712  $error++;
713  }
714  }
715 }
716 
717 
718 /*
719  * View
720  */
721 
722 $now = dol_now();
723 
724 $form = new Form($db);
725 $thirdpartytmp = new Fournisseur($db);
726 $commandestatic = new CommandeFournisseur($db);
727 $formfile = new FormFile($db);
728 $formorder = new FormOrder($db);
729 $formother = new FormOther($db);
730 $formcompany = new FormCompany($db);
731 
732 $title = $langs->trans("SuppliersOrders");
733 if ($socid > 0) {
734  $fourn = new Fournisseur($db);
735  $fourn->fetch($socid);
736  $title .= ' - '.$fourn->name;
737 }
738 
739 /*if ($search_status)
740 {
741  if ($search_status == '1,2') $title .= ' - '.$langs->trans("SuppliersOrdersToProcess");
742  elseif ($search_status == '3,4') $title .= ' - '.$langs->trans("SuppliersOrdersAwaitingReception");
743  elseif ($search_status == '1,2,3') $title .= ' - '.$langs->trans("StatusOrderToProcessShort");
744  elseif ($search_status == '6,7') $title .= ' - '.$langs->trans("StatusOrderCanceled");
745  elseif (is_numeric($search_status) && $search_status >= 0) $title .= ' - '.$commandestatic->LibStatut($search_status);
746 }*/
747 if ($search_billed > 0) {
748  $title .= ' - '.$langs->trans("Billed");
749 }
750 
751 //$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
752 $help_url = '';
753 
754 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
755 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
756 
757 $sql = 'SELECT';
758 if ($sall) {
759  $sql = 'SELECT DISTINCT';
760 }
761 $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.email,';
762 $sql .= " typent.code as typent_code,";
763 $sql .= " state.code_departement as state_code, state.nom as state_name,";
764 $sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as date_livraison,cf.date_valid, cf.date_approve,";
765 $sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
766 $sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
767 $sql .= ' cf.note_public, cf.note_private,';
768 $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,";
769 $sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status";
770 // Add fields from extrafields
771 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
772  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
773  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
774  }
775 }
776 // Add fields from hooks
777 $parameters = array();
778 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
779 $sql .= $hookmanager->resPrint;
780 
781 $sqlfields = $sql; // $sql fields to remove for count total
782 
783 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
784 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
785 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
786 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
787 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
788 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
789  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)";
790 }
791 if ($sall) {
792  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
793 }
794 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid";
795 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet";
796 // We'll need this table joined to the select in order to filter by sale
797 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
798  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
799 }
800 $parameters = array();
801 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
802 $sql .= $hookmanager->resPrint;
803 $sql .= ' WHERE cf.fk_soc = s.rowid';
804 $sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')';
805 if ($socid > 0) {
806  $sql .= " AND s.rowid = ".((int) $socid);
807 }
808 if (empty($user->rights->societe->client->voir) && !$socid) {
809  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
810 }
811 if ($search_ref) {
812  $sql .= natural_search('cf.ref', $search_ref);
813 }
814 if ($search_refsupp) {
815  $sql .= natural_search("cf.ref_supplier", $search_refsupp);
816 }
817 if ($sall) {
818  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
819 }
820 if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
821  $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
822 } else {
823  if ($search_company) {
824  $sql .= natural_search('s.nom', $search_company);
825  }
826  if ($search_company_alias) {
827  $sql .= natural_search('s.name_alias', $search_company_alias);
828  }
829 }
830 if ($search_request_author) {
831  $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
832 }
833 if ($search_billed != '' && $search_billed >= 0) {
834  $sql .= " AND cf.billed = ".((int) $search_billed);
835 }
836 //Required triple check because statut=0 means draft filter
837 if (GETPOST('statut', 'intcomma') !== '') {
838  $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")";
839 }
840 if ($search_status != '' && $search_status != '-1') {
841  $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
842 }
843 if ($search_date_order_start) {
844  $sql .= " AND cf.date_commande >= '".$db->idate($search_date_order_start)."'";
845 }
846 if ($search_date_order_end) {
847  $sql .= " AND cf.date_commande <= '".$db->idate($search_date_order_end)."'";
848 }
849 if ($search_date_delivery_start) {
850  $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
851 }
852 if ($search_date_delivery_end) {
853  $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
854 }
855 if ($search_date_valid_start) {
856  $sql .= " AND cf.date_commande >= '".$db->idate($search_date_valid_start)."'";
857 }
858 if ($search_date_valid_end) {
859  $sql .= " AND cf.date_commande <= '".$db->idate($search_date_valid_end)."'";
860 }
861 if ($search_date_approve_start) {
862  $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
863 }
864 if ($search_date_approve_end) {
865  $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
866 }
867 if ($search_town) {
868  $sql .= natural_search('s.town', $search_town);
869 }
870 if ($search_zip) {
871  $sql .= natural_search("s.zip", $search_zip);
872 }
873 if ($search_state) {
874  $sql .= natural_search("state.nom", $search_state);
875 }
876 if ($search_country) {
877  $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
878 }
879 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
880  $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
881 }
882 if ($search_sale > 0) {
883  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
884 }
885 if ($search_user > 0) {
886  $sql .= " AND EXISTS (";
887  $sql .= " SELECT ec.rowid ";
888  $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec";
889  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON tc.rowid = ec.fk_c_type_contact";
890  $sql .= " WHERE ec.element_id = cf.rowid AND ec.fk_socpeople = " . ((int) $search_user);
891  $sql .= " AND tc.element = 'order_supplier' AND tc.source = 'internal'";
892  $sql .= ")";
893 }
894 if ($search_total_ht != '') {
895  $sql .= natural_search('cf.total_ht', $search_total_ht, 1);
896 }
897 if ($search_total_tva != '') {
898  $sql .= natural_search('cf.total_tva', $search_total_tva, 1);
899 }
900 if ($search_total_ttc != '') {
901  $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1);
902 }
903 if ($search_multicurrency_code != '') {
904  $sql .= " AND cf.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
905 }
906 if ($search_multicurrency_tx != '') {
907  $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1);
908 }
909 if ($search_multicurrency_montant_ht != '') {
910  $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
911 }
912 if ($search_multicurrency_montant_tva != '') {
913  $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1);
914 }
915 if ($search_multicurrency_montant_ttc != '') {
916  $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
917 }
918 if ($search_project_ref != '') {
919  $sql .= natural_search("p.ref", $search_project_ref);
920 }
921 // Search for tag/category ($searchCategoryProductList is an array of ID)
922 $searchCategoryProductOperator = -1;
923 $searchCategoryProductList = array($search_product_category);
924 if (!empty($searchCategoryProductList)) {
925  $searchCategoryProductSqlList = array();
926  $listofcategoryid = '';
927  foreach ($searchCategoryProductList as $searchCategoryProduct) {
928  if (intval($searchCategoryProduct) == -2) {
929  $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product)";
930  } elseif (intval($searchCategoryProduct) > 0) {
931  if ($searchCategoryProductOperator == 0) {
932  $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
933  } else {
934  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
935  }
936  }
937  }
938  if ($listofcategoryid) {
939  $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
940  }
941  if ($searchCategoryProductOperator == 1) {
942  if (!empty($searchCategoryProductSqlList)) {
943  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
944  }
945  } else {
946  if (!empty($searchCategoryProductSqlList)) {
947  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
948  }
949  }
950 }
951 // Add where from extra fields
952 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
953 // Add where from hooks
954 $parameters = array();
955 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
956 $sql .= $hookmanager->resPrint;
957 
958 // Count total nb of records
959 $nbtotalofrecords = '';
960 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
961  /* The fast and low memory method to get and count full list converts the sql into a sql count */
962  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
963  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
964  $resql = $db->query($sqlforcount);
965  if ($resql) {
966  $objforcount = $db->fetch_object($resql);
967  $nbtotalofrecords = $objforcount->nbtotalofrecords;
968  } else {
969  dol_print_error($db);
970  }
971 
972  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
973  $page = 0;
974  $offset = 0;
975  }
976  $db->free($resql);
977 }
978 
979 $sql .= $db->order($sortfield, $sortorder);
980 if ($limit) {
981  $sql .= $db->plimit($limit + 1, $offset);
982 }
983 //print $sql;
984 
985 $resql = $db->query($sql);
986 if ($resql) {
987  $num = $db->num_rows($resql);
988 
989  $arrayofselected = is_array($toselect) ? $toselect : array();
990 
991  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
992  $obj = $db->fetch_object($resql);
993  $id = $obj->rowid;
994  header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id);
995  exit;
996  }
997 
998  llxHeader('', $title, $help_url);
999 
1000  $param = '';
1001  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1002  $param .= '&contextpage='.urlencode($contextpage);
1003  }
1004  if ($limit > 0 && $limit != $conf->liste_limit) {
1005  $param .= '&limit='.urlencode($limit);
1006  }
1007  if ($sall) {
1008  $param .= '&sall='.urlencode($sall);
1009  }
1010  if ($socid > 0) {
1011  $param .= '&socid='.urlencode($socid);
1012  }
1013  if ($sall) {
1014  $param .= "&search_all=".urlencode($sall);
1015  }
1016  if ($search_date_order_startday) {
1017  $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
1018  }
1019  if ($search_date_order_startmonth) {
1020  $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
1021  }
1022  if ($search_date_order_startyear) {
1023  $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
1024  }
1025  if ($search_date_order_endday) {
1026  $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
1027  }
1028  if ($search_date_order_endmonth) {
1029  $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
1030  }
1031  if ($search_date_order_endyear) {
1032  $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
1033  }
1034  if ($search_date_delivery_startday) {
1035  $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
1036  }
1037  if ($search_date_delivery_startmonth) {
1038  $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
1039  }
1040  if ($search_date_delivery_startyear) {
1041  $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
1042  }
1043  if ($search_date_delivery_endday) {
1044  $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
1045  }
1046  if ($search_date_delivery_endmonth) {
1047  $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
1048  }
1049  if ($search_date_delivery_endyear) {
1050  $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
1051  }
1052  if ($search_date_valid_startday) {
1053  $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
1054  }
1055  if ($search_date_valid_startmonth) {
1056  $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
1057  }
1058  if ($search_date_valid_startyear) {
1059  $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
1060  }
1061  if ($search_date_valid_endday) {
1062  $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
1063  }
1064  if ($search_date_valid_endmonth) {
1065  $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
1066  }
1067  if ($search_date_valid_endyear) {
1068  $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
1069  }
1070  if ($search_date_approve_startday) {
1071  $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
1072  }
1073  if ($search_date_approve_startmonth) {
1074  $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
1075  }
1076  if ($search_date_approve_startyear) {
1077  $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
1078  }
1079  if ($search_date_approve_endday) {
1080  $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
1081  }
1082  if ($search_date_approve_endmonth) {
1083  $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
1084  }
1085  if ($search_date_approve_endyear) {
1086  $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
1087  }
1088  if ($search_ref) {
1089  $param .= '&search_ref='.urlencode($search_ref);
1090  }
1091  if ($search_company) {
1092  $param .= '&search_company='.urlencode($search_company);
1093  }
1094  if ($search_company_alias) {
1095  $param .= '&search_company_alias='.urlencode($search_company_alias);
1096  }
1097  if ($search_user > 0) {
1098  $param .= '&search_user='.urlencode($search_user);
1099  }
1100  if ($search_request_author) {
1101  $param .= '&search_request_author='.urlencode($search_request_author);
1102  }
1103  if ($search_sale > 0) {
1104  $param .= '&search_sale='.urlencode($search_sale);
1105  }
1106  if ($search_total_ht != '') {
1107  $param .= '&search_total_ht='.urlencode($search_total_ht);
1108  }
1109  if ($search_total_ttc != '') {
1110  $param .= "&search_total_ttc=".urlencode($search_total_ttc);
1111  }
1112  if ($search_multicurrency_code != '') {
1113  $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1114  }
1115  if ($search_multicurrency_tx != '') {
1116  $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1117  }
1118  if ($search_multicurrency_montant_ht != '') {
1119  $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1120  }
1121  if ($search_multicurrency_montant_tva != '') {
1122  $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva);
1123  }
1124  if ($search_multicurrency_montant_ttc != '') {
1125  $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1126  }
1127  if ($search_refsupp) {
1128  $param .= "&search_refsupp=".urlencode($search_refsupp);
1129  }
1130  if ($search_status != '' && $search_status != '-1') {
1131  $param .= "&search_status=".urlencode($search_status);
1132  }
1133  if ($search_project_ref >= 0) {
1134  $param .= "&search_project_ref=".urlencode($search_project_ref);
1135  }
1136  if ($search_billed != '') {
1137  $param .= "&search_billed=".urlencode($search_billed);
1138  }
1139  if ($show_files) {
1140  $param .= '&show_files='.urlencode($show_files);
1141  }
1142  if ($optioncss != '') {
1143  $param .= '&optioncss='.urlencode($optioncss);
1144  }
1145  if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
1146  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
1147  }
1148 
1149  // Add $param from extra fields
1150  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1151 
1152  $parameters = array();
1153  $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
1154  $param .= $hookmanager->resPrint;
1155 
1156  // List of mass actions available
1157  $arrayofmassactions = array(
1158  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1159  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1160  'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1161  );
1162 
1163  if ($permissiontovalidate) {
1164  if ($permissiontoapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
1165  $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
1166  } else {
1167  $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
1168  }
1169  }
1170 
1171  if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
1172  $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier");
1173  }
1174  if ($permissiontodelete) {
1175  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1176  }
1177  if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
1178  $arrayofmassactions = array();
1179  }
1180  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1181 
1182  $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
1183  if ($socid > 0) {
1184  $url .= '&socid='.((int) $socid);
1185  $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
1186  }
1187  $newcardbutton = dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
1188 
1189  // Lines of title fields
1190  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
1191  if ($optioncss != '') {
1192  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1193  }
1194  print '<input type="hidden" name="token" value="'.newToken().'">';
1195  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1196  print '<input type="hidden" name="action" value="list">';
1197  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1198  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1199  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1200  print '<input type="hidden" name="socid" value="'.$socid.'">';
1201 
1202  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1);
1203 
1204  $topicmail = "SendOrderRef";
1205  $modelmail = "order_supplier_send";
1206  $objecttmp = new CommandeFournisseur($db); // in case $object is not the good object
1207  $trackid = 'sord'.$object->id;
1208  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1209 
1210  if ($massaction == 'prevalidate') {
1211  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1212  }
1213 
1214  if ($massaction == 'createbills') {
1215  //var_dump($_REQUEST);
1216  print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">';
1217 
1218  print '<table class="noborder" width="100%" >';
1219  print '<tr>';
1220  print '<td class="titlefield">';
1221  print $langs->trans('DateInvoice');
1222  print '</td>';
1223  print '<td>';
1224  print $form->selectDate('', '', '', '', '', '', 1, 1);
1225  print '</td>';
1226  print '</tr>';
1227  print '<tr>';
1228  print '<td>';
1229  print $langs->trans('CreateOneBillByThird');
1230  print '</td>';
1231  print '<td>';
1232  print $form->selectyesno('createbills_onebythird', '', 1);
1233  print '</td>';
1234  print '</tr>';
1235  print '<tr>';
1236  print '<td>';
1237  print $langs->trans('ValidateInvoices');
1238  print '</td>';
1239  print '<td>';
1240  print $form->selectyesno('validate_invoices', 1, 1);
1241  print '</td>';
1242  print '</tr>';
1243  print '</table>';
1244 
1245  print '<br>';
1246  print '<div class="center">';
1247  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
1248  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1249  print '</div>';
1250  print '<br>';
1251  }
1252 
1253  if ($sall) {
1254  foreach ($fieldstosearchall as $key => $val) {
1255  $fieldstosearchall[$key] = $langs->trans($val);
1256  }
1257  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
1258  }
1259 
1260  $moreforfilter = '';
1261 
1262  // If the user can view prospects other than his'
1263  if ($user->rights->user->user->lire) {
1264  $langs->load("commercial");
1265  $moreforfilter .= '<div class="divsearchfield">';
1266  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1267  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1268  $moreforfilter .= '</div>';
1269  }
1270  // If the user can view other users
1271  if ($user->rights->user->user->lire) {
1272  $moreforfilter .= '<div class="divsearchfield">';
1273  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1274  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1275  $moreforfilter .= '</div>';
1276  }
1277  // If the user can view prospects other than his'
1278  if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
1279  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1280  $moreforfilter .= '<div class="divsearchfield">';
1281  $tmptitle = $langs->trans('IncludingProductWithTag');
1282  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1283  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
1284  $moreforfilter .= '</div>';
1285  }
1286  $parameters = array();
1287  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1288  if (empty($reshook)) {
1289  $moreforfilter .= $hookmanager->resPrint;
1290  } else {
1291  $moreforfilter = $hookmanager->resPrint;
1292  }
1293 
1294  if (!empty($moreforfilter)) {
1295  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1296  print $moreforfilter;
1297  print '</div>';
1298  }
1299 
1300  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1301  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
1302  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1303 
1304  if (GETPOST('autoselectall', 'int')) {
1305  $selectedfields .= '<script>';
1306  $selectedfields .= ' $(document).ready(function() {';
1307  $selectedfields .= ' console.log("Autoclick on checkforselects");';
1308  $selectedfields .= ' $("#checkforselects").click();';
1309  $selectedfields .= ' $("#massaction").val("createbills").change();';
1310  $selectedfields .= ' });';
1311  $selectedfields .= '</script>';
1312  }
1313 
1314  print '<div class="div-table-responsive">';
1315  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1316 
1317  print '<tr class="liste_titre_filter">';
1318  // Action column
1319  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1320  print '<td class="liste_titre middle">';
1321  $searchpicto = $form->showFilterButtons('left');
1322  print $searchpicto;
1323  print '</td>';
1324  }
1325  // Ref
1326  if (!empty($arrayfields['cf.ref']['checked'])) {
1327  print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>';
1328  }
1329  // Ref customer
1330  if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1331  print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>';
1332  }
1333  // Project ref
1334  if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1335  print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>';
1336  }
1337  // Request author
1338  if (!empty($arrayfields['u.login']['checked'])) {
1339  print '<td class="liste_titre">';
1340  print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
1341  print '</td>';
1342  }
1343  // Thirpdarty
1344  if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1345  print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
1346  }
1347  // Alias
1348  if (!empty($arrayfields['s.name_alias']['checked'])) {
1349  print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company_alias" value="'.$search_company_alias.'"></td>';
1350  }
1351  // Town
1352  if (!empty($arrayfields['s.town']['checked'])) {
1353  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
1354  }
1355  // Zip
1356  if (!empty($arrayfields['s.zip']['checked'])) {
1357  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
1358  }
1359  // State
1360  if (!empty($arrayfields['state.nom']['checked'])) {
1361  print '<td class="liste_titre">';
1362  print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1363  print '</td>';
1364  }
1365  // Country
1366  if (!empty($arrayfields['country.code_iso']['checked'])) {
1367  print '<td class="liste_titre center">';
1368  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1369  print '</td>';
1370  }
1371  // Company type
1372  if (!empty($arrayfields['typent.code']['checked'])) {
1373  print '<td class="liste_titre maxwidthonsmartphone center">';
1374  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
1375  print '</td>';
1376  }
1377  // Date order
1378  if (!empty($arrayfields['cf.date_commande']['checked'])) {
1379  print '<td class="liste_titre center">';
1380  print '<div class="nowrap">';
1381  print $form->selectDate($search_date_order_start ? $search_date_order_start : -1, 'search_date_order_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1382  print '</div>';
1383  print '<div class="nowrap">';
1384  print $form->selectDate($search_date_order_end ? $search_date_order_end : -1, 'search_date_order_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1385  print '</div>';
1386  print '</td>';
1387  }
1388  // Date delivery
1389  if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1390  print '<td class="liste_titre center">';
1391  print '<div class="nowrap">';
1392  print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1393  print '</div>';
1394  print '<div class="nowrap">';
1395  print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1396  print '</div>';
1397  print '</td>';
1398  }
1399  if (!empty($arrayfields['cf.total_ht']['checked'])) {
1400  // Amount
1401  print '<td class="liste_titre right">';
1402  print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
1403  print '</td>';
1404  }
1405  if (!empty($arrayfields['cf.total_tva']['checked'])) {
1406  // Amount
1407  print '<td class="liste_titre right">';
1408  print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">';
1409  print '</td>';
1410  }
1411  if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1412  // Amount
1413  print '<td class="liste_titre right">';
1414  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1415  print '</td>';
1416  }
1417  if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1418  // Currency
1419  print '<td class="liste_titre">';
1420  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1421  print '</td>';
1422  }
1423  if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1424  // Currency rate
1425  print '<td class="liste_titre">';
1426  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1427  print '</td>';
1428  }
1429  if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1430  // Amount
1431  print '<td class="liste_titre right">';
1432  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1433  print '</td>';
1434  }
1435  if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1436  // Amount
1437  print '<td class="liste_titre right">';
1438  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">';
1439  print '</td>';
1440  }
1441  if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1442  // Amount
1443  print '<td class="liste_titre right">';
1444  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1445  print '</td>';
1446  }
1447  // Extra fields
1448  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1449 
1450  // Fields from hook
1451  $parameters = array('arrayfields'=>$arrayfields);
1452  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1453  print $hookmanager->resPrint;
1454  // Date creation
1455  if (!empty($arrayfields['cf.date_creation']['checked'])) {
1456  print '<td class="liste_titre">';
1457  print '</td>';
1458  }
1459  // Date modification
1460  if (!empty($arrayfields['cf.tms']['checked'])) {
1461  print '<td class="liste_titre">';
1462  print '</td>';
1463  }
1464  // Status
1465  if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1466  print '<td class="liste_titre right">';
1467  $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status');
1468  print '</td>';
1469  }
1470  // Status billed
1471  if (!empty($arrayfields['cf.billed']['checked'])) {
1472  print '<td class="liste_titre center">';
1473  print $form->selectyesno('search_billed', $search_billed, 1, false, 1, 1, 'maxwidth100 onrightofpage');
1474  print '</td>';
1475  }
1476  // Date valid
1477  if (!empty($arrayfields['cf.date_valid']['checked'])) {
1478  print '<td class="liste_titre center">';
1479  print '<div class="nowrap">';
1480  print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1481  print '</div>';
1482  print '<div class="nowrap">';
1483  print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1484  print '</div>';
1485  print '</td>';
1486  }
1487  // Date approve
1488  if (!empty($arrayfields['cf.date_approve']['checked'])) {
1489  print '<td class="liste_titre center">';
1490  print '<div class="nowrap">';
1491  print $form->selectDate($search_date_approve_start ? $search_date_approve_start : -1, 'search_date_approve_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1492  print '</div>';
1493  print '<div class="nowrap">';
1494  print $form->selectDate($search_date_approve_end ? $search_date_approve_end : -1, 'search_date_approve_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1495  print '</div>';
1496  print '</td>';
1497  }
1498  // Note public
1499  if (!empty($arrayfields['cf.note_public']['checked'])) {
1500  print '<td class="liste_titre">';
1501  print '</td>';
1502  }
1503  // Note private
1504  if (!empty($arrayfields['cf.note_private']['checked'])) {
1505  print '<td class="liste_titre">';
1506  print '</td>';
1507  }
1508  // Action column
1509  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1510  print '<td class="liste_titre middle">';
1511  $searchpicto = $form->showFilterButtons();
1512  print $searchpicto;
1513  print '</td>';
1514  }
1515 
1516  print "</tr>\n";
1517 
1518  // Fields title
1519  print '<tr class="liste_titre">';
1520  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1521  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1522  }
1523  if (!empty($arrayfields['cf.ref']['checked'])) {
1524  print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder);
1525  }
1526  if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1527  print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp ');
1528  }
1529  if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1530  print_liste_field_titre($arrayfields['cf.fk_projet']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1531  }
1532  if (!empty($arrayfields['u.login']['checked'])) {
1533  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder);
1534  }
1535  if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1536  print_liste_field_titre($arrayfields['cf.fk_soc']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
1537  }
1538  if (!empty($arrayfields['s.name_alias']['checked'])) {
1539  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, '', $sortfield, $sortorder);
1540  }
1541  if (!empty($arrayfields['s.town']['checked'])) {
1542  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1543  }
1544  if (!empty($arrayfields['s.zip']['checked'])) {
1545  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1546  }
1547  if (!empty($arrayfields['state.nom']['checked'])) {
1548  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1549  }
1550  if (!empty($arrayfields['country.code_iso']['checked'])) {
1551  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1552  }
1553  if (!empty($arrayfields['typent.code']['checked'])) {
1554  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1555  }
1556  if (!empty($arrayfields['cf.fk_author']['checked'])) {
1557  print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder);
1558  }
1559  if (!empty($arrayfields['cf.date_commande']['checked'])) {
1560  print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center ');
1561  }
1562  if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1563  print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1564  }
1565  if (!empty($arrayfields['cf.total_ht']['checked'])) {
1566  print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
1567  }
1568  if (!empty($arrayfields['cf.total_tva']['checked'])) {
1569  print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
1570  }
1571  if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1572  print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
1573  }
1574  if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1575  print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1576  }
1577  if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1578  print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1579  }
1580  if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1581  print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1582  }
1583  if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1584  print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1585  }
1586  if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1587  print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1588  }
1589  // Extra fields
1590  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1591  // Hook fields
1592  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1593  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1594  print $hookmanager->resPrint;
1595  if (!empty($arrayfields['cf.date_creation']['checked'])) {
1596  print_liste_field_titre($arrayfields['cf.date_creation']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1597  }
1598  if (!empty($arrayfields['cf.tms']['checked'])) {
1599  print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1600  }
1601  if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1602  print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1603  }
1604  if (!empty($arrayfields['cf.billed']['checked'])) {
1605  print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
1606  }
1607  if (!empty($arrayfields['cf.date_valid']['checked'])) {
1608  print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
1609  }
1610  if (!empty($arrayfields['cf.date_approve']['checked'])) {
1611  print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
1612  }
1613  if (!empty($arrayfields['cf.note_public']['checked'])) {
1614  print_liste_field_titre($arrayfields['cf.note_public']['label'], $_SERVER["PHP_SELF"], "cf.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
1615  }
1616  if (!empty($arrayfields['cf.note_private']['checked'])) {
1617  print_liste_field_titre($arrayfields['cf.note_private']['label'], $_SERVER["PHP_SELF"], "cf.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
1618  }
1619  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1620  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1621  }
1622  print "</tr>\n";
1623 
1624 
1625  $total = 0;
1626  $subtotal = 0;
1627  $productstat_cache = array();
1628 
1629  $userstatic = new User($db);
1630  $objectstatic = new CommandeFournisseur($db);
1631  $projectstatic = new Project($db);
1632 
1633  $i = 0;
1634  $totalarray = array('nbfield' => 0, 'val' => array(), 'pos' => array());
1635  $totalarray['val']['cf.total_ht'] = 0;
1636  $totalarray['val']['cf.total_ttc'] = 0;
1637  $totalarray['val']['cf.total_tva'] = 0;
1638 
1639  $imaxinloop = ($limit ? min($num, $limit) : $num);
1640  while ($i < $imaxinloop) {
1641  $obj = $db->fetch_object($resql);
1642 
1643  $notshippable = 0;
1644  $warning = 0;
1645  $text_info = '';
1646  $text_warning = '';
1647  $nbprod = 0;
1648 
1649  $objectstatic->id = $obj->rowid;
1650  $objectstatic->ref = $obj->ref;
1651  $objectstatic->socid = $obj->socid;
1652  $objectstatic->ref_supplier = $obj->ref_supplier;
1653  $objectstatic->socid = $obj->socid;
1654  $objectstatic->total_ht = $obj->total_ht;
1655  $objectstatic->total_tva = $obj->total_tva;
1656  $objectstatic->total_ttc = $obj->total_ttc;
1657  $objectstatic->date_commande = $db->jdate($obj->date_commande);
1658  $objectstatic->delivery_date = $db->jdate($obj->date_livraison);
1659  $objectstatic->note_public = $obj->note_public;
1660  $objectstatic->note_private = $obj->note_private;
1661  $objectstatic->statut = $obj->fk_statut;
1662 
1663  print '<tr class="oddeven">';
1664  // Action column
1665  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1666  print '<td class="nowrap center">';
1667  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1668  $selected = 0;
1669  if (in_array($obj->rowid, $arrayofselected)) {
1670  $selected = 1;
1671  }
1672  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1673  }
1674  print '</td>';
1675  }
1676  // Ref
1677  if (!empty($arrayfields['cf.ref']['checked'])) {
1678  print '<td class="nowrap">';
1679 
1680  // Picto + Ref
1681  print $objectstatic->getNomUrl(1, '', 0, -1, 1);
1682  // Other picto tool
1683  $filename = dol_sanitizeFileName($obj->ref);
1684  $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1685  print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1686 
1687  print '</td>'."\n";
1688  if (!$i) {
1689  $totalarray['nbfield']++;
1690  }
1691  }
1692  // Ref Supplier
1693  if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1694  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>'."\n";
1695  if (!$i) {
1696  $totalarray['nbfield']++;
1697  }
1698  }
1699  // Project
1700  if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1701  $projectstatic->id = $obj->project_id;
1702  $projectstatic->ref = $obj->project_ref;
1703  $projectstatic->title = $obj->project_title;
1704  print '<td>';
1705  if ($obj->project_id > 0) {
1706  print $projectstatic->getNomUrl(1);
1707  }
1708  print '</td>';
1709  if (!$i) {
1710  $totalarray['nbfield']++;
1711  }
1712  }
1713  // Author
1714  $userstatic->id = $obj->fk_user_author;
1715  $userstatic->lastname = $obj->lastname;
1716  $userstatic->firstname = $obj->firstname;
1717  $userstatic->login = $obj->login;
1718  $userstatic->photo = $obj->photo;
1719  $userstatic->email = $obj->user_email;
1720  $userstatic->statut = $obj->user_status;
1721  if (!empty($arrayfields['u.login']['checked'])) {
1722  print '<td class="tdoverflowmax150">';
1723  if ($userstatic->id) {
1724  print $userstatic->getNomUrl(1);
1725  }
1726  print "</td>";
1727  if (!$i) {
1728  $totalarray['nbfield']++;
1729  }
1730  }
1731  // Thirdparty
1732  if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1733  print '<td class="tdoverflowmax150">';
1734  $thirdpartytmp->id = $obj->socid;
1735  $thirdpartytmp->name = $obj->name;
1736  $thirdpartytmp->email = $obj->email;
1737  $thirdpartytmp->name_alias = $obj->alias;
1738  $thirdpartytmp->client = $obj->client;
1739  $thirdpartytmp->fournisseur = $obj->fournisseur;
1740  print $thirdpartytmp->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1741  print '</td>'."\n";
1742  if (!$i) {
1743  $totalarray['nbfield']++;
1744  }
1745  }
1746  //alias
1747  if (!empty($arrayfields['s.name_alias']['checked'])) {
1748  print '<td class="tdoverflowmax150">';
1749  print $obj->alias;
1750  print '</td>'."\n";
1751  if (!$i) {
1752  $totalarray['nbfield']++;
1753  }
1754  }
1755  // Town
1756  if (!empty($arrayfields['s.town']['checked'])) {
1757  print '<td>';
1758  print $obj->town;
1759  print '</td>';
1760  if (!$i) {
1761  $totalarray['nbfield']++;
1762  }
1763  }
1764  // Zip
1765  if (!empty($arrayfields['s.zip']['checked'])) {
1766  print '<td>';
1767  print $obj->zip;
1768  print '</td>';
1769  if (!$i) {
1770  $totalarray['nbfield']++;
1771  }
1772  }
1773  // State
1774  if (!empty($arrayfields['state.nom']['checked'])) {
1775  print "<td>".$obj->state_name."</td>\n";
1776  if (!$i) {
1777  $totalarray['nbfield']++;
1778  }
1779  }
1780  // Country
1781  if (!empty($arrayfields['country.code_iso']['checked'])) {
1782  print '<td class="center">';
1783  $tmparray = getCountry($obj->fk_pays, 'all');
1784  print $tmparray['label'];
1785  print '</td>';
1786  if (!$i) {
1787  $totalarray['nbfield']++;
1788  }
1789  }
1790  // Type ent
1791  if (!empty($arrayfields['typent.code']['checked'])) {
1792  print '<td class="center">';
1793  if (empty($typenArray)) {
1794  $typenArray = $formcompany->typent_array(1);
1795  }
1796  print $typenArray[$obj->typent_code];
1797  print '</td>';
1798  if (!$i) {
1799  $totalarray['nbfield']++;
1800  }
1801  }
1802 
1803  // Order date
1804  if (!empty($arrayfields['cf.date_commande']['checked'])) {
1805  print '<td class="center">';
1806  print dol_print_date($db->jdate($obj->date_commande), 'day');
1807  if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) {
1808  if ($objectstatic->hasDelay()) {
1809  print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1810  }
1811  }
1812  print '</td>';
1813  if (!$i) {
1814  $totalarray['nbfield']++;
1815  }
1816  }
1817  // Plannned date of delivery
1818  if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1819  print '<td class="center">';
1820  print dol_print_date($db->jdate($obj->date_livraison), 'day');
1821  if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) {
1822  if ($objectstatic->hasDelay()) {
1823  print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1824  }
1825  }
1826  print '</td>';
1827  if (!$i) {
1828  $totalarray['nbfield']++;
1829  }
1830  }
1831  // Amount HT
1832  if (!empty($arrayfields['cf.total_ht']['checked'])) {
1833  print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1834  if (!$i) {
1835  $totalarray['nbfield']++;
1836  }
1837  if (!$i) {
1838  $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht';
1839  }
1840  $totalarray['val']['cf.total_ht'] += $obj->total_ht;
1841  }
1842  // Amount VAT
1843  if (!empty($arrayfields['cf.total_tva']['checked'])) {
1844  print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1845  if (!$i) {
1846  $totalarray['nbfield']++;
1847  }
1848  if (!$i) {
1849  $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva';
1850  }
1851  $totalarray['val']['cf.total_tva'] += $obj->total_tva;
1852  }
1853  // Amount TTC
1854  if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1855  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1856  if (!$i) {
1857  $totalarray['nbfield']++;
1858  }
1859  if (!$i) {
1860  $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc';
1861  }
1862  $totalarray['val']['cf.total_ttc'] += $obj->total_ttc;
1863  }
1864 
1865  // Currency
1866  if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1867  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1868  if (!$i) {
1869  $totalarray['nbfield']++;
1870  }
1871  }
1872 
1873  // Currency rate
1874  if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1875  print '<td class="nowrap">';
1876  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1877  print "</td>\n";
1878  if (!$i) {
1879  $totalarray['nbfield']++;
1880  }
1881  }
1882  // Amount HT
1883  if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1884  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1885  if (!$i) {
1886  $totalarray['nbfield']++;
1887  }
1888  }
1889  // Amount VAT
1890  if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1891  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
1892  if (!$i) {
1893  $totalarray['nbfield']++;
1894  }
1895  }
1896  // Amount TTC
1897  if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1898  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1899  if (!$i) {
1900  $totalarray['nbfield']++;
1901  }
1902  }
1903 
1904  // Extra fields
1905  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1906  // Fields from hook
1907  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1908  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1909  print $hookmanager->resPrint;
1910  // Date creation
1911  if (!empty($arrayfields['cf.date_creation']['checked'])) {
1912  print '<td class="center nowrap">';
1913  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1914  print '</td>';
1915  if (!$i) {
1916  $totalarray['nbfield']++;
1917  }
1918  }
1919  // Date modification
1920  if (!empty($arrayfields['cf.tms']['checked'])) {
1921  print '<td class="center nowrap">';
1922  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1923  print '</td>';
1924  if (!$i) {
1925  $totalarray['nbfield']++;
1926  }
1927  }
1928  // Status
1929  if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1930  print '<td class="right nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>';
1931  if (!$i) {
1932  $totalarray['nbfield']++;
1933  }
1934  }
1935  // Billed
1936  if (!empty($arrayfields['cf.billed']['checked'])) {
1937  print '<td class="center">'.yn($obj->billed).'</td>';
1938  if (!$i) {
1939  $totalarray['nbfield']++;
1940  }
1941  }
1942 
1943  // valid date
1944  if (!empty($arrayfields['cf.date_valid']['checked'])) {
1945  print '<td class="center">';
1946  print dol_print_date($db->jdate($obj->date_valid), 'day');
1947  print '</td>';
1948  if (!$i) {
1949  $totalarray['nbfield']++;
1950  }
1951  }
1952  // approve date
1953  if (!empty($arrayfields['cf.date_approve']['checked'])) {
1954  print '<td class="center">';
1955  print dol_print_date($db->jdate($obj->date_approve), 'day');
1956  print '</td>';
1957  if (!$i) {
1958  $totalarray['nbfield']++;
1959  }
1960  }
1961  // Note public
1962  if (!empty($arrayfields['cf.note_public']['checked'])) {
1963  print '<td class="center">';
1964  print dol_string_nohtmltag($obj->note_public);
1965  print '</td>';
1966  if (!$i) {
1967  $totalarray['nbfield']++;
1968  }
1969  }
1970 
1971  // Note private
1972  if (!empty($arrayfields['cf.note_private']['checked'])) {
1973  print '<td class="center">';
1974  print dol_string_nohtmltag($obj->note_private);
1975  print '</td>';
1976  if (!$i) {
1977  $totalarray['nbfield']++;
1978  }
1979  }
1980 
1981  // Action column
1982  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1983  print '<td class="nowrap center">';
1984  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1985  $selected = 0;
1986  if (in_array($obj->rowid, $arrayofselected)) {
1987  $selected = 1;
1988  }
1989  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1990  }
1991  print '</td>';
1992  }
1993  if (!$i) {
1994  $totalarray['nbfield']++;
1995  }
1996 
1997  print "</tr>\n";
1998 
1999  $total += $obj->total_ht;
2000  $subtotal += $obj->total_ht;
2001  $i++;
2002  }
2003 
2004  // Show total line
2005  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2006 
2007  // If no record found
2008  if ($num == 0) {
2009  $colspan = 1;
2010  foreach ($arrayfields as $key => $val) {
2011  if (!empty($val['checked'])) {
2012  $colspan++;
2013  }
2014  }
2015  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2016  }
2017 
2018  $db->free($resql);
2019 
2020  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2021  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
2022  print $hookmanager->resPrint;
2023 
2024  print '</table>'."\n";
2025  print '</div>';
2026 
2027  print '</form>'."\n";
2028 
2029  $hidegeneratedfilelistifempty = 1;
2030  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2031  $hidegeneratedfilelistifempty = 0;
2032  }
2033 
2034  // Show list of available documents
2035  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2036  $urlsource .= str_replace('&amp;', '&', $param);
2037 
2038  $filedir = $diroutputmassaction;
2039  $genallowed = $permissiontoread;
2040  $delallowed = $permissiontoadd;
2041 
2042  print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2043 } else {
2044  dol_print_error($db);
2045 }
2046 
2047 // End of page
2048 llxFooter();
2049 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage predefined suppliers products.
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage suppliers invoices.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage HTML output components for orders Before adding component here, check they are not in...
Classe permettant la generation de composants html autre Only common components are here.
Class to manage suppliers.
Class to manage projects.
Class to manage Dolibarr users.
Definition: user.class.php:45
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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...
dol_eval($s, $returnvalue=0, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
restrictedArea(User $user, $features, $object=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.