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