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