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