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