dolibarr 19.0.4
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 $objecttmp->thirdparty = $societe;
403 }
404 $objecttmp->socid = $cmd->socid;
405 $objecttmp->type = $objecttmp::TYPE_STANDARD;
406 $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
407 $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
408 $objecttmp->fk_project = $cmd->fk_project;
409 $objecttmp->multicurrency_code = $cmd->multicurrency_code;
410 $objecttmp->ref_supplier = !empty($cmd->ref_supplier) ? $cmd->ref_supplier : $default_ref_supplier;
411 $default_ref_supplier+=1;
412
413 $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
414 if (empty($datefacture)) {
415 $datefacture = dol_now();
416 }
417
418 $objecttmp->date = $datefacture;
419 $objecttmp->origin = 'order_supplier';
420 $objecttmp->origin_id = $id_order;
421
422 $res = $objecttmp->create($user);
423
424 if ($res > 0) {
425 $nb_bills_created++;
426 $lastref = $objecttmp->ref;
427 $lastid = $objecttmp->id;
428 }
429 }
430
431 if ($objecttmp->id > 0) {
432 $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
433 $sql .= "fk_source";
434 $sql .= ", sourcetype";
435 $sql .= ", fk_target";
436 $sql .= ", targettype";
437 $sql .= ") VALUES (";
438 $sql .= $id_order;
439 $sql .= ", '".$db->escape($objecttmp->origin)."'";
440 $sql .= ", ".((int) $objecttmp->id);
441 $sql .= ", '".$db->escape($objecttmp->element)."'";
442 $sql .= ")";
443
444 if (!$db->query($sql)) {
445 $erorr++;
446 }
447
448 if (!$error) {
449 $lines = $cmd->lines;
450 if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
451 $cmd->fetch_lines();
452 $lines = $cmd->lines;
453 }
454
455 $fk_parent_line = 0;
456 $num = count($lines);
457
458 for ($i = 0; $i < $num; $i++) {
459 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
460 if ($lines[$i]->subprice < 0) {
461 // Negative line, we create a discount line
462 $discount = new DiscountAbsolute($db);
463 $discount->fk_soc = $objecttmp->socid;
464 $discount->amount_ht = abs($lines[$i]->total_ht);
465 $discount->amount_tva = abs($lines[$i]->total_tva);
466 $discount->amount_ttc = abs($lines[$i]->total_ttc);
467 $discount->tva_tx = $lines[$i]->tva_tx;
468 $discount->fk_user = $user->id;
469 $discount->description = $desc;
470 $discountid = $discount->create($user);
471 if ($discountid > 0) {
472 $result = $objecttmp->insert_discount($discountid);
473 //$result=$discount->link_to_invoice($lineid,$id);
474 } else {
475 setEventMessages($discount->error, $discount->errors, 'errors');
476 $error++;
477 break;
478 }
479 } else {
480 // Positive line
481 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
482 // Date start
483 $date_start = false;
484 if ($lines[$i]->date_debut_prevue) {
485 $date_start = $lines[$i]->date_debut_prevue;
486 }
487 if ($lines[$i]->date_debut_reel) {
488 $date_start = $lines[$i]->date_debut_reel;
489 }
490 if ($lines[$i]->date_start) {
491 $date_start = $lines[$i]->date_start;
492 }
493 //Date end
494 $date_end = false;
495 if ($lines[$i]->date_fin_prevue) {
496 $date_end = $lines[$i]->date_fin_prevue;
497 }
498 if ($lines[$i]->date_fin_reel) {
499 $date_end = $lines[$i]->date_fin_reel;
500 }
501 if ($lines[$i]->date_end) {
502 $date_end = $lines[$i]->date_end;
503 }
504 // Reset fk_parent_line for no child products and special product
505 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
506 $fk_parent_line = 0;
507 }
508
509 $tva_tx = $lines[$i]->tva_tx;
510 if (!empty($lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
511 $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
512 }
513
514 $result = $objecttmp->addline(
515 $desc,
516 $lines[$i]->subprice,
517 $tva_tx,
518 $lines[$i]->localtax1_tx,
519 $lines[$i]->localtax2_tx,
520 $lines[$i]->qty,
521 $lines[$i]->fk_product,
522 $lines[$i]->remise_percent,
523 $date_start,
524 $date_end,
525 0,
526 $lines[$i]->info_bits,
527 'HT',
528 $product_type,
529 // we dont use the rank from orderline because we may have lines from several orders
530 -1,
531 false,
532 $lines[$i]->array_options,
533 $lines[$i]->fk_unit,
534 // we use the id of each order, not the id of the first one stored in $objecttmp->origin_id
535 $lines[$i]->fk_commande,
536 $lines[$i]->pa_ht,
537 $lines[$i]->ref_supplier,
538 $lines[$i]->special_code,
539 $fk_parent_line
540 );
541 if ($result > 0) {
542 $lineid = $result;
543 } else {
544 $lineid = 0;
545 $error++;
546 break;
547 }
548 // Defined the new fk_parent_line
549 if ($result > 0 && $lines[$i]->product_type == 9) {
550 $fk_parent_line = $result;
551 }
552 }
553 }
554 }
555 }
556
557 $cmd->classifyBilled($user); // TODO Move this in workflow like done for sales orders
558
559 if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
560 $TFactThird[$cmd->socid] = $objecttmp;
561 } else {
562 $TFact[$objecttmp->id] = $objecttmp;
563 }
564 }
565
566 // Build doc with all invoices
567 $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
568 $toselect = array();
569
570 if (!$error && $validate_invoices) {
571 $massaction = $action = 'builddoc';
572
573 foreach ($TAllFact as &$objecttmp) {
574 $objecttmp->validate($user);
575 if ($result <= 0) {
576 $error++;
577 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
578 break;
579 }
580
581 $id = $objecttmp->id; // For builddoc action
582
583 // Fac builddoc
584 $donotredirect = 1;
585 $upload_dir = $conf->fournisseur->facture->dir_output;
586 $permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
587 //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
588 }
589
590 $massaction = $action = 'confirm_createsupplierbills';
591 }
592
593 if (!$error) {
594 $db->commit();
595
596 if ($nb_bills_created == 1) {
597 $texttoshow = $langs->trans('BillXCreated', '{s1}');
598 $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
599 setEventMessages($texttoshow, null, 'mesgs');
600 } else {
601 setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
602 }
603
604 // Make a redirect to avoid to bill twice if we make a refresh or back
605 $param = '';
606 if (!empty($mode)) {
607 $param .= '&mode='.urlencode($mode);
608 }
609 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
610 $param .= '&contextpage='.urlencode($contextpage);
611 }
612 if ($limit > 0 && $limit != $conf->liste_limit) {
613 $param .= '&limit='.((int) $limit);
614 }
615 if ($sall) {
616 $param .= '&sall='.urlencode($sall);
617 }
618 if ($socid > 0) {
619 $param .= '&socid='.urlencode($socid);
620 }
621 if ($search_status != '') {
622 $param .= '&search_status='.urlencode($search_status);
623 }
624 if ($search_date_order_startday) {
625 $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
626 }
627 if ($search_date_order_startmonth) {
628 $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
629 }
630 if ($search_date_order_startyear) {
631 $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
632 }
633 if ($search_date_order_endday) {
634 $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
635 }
636 if ($search_date_order_endmonth) {
637 $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
638 }
639 if ($search_date_order_endyear) {
640 $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
641 }
642 if ($search_date_delivery_startday) {
643 $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
644 }
645 if ($search_date_delivery_startmonth) {
646 $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
647 }
648 if ($search_date_delivery_startyear) {
649 $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
650 }
651 if ($search_date_delivery_endday) {
652 $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
653 }
654 if ($search_date_delivery_endmonth) {
655 $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
656 }
657 if ($search_date_delivery_endyear) {
658 $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
659 }
660 if ($search_date_valid_startday) {
661 $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
662 }
663 if ($search_date_valid_startmonth) {
664 $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
665 }
666 if ($search_date_valid_startyear) {
667 $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
668 }
669 if ($search_date_valid_endday) {
670 $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
671 }
672 if ($search_date_valid_endmonth) {
673 $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
674 }
675 if ($search_date_valid_endyear) {
676 $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
677 }
678 if ($search_date_approve_startday) {
679 $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
680 }
681 if ($search_date_approve_startmonth) {
682 $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
683 }
684 if ($search_date_approve_startyear) {
685 $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
686 }
687 if ($search_date_approve_endday) {
688 $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
689 }
690 if ($search_date_approve_endmonth) {
691 $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
692 }
693 if ($search_date_approve_endyear) {
694 $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
695 }
696 if ($search_ref) {
697 $param .= '&search_ref='.urlencode($search_ref);
698 }
699 if ($search_company) {
700 $param .= '&search_company='.urlencode($search_company);
701 }
702 if ($search_company_alias) {
703 $param .= '&search_company_alias='.urlencode($search_company_alias);
704 }
705 //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
706 if ($search_user > 0) {
707 $param .= '&search_user='.urlencode($search_user);
708 }
709 if ($search_sale > 0) {
710 $param .= '&search_sale='.urlencode($search_sale);
711 }
712 if ($search_total_ht != '') {
713 $param .= '&search_total_ht='.urlencode($search_total_ht);
714 }
715 if ($search_total_tva != '') {
716 $param .= '&search_total_tva='.urlencode($search_total_tva);
717 }
718 if ($search_total_ttc != '') {
719 $param .= '&search_total_ttc='.urlencode($search_total_ttc);
720 }
721 if ($search_project_ref >= 0) {
722 $param .= "&search_project_ref=".urlencode($search_project_ref);
723 }
724 if ($show_files) {
725 $param .= '&show_files='.urlencode($show_files);
726 }
727 if ($optioncss != '') {
728 $param .= '&optioncss='.urlencode($optioncss);
729 }
730 if ($billed != '') {
731 $param .= '&billed='.urlencode($billed);
732 }
733
734 header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
735 exit;
736 } else {
737 $db->rollback();
738 $action = 'create';
739 $_GET["origin"] = $_POST["origin"];
740 $_GET["originid"] = $_POST["originid"];
741 setEventMessages("Error", null, 'errors');
742 $error++;
743 }
744 }
745}
746
747
748/*
749 * View
750 */
751
752$now = dol_now();
753
754$form = new Form($db);
755$thirdpartytmp = new Fournisseur($db);
756$commandestatic = new CommandeFournisseur($db);
757$formfile = new FormFile($db);
758$formorder = new FormOrder($db);
759$formother = new FormOther($db);
760$formcompany = new FormCompany($db);
761
762$title = $langs->trans("SuppliersOrders");
763if ($socid > 0) {
764 $fourn = new Fournisseur($db);
765 $fourn->fetch($socid);
766 $title .= ' - '.$fourn->name;
767}
768
769/*if ($search_status)
770{
771 if ($search_status == '1,2') $title .= ' - '.$langs->trans("SuppliersOrdersToProcess");
772 elseif ($search_status == '3,4') $title .= ' - '.$langs->trans("SuppliersOrdersAwaitingReception");
773 elseif ($search_status == '1,2,3') $title .= ' - '.$langs->trans("StatusOrderToProcessShort");
774 elseif ($search_status == '6,7') $title .= ' - '.$langs->trans("StatusOrderCanceled");
775 elseif (is_numeric($search_status) && $search_status >= 0) $title .= ' - '.$commandestatic->LibStatut($search_status);
776}*/
777if ($search_billed > 0) {
778 $title .= ' - '.$langs->trans("Billed");
779}
780
781//$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
782$help_url = '';
783
784$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
785$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
786
787$sql = 'SELECT';
788if ($sall) {
789 $sql = 'SELECT DISTINCT';
790}
791$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,';
792$sql .= " typent.code as typent_code,";
793$sql .= " state.code_departement as state_code, state.nom as state_name,";
794$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,";
795$sql .= ' cf.localtax1 as total_localtax1, cf.localtax2 as total_localtax2,';
796$sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
797$sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
798$sql .= ' cf.note_public, cf.note_private,';
799$sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,";
800$sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status";
801// Add fields from extrafields
802if (!empty($extrafields->attributes[$object->table_element]['label'])) {
803 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
804 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
805 }
806}
807// Add fields from hooks
808$parameters = array();
809$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
810$sql .= $hookmanager->resPrint;
811
812$sqlfields = $sql; // $sql fields to remove for count total
813
814$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
815$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
816$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
817$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
818$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
819if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
820 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)";
821}
822if ($sall) {
823 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
824}
825$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid";
826$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet";
827$parameters = array();
828$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
829$sql .= $hookmanager->resPrint;
830$sql .= ' WHERE cf.fk_soc = s.rowid';
831$sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')';
832if ($socid > 0) {
833 $sql .= " AND s.rowid = ".((int) $socid);
834}
835if ($search_ref) {
836 $sql .= natural_search('cf.ref', $search_ref);
837}
838if ($search_refsupp) {
839 $sql .= natural_search("cf.ref_supplier", $search_refsupp);
840}
841if ($sall) {
842 $sql .= natural_search(array_keys($fieldstosearchall), $sall);
843}
844if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
845 $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
846} else {
847 if ($search_company) {
848 $sql .= natural_search('s.nom', $search_company);
849 }
850 if ($search_company_alias) {
851 $sql .= natural_search('s.name_alias', $search_company_alias);
852 }
853}
854if ($search_request_author) {
855 $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
856}
857if ($search_billed != '' && $search_billed >= 0) {
858 $sql .= " AND cf.billed = ".((int) $search_billed);
859}
860//Required triple check because statut=0 means draft filter
861if (GETPOST('statut', 'intcomma') !== '') {
862 $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")";
863}
864if ($search_status != '' && $search_status != '-1') {
865 $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
866}
867if ($search_date_order_start) {
868 $sql .= " AND cf.date_commande >= '".$db->idate($search_date_order_start)."'";
869}
870if ($search_date_order_end) {
871 $sql .= " AND cf.date_commande <= '".$db->idate($search_date_order_end)."'";
872}
873if ($search_date_delivery_start) {
874 $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
875}
876if ($search_date_delivery_end) {
877 $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
878}
879if ($search_date_valid_start) {
880 $sql .= " AND cf.date_valid >= '".$db->idate($search_date_valid_start)."'";
881}
882if ($search_date_valid_end) {
883 $sql .= " AND cf.date_valid <= '".$db->idate($search_date_valid_end)."'";
884}
885if ($search_date_approve_start) {
886 $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
887}
888if ($search_date_approve_end) {
889 $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
890}
891if ($search_town) {
892 $sql .= natural_search('s.town', $search_town);
893}
894if ($search_zip) {
895 $sql .= natural_search("s.zip", $search_zip);
896}
897if ($search_state) {
898 $sql .= natural_search("state.nom", $search_state);
899}
900if ($search_country) {
901 $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
902}
903if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
904 $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
905}
906/*if ($search_sale > 0) {
907 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
908}*/
909if ($search_user > 0) {
910 $sql .= " AND EXISTS (";
911 $sql .= " SELECT ec.rowid ";
912 $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec";
913 $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON tc.rowid = ec.fk_c_type_contact";
914 $sql .= " WHERE ec.element_id = cf.rowid AND ec.fk_socpeople = " . ((int) $search_user);
915 $sql .= " AND tc.element = 'order_supplier' AND tc.source = 'internal'";
916 $sql .= ")";
917}
918if ($search_total_ht != '') {
919 $sql .= natural_search('cf.total_ht', $search_total_ht, 1);
920}
921if ($search_total_tva != '') {
922 $sql .= natural_search('cf.total_tva', $search_total_tva, 1);
923}
924if ($search_total_ttc != '') {
925 $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1);
926}
927if ($search_multicurrency_code != '') {
928 $sql .= " AND cf.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
929}
930if ($search_multicurrency_tx != '') {
931 $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1);
932}
933if ($search_multicurrency_montant_ht != '') {
934 $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
935}
936if ($search_multicurrency_montant_tva != '') {
937 $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1);
938}
939if ($search_multicurrency_montant_ttc != '') {
940 $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
941}
942if ($search_project_ref != '') {
943 $sql .= natural_search("p.ref", $search_project_ref);
944}
945// Search on sale representative
946if ($search_sale && $search_sale != '-1') {
947 if ($search_sale == -2) {
948 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = cf.fk_soc)";
949 } elseif ($search_sale > 0) {
950 $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).")";
951 }
952}
953// Search for tag/category ($searchCategoryProductList is an array of ID)
954$searchCategoryProductOperator = -1;
955$searchCategoryProductList = array($search_product_category);
956if (!empty($searchCategoryProductList)) {
957 $searchCategoryProductSqlList = array();
958 $listofcategoryid = '';
959 foreach ($searchCategoryProductList as $searchCategoryProduct) {
960 if (intval($searchCategoryProduct) == -2) {
961 $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)";
962 } elseif (intval($searchCategoryProduct) > 0) {
963 if ($searchCategoryProductOperator == 0) {
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 = ".((int) $searchCategoryProduct).")";
965 } else {
966 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
967 }
968 }
969 }
970 if ($listofcategoryid) {
971 $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)."))";
972 }
973 if ($searchCategoryProductOperator == 1) {
974 if (!empty($searchCategoryProductSqlList)) {
975 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
976 }
977 } else {
978 if (!empty($searchCategoryProductSqlList)) {
979 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
980 }
981 }
982}
983// Add where from extra fields
984include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
985// Add where from hooks
986$parameters = array();
987$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
988$sql .= $hookmanager->resPrint;
989
990// Count total nb of records
991$nbtotalofrecords = '';
992if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
993 /* The fast and low memory method to get and count full list converts the sql into a sql count */
994 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
995 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
996 $resql = $db->query($sqlforcount);
997 if ($resql) {
998 $objforcount = $db->fetch_object($resql);
999 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1000 } else {
1001 dol_print_error($db);
1002 }
1003
1004 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
1005 $page = 0;
1006 $offset = 0;
1007 }
1008 $db->free($resql);
1009}
1010
1011$sql .= $db->order($sortfield, $sortorder);
1012if ($limit) {
1013 $sql .= $db->plimit($limit + 1, $offset);
1014}
1015//print $sql;
1016
1017$resql = $db->query($sql);
1018if ($resql) {
1019 $num = $db->num_rows($resql);
1020
1021 $arrayofselected = is_array($toselect) ? $toselect : array();
1022
1023 if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $sall) {
1024 $obj = $db->fetch_object($resql);
1025 $id = $obj->rowid;
1026 header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id);
1027 exit;
1028 }
1029
1030 llxHeader('', $title, $help_url);
1031
1032 $param = '';
1033 if (!empty($mode)) {
1034 $param .= '&mode='.urlencode($mode);
1035 }
1036 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1037 $param .= '&contextpage='.urlencode($contextpage);
1038 }
1039 if ($limit > 0 && $limit != $conf->liste_limit) {
1040 $param .= '&limit='.((int) $limit);
1041 }
1042 if ($sall) {
1043 $param .= '&sall='.urlencode($sall);
1044 }
1045 if ($socid > 0) {
1046 $param .= '&socid='.urlencode($socid);
1047 }
1048 if ($sall) {
1049 $param .= "&search_all=".urlencode($sall);
1050 }
1051 if ($search_date_order_startday) {
1052 $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
1053 }
1054 if ($search_date_order_startmonth) {
1055 $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
1056 }
1057 if ($search_date_order_startyear) {
1058 $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
1059 }
1060 if ($search_date_order_endday) {
1061 $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
1062 }
1063 if ($search_date_order_endmonth) {
1064 $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
1065 }
1066 if ($search_date_order_endyear) {
1067 $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
1068 }
1069 if ($search_date_delivery_startday) {
1070 $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
1071 }
1072 if ($search_date_delivery_startmonth) {
1073 $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
1074 }
1075 if ($search_date_delivery_startyear) {
1076 $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
1077 }
1078 if ($search_date_delivery_endday) {
1079 $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
1080 }
1081 if ($search_date_delivery_endmonth) {
1082 $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
1083 }
1084 if ($search_date_delivery_endyear) {
1085 $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
1086 }
1087 if ($search_date_valid_startday) {
1088 $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
1089 }
1090 if ($search_date_valid_startmonth) {
1091 $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
1092 }
1093 if ($search_date_valid_startyear) {
1094 $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
1095 }
1096 if ($search_date_valid_endday) {
1097 $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
1098 }
1099 if ($search_date_valid_endmonth) {
1100 $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
1101 }
1102 if ($search_date_valid_endyear) {
1103 $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
1104 }
1105 if ($search_date_approve_startday) {
1106 $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
1107 }
1108 if ($search_date_approve_startmonth) {
1109 $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
1110 }
1111 if ($search_date_approve_startyear) {
1112 $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
1113 }
1114 if ($search_date_approve_endday) {
1115 $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
1116 }
1117 if ($search_date_approve_endmonth) {
1118 $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
1119 }
1120 if ($search_date_approve_endyear) {
1121 $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
1122 }
1123 if ($search_ref) {
1124 $param .= '&search_ref='.urlencode($search_ref);
1125 }
1126 if ($search_company) {
1127 $param .= '&search_company='.urlencode($search_company);
1128 }
1129 if ($search_company_alias) {
1130 $param .= '&search_company_alias='.urlencode($search_company_alias);
1131 }
1132 if ($search_user > 0) {
1133 $param .= '&search_user='.urlencode($search_user);
1134 }
1135 if ($search_request_author) {
1136 $param .= '&search_request_author='.urlencode($search_request_author);
1137 }
1138 if ($search_sale > 0) {
1139 $param .= '&search_sale='.urlencode($search_sale);
1140 }
1141 if ($search_total_ht != '') {
1142 $param .= '&search_total_ht='.urlencode($search_total_ht);
1143 }
1144 if ($search_total_ttc != '') {
1145 $param .= "&search_total_ttc=".urlencode($search_total_ttc);
1146 }
1147 if ($search_multicurrency_code != '') {
1148 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1149 }
1150 if ($search_multicurrency_tx != '') {
1151 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1152 }
1153 if ($search_multicurrency_montant_ht != '') {
1154 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1155 }
1156 if ($search_multicurrency_montant_tva != '') {
1157 $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva);
1158 }
1159 if ($search_multicurrency_montant_ttc != '') {
1160 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1161 }
1162 if ($search_refsupp) {
1163 $param .= "&search_refsupp=".urlencode($search_refsupp);
1164 }
1165 if ($search_status != '' && $search_status != '-1') {
1166 $param .= "&search_status=".urlencode($search_status);
1167 }
1168 if ($search_project_ref >= 0) {
1169 $param .= "&search_project_ref=".urlencode($search_project_ref);
1170 }
1171 if ($search_billed != '') {
1172 $param .= "&search_billed=".urlencode($search_billed);
1173 }
1174 if ($show_files) {
1175 $param .= '&show_files='.urlencode($show_files);
1176 }
1177 if ($optioncss != '') {
1178 $param .= '&optioncss='.urlencode($optioncss);
1179 }
1180 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
1181 $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
1182 }
1183
1184 // Add $param from extra fields
1185 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1186
1187 $parameters = array('param' => &$param);
1188 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
1189 $param .= $hookmanager->resPrint;
1190
1191 // List of mass actions available
1192 $arrayofmassactions = array(
1193 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1194 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1195 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1196 );
1197
1198 if ($permissiontovalidate) {
1199 if ($permissiontoapprove && !getDolGlobalString('SUPPLIER_ORDER_NO_DIRECT_APPROVE')) {
1200 $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
1201 } else {
1202 $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
1203 }
1204 }
1205
1206 if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight("supplier_invoice", "creer")) {
1207 $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier");
1208 }
1209 if ($permissiontodelete) {
1210 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1211 }
1212 if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
1213 $arrayofmassactions = array();
1214 }
1215 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1216
1217 $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
1218 if ($socid > 0) {
1219 $url .= '&socid='.((int) $socid);
1220 $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
1221 }
1222 $newcardbutton = '';
1223 $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'));
1224 $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'));
1225 $newcardbutton .= dolGetButtonTitleSeparator();
1226 $newcardbutton .= dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
1227
1228 // Lines of title fields
1229 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
1230 if ($optioncss != '') {
1231 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1232 }
1233 print '<input type="hidden" name="token" value="'.newToken().'">';
1234 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1235 print '<input type="hidden" name="action" value="list">';
1236 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1237 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1238 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1239 print '<input type="hidden" name="socid" value="'.$socid.'">';
1240 print '<input type="hidden" name="mode" value="'.$mode.'">';
1241
1242 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1);
1243
1244 $topicmail = "SendOrderRef";
1245 $modelmail = "order_supplier_send";
1246 $objecttmp = new CommandeFournisseur($db); // in case $object is not the good object
1247 $trackid = 'sord'.$object->id;
1248 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1249
1250 if ($massaction == 'prevalidate') {
1251 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1252 }
1253
1254 if ($massaction == 'createbills') {
1255 //var_dump($_REQUEST);
1256 print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">';
1257
1258 print '<table class="noborder centpercent">';
1259 print '<tr>';
1260 print '<td class="titlefield">';
1261 print $langs->trans('DateInvoice');
1262 print '</td>';
1263 print '<td>';
1264 print $form->selectDate('', '', '', '', '', '', 1, 1);
1265 print '</td>';
1266 print '</tr>';
1267 print '<tr>';
1268 print '<td>';
1269 print $langs->trans('CreateOneBillByThird');
1270 print '</td>';
1271 print '<td>';
1272 print $form->selectyesno('createbills_onebythird', '', 1);
1273 print '</td>';
1274 print '</tr>';
1275 print '<tr>';
1276 print '<td>';
1277 print $langs->trans('ValidateInvoices');
1278 print '</td>';
1279 print '<td>';
1280 print $form->selectyesno('validate_invoices', 1, 1);
1281 print '</td>';
1282 print '</tr>';
1283 print '</table>';
1284
1285 print '<div class="center">';
1286 print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
1287 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1288 print '</div>';
1289 print '<br>';
1290 print '<br>';
1291 }
1292
1293 if ($sall) {
1294 foreach ($fieldstosearchall as $key => $val) {
1295 $fieldstosearchall[$key] = $langs->trans($val);
1296 }
1297 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
1298 }
1299
1300 $moreforfilter = '';
1301
1302 // If the user can view prospects other than his'
1303 if ($user->hasRight("user", "user", "lire")) {
1304 $langs->load("commercial");
1305 $moreforfilter .= '<div class="divsearchfield">';
1306 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1307 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1308 $moreforfilter .= '</div>';
1309 }
1310 // If the user can view other users
1311 if ($user->hasRight("user", "user", "lire")) {
1312 $moreforfilter .= '<div class="divsearchfield">';
1313 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1314 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1315 $moreforfilter .= '</div>';
1316 }
1317 // If the user can view prospects other than his'
1318 if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
1319 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1320 $moreforfilter .= '<div class="divsearchfield">';
1321 $tmptitle = $langs->trans('IncludingProductWithTag');
1322 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1323 $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);
1324 $moreforfilter .= '</div>';
1325 }
1326 $parameters = array();
1327 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1328 if (empty($reshook)) {
1329 $moreforfilter .= $hookmanager->resPrint;
1330 } else {
1331 $moreforfilter = $hookmanager->resPrint;
1332 }
1333
1334 if (!empty($moreforfilter)) {
1335 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1336 print $moreforfilter;
1337 print '</div>';
1338 }
1339
1340 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1341 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
1342 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
1343
1344 if (GETPOST('autoselectall', 'int')) {
1345 $selectedfields .= '<script>';
1346 $selectedfields .= ' $(document).ready(function() {';
1347 $selectedfields .= ' console.log("Autoclick on checkforselects");';
1348 $selectedfields .= ' $("#checkforselects").click();';
1349 $selectedfields .= ' $("#massaction").val("createbills").change();';
1350 $selectedfields .= ' });';
1351 $selectedfields .= '</script>';
1352 }
1353
1354 print '<div class="div-table-responsive">';
1355 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1356
1357 print '<tr class="liste_titre_filter">';
1358 // Action column
1359 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1360 print '<td class="liste_titre middle">';
1361 $searchpicto = $form->showFilterButtons('left');
1362 print $searchpicto;
1363 print '</td>';
1364 }
1365 // Ref
1366 if (!empty($arrayfields['cf.ref']['checked'])) {
1367 print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>';
1368 }
1369 // Ref customer
1370 if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1371 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>';
1372 }
1373 // Project ref
1374 if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1375 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>';
1376 }
1377 // Request author
1378 if (!empty($arrayfields['u.login']['checked'])) {
1379 print '<td class="liste_titre">';
1380 print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
1381 print '</td>';
1382 }
1383 // Thirpdarty
1384 if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1385 print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
1386 }
1387 // Alias
1388 if (!empty($arrayfields['s.name_alias']['checked'])) {
1389 print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company_alias" value="'.$search_company_alias.'"></td>';
1390 }
1391 // Town
1392 if (!empty($arrayfields['s.town']['checked'])) {
1393 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
1394 }
1395 // Zip
1396 if (!empty($arrayfields['s.zip']['checked'])) {
1397 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
1398 }
1399 // State
1400 if (!empty($arrayfields['state.nom']['checked'])) {
1401 print '<td class="liste_titre">';
1402 print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1403 print '</td>';
1404 }
1405 // Country
1406 if (!empty($arrayfields['country.code_iso']['checked'])) {
1407 print '<td class="liste_titre center">';
1408 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1409 print '</td>';
1410 }
1411 // Company type
1412 if (!empty($arrayfields['typent.code']['checked'])) {
1413 print '<td class="liste_titre maxwidthonsmartphone center">';
1414 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);
1415 print '</td>';
1416 }
1417 // Date order
1418 if (!empty($arrayfields['cf.date_commande']['checked'])) {
1419 print '<td class="liste_titre center">';
1420 print '<div class="nowrapfordate">';
1421 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'));
1422 print '</div>';
1423 print '<div class="nowrapfordate">';
1424 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'));
1425 print '</div>';
1426 print '</td>';
1427 }
1428 // Date delivery
1429 if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1430 print '<td class="liste_titre center">';
1431 print '<div class="nowrapfordate">';
1432 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'));
1433 print '</div>';
1434 print '<div class="nowrapfordate">';
1435 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'));
1436 print '</div>';
1437 print '</td>';
1438 }
1439 if (!empty($arrayfields['cf.total_ht']['checked'])) {
1440 // Amount
1441 print '<td class="liste_titre right">';
1442 print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
1443 print '</td>';
1444 }
1445 if (!empty($arrayfields['cf.total_tva']['checked'])) {
1446 // Amount
1447 print '<td class="liste_titre right">';
1448 print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">';
1449 print '</td>';
1450 }
1451 if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1452 // Amount
1453 print '<td class="liste_titre right">';
1454 print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1455 print '</td>';
1456 }
1457 if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1458 // Currency
1459 print '<td class="liste_titre">';
1460 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1461 print '</td>';
1462 }
1463 if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1464 // Currency rate
1465 print '<td class="liste_titre">';
1466 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1467 print '</td>';
1468 }
1469 if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1470 // Amount
1471 print '<td class="liste_titre right">';
1472 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1473 print '</td>';
1474 }
1475 if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1476 // Amount
1477 print '<td class="liste_titre right">';
1478 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">';
1479 print '</td>';
1480 }
1481 if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1482 // Amount
1483 print '<td class="liste_titre right">';
1484 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1485 print '</td>';
1486 }
1487 // Extra fields
1488 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1489
1490 // Fields from hook
1491 $parameters = array('arrayfields'=>$arrayfields);
1492 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1493 print $hookmanager->resPrint;
1494 // Date creation
1495 if (!empty($arrayfields['cf.date_creation']['checked'])) {
1496 print '<td class="liste_titre">';
1497 print '</td>';
1498 }
1499 // Date modification
1500 if (!empty($arrayfields['cf.tms']['checked'])) {
1501 print '<td class="liste_titre">';
1502 print '</td>';
1503 }
1504 // Billed
1505 if (!empty($arrayfields['cf.billed']['checked'])) {
1506 print '<td class="liste_titre center parentonrightofpage">';
1507 print $form->selectyesno('search_billed', $search_billed, 1, false, 1, 1, 'search_status width100 onrightofpage');
1508 print '</td>';
1509 }
1510 // Status
1511 if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1512 print '<td class="liste_titre center parentonrightofpage">';
1513 $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status', 'search_status width100 onrightofpage');
1514 print '</td>';
1515 }
1516 // Date valid
1517 if (!empty($arrayfields['cf.date_valid']['checked'])) {
1518 print '<td class="liste_titre center">';
1519 print '<div class="nowrapfordate">';
1520 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'));
1521 print '</div>';
1522 print '<div class="nowrapfordate">';
1523 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'));
1524 print '</div>';
1525 print '</td>';
1526 }
1527 // Date approve
1528 if (!empty($arrayfields['cf.date_approve']['checked'])) {
1529 print '<td class="liste_titre center">';
1530 print '<div class="nowrapfordate">';
1531 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'));
1532 print '</div>';
1533 print '<div class="nowrapfordate">';
1534 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'));
1535 print '</div>';
1536 print '</td>';
1537 }
1538 // Note public
1539 if (!empty($arrayfields['cf.note_public']['checked'])) {
1540 print '<td class="liste_titre">';
1541 print '</td>';
1542 }
1543 // Note private
1544 if (!empty($arrayfields['cf.note_private']['checked'])) {
1545 print '<td class="liste_titre">';
1546 print '</td>';
1547 }
1548 // Action column
1549 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1550 print '<td class="liste_titre center">';
1551 $searchpicto = $form->showFilterButtons();
1552 print $searchpicto;
1553 print '</td>';
1554 }
1555
1556 print "</tr>\n";
1557
1558 $totalarray = array();
1559 $totalarray['nbfield'] = 0;
1560
1561 // Fields title
1562 print '<tr class="liste_titre">';
1563 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1564 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1565 $totalarray['nbfield']++;
1566 }
1567 if (!empty($arrayfields['cf.ref']['checked'])) {
1568 print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder);
1569 $totalarray['nbfield']++;
1570 }
1571 if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1572 print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp ');
1573 $totalarray['nbfield']++;
1574 }
1575 if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1576 print_liste_field_titre($arrayfields['cf.fk_projet']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1577 $totalarray['nbfield']++;
1578 }
1579 if (!empty($arrayfields['u.login']['checked'])) {
1580 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder);
1581 $totalarray['nbfield']++;
1582 }
1583 if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1584 print_liste_field_titre($arrayfields['cf.fk_soc']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
1585 $totalarray['nbfield']++;
1586 }
1587 if (!empty($arrayfields['s.name_alias']['checked'])) {
1588 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, '', $sortfield, $sortorder);
1589 $totalarray['nbfield']++;
1590 }
1591 if (!empty($arrayfields['s.town']['checked'])) {
1592 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1593 $totalarray['nbfield']++;
1594 }
1595 if (!empty($arrayfields['s.zip']['checked'])) {
1596 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1597 $totalarray['nbfield']++;
1598 }
1599 if (!empty($arrayfields['state.nom']['checked'])) {
1600 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1601 $totalarray['nbfield']++;
1602 }
1603 if (!empty($arrayfields['country.code_iso']['checked'])) {
1604 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1605 $totalarray['nbfield']++;
1606 }
1607 if (!empty($arrayfields['typent.code']['checked'])) {
1608 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1609 $totalarray['nbfield']++;
1610 }
1611 if (!empty($arrayfields['cf.fk_author']['checked'])) {
1612 print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder);
1613 $totalarray['nbfield']++;
1614 }
1615 if (!empty($arrayfields['cf.date_commande']['checked'])) {
1616 print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center ');
1617 $totalarray['nbfield']++;
1618 }
1619 if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1620 print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1621 $totalarray['nbfield']++;
1622 }
1623 if (!empty($arrayfields['cf.total_ht']['checked'])) {
1624 print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
1625 $totalarray['nbfield']++;
1626 }
1627 if (!empty($arrayfields['cf.total_tva']['checked'])) {
1628 print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
1629 $totalarray['nbfield']++;
1630 }
1631 if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1632 print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
1633 $totalarray['nbfield']++;
1634 }
1635 if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1636 print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1637 $totalarray['nbfield']++;
1638 }
1639 if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1640 print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1641 $totalarray['nbfield']++;
1642 }
1643 if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1644 print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1645 $totalarray['nbfield']++;
1646 }
1647 if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1648 print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1649 $totalarray['nbfield']++;
1650 }
1651 if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1652 print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1653 $totalarray['nbfield']++;
1654 }
1655 // Extra fields
1656 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1657 // Hook fields
1658 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1659 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1660 print $hookmanager->resPrint;
1661 if (!empty($arrayfields['cf.date_creation']['checked'])) {
1662 print_liste_field_titre($arrayfields['cf.date_creation']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowraponall ');
1663 $totalarray['nbfield']++;
1664 }
1665 if (!empty($arrayfields['cf.tms']['checked'])) {
1666 print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowraponall ');
1667 $totalarray['nbfield']++;
1668 }
1669 if (!empty($arrayfields['cf.billed']['checked'])) {
1670 print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
1671 $totalarray['nbfield']++;
1672 }
1673 if (!empty($arrayfields['cf.fk_statut']['checked'])) {
1674 print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
1675 $totalarray['nbfield']++;
1676 }
1677 if (!empty($arrayfields['cf.date_valid']['checked'])) {
1678 print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
1679 $totalarray['nbfield']++;
1680 }
1681 if (!empty($arrayfields['cf.date_approve']['checked'])) {
1682 print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
1683 $totalarray['nbfield']++;
1684 }
1685 if (!empty($arrayfields['cf.note_public']['checked'])) {
1686 print_liste_field_titre($arrayfields['cf.note_public']['label'], $_SERVER["PHP_SELF"], "cf.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
1687 $totalarray['nbfield']++;
1688 }
1689 if (!empty($arrayfields['cf.note_private']['checked'])) {
1690 print_liste_field_titre($arrayfields['cf.note_private']['label'], $_SERVER["PHP_SELF"], "cf.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
1691 $totalarray['nbfield']++;
1692 }
1693 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1694 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1695 $totalarray['nbfield']++;
1696 }
1697 print "</tr>\n";
1698
1699 $total = 0;
1700 $subtotal = 0;
1701 $productstat_cache = array();
1702
1703 $userstatic = new User($db);
1704 $objectstatic = new CommandeFournisseur($db);
1705 $projectstatic = new Project($db);
1706
1707 $i = 0;
1708 $savnbfield = $totalarray['nbfield'];
1709 $totalarray = array('nbfield' => 0, 'val' => array(), 'pos' => array());
1710 $totalarray['val']['cf.total_ht'] = 0;
1711 $totalarray['val']['cf.total_ttc'] = 0;
1712 $totalarray['val']['cf.total_tva'] = 0;
1713
1714 $imaxinloop = ($limit ? min($num, $limit) : $num);
1715 while ($i < $imaxinloop) {
1716 $obj = $db->fetch_object($resql);
1717
1718 $notshippable = 0;
1719 $warning = 0;
1720 $text_info = '';
1721 $text_warning = '';
1722 $nbprod = 0;
1723
1724 $objectstatic->id = $obj->rowid;
1725 $objectstatic->ref = $obj->ref;
1726 $objectstatic->ref_supplier = $obj->ref_supplier;
1727 $objectstatic->socid = $obj->socid;
1728 $objectstatic->total_ht = $obj->total_ht;
1729 $objectstatic->total_tva = $obj->total_tva;
1730 $objectstatic->total_ttc = $obj->total_ttc;
1731 $objectstatic->date_commande = $db->jdate($obj->date_commande);
1732 $objectstatic->delivery_date = $db->jdate($obj->delivery_date);
1733 $objectstatic->note_public = $obj->note_public;
1734 $objectstatic->note_private = $obj->note_private;
1735 $objectstatic->statut = $obj->fk_statut;
1736
1737 if ($mode == 'kanban') {
1738 if ($i == 0) {
1739 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1740 print '<div class="box-flex-container kanban">';
1741 }
1742
1743 $thirdpartytmp->id = $obj->socid;
1744 $thirdpartytmp->name = $obj->name;
1745 $thirdpartytmp->email = $obj->email;
1746 $thirdpartytmp->name_alias = $obj->alias;
1747 $thirdpartytmp->client = $obj->client;
1748 $thirdpartytmp->fournisseur = $obj->fournisseur;
1749 // Output Kanban
1750 print $objectstatic->getKanbanView('', array('thirdparty'=>$thirdpartytmp->getNomUrl('supplier', 0, 0, -1), 'selected' => in_array($objectstatic->id, $arrayofselected)));
1751 if ($i == ($imaxinloop - 1)) {
1752 print '</div>';
1753 print '</td></tr>';
1754 }
1755 } else {
1756 print '<tr class="oddeven">';
1757 // Action column
1758 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1759 print '<td class="nowrap center">';
1760 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1761 $selected = 0;
1762 if (in_array($obj->rowid, $arrayofselected)) {
1763 $selected = 1;
1764 }
1765 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1766 }
1767 print '</td>';
1768 }
1769 // Ref
1770 if (!empty($arrayfields['cf.ref']['checked'])) {
1771 print '<td class="nowrap">';
1772
1773 // Picto + Ref
1774 print $objectstatic->getNomUrl(1, '', 0, -1, 1);
1775 // Other picto tool
1776 $filename = dol_sanitizeFileName($obj->ref);
1777 $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
1778 print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1779
1780 print '</td>'."\n";
1781 if (!$i) {
1782 $totalarray['nbfield']++;
1783 }
1784 }
1785 // Ref Supplier
1786 if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
1787 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>'."\n";
1788 if (!$i) {
1789 $totalarray['nbfield']++;
1790 }
1791 }
1792 // Project
1793 if (!empty($arrayfields['cf.fk_projet']['checked'])) {
1794 $projectstatic->id = $obj->project_id;
1795 $projectstatic->ref = $obj->project_ref;
1796 $projectstatic->title = $obj->project_title;
1797 print '<td>';
1798 if ($obj->project_id > 0) {
1799 print $projectstatic->getNomUrl(1);
1800 }
1801 print '</td>';
1802 if (!$i) {
1803 $totalarray['nbfield']++;
1804 }
1805 }
1806 // Author
1807 $userstatic->id = $obj->fk_user_author;
1808 $userstatic->lastname = $obj->lastname;
1809 $userstatic->firstname = $obj->firstname;
1810 $userstatic->login = $obj->login;
1811 $userstatic->photo = $obj->photo;
1812 $userstatic->email = $obj->user_email;
1813 $userstatic->statut = $obj->user_status;
1814 if (!empty($arrayfields['u.login']['checked'])) {
1815 print '<td class="tdoverflowmax150">';
1816 if ($userstatic->id) {
1817 print $userstatic->getNomUrl(1);
1818 }
1819 print "</td>";
1820 if (!$i) {
1821 $totalarray['nbfield']++;
1822 }
1823 }
1824 // Thirdparty
1825 if (!empty($arrayfields['cf.fk_soc']['checked'])) {
1826 print '<td class="tdoverflowmax150">';
1827 $thirdpartytmp->id = $obj->socid;
1828 $thirdpartytmp->name = $obj->name;
1829 $thirdpartytmp->email = $obj->email;
1830 $thirdpartytmp->name_alias = $obj->alias;
1831 $thirdpartytmp->client = $obj->client;
1832 $thirdpartytmp->fournisseur = $obj->fournisseur;
1833 print $thirdpartytmp->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1834 print '</td>'."\n";
1835 if (!$i) {
1836 $totalarray['nbfield']++;
1837 }
1838 }
1839 // Alias
1840 if (!empty($arrayfields['s.name_alias']['checked'])) {
1841 print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->alias).'">';
1842 print dol_escape_htmltag($obj->alias);
1843 print '</td>'."\n";
1844 if (!$i) {
1845 $totalarray['nbfield']++;
1846 }
1847 }
1848 // Town
1849 if (!empty($arrayfields['s.town']['checked'])) {
1850 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
1851 print dol_escape_htmltag($obj->town);
1852 print '</td>';
1853 if (!$i) {
1854 $totalarray['nbfield']++;
1855 }
1856 }
1857 // Zip
1858 if (!empty($arrayfields['s.zip']['checked'])) {
1859 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
1860 print dol_escape_htmltag($obj->zip);
1861 print '</td>';
1862 if (!$i) {
1863 $totalarray['nbfield']++;
1864 }
1865 }
1866 // State
1867 if (!empty($arrayfields['state.nom']['checked'])) {
1868 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">'.dol_escape_htmltag($obj->state_name)."</td>\n";
1869 if (!$i) {
1870 $totalarray['nbfield']++;
1871 }
1872 }
1873 // Country
1874 if (!empty($arrayfields['country.code_iso']['checked'])) {
1875 print '<td class="center">';
1876 $tmparray = getCountry($obj->fk_pays, 'all');
1877 print $tmparray['label'];
1878 print '</td>';
1879 if (!$i) {
1880 $totalarray['nbfield']++;
1881 }
1882 }
1883 // Type ent
1884 if (!empty($arrayfields['typent.code']['checked'])) {
1885 print '<td class="center">';
1886 if (empty($typenArray)) {
1887 $typenArray = $formcompany->typent_array(1);
1888 }
1889 print $typenArray[$obj->typent_code];
1890 print '</td>';
1891 if (!$i) {
1892 $totalarray['nbfield']++;
1893 }
1894 }
1895
1896 // Order date
1897 if (!empty($arrayfields['cf.date_commande']['checked'])) {
1898 print '<td class="center">';
1899 print dol_print_date($db->jdate($obj->date_commande), 'day');
1900 if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) {
1901 if ($objectstatic->hasDelay()) {
1902 print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1903 }
1904 }
1905 print '</td>';
1906 if (!$i) {
1907 $totalarray['nbfield']++;
1908 }
1909 }
1910 // Plannned date of delivery
1911 if (!empty($arrayfields['cf.date_livraison']['checked'])) {
1912 print '<td class="center">';
1913 print dol_print_date($db->jdate($obj->delivery_date), 'day');
1914 if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) {
1915 if ($objectstatic->hasDelay()) {
1916 print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
1917 }
1918 }
1919 print '</td>';
1920 if (!$i) {
1921 $totalarray['nbfield']++;
1922 }
1923 }
1924 // Amount HT
1925 if (!empty($arrayfields['cf.total_ht']['checked'])) {
1926 print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1927 if (!$i) {
1928 $totalarray['nbfield']++;
1929 }
1930 if (!$i) {
1931 $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht';
1932 }
1933 $totalarray['val']['cf.total_ht'] += $obj->total_ht;
1934 }
1935 // Amount VAT
1936 if (!empty($arrayfields['cf.total_tva']['checked'])) {
1937 print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1938 if (!$i) {
1939 $totalarray['nbfield']++;
1940 }
1941 if (!$i) {
1942 $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva';
1943 }
1944 $totalarray['val']['cf.total_tva'] += $obj->total_tva;
1945 }
1946 // Amount TTC
1947 if (!empty($arrayfields['cf.total_ttc']['checked'])) {
1948 print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1949 if (!$i) {
1950 $totalarray['nbfield']++;
1951 }
1952 if (!$i) {
1953 $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc';
1954 }
1955 $totalarray['val']['cf.total_ttc'] += $obj->total_ttc;
1956 }
1957
1958 // Currency
1959 if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
1960 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1961 if (!$i) {
1962 $totalarray['nbfield']++;
1963 }
1964 }
1965
1966 // Currency rate
1967 if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
1968 print '<td class="nowrap">';
1969 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1970 print "</td>\n";
1971 if (!$i) {
1972 $totalarray['nbfield']++;
1973 }
1974 }
1975 // Amount HT
1976 if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
1977 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1978 if (!$i) {
1979 $totalarray['nbfield']++;
1980 }
1981 }
1982 // Amount VAT
1983 if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
1984 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
1985 if (!$i) {
1986 $totalarray['nbfield']++;
1987 }
1988 }
1989 // Amount TTC
1990 if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
1991 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1992 if (!$i) {
1993 $totalarray['nbfield']++;
1994 }
1995 }
1996
1997 // Extra fields
1998 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1999 // Fields from hook
2000 $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
2001 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
2002 print $hookmanager->resPrint;
2003 // Date creation
2004 if (!empty($arrayfields['cf.date_creation']['checked'])) {
2005 print '<td class="center nowraponall">';
2006 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2007 print '</td>';
2008 if (!$i) {
2009 $totalarray['nbfield']++;
2010 }
2011 }
2012 // Date modification
2013 if (!empty($arrayfields['cf.tms']['checked'])) {
2014 print '<td class="center nowraponall">';
2015 print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
2016 print '</td>';
2017 if (!$i) {
2018 $totalarray['nbfield']++;
2019 }
2020 }
2021 // Billed
2022 if (!empty($arrayfields['cf.billed']['checked'])) {
2023 print '<td class="center">'.yn($obj->billed).'</td>';
2024 if (!$i) {
2025 $totalarray['nbfield']++;
2026 }
2027 }
2028 // Status
2029 if (!empty($arrayfields['cf.fk_statut']['checked'])) {
2030 print '<td class="center nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>';
2031 if (!$i) {
2032 $totalarray['nbfield']++;
2033 }
2034 }
2035
2036 // valid date
2037 if (!empty($arrayfields['cf.date_valid']['checked'])) {
2038 print '<td class="center">';
2039 print dol_print_date($db->jdate($obj->date_valid), 'day');
2040 print '</td>';
2041 if (!$i) {
2042 $totalarray['nbfield']++;
2043 }
2044 }
2045 // approve date
2046 if (!empty($arrayfields['cf.date_approve']['checked'])) {
2047 print '<td class="center">';
2048 print dol_print_date($db->jdate($obj->date_approve), 'day');
2049 print '</td>';
2050 if (!$i) {
2051 $totalarray['nbfield']++;
2052 }
2053 }
2054 // Note public
2055 if (!empty($arrayfields['cf.note_public']['checked'])) {
2056 print '<td class="center">';
2057 print dol_string_nohtmltag($obj->note_public);
2058 print '</td>';
2059 if (!$i) {
2060 $totalarray['nbfield']++;
2061 }
2062 }
2063
2064 // Note private
2065 if (!empty($arrayfields['cf.note_private']['checked'])) {
2066 print '<td class="center">';
2067 print dol_string_nohtmltag($obj->note_private);
2068 print '</td>';
2069 if (!$i) {
2070 $totalarray['nbfield']++;
2071 }
2072 }
2073
2074 // Action column
2075 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2076 print '<td class="nowrap center">';
2077 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2078 $selected = 0;
2079 if (in_array($obj->rowid, $arrayofselected)) {
2080 $selected = 1;
2081 }
2082 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2083 }
2084 print '</td>';
2085 }
2086 if (!$i) {
2087 $totalarray['nbfield']++;
2088 }
2089
2090 print "</tr>\n";
2091
2092 $total += $obj->total_ht;
2093 $subtotal += $obj->total_ht;
2094 }
2095 $i++;
2096 }
2097
2098 // Show total line
2099 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2100
2101 // If no record found
2102 if ($num == 0) {
2103 $colspan = 1;
2104 foreach ($arrayfields as $key => $val) {
2105 if (!empty($val['checked'])) {
2106 $colspan++;
2107 }
2108 }
2109 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2110 }
2111
2112 $db->free($resql);
2113
2114 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2115 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
2116 print $hookmanager->resPrint;
2117
2118 print '</table>'."\n";
2119 print '</div>';
2120
2121 print '</form>'."\n";
2122
2123 $hidegeneratedfilelistifempty = 1;
2124 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2125 $hidegeneratedfilelistifempty = 0;
2126 }
2127
2128 // Show list of available documents
2129 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2130 $urlsource .= str_replace('&amp;', '&', $param);
2131
2132 $filedir = $diroutputmassaction;
2133 $genallowed = $permissiontoread;
2134 $delallowed = $permissiontoadd;
2135
2136 print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2137} else {
2138 dol_print_error($db);
2139}
2140
2141// End of page
2142llxFooter();
2143$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.