dolibarr  17.0.4
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();
366  $TFactThird = array();
367 
368  $nb_bills_created = 0;
369  $lastid = 0;
370  $lastref = '';
371 
372  $db->begin();
373 
374  $default_ref_supplier=dol_print_date(dol_now(), '%Y%m%d%H%M%S');
375 
376  foreach ($orders as $id_order) {
377  $cmd = new CommandeFournisseur($db);
378  if ($cmd->fetch($id_order) <= 0) {
379  continue;
380  }
381 
382  $objecttmp = new FactureFournisseur($db);
383  if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
384  $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created supplier invoice.
385  } else {
386  $objecttmp->socid = $cmd->socid;
387  $objecttmp->type = $objecttmp::TYPE_STANDARD;
388  $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
389  $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
390  $objecttmp->fk_project = $cmd->fk_project;
391  $objecttmp->multicurrency_code = $cmd->multicurrency_code;
392  $objecttmp->ref_supplier = !empty($cmd->ref_supplier) ? $cmd->ref_supplier : $default_ref_supplier;
393  $default_ref_supplier+=1;
394 
395  $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
396  if (empty($datefacture)) {
397  $datefacture = dol_now();
398  }
399 
400  $objecttmp->date = $datefacture;
401  $objecttmp->origin = 'order_supplier';
402  $objecttmp->origin_id = $id_order;
403 
404  $res = $objecttmp->create($user);
405 
406  if ($res > 0) {
407  $nb_bills_created++;
408  $lastref = $objecttmp->ref;
409  $lastid = $objecttmp->id;
410  }
411  }
412 
413  if ($objecttmp->id > 0) {
414  $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
415  $sql .= "fk_source";
416  $sql .= ", sourcetype";
417  $sql .= ", fk_target";
418  $sql .= ", targettype";
419  $sql .= ") VALUES (";
420  $sql .= $id_order;
421  $sql .= ", '".$db->escape($objecttmp->origin)."'";
422  $sql .= ", ".((int) $objecttmp->id);
423  $sql .= ", '".$db->escape($objecttmp->element)."'";
424  $sql .= ")";
425 
426  if (!$db->query($sql)) {
427  $erorr++;
428  }
429 
430  if (!$error) {
431  $lines = $cmd->lines;
432  if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
433  $cmd->fetch_lines();
434  $lines = $cmd->lines;
435  }
436 
437  $fk_parent_line = 0;
438  $num = count($lines);
439 
440  for ($i = 0; $i < $num; $i++) {
441  $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
442  if ($lines[$i]->subprice < 0) {
443  // Negative line, we create a discount line
444  $discount = new DiscountAbsolute($db);
445  $discount->fk_soc = $objecttmp->socid;
446  $discount->amount_ht = abs($lines[$i]->total_ht);
447  $discount->amount_tva = abs($lines[$i]->total_tva);
448  $discount->amount_ttc = abs($lines[$i]->total_ttc);
449  $discount->tva_tx = $lines[$i]->tva_tx;
450  $discount->fk_user = $user->id;
451  $discount->description = $desc;
452  $discountid = $discount->create($user);
453  if ($discountid > 0) {
454  $result = $objecttmp->insert_discount($discountid);
455  //$result=$discount->link_to_invoice($lineid,$id);
456  } else {
457  setEventMessages($discount->error, $discount->errors, 'errors');
458  $error++;
459  break;
460  }
461  } else {
462  // Positive line
463  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
464  // Date start
465  $date_start = false;
466  if ($lines[$i]->date_debut_prevue) {
467  $date_start = $lines[$i]->date_debut_prevue;
468  }
469  if ($lines[$i]->date_debut_reel) {
470  $date_start = $lines[$i]->date_debut_reel;
471  }
472  if ($lines[$i]->date_start) {
473  $date_start = $lines[$i]->date_start;
474  }
475  //Date end
476  $date_end = false;
477  if ($lines[$i]->date_fin_prevue) {
478  $date_end = $lines[$i]->date_fin_prevue;
479  }
480  if ($lines[$i]->date_fin_reel) {
481  $date_end = $lines[$i]->date_fin_reel;
482  }
483  if ($lines[$i]->date_end) {
484  $date_end = $lines[$i]->date_end;
485  }
486  // Reset fk_parent_line for no child products and special product
487  if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
488  $fk_parent_line = 0;
489  }
490  $result = $objecttmp->addline(
491  $desc,
492  $lines[$i]->subprice,
493  $lines[$i]->tva_tx,
494  $lines[$i]->localtax1_tx,
495  $lines[$i]->localtax2_tx,
496  $lines[$i]->qty,
497  $lines[$i]->fk_product,
498  $lines[$i]->remise_percent,
499  $date_start,
500  $date_end,
501  0,
502  $lines[$i]->info_bits,
503  'HT',
504  $product_type,
505  // we dont use the rank from orderline because we may have lines from several orders
506  -1,
507  false,
508  $lines[$i]->array_options,
509  $lines[$i]->fk_unit,
510  // we use the id of each order, not the id of the first one stored in $objecttmp->origin_id
511  $lines[$i]->fk_commande,
512  $lines[$i]->pa_ht,
513  $lines[$i]->ref_supplier,
514  $lines[$i]->special_code,
515  $fk_parent_line
516  );
517  if ($result > 0) {
518  $lineid = $result;
519  } else {
520  $lineid = 0;
521  $error++;
522  break;
523  }
524  // Defined the new fk_parent_line
525  if ($result > 0 && $lines[$i]->product_type == 9) {
526  $fk_parent_line = $result;
527  }
528  }
529  }
530  }
531  }
532 
533  $cmd->classifyBilled($user); // TODO Move this in workflow like done for sales orders
534 
535  if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
536  $TFactThird[$cmd->socid] = $objecttmp;
537  } else {
538  $TFact[$objecttmp->id] = $objecttmp;
539  }
540  }
541 
542  // Build doc with all invoices
543  $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
544  $toselect = array();
545 
546  if (!$error && $validate_invoices) {
547  $massaction = $action = 'builddoc';
548 
549  foreach ($TAllFact as &$objecttmp) {
550  $objecttmp->validate($user);
551  if ($result <= 0) {
552  $error++;
553  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
554  break;
555  }
556 
557  $id = $objecttmp->id; // For builddoc action
558 
559  // Fac builddoc
560  $donotredirect = 1;
561  $upload_dir = $conf->fournisseur->facture->dir_output;
562  $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
563  //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
564  }
565 
566  $massaction = $action = 'confirm_createsupplierbills';
567  }
568 
569  if (!$error) {
570  $db->commit();
571 
572  if ($nb_bills_created == 1) {
573  $texttoshow = $langs->trans('BillXCreated', '{s1}');
574  $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
575  setEventMessages($texttoshow, null, 'mesgs');
576  } else {
577  setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
578  }
579 
580  // Make a redirect to avoid to bill twice if we make a refresh or back
581  $param = '';
582  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
583  $param .= '&contextpage='.urlencode($contextpage);
584  }
585  if ($limit > 0 && $limit != $conf->liste_limit) {
586  $param .= '&limit='.urlencode($limit);
587  }
588  if ($sall) {
589  $param .= '&sall='.urlencode($sall);
590  }
591  if ($socid > 0) {
592  $param .= '&socid='.urlencode($socid);
593  }
594  if ($search_status != '') {
595  $param .= '&search_status='.urlencode($search_status);
596  }
597  if ($search_date_order_startday) {
598  $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
599  }
600  if ($search_date_order_startmonth) {
601  $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
602  }
603  if ($search_date_order_startyear) {
604  $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
605  }
606  if ($search_date_order_endday) {
607  $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
608  }
609  if ($search_date_order_endmonth) {
610  $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
611  }
612  if ($search_date_order_endyear) {
613  $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
614  }
615  if ($search_date_delivery_startday) {
616  $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
617  }
618  if ($search_date_delivery_startmonth) {
619  $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
620  }
621  if ($search_date_delivery_startyear) {
622  $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
623  }
624  if ($search_date_delivery_endday) {
625  $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
626  }
627  if ($search_date_delivery_endmonth) {
628  $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
629  }
630  if ($search_date_delivery_endyear) {
631  $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
632  }
633  if ($search_date_valid_startday) {
634  $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
635  }
636  if ($search_date_valid_startmonth) {
637  $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
638  }
639  if ($search_date_valid_startyear) {
640  $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
641  }
642  if ($search_date_valid_endday) {
643  $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
644  }
645  if ($search_date_valid_endmonth) {
646  $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
647  }
648  if ($search_date_valid_endyear) {
649  $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
650  }
651  if ($search_date_approve_startday) {
652  $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
653  }
654  if ($search_date_approve_startmonth) {
655  $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
656  }
657  if ($search_date_approve_startyear) {
658  $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
659  }
660  if ($search_date_approve_endday) {
661  $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
662  }
663  if ($search_date_approve_endmonth) {
664  $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
665  }
666  if ($search_date_approve_endyear) {
667  $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
668  }
669  if ($search_ref) {
670  $param .= '&search_ref='.urlencode($search_ref);
671  }
672  if ($search_company) {
673  $param .= '&search_company='.urlencode($search_company);
674  }
675  if ($search_company_alias) {
676  $param .= '&search_company_alias='.urlencode($search_company_alias);
677  }
678  //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
679  if ($search_user > 0) {
680  $param .= '&search_user='.urlencode($search_user);
681  }
682  if ($search_sale > 0) {
683  $param .= '&search_sale='.urlencode($search_sale);
684  }
685  if ($search_total_ht != '') {
686  $param .= '&search_total_ht='.urlencode($search_total_ht);
687  }
688  if ($search_total_tva != '') {
689  $param .= '&search_total_tva='.urlencode($search_total_tva);
690  }
691  if ($search_total_ttc != '') {
692  $param .= '&search_total_ttc='.urlencode($search_total_ttc);
693  }
694  if ($search_project_ref >= 0) {
695  $param .= "&search_project_ref=".urlencode($search_project_ref);
696  }
697  if ($show_files) {
698  $param .= '&show_files='.urlencode($show_files);
699  }
700  if ($optioncss != '') {
701  $param .= '&optioncss='.urlencode($optioncss);
702  }
703  if ($billed != '') {
704  $param .= '&billed='.urlencode($billed);
705  }
706 
707  header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
708  exit;
709  } else {
710  $db->rollback();
711  $action = 'create';
712  $_GET["origin"] = $_POST["origin"];
713  $_GET["originid"] = $_POST["originid"];
714  setEventMessages("Error", null, 'errors');
715  $error++;
716  }
717  }
718 }
719 
720 
721 /*
722  * View
723  */
724 
725 $now = dol_now();
726 
727 $form = new Form($db);
728 $thirdpartytmp = new Fournisseur($db);
729 $commandestatic = new CommandeFournisseur($db);
730 $formfile = new FormFile($db);
731 $formorder = new FormOrder($db);
732 $formother = new FormOther($db);
733 $formcompany = new FormCompany($db);
734 
735 $title = $langs->trans("SuppliersOrders");
736 if ($socid > 0) {
737  $fourn = new Fournisseur($db);
738  $fourn->fetch($socid);
739  $title .= ' - '.$fourn->name;
740 }
741 
742 /*if ($search_status)
743 {
744  if ($search_status == '1,2') $title .= ' - '.$langs->trans("SuppliersOrdersToProcess");
745  elseif ($search_status == '3,4') $title .= ' - '.$langs->trans("SuppliersOrdersAwaitingReception");
746  elseif ($search_status == '1,2,3') $title .= ' - '.$langs->trans("StatusOrderToProcessShort");
747  elseif ($search_status == '6,7') $title .= ' - '.$langs->trans("StatusOrderCanceled");
748  elseif (is_numeric($search_status) && $search_status >= 0) $title .= ' - '.$commandestatic->LibStatut($search_status);
749 }*/
750 if ($search_billed > 0) {
751  $title .= ' - '.$langs->trans("Billed");
752 }
753 
754 //$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
755 $help_url = '';
756 
757 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
758 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
759 
760 $sql = 'SELECT';
761 if ($sall) {
762  $sql = 'SELECT DISTINCT';
763 }
764 $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,';
765 $sql .= " typent.code as typent_code,";
766 $sql .= " state.code_departement as state_code, state.nom as state_name,";
767 $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,";
768 $sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
769 $sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
770 $sql .= ' cf.note_public, cf.note_private,';
771 $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,";
772 $sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status";
773 // Add fields from extrafields
774 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
775  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
776  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
777  }
778 }
779 // Add fields from hooks
780 $parameters = array();
781 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
782 $sql .= $hookmanager->resPrint;
783 
784 $sqlfields = $sql; // $sql fields to remove for count total
785 
786 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
787 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
788 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
789 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
790 $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
791 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
792  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)";
793 }
794 if ($sall) {
795  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
796 }
797 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid";
798 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet";
799 // We'll need this table joined to the select in order to filter by sale
800 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
801  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
802 }
803 $parameters = array();
804 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
805 $sql .= $hookmanager->resPrint;
806 $sql .= ' WHERE cf.fk_soc = s.rowid';
807 $sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')';
808 if ($socid > 0) {
809  $sql .= " AND s.rowid = ".((int) $socid);
810 }
811 if (empty($user->rights->societe->client->voir) && !$socid) {
812  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
813 }
814 if ($search_ref) {
815  $sql .= natural_search('cf.ref', $search_ref);
816 }
817 if ($search_refsupp) {
818  $sql .= natural_search("cf.ref_supplier", $search_refsupp);
819 }
820 if ($sall) {
821  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
822 }
823 if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
824  $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
825 } else {
826  if ($search_company) {
827  $sql .= natural_search('s.nom', $search_company);
828  }
829  if ($search_company_alias) {
830  $sql .= natural_search('s.name_alias', $search_company_alias);
831  }
832 }
833 if ($search_request_author) {
834  $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
835 }
836 if ($search_billed != '' && $search_billed >= 0) {
837  $sql .= " AND cf.billed = ".((int) $search_billed);
838 }
839 //Required triple check because statut=0 means draft filter
840 if (GETPOST('statut', 'intcomma') !== '') {
841  $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")";
842 }
843 if ($search_status != '' && $search_status != '-1') {
844  $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
845 }
846 if ($search_date_order_start) {
847  $sql .= " AND cf.date_commande >= '".$db->idate($search_date_order_start)."'";
848 }
849 if ($search_date_order_end) {
850  $sql .= " AND cf.date_commande <= '".$db->idate($search_date_order_end)."'";
851 }
852 if ($search_date_delivery_start) {
853  $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
854 }
855 if ($search_date_delivery_end) {
856  $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
857 }
858 if ($search_date_valid_start) {
859  $sql .= " AND cf.date_commande >= '".$db->idate($search_date_valid_start)."'";
860 }
861 if ($search_date_valid_end) {
862  $sql .= " AND cf.date_commande <= '".$db->idate($search_date_valid_end)."'";
863 }
864 if ($search_date_approve_start) {
865  $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
866 }
867 if ($search_date_approve_end) {
868  $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
869 }
870 if ($search_town) {
871  $sql .= natural_search('s.town', $search_town);
872 }
873 if ($search_zip) {
874  $sql .= natural_search("s.zip", $search_zip);
875 }
876 if ($search_state) {
877  $sql .= natural_search("state.nom", $search_state);
878 }
879 if ($search_country) {
880  $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
881 }
882 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
883  $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
884 }
885 if ($search_sale > 0) {
886  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
887 }
888 if ($search_user > 0) {
889  $sql .= " AND EXISTS (";
890  $sql .= " SELECT ec.rowid ";
891  $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec";
892  $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON tc.rowid = ec.fk_c_type_contact";
893  $sql .= " WHERE ec.element_id = cf.rowid AND ec.fk_socpeople = " . ((int) $search_user);
894  $sql .= " AND tc.element = 'order_supplier' AND tc.source = 'internal'";
895  $sql .= ")";
896 }
897 if ($search_total_ht != '') {
898  $sql .= natural_search('cf.total_ht', $search_total_ht, 1);
899 }
900 if ($search_total_tva != '') {
901  $sql .= natural_search('cf.total_tva', $search_total_tva, 1);
902 }
903 if ($search_total_ttc != '') {
904  $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1);
905 }
906 if ($search_multicurrency_code != '') {
907  $sql .= " AND cf.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
908 }
909 if ($search_multicurrency_tx != '') {
910  $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1);
911 }
912 if ($search_multicurrency_montant_ht != '') {
913  $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
914 }
915 if ($search_multicurrency_montant_tva != '') {
916  $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1);
917 }
918 if ($search_multicurrency_montant_ttc != '') {
919  $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
920 }
921 if ($search_project_ref != '') {
922  $sql .= natural_search("p.ref", $search_project_ref);
923 }
924 // Search for tag/category ($searchCategoryProductList is an array of ID)
925 $searchCategoryProductOperator = -1;
926 $searchCategoryProductList = array($search_product_category);
927 if (!empty($searchCategoryProductList)) {
928  $searchCategoryProductSqlList = array();
929  $listofcategoryid = '';
930  foreach ($searchCategoryProductList as $searchCategoryProduct) {
931  if (intval($searchCategoryProduct) == -2) {
932  $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)";
933  } elseif (intval($searchCategoryProduct) > 0) {
934  if ($searchCategoryProductOperator == 0) {
935  $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).")";
936  } else {
937  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
938  }
939  }
940  }
941  if ($listofcategoryid) {
942  $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)."))";
943  }
944  if ($searchCategoryProductOperator == 1) {
945  if (!empty($searchCategoryProductSqlList)) {
946  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
947  }
948  } else {
949  if (!empty($searchCategoryProductSqlList)) {
950  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
951  }
952  }
953 }
954 // Add where from extra fields
955 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
956 // Add where from hooks
957 $parameters = array();
958 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
959 $sql .= $hookmanager->resPrint;
960 
961 // Count total nb of records
962 $nbtotalofrecords = '';
963 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
964  /* The fast and low memory method to get and count full list converts the sql into a sql count */
965  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
966  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
967  $resql = $db->query($sqlforcount);
968  if ($resql) {
969  $objforcount = $db->fetch_object($resql);
970  $nbtotalofrecords = $objforcount->nbtotalofrecords;
971  } else {
972  dol_print_error($db);
973  }
974 
975  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
976  $page = 0;
977  $offset = 0;
978  }
979  $db->free($resql);
980 }
981 
982 $sql .= $db->order($sortfield, $sortorder);
983 if ($limit) {
984  $sql .= $db->plimit($limit + 1, $offset);
985 }
986 //print $sql;
987 
988 $resql = $db->query($sql);
989 if ($resql) {
990  $num = $db->num_rows($resql);
991 
992  $arrayofselected = is_array($toselect) ? $toselect : array();
993 
994  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
995  $obj = $db->fetch_object($resql);
996  $id = $obj->rowid;
997  header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id);
998  exit;
999  }
1000 
1001  llxHeader('', $title, $help_url);
1002 
1003  $param = '';
1004  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1005  $param .= '&contextpage='.urlencode($contextpage);
1006  }
1007  if ($limit > 0 && $limit != $conf->liste_limit) {
1008  $param .= '&limit='.urlencode($limit);
1009  }
1010  if ($sall) {
1011  $param .= '&sall='.urlencode($sall);
1012  }
1013  if ($socid > 0) {
1014  $param .= '&socid='.urlencode($socid);
1015  }
1016  if ($sall) {
1017  $param .= "&search_all=".urlencode($sall);
1018  }
1019  if ($search_date_order_startday) {
1020  $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
1021  }
1022  if ($search_date_order_startmonth) {
1023  $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
1024  }
1025  if ($search_date_order_startyear) {
1026  $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
1027  }
1028  if ($search_date_order_endday) {
1029  $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
1030  }
1031  if ($search_date_order_endmonth) {
1032  $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
1033  }
1034  if ($search_date_order_endyear) {
1035  $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
1036  }
1037  if ($search_date_delivery_startday) {
1038  $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
1039  }
1040  if ($search_date_delivery_startmonth) {
1041  $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
1042  }
1043  if ($search_date_delivery_startyear) {
1044  $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
1045  }
1046  if ($search_date_delivery_endday) {
1047  $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
1048  }
1049  if ($search_date_delivery_endmonth) {
1050  $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
1051  }
1052  if ($search_date_delivery_endyear) {
1053  $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
1054  }
1055  if ($search_date_valid_startday) {
1056  $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
1057  }
1058  if ($search_date_valid_startmonth) {
1059  $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
1060  }
1061  if ($search_date_valid_startyear) {
1062  $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
1063  }
1064  if ($search_date_valid_endday) {
1065  $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
1066  }
1067  if ($search_date_valid_endmonth) {
1068  $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
1069  }
1070  if ($search_date_valid_endyear) {
1071  $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
1072  }
1073  if ($search_date_approve_startday) {
1074  $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
1075  }
1076  if ($search_date_approve_startmonth) {
1077  $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
1078  }
1079  if ($search_date_approve_startyear) {
1080  $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
1081  }
1082  if ($search_date_approve_endday) {
1083  $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
1084  }
1085  if ($search_date_approve_endmonth) {
1086  $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
1087  }
1088  if ($search_date_approve_endyear) {
1089  $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
1090  }
1091  if ($search_ref) {
1092  $param .= '&search_ref='.urlencode($search_ref);
1093  }
1094  if ($search_company) {
1095  $param .= '&search_company='.urlencode($search_company);
1096  }
1097  if ($search_company_alias) {
1098  $param .= '&search_company_alias='.urlencode($search_company_alias);
1099  }
1100  if ($search_user > 0) {
1101  $param .= '&search_user='.urlencode($search_user);
1102  }
1103  if ($search_request_author) {
1104  $param .= '&search_request_author='.urlencode($search_request_author);
1105  }
1106  if ($search_sale > 0) {
1107  $param .= '&search_sale='.urlencode($search_sale);
1108  }
1109  if ($search_total_ht != '') {
1110  $param .= '&search_total_ht='.urlencode($search_total_ht);
1111  }
1112  if ($search_total_ttc != '') {
1113  $param .= "&search_total_ttc=".urlencode($search_total_ttc);
1114  }
1115  if ($search_multicurrency_code != '') {
1116  $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1117  }
1118  if ($search_multicurrency_tx != '') {
1119  $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1120  }
1121  if ($search_multicurrency_montant_ht != '') {
1122  $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1123  }
1124  if ($search_multicurrency_montant_tva != '') {
1125  $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva);
1126  }
1127  if ($search_multicurrency_montant_ttc != '') {
1128  $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1129  }
1130  if ($search_refsupp) {
1131  $param .= "&search_refsupp=".urlencode($search_refsupp);
1132  }
1133  if ($search_status != '' && $search_status != '-1') {
1134  $param .= "&search_status=".urlencode($search_status);
1135  }
1136  if ($search_project_ref >= 0) {
1137  $param .= "&search_project_ref=".urlencode($search_project_ref);
1138  }
1139  if ($search_billed != '') {
1140  $param .= "&search_billed=".urlencode($search_billed);
1141  }
1142  if ($show_files) {
1143  $param .= '&show_files='.urlencode($show_files);
1144  }
1145  if ($optioncss != '') {
1146  $param .= '&optioncss='.urlencode($optioncss);
1147  }
1148  if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
1149  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
1150  }
1151 
1152  // Add $param from extra fields
1153  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1154 
1155  $parameters = array();
1156  $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
1157  $param .= $hookmanager->resPrint;
1158 
1159  // List of mass actions available
1160  $arrayofmassactions = array(
1161  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1162  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1163  'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1164  );
1165 
1166  if ($permissiontovalidate) {
1167  if ($permissiontoapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
1168  $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
1169  } else {
1170  $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
1171  }
1172  }
1173 
1174  if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
1175  $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier");
1176  }
1177  if ($permissiontodelete) {
1178  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1179  }
1180  if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
1181  $arrayofmassactions = array();
1182  }
1183  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1184 
1185  $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
1186  if ($socid > 0) {
1187  $url .= '&socid='.((int) $socid);
1188  $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
1189  }
1190  $newcardbutton = dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
1191 
1192  // Lines of title fields
1193  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
1194  if ($optioncss != '') {
1195  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1196  }
1197  print '<input type="hidden" name="token" value="'.newToken().'">';
1198  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1199  print '<input type="hidden" name="action" value="list">';
1200  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1201  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1202  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1203  print '<input type="hidden" name="socid" value="'.$socid.'">';
1204 
1205  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1);
1206 
1207  $topicmail = "SendOrderRef";
1208  $modelmail = "order_supplier_send";
1209  $objecttmp = new CommandeFournisseur($db);
1210  $trackid = 'sord'.$object->id;
1211  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1212 
1213  if ($massaction == 'prevalidate') {
1214  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1215  }
1216 
1217  if ($massaction == 'createbills') {
1218  //var_dump($_REQUEST);
1219  print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">';
1220 
1221  print '<table class="noborder centpercent">';
1222  print '<tr>';
1223  print '<td class="titlefield">';
1224  print $langs->trans('DateInvoice');
1225  print '</td>';
1226  print '<td>';
1227  print $form->selectDate('', '', '', '', '', '', 1, 1);
1228  print '</td>';
1229  print '</tr>';
1230  print '<tr>';
1231  print '<td>';
1232  print $langs->trans('CreateOneBillByThird');
1233  print '</td>';
1234  print '<td>';
1235  print $form->selectyesno('createbills_onebythird', '', 1);
1236  print '</td>';
1237  print '</tr>';
1238  print '<tr>';
1239  print '<td>';
1240  print $langs->trans('ValidateInvoices');
1241  print '</td>';
1242  print '<td>';
1243  print $form->selectyesno('validate_invoices', 1, 1);
1244  print '</td>';
1245  print '</tr>';
1246  print '</table>';
1247 
1248  print '<div class="center">';
1249  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
1250  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1251  print '</div>';
1252  print '<br>';
1253  print '<br>';
1254  }
1255 
1256  if ($sall) {
1257  foreach ($fieldstosearchall as $key => $val) {
1258  $fieldstosearchall[$key] = $langs->trans($val);
1259  }
1260  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
1261  }
1262 
1263  $moreforfilter = '';
1264 
1265  // If the user can view prospects other than his'
1266  if ($user->rights->user->user->lire) {
1267  $langs->load("commercial");
1268  $moreforfilter .= '<div class="divsearchfield">';
1269  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1270  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1271  $moreforfilter .= '</div>';
1272  }
1273  // If the user can view other users
1274  if ($user->rights->user->user->lire) {
1275  $moreforfilter .= '<div class="divsearchfield">';
1276  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1277  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1278  $moreforfilter .= '</div>';
1279  }
1280  // If the user can view prospects other than his'
1281  if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
1282  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1283  $moreforfilter .= '<div class="divsearchfield">';
1284  $tmptitle = $langs->trans('IncludingProductWithTag');
1285  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1286  $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);
1287  $moreforfilter .= '</div>';
1288  }
1289  $parameters = array();
1290  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1291  if (empty($reshook)) {
1292  $moreforfilter .= $hookmanager->resPrint;
1293  } else {
1294  $moreforfilter = $hookmanager->resPrint;
1295  }
1296 
1297  if (!empty($moreforfilter)) {
1298  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1299  print $moreforfilter;
1300  print '</div>';
1301  }
1302 
1303  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1304  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
1305  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1306 
1307  if (GETPOST('autoselectall', 'int')) {
1308  $selectedfields .= '<script>';
1309  $selectedfields .= ' $(document).ready(function() {';
1310  $selectedfields .= ' console.log("Autoclick on checkforselects");';
1311  $selectedfields .= ' $("#checkforselects").click();';
1312  $selectedfields .= ' $("#massaction").val("createbills").change();';
1313  $selectedfields .= ' });';
1314  $selectedfields .= '</script>';
1315  }
1316 
1317  print '<div class="div-table-responsive">';
1318  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1319 
1320  print '<tr class="liste_titre_filter">';
1321  // Action column
1322  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1323  print '<td class="liste_titre middle">';
1324  $searchpicto = $form->showFilterButtons('left');
1325  print $searchpicto;
1326  print '</td>';
1327  }
1328  // Ref
1329  if (!empty($arrayfields['cf.ref']['checked'])) {
1330  print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>';
1331  }
1332  // Ref customer
1333  if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1334  print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>';
1335  }
1336  // Project ref
1337  if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1338  print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>';
1339  }
1340  // Request author
1341  if (!empty($arrayfields['u.login']['checked'])) {
1342  print '<td class="liste_titre">';
1343  print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
1344  print '</td>';
1345  }
1346  // Thirpdarty
1347  if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1348  print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
1349  }
1350  // Alias
1351  if (!empty($arrayfields['s.name_alias']['checked'])) {
1352  print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company_alias" value="'.$search_company_alias.'"></td>';
1353  }
1354  // Town
1355  if (!empty($arrayfields['s.town']['checked'])) {
1356  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
1357  }
1358  // Zip
1359  if (!empty($arrayfields['s.zip']['checked'])) {
1360  print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
1361  }
1362  // State
1363  if (!empty($arrayfields['state.nom']['checked'])) {
1364  print '<td class="liste_titre">';
1365  print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1366  print '</td>';
1367  }
1368  // Country
1369  if (!empty($arrayfields['country.code_iso']['checked'])) {
1370  print '<td class="liste_titre center">';
1371  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1372  print '</td>';
1373  }
1374  // Company type
1375  if (!empty($arrayfields['typent.code']['checked'])) {
1376  print '<td class="liste_titre maxwidthonsmartphone center">';
1377  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);
1378  print '</td>';
1379  }
1380  // Date order
1381  if (!empty($arrayfields['cf.date_commande']['checked'])) {
1382  print '<td class="liste_titre center">';
1383  print '<div class="nowrap">';
1384  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'));
1385  print '</div>';
1386  print '<div class="nowrap">';
1387  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'));
1388  print '</div>';
1389  print '</td>';
1390  }
1391  // Date delivery
1392  if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1393  print '<td class="liste_titre center">';
1394  print '<div class="nowrap">';
1395  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'));
1396  print '</div>';
1397  print '<div class="nowrap">';
1398  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'));
1399  print '</div>';
1400  print '</td>';
1401  }
1402  if (!empty($arrayfields['cf.total_ht']['checked'])) {
1403  // Amount
1404  print '<td class="liste_titre right">';
1405  print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
1406  print '</td>';
1407  }
1408  if (!empty($arrayfields['cf.total_tva']['checked'])) {
1409  // Amount
1410  print '<td class="liste_titre right">';
1411  print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">';
1412  print '</td>';
1413  }
1414  if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1415  // Amount
1416  print '<td class="liste_titre right">';
1417  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1418  print '</td>';
1419  }
1420  if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1421  // Currency
1422  print '<td class="liste_titre">';
1423  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1424  print '</td>';
1425  }
1426  if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1427  // Currency rate
1428  print '<td class="liste_titre">';
1429  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1430  print '</td>';
1431  }
1432  if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1433  // Amount
1434  print '<td class="liste_titre right">';
1435  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1436  print '</td>';
1437  }
1438  if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1439  // Amount
1440  print '<td class="liste_titre right">';
1441  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">';
1442  print '</td>';
1443  }
1444  if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1445  // Amount
1446  print '<td class="liste_titre right">';
1447  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1448  print '</td>';
1449  }
1450  // Extra fields
1451  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1452 
1453  // Fields from hook
1454  $parameters = array('arrayfields'=>$arrayfields);
1455  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1456  print $hookmanager->resPrint;
1457  // Date creation
1458  if (!empty($arrayfields['cf.date_creation']['checked'])) {
1459  print '<td class="liste_titre">';
1460  print '</td>';
1461  }
1462  // Date modification
1463  if (!empty($arrayfields['cf.tms']['checked'])) {
1464  print '<td class="liste_titre">';
1465  print '</td>';
1466  }
1467  // Status
1468  if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1469  print '<td class="liste_titre right">';
1470  $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status');
1471  print '</td>';
1472  }
1473  // Status billed
1474  if (!empty($arrayfields['cf.billed']['checked'])) {
1475  print '<td class="liste_titre center">';
1476  print $form->selectyesno('search_billed', $search_billed, 1, false, 1, 1, 'maxwidth100 onrightofpage');
1477  print '</td>';
1478  }
1479  // Date valid
1480  if (!empty($arrayfields['cf.date_valid']['checked'])) {
1481  print '<td class="liste_titre center">';
1482  print '<div class="nowrap">';
1483  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'));
1484  print '</div>';
1485  print '<div class="nowrap">';
1486  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'));
1487  print '</div>';
1488  print '</td>';
1489  }
1490  // Date approve
1491  if (!empty($arrayfields['cf.date_approve']['checked'])) {
1492  print '<td class="liste_titre center">';
1493  print '<div class="nowrap">';
1494  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'));
1495  print '</div>';
1496  print '<div class="nowrap">';
1497  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'));
1498  print '</div>';
1499  print '</td>';
1500  }
1501  // Note public
1502  if (!empty($arrayfields['cf.note_public']['checked'])) {
1503  print '<td class="liste_titre">';
1504  print '</td>';
1505  }
1506  // Note private
1507  if (!empty($arrayfields['cf.note_private']['checked'])) {
1508  print '<td class="liste_titre">';
1509  print '</td>';
1510  }
1511  // Action column
1512  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1513  print '<td class="liste_titre middle">';
1514  $searchpicto = $form->showFilterButtons();
1515  print $searchpicto;
1516  print '</td>';
1517  }
1518 
1519  print "</tr>\n";
1520 
1521  // Fields title
1522  print '<tr class="liste_titre">';
1523  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1524  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1525  }
1526  if (!empty($arrayfields['cf.ref']['checked'])) {
1527  print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder);
1528  }
1529  if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1530  print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp ');
1531  }
1532  if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1533  print_liste_field_titre($arrayfields['cf.fk_projet']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1534  }
1535  if (!empty($arrayfields['u.login']['checked'])) {
1536  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder);
1537  }
1538  if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1539  print_liste_field_titre($arrayfields['cf.fk_soc']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
1540  }
1541  if (!empty($arrayfields['s.name_alias']['checked'])) {
1542  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, '', $sortfield, $sortorder);
1543  }
1544  if (!empty($arrayfields['s.town']['checked'])) {
1545  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1546  }
1547  if (!empty($arrayfields['s.zip']['checked'])) {
1548  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1549  }
1550  if (!empty($arrayfields['state.nom']['checked'])) {
1551  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1552  }
1553  if (!empty($arrayfields['country.code_iso']['checked'])) {
1554  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1555  }
1556  if (!empty($arrayfields['typent.code']['checked'])) {
1557  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1558  }
1559  if (!empty($arrayfields['cf.fk_author']['checked'])) {
1560  print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder);
1561  }
1562  if (!empty($arrayfields['cf.date_commande']['checked'])) {
1563  print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center ');
1564  }
1565  if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1566  print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1567  }
1568  if (!empty($arrayfields['cf.total_ht']['checked'])) {
1569  print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
1570  }
1571  if (!empty($arrayfields['cf.total_tva']['checked'])) {
1572  print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
1573  }
1574  if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1575  print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
1576  }
1577  if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1578  print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1579  }
1580  if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1581  print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1582  }
1583  if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1584  print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1585  }
1586  if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1587  print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1588  }
1589  if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1590  print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1591  }
1592  // Extra fields
1593  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1594  // Hook fields
1595  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1596  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1597  print $hookmanager->resPrint;
1598  if (!empty($arrayfields['cf.date_creation']['checked'])) {
1599  print_liste_field_titre($arrayfields['cf.date_creation']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1600  }
1601  if (!empty($arrayfields['cf.tms']['checked'])) {
1602  print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1603  }
1604  if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1605  print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1606  }
1607  if (!empty($arrayfields['cf.billed']['checked'])) {
1608  print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
1609  }
1610  if (!empty($arrayfields['cf.date_valid']['checked'])) {
1611  print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
1612  }
1613  if (!empty($arrayfields['cf.date_approve']['checked'])) {
1614  print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
1615  }
1616  if (!empty($arrayfields['cf.note_public']['checked'])) {
1617  print_liste_field_titre($arrayfields['cf.note_public']['label'], $_SERVER["PHP_SELF"], "cf.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
1618  }
1619  if (!empty($arrayfields['cf.note_private']['checked'])) {
1620  print_liste_field_titre($arrayfields['cf.note_private']['label'], $_SERVER["PHP_SELF"], "cf.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
1621  }
1622  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1623  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1624  }
1625  print "</tr>\n";
1626 
1627 
1628  $total = 0;
1629  $subtotal = 0;
1630  $productstat_cache = array();
1631 
1632  $userstatic = new User($db);
1633  $objectstatic = new CommandeFournisseur($db);
1634  $projectstatic = new Project($db);
1635 
1636  $i = 0;
1637  $totalarray = array('nbfield' => 0, 'val' => array(), 'pos' => array());
1638  $totalarray['val']['cf.total_ht'] = 0;
1639  $totalarray['val']['cf.total_ttc'] = 0;
1640  $totalarray['val']['cf.total_tva'] = 0;
1641 
1642  $imaxinloop = ($limit ? min($num, $limit) : $num);
1643  while ($i < $imaxinloop) {
1644  $obj = $db->fetch_object($resql);
1645 
1646  $notshippable = 0;
1647  $warning = 0;
1648  $text_info = '';
1649  $text_warning = '';
1650  $nbprod = 0;
1651 
1652  $objectstatic->id = $obj->rowid;
1653  $objectstatic->ref = $obj->ref;
1654  $objectstatic->socid = $obj->socid;
1655  $objectstatic->ref_supplier = $obj->ref_supplier;
1656  $objectstatic->socid = $obj->socid;
1657  $objectstatic->total_ht = $obj->total_ht;
1658  $objectstatic->total_tva = $obj->total_tva;
1659  $objectstatic->total_ttc = $obj->total_ttc;
1660  $objectstatic->date_commande = $db->jdate($obj->date_commande);
1661  $objectstatic->delivery_date = $db->jdate($obj->date_livraison);
1662  $objectstatic->note_public = $obj->note_public;
1663  $objectstatic->note_private = $obj->note_private;
1664  $objectstatic->statut = $obj->fk_statut;
1665 
1666  print '<tr class="oddeven">';
1667  // Action column
1668  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1669  print '<td class="nowrap center">';
1670  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1671  $selected = 0;
1672  if (in_array($obj->rowid, $arrayofselected)) {
1673  $selected = 1;
1674  }
1675  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1676  }
1677  print '</td>';
1678  }
1679  // Ref
1680  if (!empty($arrayfields['cf.ref']['checked'])) {
1681  print '<td class="nowrap">';
1682 
1683  // Picto + Ref
1684  print $objectstatic->getNomUrl(1, '', 0, -1, 1);
1685  // Other picto tool
1686  $filename = dol_sanitizeFileName($obj->ref);
1687  $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1688  print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1689 
1690  print '</td>'."\n";
1691  if (!$i) {
1692  $totalarray['nbfield']++;
1693  }
1694  }
1695  // Ref Supplier
1696  if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1697  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>'."\n";
1698  if (!$i) {
1699  $totalarray['nbfield']++;
1700  }
1701  }
1702  // Project
1703  if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1704  $projectstatic->id = $obj->project_id;
1705  $projectstatic->ref = $obj->project_ref;
1706  $projectstatic->title = $obj->project_title;
1707  print '<td>';
1708  if ($obj->project_id > 0) {
1709  print $projectstatic->getNomUrl(1);
1710  }
1711  print '</td>';
1712  if (!$i) {
1713  $totalarray['nbfield']++;
1714  }
1715  }
1716  // Author
1717  $userstatic->id = $obj->fk_user_author;
1718  $userstatic->lastname = $obj->lastname;
1719  $userstatic->firstname = $obj->firstname;
1720  $userstatic->login = $obj->login;
1721  $userstatic->photo = $obj->photo;
1722  $userstatic->email = $obj->user_email;
1723  $userstatic->statut = $obj->user_status;
1724  if (!empty($arrayfields['u.login']['checked'])) {
1725  print '<td class="tdoverflowmax150">';
1726  if ($userstatic->id) {
1727  print $userstatic->getNomUrl(1);
1728  }
1729  print "</td>";
1730  if (!$i) {
1731  $totalarray['nbfield']++;
1732  }
1733  }
1734  // Thirdparty
1735  if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1736  print '<td class="tdoverflowmax150">';
1737  $thirdpartytmp->id = $obj->socid;
1738  $thirdpartytmp->name = $obj->name;
1739  $thirdpartytmp->email = $obj->email;
1740  $thirdpartytmp->name_alias = $obj->alias;
1741  $thirdpartytmp->client = $obj->client;
1742  $thirdpartytmp->fournisseur = $obj->fournisseur;
1743  print $thirdpartytmp->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1744  print '</td>'."\n";
1745  if (!$i) {
1746  $totalarray['nbfield']++;
1747  }
1748  }
1749  //alias
1750  if (!empty($arrayfields['s.name_alias']['checked'])) {
1751  print '<td class="tdoverflowmax150">';
1752  print $obj->alias;
1753  print '</td>'."\n";
1754  if (!$i) {
1755  $totalarray['nbfield']++;
1756  }
1757  }
1758  // Town
1759  if (!empty($arrayfields['s.town']['checked'])) {
1760  print '<td>';
1761  print $obj->town;
1762  print '</td>';
1763  if (!$i) {
1764  $totalarray['nbfield']++;
1765  }
1766  }
1767  // Zip
1768  if (!empty($arrayfields['s.zip']['checked'])) {
1769  print '<td>';
1770  print $obj->zip;
1771  print '</td>';
1772  if (!$i) {
1773  $totalarray['nbfield']++;
1774  }
1775  }
1776  // State
1777  if (!empty($arrayfields['state.nom']['checked'])) {
1778  print "<td>".$obj->state_name."</td>\n";
1779  if (!$i) {
1780  $totalarray['nbfield']++;
1781  }
1782  }
1783  // Country
1784  if (!empty($arrayfields['country.code_iso']['checked'])) {
1785  print '<td class="center">';
1786  $tmparray = getCountry($obj->fk_pays, 'all');
1787  print $tmparray['label'];
1788  print '</td>';
1789  if (!$i) {
1790  $totalarray['nbfield']++;
1791  }
1792  }
1793  // Type ent
1794  if (!empty($arrayfields['typent.code']['checked'])) {
1795  print '<td class="center">';
1796  if (empty($typenArray)) {
1797  $typenArray = $formcompany->typent_array(1);
1798  }
1799  print $typenArray[$obj->typent_code];
1800  print '</td>';
1801  if (!$i) {
1802  $totalarray['nbfield']++;
1803  }
1804  }
1805 
1806  // Order date
1807  if (!empty($arrayfields['cf.date_commande']['checked'])) {
1808  print '<td class="center">';
1809  print dol_print_date($db->jdate($obj->date_commande), 'day');
1810  if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) {
1811  if ($objectstatic->hasDelay()) {
1812  print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1813  }
1814  }
1815  print '</td>';
1816  if (!$i) {
1817  $totalarray['nbfield']++;
1818  }
1819  }
1820  // Plannned date of delivery
1821  if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1822  print '<td class="center">';
1823  print dol_print_date($db->jdate($obj->date_livraison), 'day');
1824  if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) {
1825  if ($objectstatic->hasDelay()) {
1826  print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1827  }
1828  }
1829  print '</td>';
1830  if (!$i) {
1831  $totalarray['nbfield']++;
1832  }
1833  }
1834  // Amount HT
1835  if (!empty($arrayfields['cf.total_ht']['checked'])) {
1836  print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1837  if (!$i) {
1838  $totalarray['nbfield']++;
1839  }
1840  if (!$i) {
1841  $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht';
1842  }
1843  $totalarray['val']['cf.total_ht'] += $obj->total_ht;
1844  }
1845  // Amount VAT
1846  if (!empty($arrayfields['cf.total_tva']['checked'])) {
1847  print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1848  if (!$i) {
1849  $totalarray['nbfield']++;
1850  }
1851  if (!$i) {
1852  $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva';
1853  }
1854  $totalarray['val']['cf.total_tva'] += $obj->total_tva;
1855  }
1856  // Amount TTC
1857  if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1858  print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1859  if (!$i) {
1860  $totalarray['nbfield']++;
1861  }
1862  if (!$i) {
1863  $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc';
1864  }
1865  $totalarray['val']['cf.total_ttc'] += $obj->total_ttc;
1866  }
1867 
1868  // Currency
1869  if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1870  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1871  if (!$i) {
1872  $totalarray['nbfield']++;
1873  }
1874  }
1875 
1876  // Currency rate
1877  if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1878  print '<td class="nowrap">';
1879  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1880  print "</td>\n";
1881  if (!$i) {
1882  $totalarray['nbfield']++;
1883  }
1884  }
1885  // Amount HT
1886  if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1887  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1888  if (!$i) {
1889  $totalarray['nbfield']++;
1890  }
1891  }
1892  // Amount VAT
1893  if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1894  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
1895  if (!$i) {
1896  $totalarray['nbfield']++;
1897  }
1898  }
1899  // Amount TTC
1900  if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1901  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1902  if (!$i) {
1903  $totalarray['nbfield']++;
1904  }
1905  }
1906 
1907  // Extra fields
1908  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1909  // Fields from hook
1910  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1911  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1912  print $hookmanager->resPrint;
1913  // Date creation
1914  if (!empty($arrayfields['cf.date_creation']['checked'])) {
1915  print '<td class="center nowrap">';
1916  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1917  print '</td>';
1918  if (!$i) {
1919  $totalarray['nbfield']++;
1920  }
1921  }
1922  // Date modification
1923  if (!empty($arrayfields['cf.tms']['checked'])) {
1924  print '<td class="center nowrap">';
1925  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1926  print '</td>';
1927  if (!$i) {
1928  $totalarray['nbfield']++;
1929  }
1930  }
1931  // Status
1932  if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1933  print '<td class="right nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>';
1934  if (!$i) {
1935  $totalarray['nbfield']++;
1936  }
1937  }
1938  // Billed
1939  if (!empty($arrayfields['cf.billed']['checked'])) {
1940  print '<td class="center">'.yn($obj->billed).'</td>';
1941  if (!$i) {
1942  $totalarray['nbfield']++;
1943  }
1944  }
1945 
1946  // valid date
1947  if (!empty($arrayfields['cf.date_valid']['checked'])) {
1948  print '<td class="center">';
1949  print dol_print_date($db->jdate($obj->date_valid), 'day');
1950  print '</td>';
1951  if (!$i) {
1952  $totalarray['nbfield']++;
1953  }
1954  }
1955  // approve date
1956  if (!empty($arrayfields['cf.date_approve']['checked'])) {
1957  print '<td class="center">';
1958  print dol_print_date($db->jdate($obj->date_approve), 'day');
1959  print '</td>';
1960  if (!$i) {
1961  $totalarray['nbfield']++;
1962  }
1963  }
1964  // Note public
1965  if (!empty($arrayfields['cf.note_public']['checked'])) {
1966  print '<td class="center">';
1967  print dol_string_nohtmltag($obj->note_public);
1968  print '</td>';
1969  if (!$i) {
1970  $totalarray['nbfield']++;
1971  }
1972  }
1973 
1974  // Note private
1975  if (!empty($arrayfields['cf.note_private']['checked'])) {
1976  print '<td class="center">';
1977  print dol_string_nohtmltag($obj->note_private);
1978  print '</td>';
1979  if (!$i) {
1980  $totalarray['nbfield']++;
1981  }
1982  }
1983 
1984  // Action column
1985  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1986  print '<td class="nowrap center">';
1987  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1988  $selected = 0;
1989  if (in_array($obj->rowid, $arrayofselected)) {
1990  $selected = 1;
1991  }
1992  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1993  }
1994  print '</td>';
1995  }
1996  if (!$i) {
1997  $totalarray['nbfield']++;
1998  }
1999 
2000  print "</tr>\n";
2001 
2002  $total += $obj->total_ht;
2003  $subtotal += $obj->total_ht;
2004  $i++;
2005  }
2006 
2007  // Show total line
2008  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2009 
2010  // If no record found
2011  if ($num == 0) {
2012  $colspan = 1;
2013  foreach ($arrayfields as $key => $val) {
2014  if (!empty($val['checked'])) {
2015  $colspan++;
2016  }
2017  }
2018  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2019  }
2020 
2021  $db->free($resql);
2022 
2023  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2024  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
2025  print $hookmanager->resPrint;
2026 
2027  print '</table>'."\n";
2028  print '</div>';
2029 
2030  print '</form>'."\n";
2031 
2032  $hidegeneratedfilelistifempty = 1;
2033  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2034  $hidegeneratedfilelistifempty = 0;
2035  }
2036 
2037  // Show list of available documents
2038  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2039  $urlsource .= str_replace('&amp;', '&', $param);
2040 
2041  $filedir = $diroutputmassaction;
2042  $genallowed = $permissiontoread;
2043  $delallowed = $permissiontoadd;
2044 
2045  print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2046 } else {
2047  dol_print_error($db);
2048 }
2049 
2050 // End of page
2051 llxFooter();
2052 $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:47
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.