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