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