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