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