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