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