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