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