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