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