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