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