dolibarr 21.0.0-beta
list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
8 * Copyright (C) 2013 Cédric Salvado <csalvador@gpcsolutions.fr>
9 * Copyright (C) 2015-2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
11 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
12 * Copyright (C) 2016-2023 Ferran Marcet <fmarcet@2byte.es>
13 * Copyright (C) 2018-2023 Charlene Benke <charlene@patas-monkey.com>
14 * Copyright (C) 2021-2024 Anthony Berton <anthony.berton@bb2a.fr>
15 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
16 * Copyright (C) 2024 Noé Cendrier <noe.cendrier@altairis.fr>
17 * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
18 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
19 * Copyright (C) 2024 William Mead <william.mead@manchenumerique.fr>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 3 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program. If not, see <https://www.gnu.org/licenses/>.
33 */
34
42// Load Dolibarr environment
43require '../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
49require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
50if (isModEnabled('margin')) {
51 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
52}
53require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
54require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
55require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
56require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
57
66// Load translation files required by the page
67$langs->loadLangs(array('orders', 'sendings', 'deliveries', 'companies', 'compta', 'bills', 'stocks', 'products'));
68
69// Get Parameters
70$action = GETPOST('action', 'aZ09');
71$massaction = GETPOST('massaction', 'alpha');
72$show_files = GETPOSTINT('show_files');
73$confirm = GETPOST('confirm', 'alpha');
74$toselect = GETPOST('toselect', 'array');
75$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'orderlist';
76$optioncss = GETPOST('optioncss', 'alpha');
77$mode = GETPOST('mode', 'alpha');
78
79if (getDolGlobalInt('MAIN_SEE_SUBORDINATES')) {
80 $userschilds = $user->getAllChildIds();
81} else {
82 $userschilds = array();
83}
84
85// Search Parameters
86$search_datecloture_start = GETPOSTINT('search_datecloture_start');
87if (empty($search_datecloture_start)) {
88 $search_datecloture_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datecloture_startmonth'), GETPOSTINT('search_datecloture_startday'), GETPOSTINT('search_datecloture_startyear'));
89}
90$search_datecloture_end = GETPOSTINT('search_datecloture_end');
91if (empty($search_datecloture_end)) {
92 $search_datecloture_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datecloture_endmonth'), GETPOSTINT('search_datecloture_endday'), GETPOSTINT('search_datecloture_endyear'));
93}
94$search_dateorder_start = dol_mktime(0, 0, 0, GETPOSTINT('search_dateorder_start_month'), GETPOSTINT('search_dateorder_start_day'), GETPOSTINT('search_dateorder_start_year'));
95$search_dateorder_end = dol_mktime(23, 59, 59, GETPOSTINT('search_dateorder_end_month'), GETPOSTINT('search_dateorder_end_day'), GETPOSTINT('search_dateorder_end_year'));
96$search_datedelivery_start = dol_mktime(0, 0, 0, GETPOSTINT('search_datedelivery_start_month'), GETPOSTINT('search_datedelivery_start_day'), GETPOSTINT('search_datedelivery_start_year'));
97$search_datedelivery_end = dol_mktime(23, 59, 59, GETPOSTINT('search_datedelivery_end_month'), GETPOSTINT('search_datedelivery_end_day'), GETPOSTINT('search_datedelivery_end_year'));
98
99$socid = GETPOSTINT('socid');
100
101$search_all = trim(GETPOST('search_all', 'alphanohtml'));
102$search_product_category = GETPOST('search_product_category', 'intcomma');
103$search_id = GETPOST('search_id', 'int');
104$search_ref = GETPOST('search_ref', 'alpha') != '' ? GETPOST('search_ref', 'alpha') : GETPOST('sref', 'alpha');
105$search_ref_customer = GETPOST('search_ref_customer', 'alpha');
106$search_company = GETPOST('search_company', 'alpha');
107$search_company_alias = GETPOST('search_company_alias', 'alpha');
108$search_parent_name = trim(GETPOST('search_parent_name', 'alphanohtml'));
109$search_town = GETPOST('search_town', 'alpha');
110$search_zip = GETPOST('search_zip', 'alpha');
111$search_state = GETPOST('search_state', 'alpha');
112$search_country = GETPOST('search_country', 'aZ09');
113$search_type_thirdparty = GETPOST('search_type_thirdparty', 'intcomma');
114$search_user = GETPOST('search_user', 'intcomma');
115$search_sale = GETPOST('search_sale', 'intcomma');
116$search_total_ht = GETPOST('search_total_ht', 'alpha');
117$search_total_vat = GETPOST('search_total_vat', 'alpha');
118$search_total_ttc = GETPOST('search_total_ttc', 'alpha');
119$search_warehouse = GETPOST('search_warehouse', 'intcomma');
120
121$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
122$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
123$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
124$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
125$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
126
127$search_login = GETPOST('search_login', 'alpha');
128$search_categ_cus = GETPOST("search_categ_cus", 'intcomma');
129$search_billed = GETPOST('search_billed', 'intcomma');
130$search_status = GETPOST('search_status', 'intcomma');
131$search_project_ref = GETPOST('search_project_ref', 'alpha');
132$search_project = GETPOST('search_project', 'alpha');
133$search_shippable = GETPOST('search_shippable', 'aZ09');
134
135$search_fk_cond_reglement = GETPOST('search_fk_cond_reglement', 'intcomma');
136$search_fk_shipping_method = GETPOST('search_fk_shipping_method', 'intcomma');
137$search_fk_mode_reglement = GETPOST('search_fk_mode_reglement', 'intcomma');
138$search_fk_input_reason = GETPOST('search_fk_input_reason', 'intcomma');
139
140$search_option = GETPOST('search_option', 'alpha');
141if ($search_option == 'late') {
142 $search_status = '-2';
143}
144$search_orderday = '';
145$search_ordermonth = '';
146$search_orderyear = '';
147$search_deliveryday = '';
148$search_deliverymonth = '';
149$search_deliveryyear = '';
150
151$search_import_key = trim(GETPOST("search_import_key", "alpha"));
152
153$diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
154
155// Load variable for pagination
156$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
157$sortfield = GETPOST('sortfield', 'aZ09comma');
158$sortorder = GETPOST('sortorder', 'aZ09comma');
159$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
160if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
161 // If $page is not defined, or '' or -1 or if we click on clear filters
162 $page = 0;
163}
164$offset = $limit * $page;
165$pageprev = $page - 1;
166$pagenext = $page + 1;
167if (!$sortfield) {
168 $sortfield = 'c.ref';
169}
170if (!$sortorder) {
171 $sortorder = 'DESC';
172}
173
174$show_shippable_command = GETPOST('show_shippable_command', 'aZ09');
175
176// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
177$object = new Commande($db);
178$hookmanager->initHooks(array('orderlist'));
179$extrafields = new ExtraFields($db);
180
181// fetch optionals attributes and labels
182$extrafields->fetch_name_optionals_label($object->table_element);
183$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
184
185// List of fields to search into when doing a "search in all"
186$fieldstosearchall = array(
187 'c.ref' => 'Ref',
188 'c.ref_client' => 'RefCustomerOrder',
189 'pd.description' => 'Description',
190 's.nom' => "ThirdParty",
191 's.name_alias' => "AliasNameShort",
192 's.zip' => "Zip",
193 's.town' => "Town",
194 'c.note_public' => 'NotePublic',
195);
196if (empty($user->socid)) {
197 $fieldstosearchall["c.note_private"] = "NotePrivate";
198}
199
200$checkedtypetiers = 0;
201$arrayfields = array(
202 'c.rowid' => array('label' => "ID", 'checked' => 1, 'enabled' => getDolGlobalInt('MAIN_SHOW_TECHNICAL_ID'), 'position' => 1),
203 'c.ref' => array('label' => "Ref", 'checked' => 1, 'position' => 5, 'searchall' => 1),
204 'c.ref_client' => array('label' => "RefCustomerOrder", 'checked' => -1, 'position' => 10, 'searchall' => 1),
205 'p.ref' => array('label' => "ProjectRef", 'checked' => -1, 'enabled' => (!isModEnabled('project') ? 0 : 1), 'position' => 20),
206 'p.title' => array('label' => "ProjectLabel", 'checked' => 0, 'enabled' => (!isModEnabled('project') ? 0 : 1), 'position' => 25),
207 's.nom' => array('label' => "ThirdParty", 'checked' => 1, 'position' => 30, 'searchall' => 1),
208 's.name_alias' => array('label' => "AliasNameShort", 'checked' => -1, 'position' => 31, 'searchall' => 1),
209 's2.nom' => array('label' => 'ParentCompany', 'position' => 32, 'checked' => 0),
210 's.town' => array('label' => "Town", 'checked' => -1, 'position' => 35, 'searchall' => 1),
211 's.zip' => array('label' => "Zip", 'checked' => -1, 'position' => 40, 'searchall' => 1),
212 'state.nom' => array('label' => "StateShort", 'checked' => 0, 'position' => 45),
213 'country.code_iso' => array('label' => "Country", 'checked' => 0, 'position' => 50),
214 'typent.code' => array('label' => "ThirdPartyType", 'checked' => $checkedtypetiers, 'position' => 55),
215 'c.date_commande' => array('label' => "OrderDateShort", 'checked' => 1, 'position' => 60, 'csslist' => 'nowraponall'),
216 'c.date_delivery' => array('label' => "DateDeliveryPlanned", 'checked' => 1, 'enabled' => !getDolGlobalString('ORDER_DISABLE_DELIVERY_DATE'), 'position' => 65, 'csslist' => 'nowraponall'),
217 'c.fk_shipping_method' => array('label' => "SendingMethod", 'checked' => -1, 'position' => 66 , 'enabled' => isModEnabled("shipping")),
218 'c.fk_cond_reglement' => array('label' => "PaymentConditionsShort", 'checked' => -1, 'position' => 67),
219 'c.fk_mode_reglement' => array('label' => "PaymentMode", 'checked' => -1, 'position' => 68),
220 'c.fk_input_reason' => array('label' => "Origin", 'checked' => -1, 'position' => 69),
221 'c.total_ht' => array('label' => "AmountHT", 'checked' => 1, 'position' => 75),
222 'c.total_vat' => array('label' => "AmountVAT", 'checked' => 0, 'position' => 80),
223 'c.total_ttc' => array('label' => "AmountTTC", 'checked' => 0, 'position' => 85),
224 'c.multicurrency_code' => array('label' => 'Currency', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 90),
225 'c.multicurrency_tx' => array('label' => 'CurrencyRate', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 95),
226 'c.multicurrency_total_ht' => array('label' => 'MulticurrencyAmountHT', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 100),
227 'c.multicurrency_total_vat' => array('label' => 'MulticurrencyAmountVAT', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 105),
228 'c.multicurrency_total_ttc' => array('label' => 'MulticurrencyAmountTTC', 'checked' => 0, 'enabled' => (!isModEnabled("multicurrency") ? 0 : 1), 'position' => 110),
229 'u.login' => array('label' => "Author", 'checked' => -1, 'position' => 115),
230 'sale_representative' => array('label' => "SaleRepresentativesOfThirdParty", 'checked' => 0, 'position' => 116),
231 'total_pa' => array('label' => (getDolGlobalString('MARGIN_TYPE') == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") ? 0 : 1)),
232 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") ? 0 : 1)),
233 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") || !getDolGlobalString('DISPLAY_MARGIN_RATES') ? 0 : 1)),
234 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (!isModEnabled('margin') || !$user->hasRight("margins", "liretous") || !getDolGlobalString('DISPLAY_MARK_RATES') ? 0 : 1)),
235 'c.datec' => array('label' => "DateCreation", 'checked' => 0, 'position' => 120),
236 'c.tms' => array('label' => "DateModificationShort", 'checked' => 0, 'position' => 125),
237 'c.date_cloture' => array('label' => "DateClosing", 'checked' => 0, 'position' => 130),
238 'c.note_public' => array('label' => 'NotePublic', 'checked' => 0, 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES')), 'position' => 135, 'searchall' => 1),
239 'c.note_private' => array('label' => 'NotePrivate', 'checked' => 0, 'enabled' => (!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'position' => 140),
240 'shippable' => array('label' => "Shippable", 'checked' => 1,'enabled' => (isModEnabled("shipping")), 'position' => 990),
241 'c.facture' => array('label' => "Billed", 'checked' => 1, 'enabled' => (!getDolGlobalString('WORKFLOW_BILL_ON_SHIPMENT')), 'position' => 995),
242 'c.import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 999),
243 'c.fk_statut' => array('label' => "Status", 'checked' => 1, 'position' => 1000)
244);
245
246$parameters = array('fieldstosearchall' => $fieldstosearchall);
247$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
248if ($reshook > 0) {
249 $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
250} elseif ($reshook == 0) {
251 $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
252}
253
254// Extra fields
255include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
256
257$object->fields = dol_sort_array($object->fields, 'position');
258//$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
259$arrayfields = dol_sort_array($arrayfields, 'position');
260'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
261
262
263// Security check
264$id = GETPOSTINT('orderid', GETPOSTINT('id'));
265if ($user->socid) {
266 $socid = $user->socid;
267}
268
269$permissiontoreadallthirdparty = $user->hasRight('societe', 'client', 'voir');
270$permissiontoread = false;
271$permissiontovalidate = false;
272$permissiontoclose = false;
273$permissiontocancel = false;
274$permissiontosendbymail = false;
275$objectclass = null;
276
277
278$result = restrictedArea($user, 'commande', $id, '');
279
280$error = 0;
281
282
283/*
284 * Actions
285 */
286
287if (GETPOST('cancel', 'alpha')) {
288 $action = 'list';
289 $massaction = '';
290}
291if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') {
292 $massaction = '';
293}
294
295$parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
296$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
297if ($reshook < 0) {
298 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
299}
300
301if (empty($reshook)) {
302 // Selection of new fields
303 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
304
305 // Purge search criteria
306 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
307 $search_user = '';
308 $search_sale = '';
309 $search_product_category = '';
310 $search_id = '';
311 $search_ref = '';
312 $search_ref_customer = '';
313 $search_company = '';
314 $search_company_alias = '';
315 $search_parent_name = '';
316 $search_town = '';
317 $search_zip = "";
318 $search_state = "";
319 $search_type = '';
320 $search_country = '';
321 $search_type_thirdparty = '';
322 $search_total_ht = '';
323 $search_total_vat = '';
324 $search_total_ttc = '';
325 $search_warehouse = '';
326 $search_multicurrency_code = '';
327 $search_multicurrency_tx = '';
328 $search_multicurrency_montant_ht = '';
329 $search_multicurrency_montant_vat = '';
330 $search_multicurrency_montant_ttc = '';
331 $search_login = '';
332 $search_dateorder_start = '';
333 $search_dateorder_end = '';
334 $search_datedelivery_start = '';
335 $search_datedelivery_end = '';
336 $search_project_ref = '';
337 $search_project = '';
338 $search_status = '';
339 $search_billed = '';
340 $search_datecloture_start = '';
341 $search_datecloture_end = '';
342 $search_fk_cond_reglement = '';
343 $search_fk_shipping_method = '';
344 $search_fk_mode_reglement = '';
345 $search_fk_input_reason = '';
346 $search_option = '';
347 $search_import_key = '';
348 $search_categ_cus = 0;
349
350 $search_all = '';
351 $toselect = array();
352 $search_array_options = array();
353 }
354 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
355 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
356 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
357 }
358
359 // Mass actions
360 $objectclass = 'Commande';
361 $objectlabel = 'Orders';
362 $permissiontoread = $user->hasRight("commande", "lire");
363 $permissiontoadd = $user->hasRight("commande", "creer");
364 $permissiontodelete = $user->hasRight("commande", "supprimer");
365 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
366 $permissiontovalidate = $user->hasRight("commande", "order_advance", "validate");
367 $permissiontoclose = $user->hasRight("commande", "order_advance", "close");
368 $permissiontocancel = $user->hasRight("commande", "order_advance", "annuler");
369 $permissiontosendbymail = $user->hasRight("commande", "order_advance", "send");
370 } else {
371 $permissiontovalidate = $user->hasRight("commande", "creer");
372 $permissiontoclose = $user->hasRight("commande", "creer");
373 $permissiontocancel = $user->hasRight("commande", "creer");
374 $permissiontosendbymail = $user->hasRight("commande", "creer");
375 }
376 $uploaddir = $conf->commande->multidir_output[$conf->entity];
377 $triggersendname = 'ORDER_SENTBYMAIL';
378 $year = "";
379 $month = "";
380 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
381
382 if ($massaction == 'confirm_createbills') { // Create bills from orders.
383 $orders = GETPOST('toselect', 'array');
384 $createbills_onebythird = GETPOSTINT('createbills_onebythird');
385 $validate_invoices = GETPOSTINT('validate_invoices');
386
387 $errors = array();
388
389 $TFact = array();
390 $TFactThird = array();
391 $TFactThirdNbLines = array();
392
393 $nb_bills_created = 0;
394 $lastid = 0;
395 $lastref = '';
396
397 $db->begin();
398
399 $nbOrders = is_array($orders) ? count($orders) : 1;
400
401 $currentIndex = 0;
402 foreach ($orders as $id_order) {
403 $cmd = new Commande($db);
404 if ($cmd->fetch($id_order) <= 0) {
405 continue;
406 }
407 $cmd->fetch_thirdparty();
408
409 $objecttmp = new Facture($db);
410 if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
411 // If option "one bill per third" is set, and an invoice for this thirdparty was already created, we reuse it.
412 $currentIndex++;
413 $objecttmp = $TFactThird[$cmd->socid];
414 } else {
415 // If we want one invoice per order or if there is no first invoice yet for this thirdparty.
416 $objecttmp->socid = $cmd->socid;
417 $objecttmp->thirdparty = $cmd->thirdparty;
418
419 $objecttmp->type = $objecttmp::TYPE_STANDARD;
420 $objecttmp->cond_reglement_id = !empty($cmd->cond_reglement_id) ? $cmd->cond_reglement_id : $cmd->thirdparty->cond_reglement_id;
421 $objecttmp->mode_reglement_id = !empty($cmd->mode_reglement_id) ? $cmd->mode_reglement_id : $cmd->thirdparty->mode_reglement_id;
422
423 $objecttmp->fk_project = $cmd->fk_project;
424 $objecttmp->multicurrency_code = $cmd->multicurrency_code;
425 if (empty($createbills_onebythird)) {
426 $objecttmp->ref_client = $cmd->ref_client;
427 }
428
429 if (empty($objecttmp->note_public)) {
430 $objecttmp->note_public = $langs->transnoentities("Orders");
431 }
432
433 $datefacture = dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear'));
434 if (empty($datefacture)) {
435 $datefacture = dol_now();
436 }
437
438 $objecttmp->date = $datefacture;
439 $objecttmp->origin = 'commande';
440 $objecttmp->origin_id = $id_order;
441
442 $objecttmp->array_options = $cmd->array_options; // Copy extrafields
443
444 $res = $objecttmp->create($user);
445
446 if ($res > 0) {
447 $nb_bills_created++;
448 $lastref = $objecttmp->ref;
449 $lastid = $objecttmp->id;
450
451 $TFactThird[$cmd->socid] = $objecttmp;
452 $TFactThirdNbLines[$cmd->socid] = 0; //init nblines to have lines ordered by expedition and rang
453 } else {
454 $langs->load("errors");
455 $errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->errors[0]);
456 $error++;
457 }
458 }
459
460 if ($objecttmp->id > 0) {
461 $res = $objecttmp->add_object_linked($objecttmp->origin, $id_order);
462
463 if ($res == 0) {
464 $errors[] = $cmd->ref.' : '.$langs->trans($objecttmp->errors[0]);
465 $error++;
466 }
467
468 if (!$error) {
469 $lines = $cmd->lines;
470 if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
471 $cmd->fetch_lines();
472 $lines = $cmd->lines;
473 }
474
475 $fk_parent_line = 0;
476 $num = count($lines);
477 $array_options = array();
478
479 for ($i = 0; $i < $num; $i++) {
480 $desc = ($lines[$i]->desc ? $lines[$i]->desc : '');
481 // If we build one invoice for several orders, we must put the ref of order on the invoice line
482 if (!empty($createbills_onebythird)) {
483 $desc = dol_concatdesc($desc, $langs->trans("Order").' '.$cmd->ref.' - '.dol_print_date($cmd->date, 'day'));
484 }
485
486 if ($lines[$i]->subprice < 0 && !getDolGlobalString('INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN')) {
487 // Negative line, we create a discount line
488 $discount = new DiscountAbsolute($db);
489 $discount->fk_soc = $objecttmp->socid;
490 $discount->socid = $objecttmp->socid;
491 $discount->amount_ht = abs($lines[$i]->total_ht);
492 $discount->amount_tva = abs($lines[$i]->total_tva);
493 $discount->amount_ttc = abs($lines[$i]->total_ttc);
494 $discount->tva_tx = $lines[$i]->tva_tx;
495 $discount->fk_user = $user->id;
496 $discount->description = $desc;
497 $discountid = $discount->create($user);
498 if ($discountid > 0) {
499 $result = $objecttmp->insert_discount($discountid);
500 //$result=$discount->link_to_invoice($lineid,$id);
501 } else {
502 setEventMessages($discount->error, $discount->errors, 'errors');
503 $error++;
504 break;
505 }
506 } else {
507 // Positive line
508 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
509 // Date start
510 $date_start = false;
511 if ($lines[$i]->date_debut_prevue) {
512 $date_start = $lines[$i]->date_debut_prevue;
513 }
514 if ($lines[$i]->date_debut_reel) {
515 $date_start = $lines[$i]->date_debut_reel;
516 }
517 if ($lines[$i]->date_start) {
518 $date_start = $lines[$i]->date_start;
519 }
520 //Date end
521 $date_end = false;
522 if ($lines[$i]->date_fin_prevue) {
523 $date_end = $lines[$i]->date_fin_prevue;
524 }
525 if ($lines[$i]->date_fin_reel) {
526 $date_end = $lines[$i]->date_fin_reel;
527 }
528 if ($lines[$i]->date_end) {
529 $date_end = $lines[$i]->date_end;
530 }
531 // Reset fk_parent_line for no child products and special product
532 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
533 $fk_parent_line = 0;
534 }
535
536 // Extrafields
537 if (method_exists($lines[$i], 'fetch_optionals')) {
538 $lines[$i]->fetch_optionals();
539 $array_options = $lines[$i]->array_options;
540 }
541
542 $objecttmp->context['createfromclone'] = 'createfromclone';
543
544 $rang = ($nbOrders > 1) ? -1 : $lines[$i]->rang;
545 //there may already be rows from previous orders
546 if (!empty($createbills_onebythird)) {
547 $TFactThirdNbLines[$cmd->socid]++;
548 $rang = $TFactThirdNbLines[$cmd->socid];
549 }
550
551 $result = $objecttmp->addline(
552 $desc,
553 $lines[$i]->subprice,
554 $lines[$i]->qty,
555 $lines[$i]->tva_tx,
556 $lines[$i]->localtax1_tx,
557 $lines[$i]->localtax2_tx,
558 $lines[$i]->fk_product,
559 $lines[$i]->remise_percent,
560 $date_start,
561 $date_end,
562 0,
563 $lines[$i]->info_bits,
564 $lines[$i]->fk_remise_except,
565 'HT',
566 0,
567 $product_type,
568 $rang,
569 $lines[$i]->special_code,
570 $objecttmp->origin,
571 $lines[$i]->rowid,
572 $fk_parent_line,
573 $lines[$i]->fk_fournprice,
574 $lines[$i]->pa_ht,
575 $lines[$i]->label,
576 $array_options,
577 100,
578 0,
579 $lines[$i]->fk_unit
580 );
581 if ($result > 0) {
582 $lineid = $result;
583 } else {
584 $lineid = 0;
585 $error++;
586 $errors[] = $objecttmp->error;
587 break;
588 }
589 // Defined the new fk_parent_line
590 if ($result > 0 && $lines[$i]->product_type == 9) {
591 $fk_parent_line = $result;
592 }
593 }
594 }
595 }
596 }
597
598 if ($currentIndex <= (getDolGlobalInt("MAXREFONDOC") ? getDolGlobalInt("MAXREFONDOC") : 10)) {
599 $objecttmp->note_public = dol_concatdesc($objecttmp->note_public, $langs->transnoentities($cmd->ref).(empty($cmd->ref_client) ? '' : ' ('.$cmd->ref_client.')'));
600 $objecttmp->update($user);
601 }
602
603 //$cmd->classifyBilled($user); // Disabled. This behavior must be set or not using the workflow module.
604
605 if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
606 $TFactThird[$cmd->socid] = $objecttmp;
607 } else {
608 $TFact[$objecttmp->id] = $objecttmp;
609 }
610 }
611
612 // Build doc with all invoices
613 $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
614 $toselect = array();
615
616 if (!$error && $validate_invoices) {
617 $massaction = $action = 'builddoc';
618
619 foreach ($TAllFact as &$objecttmp) {
620 $result = $objecttmp->validate($user);
621 if ($result <= 0) {
622 $error++;
623 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
624 break;
625 }
626
627 $id = $objecttmp->id; // For builddoc action
628
629 // Builddoc
630 $donotredirect = 1;
631 $upload_dir = $conf->facture->dir_output;
632 $permissiontoadd = $user->hasRight('facture', 'creer');
633
634 // Call action to build doc
635 $savobject = $object;
636 $object = $objecttmp;
637 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
638 $object = $savobject;
639 }
640
641 $massaction = $action = 'confirm_createbills';
642 }
643
644 if (!$error) {
645 $db->commit();
646
647 if ($nb_bills_created == 1) {
648 if (getDolGlobalInt('MAIN_MASSACTION_CREATEBILLS_REDIRECT_IF_ONE') == 1) {
649 // Redirect to generated invoice if unique
650 header('Location: '.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode((string) $lastid));
651 exit;
652 }
653 $texttoshow = $langs->trans('BillXCreated', '{s1}');
654 $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?id='.urlencode((string) ($lastid)).'">'.$lastref.'</a>', $texttoshow);
655 setEventMessages($texttoshow, null, 'mesgs');
656 } else {
657 if (getDolGlobalInt('MAIN_MASSACTION_CREATEBILLS_REDIRECT_IF_MANY') == 1) {
658 // Redirect to invoice list
659 header("Location: ".DOL_URL_ROOT.'/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills');
660 exit;
661 }
662 setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
663 }
664
665 // Make a redirect to avoid to bill twice if we make a refresh or back
666 $param = '';
667 if (!empty($mode)) {
668 $param .= '&mode='.urlencode($mode);
669 }
670 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
671 $param .= '&contextpage='.urlencode($contextpage);
672 }
673 if ($limit > 0 && $limit != $conf->liste_limit) {
674 $param .= '&limit='.((int) $limit);
675 }
676 if ($optioncss != '') {
677 $param .= '&optioncss='.urlencode($optioncss);
678 }
679 if ($search_all) {
680 $param .= '&search_all='.urlencode($search_all);
681 }
682 if ($show_files) {
683 $param .= '&show_files='.urlencode((string) ($show_files));
684 }
685 if ($socid > 0) {
686 $param .= '&socid='.urlencode((string) ($socid));
687 }
688 if ($search_status != '') {
689 $param .= '&search_status='.urlencode($search_status);
690 }
691 if ($search_option) {
692 $param .= "&search_option=".urlencode($search_option);
693 }
694 if ($search_orderday) {
695 $param .= '&search_orderday='.urlencode($search_orderday);
696 }
697 if ($search_ordermonth) {
698 $param .= '&search_ordermonth='.urlencode($search_ordermonth);
699 }
700 if ($search_orderyear) {
701 $param .= '&search_orderyear='.urlencode($search_orderyear);
702 }
703 if ($search_deliveryday) {
704 $param .= '&search_deliveryday='.urlencode($search_deliveryday);
705 }
706 if ($search_deliverymonth) {
707 $param .= '&search_deliverymonth='.urlencode($search_deliverymonth);
708 }
709 if ($search_deliveryyear) {
710 $param .= '&search_deliveryyear='.urlencode($search_deliveryyear);
711 }
712 if ($search_id) {
713 $param .= '&search_id='.urlencode((string) $search_id);
714 }
715 if ($search_ref) {
716 $param .= '&search_ref='.urlencode($search_ref);
717 }
718 if ($search_company) {
719 $param .= '&search_company='.urlencode($search_company);
720 }
721 if ($search_ref_customer) {
722 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
723 }
724 if ($search_user > 0) {
725 $param .= '&search_user='.urlencode((string) ($search_user));
726 }
727 if ($search_sale > 0) {
728 $param .= '&search_sale='.urlencode((string) ($search_sale));
729 }
730 if ($search_total_ht != '') {
731 $param .= '&search_total_ht='.urlencode($search_total_ht);
732 }
733 if ($search_total_vat != '') {
734 $param .= '&search_total_vat='.urlencode($search_total_vat);
735 }
736 if ($search_total_ttc != '') {
737 $param .= '&search_total_ttc='.urlencode($search_total_ttc);
738 }
739 if ($search_project_ref >= 0) {
740 $param .= "&search_project_ref=".urlencode($search_project_ref);
741 }
742 if ($search_billed != '') {
743 $param .= '&search_billed='.urlencode($search_billed);
744 }
745
746 header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
747 exit;
748 } else {
749 $db->rollback();
750
751 $action = 'create';
752 $_GET["origin"] = $_POST["origin"]; // Keep GET and POST here ?
753 $_GET["originid"] = $_POST["originid"]; // Keep GET and POST here ?
754 if (!empty($errors)) {
755 setEventMessages(null, $errors, 'errors');
756 } else {
757 setEventMessages("Error", null, 'errors');
758 }
759 $error++;
760 }
761 }
762}
763if ($action == 'validate' && $permissiontoadd && $objectclass !== null) {
764 if (GETPOST('confirm') == 'yes') {
765 $objecttmp = new $objectclass($db);
766 $db->begin();
767 $error = 0;
768 foreach ($toselect as $checked) {
769 if ($objecttmp->fetch($checked)) {
770 if ($objecttmp->statut == 0) {
771 if (!empty($objecttmp->fk_warehouse)) {
772 $idwarehouse = $objecttmp->fk_warehouse;
773 } else {
774 $idwarehouse = 0;
775 }
776 if ($objecttmp->valid($user, $idwarehouse)) {
777 setEventMessages($langs->trans('hasBeenValidated', $objecttmp->ref), null, 'mesgs');
778 } else {
779 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
780 $error++;
781 }
782 } else {
783 $langs->load("errors");
784 setEventMessages($langs->trans('ErrorIsNotADraft', $objecttmp->ref), null, 'errors');
785 $error++;
786 }
787 } else {
788 dol_print_error($db);
789 $error++;
790 }
791 }
792 if ($error) {
793 $db->rollback();
794 } else {
795 $db->commit();
796 }
797 }
798}
799if ($action == 'shipped' && $permissiontoadd && $objectclass !== null) {
800 if (GETPOST('confirm') == 'yes') {
801 $objecttmp = new $objectclass($db);
802 $db->begin();
803 $error = 0;
804 foreach ($toselect as $checked) {
805 if ($objecttmp->fetch($checked)) {
806 if ($objecttmp->statut == 1 || $objecttmp->statut == 2) {
807 if ($objecttmp->cloture($user)) {
808 setEventMessages($langs->trans('StatusOrderDelivered', $objecttmp->ref), null, 'mesgs');
809 } else {
810 setEventMessages($langs->trans('ErrorOrderStatusCantBeSetToDelivered'), null, 'errors');
811 $error++;
812 }
813 } else {
814 $langs->load("errors");
815 setEventMessages($langs->trans('ErrorIsNotADraft', $objecttmp->ref), null, 'errors');
816 $error++;
817 }
818 } else {
819 dol_print_error($db);
820 $error++;
821 }
822 }
823 if ($error) {
824 $db->rollback();
825 } else {
826 $db->commit();
827 }
828 }
829}
830
831// Closed records
832if (!$error && $massaction === 'setbilled' && $permissiontoclose && $objectclass !== null) {
833 $db->begin();
834
835 $objecttmp = new $objectclass($db);
836 $nbok = 0;
837 foreach ($toselect as $toselectid) {
838 $result = $objecttmp->fetch($toselectid);
839 if ($result > 0) {
840 $result = $objecttmp->classifyBilled($user, 0);
841 if ($result <= 0) {
842 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
843 $error++;
844 break;
845 } else {
846 $nbok++;
847 }
848 } else {
849 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
850 $error++;
851 break;
852 }
853 }
854
855 if (!$error) {
856 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
857 $db->commit();
858 } else {
859 $db->rollback();
860 }
861}
862
863
864/*
865 * View
866 */
867
868$form = new Form($db);
869$formother = new FormOther($db);
870$formfile = new FormFile($db);
871$formmargin = null;
872if (isModEnabled('margin')) {
873 $formmargin = new FormMargin($db);
874}
875$companystatic = new Societe($db);
876$company_url_list = array();
877$formcompany = new FormCompany($db);
878$projectstatic = new Project($db);
879
880$now = dol_now();
881
882$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
883$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
884
885$title = $langs->trans("Orders");
886$help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
887
888// Build and execute select
889// --------------------------------------------------------------------
890$sql = 'SELECT';
891if ($search_all) {
892 $sql = 'SELECT DISTINCT';
893}
894$sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client,';
895$sql .= " s.parent as fk_parent,";
896$sql .= " s2.nom as name2,";
897$sql .= " typent.code as typent_code,";
898$sql .= " state.code_departement as state_code, state.nom as state_name,";
899$sql .= " country.code as country_code,";
900$sql .= ' c.rowid, c.ref, c.total_ht, c.total_tva, c.total_ttc, c.ref_client, c.fk_user_author,';
901$sql .= ' c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva as multicurrency_total_vat, c.multicurrency_total_ttc,';
902$sql .= ' c.date_valid, c.date_commande, c.note_public, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as billed,';
903$sql .= ' c.date_creation as date_creation, c.tms as date_modification, c.date_cloture as date_cloture,';
904$sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
905$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender,';
906$sql .= ' c.fk_cond_reglement,c.deposit_percent,c.fk_mode_reglement,c.fk_shipping_method,';
907$sql .= ' c.fk_input_reason, c.import_key';
908
909// Add fields from extrafields
910if (!empty($extrafields->attributes[$object->table_element]['label'])) {
911 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
912 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
913 }
914}
915
916// Add fields from hooks
917$parameters = array();
918$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
919$sql .= $hookmanager->resPrint;
920$sql = preg_replace('/,\s*$/', '', $sql);
921
922$sqlfields = $sql; // $sql fields to remove for count total
923
924$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
925$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s2.rowid = s.parent";
926$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
927$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
928$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
929$sql .= ', '.MAIN_DB_PREFIX.'commande as c';
930if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
931 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
932}
933if ($search_all) {
934 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
935}
936$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
937$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid';
938// Add table from hooks
939$parameters = array();
940$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
941$sql .= $hookmanager->resPrint;
942
943$sql .= ' WHERE c.fk_soc = s.rowid';
944$sql .= ' AND c.entity IN ('.getEntity('commande').')';
945if ($socid > 0) {
946 $sql .= ' AND s.rowid = '.((int) $socid);
947}
948
949// Restriction on sale representative
950if (!$permissiontoreadallthirdparty) {
951 $sql .= " AND (EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $user->id).")";
952 if (getDolGlobalInt('MAIN_SEE_SUBORDINATES') && $userschilds) {
953 $sql .= " OR EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user IN (".$db->sanitize(implode(',', $userschilds))."))";
954 }
955 $sql .= ")";
956}
957
958if ($search_id > 0) {
959 $sql .= natural_search('c.rowid', $search_id);
960}
961if ($search_ref) {
962 $sql .= natural_search('c.ref', $search_ref);
963}
964if ($search_ref_customer) {
965 $sql .= natural_search('c.ref_client', $search_ref_customer);
966}
967if ($search_all) {
968 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
969}
970if ($search_billed != '' && $search_billed >= 0) {
971 $sql .= ' AND c.facture = '.((int) $search_billed);
972}
973if ($search_status != '') {
974 if ($search_status <= 3 && $search_status >= -1) { // status from -1 to 3 are real status (other are virtual combination)
975 if ($search_status == 1 && !isModEnabled('shipping')) {
976 $sql .= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status "sent" into "validated"
977 } else {
978 $sql .= ' AND c.fk_statut = '.((int) $search_status); // draft, validated, in process or canceled
979 }
980 }
981 if ($search_status == -2) { // "validated + in progress"
982 //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
983 $sql .= " AND (c.fk_statut IN (1,2))";
984 }
985 if ($search_status == -3) { // "validated + in progress + shipped"
986 //$sql.= ' AND c.fk_statut in (1,2,3)';
987 //$sql.= ' AND c.facture = 0'; // invoice not created
988 $sql .= ' AND (c.fk_statut IN (1,2,3))'; // validated, in process or closed
989 }
990}
991if ($search_option == 'late') {
992 $sql .= " AND c.date_commande < '".$db->idate(dol_now() - $conf->commande->client->warning_delay)."'";
993}
994if ($search_datecloture_start) {
995 $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
996}
997if ($search_datecloture_end) {
998 $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
999}
1000if ($search_dateorder_start) {
1001 $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
1002}
1003if ($search_dateorder_end) {
1004 $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
1005}
1006if ($search_datedelivery_start) {
1007 $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
1008}
1009if ($search_datedelivery_end) {
1010 $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
1011}
1012if ($search_town) {
1013 $sql .= natural_search('s.town', $search_town);
1014}
1015if ($search_zip) {
1016 $sql .= natural_search("s.zip", $search_zip);
1017}
1018if ($search_state) {
1019 $sql .= natural_search("state.nom", $search_state);
1020}
1021if ($search_country) {
1022 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
1023}
1024if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
1025 $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
1026}
1027if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
1028 $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
1029} else {
1030 if ($search_company) {
1031 $sql .= natural_search('s.nom', $search_company);
1032 }
1033 if ($search_company_alias) {
1034 $sql .= natural_search('s.name_alias', $search_company_alias);
1035 }
1036}
1037if ($search_parent_name) {
1038 $sql .= natural_search('s2.nom', $search_parent_name);
1039}
1040if ($search_total_ht != '') {
1041 $sql .= natural_search('c.total_ht', $search_total_ht, 1);
1042}
1043if ($search_total_vat != '') {
1044 $sql .= natural_search('c.total_tva', $search_total_vat, 1);
1045}
1046if ($search_total_ttc != '') {
1047 $sql .= natural_search('c.total_ttc', $search_total_ttc, 1);
1048}
1049if ($search_warehouse != '' && $search_warehouse > 0) {
1050 $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
1051}
1052if ($search_multicurrency_code != '') {
1053 $sql .= " AND c.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
1054}
1055if ($search_multicurrency_tx != '') {
1056 $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
1057}
1058if ($search_multicurrency_montant_ht != '') {
1059 $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
1060}
1061if ($search_multicurrency_montant_vat != '') {
1062 $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
1063}
1064if ($search_multicurrency_montant_ttc != '') {
1065 $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
1066}
1067if ($search_login) {
1068 $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
1069}
1070if ($search_project_ref != '') {
1071 $sql .= natural_search("p.ref", $search_project_ref);
1072}
1073if ($search_project != '') {
1074 $sql .= natural_search("p.title", $search_project);
1075}
1076if ($search_fk_cond_reglement > 0) {
1077 $sql .= " AND c.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
1078}
1079if ($search_fk_shipping_method > 0) {
1080 $sql .= " AND c.fk_shipping_method = ".((int) $search_fk_shipping_method);
1081}
1082if ($search_fk_mode_reglement > 0) {
1083 $sql .= " AND c.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
1084}
1085if ($search_fk_input_reason > 0) {
1086 $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason);
1087}
1088if ($search_import_key) {
1089 $sql .= natural_search("s.import_key", $search_import_key);
1090}
1091// Search on user
1092if ($search_user > 0) {
1093 $sql .= " AND EXISTS (";
1094 $sql .= " SELECT ec.fk_c_type_contact, ec.element_id, ec.fk_socpeople";
1095 $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec";
1096 $sql .= " INNER JOIN ".MAIN_DB_PREFIX."c_type_contact as tc";
1097 $sql .= " ON ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal'";
1098 $sql .= " WHERE ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user).")";
1099}
1100// Search on sale representative
1101if ($search_sale && $search_sale != '-1') {
1102 if ($search_sale == -2) {
1103 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
1104 } elseif ($search_sale > 0) {
1105 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
1106 }
1107}
1108// Search for tag/category ($searchCategoryCustomerList is an array of ID)
1109$searchCategoryCustomerOperator = -1;
1110$searchCategoryCustomerList = array($search_categ_cus);
1111if (!empty($searchCategoryCustomerList)) {
1112 $searchCategoryCustomerSqlList = array();
1113 $listofcategoryid = '';
1114 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
1115 if (intval($searchCategoryCustomer) == -2) {
1116 $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc)";
1117 } elseif (intval($searchCategoryCustomer) > 0) {
1118 if ($searchCategoryCustomerOperator == 0) {
1119 $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategoryCustomer).")";
1120 } else {
1121 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
1122 }
1123 }
1124 }
1125 if ($listofcategoryid) {
1126 $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1127 }
1128 if ($searchCategoryCustomerOperator == 1) {
1129 if (!empty($searchCategoryCustomerSqlList)) {
1130 $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
1131 }
1132 } else {
1133 if (!empty($searchCategoryCustomerSqlList)) {
1134 $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
1135 }
1136 }
1137}
1138// Search for tag/category ($searchCategoryProductList is an array of ID)
1139$searchCategoryProductOperator = -1;
1140$searchCategoryProductList = array($search_product_category);
1141if (!empty($searchCategoryProductList)) {
1142 $searchCategoryProductSqlList = array();
1143 $listofcategoryid = '';
1144 foreach ($searchCategoryProductList as $searchCategoryProduct) {
1145 if (intval($searchCategoryProduct) == -2) {
1146 $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product)";
1147 } elseif (intval($searchCategoryProduct) > 0) {
1148 if ($searchCategoryProductOperator == 0) {
1149 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
1150 } else {
1151 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
1152 }
1153 }
1154 }
1155 if ($listofcategoryid) {
1156 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
1157 }
1158 if ($searchCategoryProductOperator == 1) {
1159 if (!empty($searchCategoryProductSqlList)) {
1160 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
1161 }
1162 } else {
1163 if (!empty($searchCategoryProductSqlList)) {
1164 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
1165 }
1166 }
1167}
1168// Add where from extra fields
1169include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1170// Add where from hooks
1171$parameters = array();
1172$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1173$sql .= $hookmanager->resPrint;
1174
1175// Add HAVING from hooks
1176$parameters = array();
1177$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1178$sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
1179//print $sql;
1180
1181// Count total nb of records
1182$nbtotalofrecords = '';
1183if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1184 /* The fast and low memory method to get and count full list converts the sql into a sql count */
1185 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
1186 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1187 $resql = $db->query($sqlforcount);
1188 if ($resql) {
1189 $objforcount = $db->fetch_object($resql);
1190 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1191 } else {
1192 dol_print_error($db);
1193 }
1194
1195 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than paging size (filtering), goto and load page 0
1196 $page = 0;
1197 $offset = 0;
1198 }
1199 $db->free($resql);
1200}
1201
1202$sql .= $db->order($sortfield, $sortorder);
1203if ($limit) {
1204 $sql .= $db->plimit($limit + 1, $offset);
1205}
1206//print $sql;
1207
1208$resql = $db->query($sql);
1209if (!$resql) {
1210 dol_print_error($db);
1211 exit;
1212}
1213
1214if ($socid > 0) {
1215 $soc = new Societe($db);
1216 $soc->fetch($socid);
1217 $title = $langs->trans('CustomersOrders').' - '.$soc->name;
1218 if (empty($search_company)) {
1219 $search_company = $soc->name;
1220 }
1221} else {
1222 $title = $langs->trans('CustomersOrders');
1223}
1224if (strval($search_status) == '0') {
1225 $title .= ' - '.$langs->trans('StatusOrderDraftShort');
1226}
1227if ($search_status == 1) {
1228 $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
1229}
1230if ($search_status == 2) {
1231 $title .= ' - '.$langs->trans('StatusOrderSentShort');
1232}
1233if ($search_status == 3) {
1234 $title .= ' - '.$langs->trans('StatusOrderToBillShort');
1235}
1236if ($search_status == -1) {
1237 $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
1238}
1239if ($search_status == -2) {
1240 $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
1241}
1242if ($search_status == -3) {
1243 $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(!isModEnabled('shipping') ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
1244}
1245if ($search_status == -4) {
1246 $title .= ' - '.$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort");
1247}
1248
1249$num = $db->num_rows($resql);
1250
1251$arrayofselected = is_array($toselect) ? $toselect : array();
1252
1253if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all) {
1254 $obj = $db->fetch_object($resql);
1255 $id = $obj->rowid;
1256 header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
1257 exit;
1258}
1259
1260// Output page
1261// --------------------------------------------------------------------
1262
1263llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'bodyforlist mod-order page-list');
1264
1265$arrayofselected = is_array($toselect) ? $toselect : array();
1266
1267$param = '';
1268if (!empty($mode)) {
1269 $param .= '&mode='.urlencode($mode);
1270}
1271if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1272 $param .= '&contextpage='.urlencode($contextpage);
1273}
1274if ($limit > 0 && $limit != $conf->liste_limit) {
1275 $param .= '&limit='.((int) $limit);
1276}
1277if ($optioncss != '') {
1278 $param .= '&optioncss='.urlencode($optioncss);
1279}
1280if ($show_files) {
1281 $param .= '&show_files='.urlencode((string) ($show_files));
1282}
1283if ($search_all) {
1284 $param .= '&search_all='.urlencode($search_all);
1285}
1286if ($socid > 0) {
1287 $param .= '&socid='.((int) $socid);
1288}
1289if ($search_status != '') {
1290 $param .= '&search_status='.urlencode($search_status);
1291}
1292if ($search_option) {
1293 $param .= "&search_option=".urlencode($search_option);
1294}
1295if ($search_datecloture_start) {
1296 $param .= '&search_datecloture_startday='.dol_print_date($search_datecloture_start, '%d').'&search_datecloture_startmonth='.dol_print_date($search_datecloture_start, '%m').'&search_datecloture_startyear='.dol_print_date($search_datecloture_start, '%Y');
1297}
1298if ($search_datecloture_end) {
1299 $param .= '&search_datecloture_endday='.dol_print_date($search_datecloture_end, '%d').'&search_datecloture_endmonth='.dol_print_date($search_datecloture_end, '%m').'&search_datecloture_endyear='.dol_print_date($search_datecloture_end, '%Y');
1300}
1301if ($search_dateorder_start) {
1302 $param .= '&search_dateorder_start_day='.dol_print_date($search_dateorder_start, '%d').'&search_dateorder_start_month='.dol_print_date($search_dateorder_start, '%m').'&search_dateorder_start_year='.dol_print_date($search_dateorder_start, '%Y');
1303}
1304if ($search_dateorder_end) {
1305 $param .= '&search_dateorder_end_day='.dol_print_date($search_dateorder_end, '%d').'&search_dateorder_end_month='.dol_print_date($search_dateorder_end, '%m').'&search_dateorder_end_year='.dol_print_date($search_dateorder_end, '%Y');
1306}
1307if ($search_datedelivery_start) {
1308 $param .= '&search_datedelivery_start_day='.dol_print_date($search_datedelivery_start, '%d').'&search_datedelivery_start_month='.dol_print_date($search_datedelivery_start, '%m').'&search_datedelivery_start_year='.dol_print_date($search_datedelivery_start, '%Y');
1309}
1310if ($search_datedelivery_end) {
1311 $param .= '&search_datedelivery_end_day='.dol_print_date($search_datedelivery_end, '%d').'&search_datedelivery_end_month='.dol_print_date($search_datedelivery_end, '%m').'&search_datedelivery_end_year='.dol_print_date($search_datedelivery_end, '%Y');
1312}
1313if ($search_id) {
1314 $param .= '&search_id='.urlencode((string) $search_id);
1315}
1316if ($search_ref) {
1317 $param .= '&search_ref='.urlencode($search_ref);
1318}
1319if ($search_company) {
1320 $param .= '&search_company='.urlencode($search_company);
1321}
1322if ($search_company_alias) {
1323 $param .= '&search_company_alias='.urlencode($search_company_alias);
1324}
1325if ($search_parent_name != '') {
1326 $param .= '&search_parent_name='.urlencode($search_parent_name);
1327}
1328if ($search_ref_customer) {
1329 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
1330}
1331if ($search_user > 0) {
1332 $param .= '&search_user='.urlencode((string) ($search_user));
1333}
1334if ($search_sale > 0) {
1335 $param .= '&search_sale='.urlencode((string) ($search_sale));
1336}
1337if ($search_total_ht != '') {
1338 $param .= '&search_total_ht='.urlencode($search_total_ht);
1339}
1340if ($search_total_vat != '') {
1341 $param .= '&search_total_vat='.urlencode($search_total_vat);
1342}
1343if ($search_total_ttc != '') {
1344 $param .= '&search_total_ttc='.urlencode($search_total_ttc);
1345}
1346if ($search_warehouse != '') {
1347 $param .= '&search_warehouse='.urlencode((string) ($search_warehouse));
1348}
1349if ($search_login) {
1350 $param .= '&search_login='.urlencode($search_login);
1351}
1352if ($search_multicurrency_code != '') {
1353 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1354}
1355if ($search_multicurrency_tx != '') {
1356 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1357}
1358if ($search_multicurrency_montant_ht != '') {
1359 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1360}
1361if ($search_multicurrency_montant_vat != '') {
1362 $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
1363}
1364if ($search_multicurrency_montant_ttc != '') {
1365 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1366}
1367if ($search_project_ref >= 0) {
1368 $param .= "&search_project_ref=".urlencode($search_project_ref);
1369}
1370if ($search_town != '') {
1371 $param .= '&search_town='.urlencode($search_town);
1372}
1373if ($search_zip != '') {
1374 $param .= '&search_zip='.urlencode($search_zip);
1375}
1376if ($search_state != '') {
1377 $param .= '&search_state='.urlencode($search_state);
1378}
1379if ($search_country != '') {
1380 $param .= '&search_country='.urlencode((string) ($search_country));
1381}
1382if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
1383 $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
1384}
1385if ($search_product_category != '') {
1386 $param .= '&search_product_category='.urlencode((string) ($search_product_category));
1387}
1388if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
1389 $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
1390}
1391if ($search_billed != '') {
1392 $param .= '&search_billed='.urlencode($search_billed);
1393}
1394if ($search_fk_cond_reglement > 0) {
1395 $param .= '&search_fk_cond_reglement='.urlencode((string) ($search_fk_cond_reglement));
1396}
1397if ($search_fk_shipping_method > 0) {
1398 $param .= '&search_fk_shipping_method='.urlencode((string) ($search_fk_shipping_method));
1399}
1400if ($search_fk_mode_reglement > 0) {
1401 $param .= '&search_fk_mode_reglement='.urlencode((string) ($search_fk_mode_reglement));
1402}
1403if ($search_fk_input_reason > 0) {
1404 $param .= '&search_fk_input_reason='.urlencode((string) ($search_fk_input_reason));
1405}
1406if ($search_import_key != '') {
1407 $param .= '&search_import_key='.urlencode($search_import_key);
1408}
1409
1410// Add $param from extra fields
1411include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1412
1413// Add $param from hooks
1414$parameters = array();
1415$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1416$param .= $hookmanager->resPrint;
1417
1418// List of mass actions available
1419$arrayofmassactions = array(
1420 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1421 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1422);
1423if ($permissiontovalidate) {
1424 $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
1425}
1426if ($permissiontoclose) {
1427 $arrayofmassactions['preshipped'] = img_picto('', 'dolly', 'class="pictofixedwidth"').$langs->trans("ClassifyShipped");
1428}
1429if (isModEnabled('invoice') && $user->hasRight("facture", "creer")) {
1430 $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisCustomer");
1431}
1432if ($permissiontoclose) {
1433 $arrayofmassactions['setbilled'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
1434}
1435if ($permissiontocancel) {
1436 $arrayofmassactions['cancelorders'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("CancelOrder");
1437}
1438if (!empty($permissiontodelete)) {
1439 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1440}
1441if ($permissiontosendbymail) {
1442 $arrayofmassactions['presend'] = img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
1443}
1444if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
1445 $arrayofmassactions = array();
1446}
1447$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1448
1449$url = DOL_URL_ROOT.'/commande/card.php?action=create';
1450if (!empty($socid)) {
1451 $url .= '&socid='.$socid;
1452}
1453$newcardbutton = '';
1454$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'));
1455$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'));
1456$newcardbutton .= dolGetButtonTitleSeparator();
1457$newcardbutton .= dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', (int) (($contextpage == 'orderlist' || $contextpage == 'billableorders') && $permissiontoadd));
1458
1459// Lines of title fields
1460print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1461if ($optioncss != '') {
1462 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1463}
1464print '<input type="hidden" name="token" value="'.newToken().'">';
1465print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1466print '<input type="hidden" name="action" value="list">';
1467print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1468print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1469print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1470print '<input type="hidden" name="search_status" value="'.$search_status.'">';
1471print '<input type="hidden" name="socid" value="'.$socid.'">';
1472print '<input type="hidden" name="page_y" value="">';
1473print '<input type="hidden" name="mode" value="'.$mode.'">';
1474
1475
1476print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
1477
1478$topicmail = "SendOrderRef";
1479$modelmail = "order_send";
1480$objecttmp = new Commande($db);
1481$trackid = 'ord'.$object->id;
1482include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1483
1484if ($massaction == 'prevalidate') {
1485 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1486}
1487if ($massaction == 'preshipped') {
1488 print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("CloseOrder"), $langs->trans("ConfirmCloseOrder"), "shipped", null, '', 0, 200, 500, 1);
1489}
1490
1491if ($massaction == 'createbills') {
1492 print '<input type="hidden" name="massaction" value="confirm_createbills">';
1493
1494 print '<table class="noborder centpercent">';
1495 print '<tr>';
1496 print '<td>';
1497 print $langs->trans('DateInvoice');
1498 print '</td>';
1499 print '<td>';
1500 print $form->selectDate('', '', 0, 0, 0, '', 1, 1);
1501 print '</td>';
1502 print '</tr>';
1503 print '<tr>';
1504 print '<td>';
1505 print $langs->trans('CreateOneBillByThird');
1506 print '</td>';
1507 print '<td>';
1508 print $form->selectyesno('createbills_onebythird', getDolGlobalString('MAIN_ORDERLIST_CREATEBILLS_ONEBYTHIRD', 'no'), 1);
1509 print '</td>';
1510 print '</tr>';
1511 print '<tr>';
1512 print '<td>';
1513 print $langs->trans('ValidateInvoices');
1514 print '</td>';
1515 print '<td>';
1516 if (isModEnabled('stock') && getDolGlobalString('STOCK_CALCULATE_ON_BILL')) {
1517 print $form->selectyesno('validate_invoices', 0, 1, 1);
1518 $langs->load("errors");
1519 print ' ('.$langs->trans("WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal").')';
1520 } else {
1521 print $form->selectyesno('validate_invoices', 0, 1);
1522 }
1523 if (!empty($conf->workflow->enabled) && getDolGlobalString('WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER')) {
1524 print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoOrderStayUnbilled").'</span>';
1525 } else {
1526 print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetOrderBilledNotEnabled").'</span>';
1527 }
1528 print '</td>';
1529 print '</tr>';
1530 print '</table>';
1531
1532 print '<div class="center">';
1533 print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
1534 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1535 print '</div>';
1536 print '<br><br>';
1537}
1538
1539if ($search_all) {
1540 $setupstring = '';
1541 foreach ($fieldstosearchall as $key => $val) {
1542 $fieldstosearchall[$key] = $langs->trans($val);
1543 $setupstring .= $key."=".$val.";";
1544 }
1545 print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1546 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
1547}
1548
1549$moreforfilter = '';
1550
1551// If the user can view prospects? sales other than his own
1552if ($user->hasRight("user", "user", "lire")) {
1553 $langs->load("commercial");
1554 $moreforfilter .= '<div class="divsearchfield">';
1555 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1556 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1557 $moreforfilter .= '</div>';
1558}
1559// If the user can view other users
1560if ($user->hasRight("user", "user", "lire")) {
1561 $moreforfilter .= '<div class="divsearchfield">';
1562 $tmptitle = $langs->trans('LinkedToSpecificUsers');
1563 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1564 $moreforfilter .= '</div>';
1565}
1566
1567// If the user can view other products/services than his own
1568if (isModEnabled('category') && $user->hasRight("categorie", "lire") && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
1569 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1570 $moreforfilter .= '<div class="divsearchfield">';
1571 $tmptitle = $langs->trans('IncludingProductWithTag');
1572 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, array(), 1);
1573 $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);
1574 $moreforfilter .= '</div>';
1575}
1576// If Categories are enabled & user has rights to see
1577if (isModEnabled('category') && $user->hasRight("categorie", "lire")) {
1578 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1579 $moreforfilter .= '<div class="divsearchfield">';
1580 $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1581 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, 'maxwidth300 widthcentpercentminusx');
1582 $moreforfilter .= '</div>';
1583}
1584// If Stock is enabled
1585if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER')) {
1586 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1587 $formproduct = new FormProduct($db);
1588 $moreforfilter .= '<div class="divsearchfield">';
1589 $tmptitle = $langs->trans('Warehouse');
1590 $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1, 0, 0, $tmptitle, 0, 0, array(), 'maxwidth250 widthcentpercentminusx');
1591 $moreforfilter .= '</div>';
1592}
1593
1594$parameters = array();
1595$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1596if (empty($reshook)) {
1597 $moreforfilter .= $hookmanager->resPrint;
1598} else {
1599 $moreforfilter = $hookmanager->resPrint;
1600}
1601
1602if (!empty($moreforfilter)) {
1603 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1604 print $moreforfilter;
1605 print '</div>';
1606}
1607
1608$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1609$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1610$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1611$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1612
1613if (GETPOSTINT('autoselectall')) {
1614 $selectedfields .= '<script>';
1615 $selectedfields .= ' $(document).ready(function() {';
1616 $selectedfields .= ' console.log("Autoclick on checkforselects");';
1617 $selectedfields .= ' $("#checkforselects").click();';
1618 $selectedfields .= ' $("#massaction").val("createbills").change();';
1619 $selectedfields .= ' });';
1620 $selectedfields .= '</script>';
1621}
1622
1623print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1624print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1625
1626// Fields title search
1627// --------------------------------------------------------------------
1628print '<tr class="liste_titre_filter">';
1629// Action column
1630if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1631 print '<td class="liste_titre center maxwidthsearch">';
1632 $searchpicto = $form->showFilterButtons('left');
1633 print $searchpicto;
1634 print '</td>';
1635}
1636
1637// Line numbering
1638if (!empty($arrayfields['c.rowid']['checked'])) {
1639 print '<td class="liste_titre">';
1640 print '<input class="flat" size="6" type="text" name="search_id" value="'.dol_escape_htmltag($search_id).'">';
1641 print '</td>';
1642}
1643
1644// Ref
1645if (!empty($arrayfields['c.ref']['checked'])) {
1646 print '<td class="liste_titre">';
1647 print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1648 print '</td>';
1649}
1650// Ref customer
1651if (!empty($arrayfields['c.ref_client']['checked'])) {
1652 print '<td class="liste_titre" align="left">';
1653 print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
1654 print '</td>';
1655}
1656// Project ref
1657if (!empty($arrayfields['p.ref']['checked'])) {
1658 print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
1659}
1660// Project title
1661if (!empty($arrayfields['p.title']['checked'])) {
1662 print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1663}
1664// Thirpdarty
1665if (!empty($arrayfields['s.nom']['checked'])) {
1666 print '<td class="liste_titre" align="left">';
1667 print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
1668 print '</td>';
1669}
1670// Alias
1671if (!empty($arrayfields['s.name_alias']['checked'])) {
1672 print '<td class="liste_titre" align="left">';
1673 print '<input class="flat maxwidth100" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'">';
1674 print '</td>';
1675}
1676// Parent company
1677if (!empty($arrayfields['s2.nom']['checked'])) {
1678 print '<td class="liste_titre">';
1679 print '<input class="flat maxwidth100" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
1680 print '</td>';
1681}
1682// Town
1683if (!empty($arrayfields['s.town']['checked'])) {
1684 print '<td class="liste_titre"><input class="flat width50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1685}
1686// Zip
1687if (!empty($arrayfields['s.zip']['checked'])) {
1688 print '<td class="liste_titre"><input class="flat width50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1689}
1690// State
1691if (!empty($arrayfields['state.nom']['checked'])) {
1692 print '<td class="liste_titre">';
1693 print '<input class="flat width50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1694 print '</td>';
1695}
1696// Country
1697if (!empty($arrayfields['country.code_iso']['checked'])) {
1698 print '<td class="liste_titre" align="center">';
1699 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1700 print '</td>';
1701}
1702// Company type
1703if (!empty($arrayfields['typent.code']['checked'])) {
1704 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1705 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);
1706 print '</td>';
1707}
1708// Date order
1709if (!empty($arrayfields['c.date_commande']['checked'])) {
1710 print '<td class="liste_titre center">';
1711 print '<div class="nowrapfordate">';
1712 print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1713 print '</div>';
1714 print '<div class="nowrapfordate">';
1715 print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1716 print '</div>';
1717 print '</td>';
1718}
1719if (!empty($arrayfields['c.date_delivery']['checked'])) {
1720 print '<td class="liste_titre center">';
1721 print '<div class="nowrapfordate">';
1722 print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1723 print '</div>';
1724 print '<div class="nowrapfordate">';
1725 print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1726 print '</div>';
1727 print '</td>';
1728}
1729// Shipping Method
1730if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1731 print '<td class="liste_titre">';
1732 $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
1733 print '</td>';
1734}
1735// Payment term
1736if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1737 print '<td class="liste_titre">';
1738 print $form->getSelectConditionsPaiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
1739 print '</td>';
1740}
1741// Payment mode
1742if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1743 print '<td class="liste_titre">';
1744 print $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1, '', 1);
1745 print '</td>';
1746}
1747// Channel
1748if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1749 print '<td class="liste_titre">';
1750 $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
1751 print '</td>';
1752}
1753// Amount HT / net
1754if (!empty($arrayfields['c.total_ht']['checked'])) {
1755 print '<td class="liste_titre right">';
1756 print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
1757 print '</td>';
1758}
1759// Amount of VAT
1760if (!empty($arrayfields['c.total_vat']['checked'])) {
1761 print '<td class="liste_titre right">';
1762 print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
1763 print '</td>';
1764}
1765// Total Amount (TTC / gross)
1766if (!empty($arrayfields['c.total_ttc']['checked'])) {
1767 print '<td class="liste_titre right">';
1768 print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1769 print '</td>';
1770}
1771// Currency
1772if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1773 print '<td class="liste_titre">';
1774 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1775 print '</td>';
1776}
1777// Currency rate
1778if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1779 print '<td class="liste_titre">';
1780 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1781 print '</td>';
1782}
1783// Amount HT/net in foreign currency
1784if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1785 print '<td class="liste_titre right">';
1786 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1787 print '</td>';
1788}
1789// VAT in foreign currency
1790if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1791 print '<td class="liste_titre right">';
1792 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1793 print '</td>';
1794}
1795// Amount/Total (TTC / gross) in foreign currency
1796if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1797 print '<td class="liste_titre right">';
1798 print '<input class="flat width75" type="text" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1799 print '</td>';
1800}
1801// Author
1802if (!empty($arrayfields['u.login']['checked'])) {
1803 print '<td class="liste_titre">';
1804 print '<input class="flat width75" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1805 print '</td>';
1806}
1807// Sales Representative
1808if (!empty($arrayfields['sale_representative']['checked'])) {
1809 print '<td class="liste_titre"></td>';
1810}
1811if (!empty($arrayfields['total_pa']['checked'])) {
1812 print '<td class="liste_titre right">';
1813 print '</td>';
1814}
1815if (!empty($arrayfields['total_margin']['checked'])) {
1816 print '<td class="liste_titre right">';
1817 print '</td>';
1818}
1819if (!empty($arrayfields['total_margin_rate']['checked'])) {
1820 print '<td class="liste_titre right">';
1821 print '</td>';
1822}
1823if (!empty($arrayfields['total_mark_rate']['checked'])) {
1824 print '<td class="liste_titre right">';
1825 print '</td>';
1826}
1827
1828// Date creation
1829if (!empty($arrayfields['c.datec']['checked'])) {
1830 print '<td class="liste_titre">';
1831 print '</td>';
1832}
1833// Date modification
1834if (!empty($arrayfields['c.tms']['checked'])) {
1835 print '<td class="liste_titre">';
1836 print '</td>';
1837}
1838// Date cloture
1839if (!empty($arrayfields['c.date_cloture']['checked'])) {
1840 print '<td class="liste_titre center">';
1841 print '<div class="nowrapfordate">';
1842 print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1843 print '</div>';
1844 print '<div class="nowrapfordate">';
1845 print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1846 print '</div>';
1847 print '</td>';
1848}
1849// Note public
1850if (!empty($arrayfields['c.note_public']['checked'])) {
1851 print '<td class="liste_titre">';
1852 print '</td>';
1853}
1854// Note private
1855if (!empty($arrayfields['c.note_private']['checked'])) {
1856 print '<td class="liste_titre">';
1857 print '</td>';
1858}
1859// Shippable
1860if (!empty($arrayfields['shippable']['checked'])) {
1861 print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1862 //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
1863 if (getDolGlobalString('ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT')) {
1864 print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
1865 print $langs->trans('ShowShippableStatus');
1866 } else {
1867 $show_shippable_command = 1;
1868 }
1869 print '</td>';
1870}
1871
1872// Extra fields
1873include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1874
1875// Fields from hook
1876$parameters = array('arrayfields' => $arrayfields);
1877$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1878print $hookmanager->resPrint;
1879
1880// Status billed
1881if (!empty($arrayfields['c.facture']['checked'])) {
1882 print '<td class="liste_titre maxwidthonsmartphone center">';
1883 print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
1884 print '</td>';
1885}
1886
1887// Import key
1888if (!empty($arrayfields['c.import_key']['checked'])) {
1889 print '<td class="liste_titre maxwidthonsmartphone center">';
1890 print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
1891 print '</td>';
1892}
1893
1894// Status
1895if (!empty($arrayfields['c.fk_statut']['checked'])) {
1896 print '<td class="liste_titre center parentonrightofpage">';
1897 $liststatus = array(
1898 Commande::STATUS_DRAFT => $langs->trans("StatusOrderDraftShort"),
1899 Commande::STATUS_VALIDATED => $langs->trans("StatusOrderValidated"),
1900 Commande::STATUS_SHIPMENTONPROCESS => $langs->trans("StatusOrderSentShort"),
1901 -2 => $langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
1902 -3 => $langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
1903 Commande::STATUS_CLOSED => $langs->trans("StatusOrderDelivered"),
1904 Commande::STATUS_CANCELED => $langs->trans("StatusOrderCanceledShort")
1905 );
1906 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1907 print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage', 1);
1908 print '</td>';
1909}
1910// Action column
1911if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1912 print '<td class="liste_titre center maxwidthsearch">';
1913 $searchpicto = $form->showFilterButtons();
1914 print $searchpicto;
1915 print '</td>';
1916}
1917print '</tr>'."\n";
1918
1919$totalarray = array(
1920 'nbfield' => 0,
1921 'val' => array(
1922 'c.total_ht' => 0,
1923 'c.total_tva' => 0,
1924 'c.total_ttc' => 0,
1925 ),
1926 'pos' => array(),
1927);
1928
1929
1930// Fields title label
1931// --------------------------------------------------------------------
1932print '<tr class="liste_titre">';
1933
1934// Action column
1935if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1936 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
1937 $totalarray['nbfield']++;
1938}
1939if (!empty($arrayfields['c.rowid']['checked'])) {
1940 print_liste_field_titre($arrayfields['c.rowid']['label'], $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
1941 $totalarray['nbfield']++;
1942}
1943if (!empty($arrayfields['c.ref']['checked'])) {
1944 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
1945 $totalarray['nbfield']++;
1946}
1947if (!empty($arrayfields['c.ref_client']['checked'])) {
1948 print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
1949 $totalarray['nbfield']++;
1950}
1951if (!empty($arrayfields['p.ref']['checked'])) {
1952 print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1953 $totalarray['nbfield']++;
1954}
1955if (!empty($arrayfields['p.title']['checked'])) {
1956 print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
1957 $totalarray['nbfield']++;
1958}
1959if (!empty($arrayfields['s.nom']['checked'])) {
1960 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1961 $totalarray['nbfield']++;
1962}
1963if (!empty($arrayfields['s.name_alias']['checked'])) {
1964 // @phan-suppress-next-line PhanTypeInvalidDimOffset
1965 print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1966 $totalarray['nbfield']++;
1967}
1968if (!empty($arrayfields['s2.nom']['checked'])) {
1969 print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER['PHP_SELF'], 's2.nom', '', $param, '', $sortfield, $sortorder);
1970 $totalarray['nbfield']++;
1971}
1972if (!empty($arrayfields['s.town']['checked'])) {
1973 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1974 $totalarray['nbfield']++;
1975}
1976if (!empty($arrayfields['s.zip']['checked'])) {
1977 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1978 $totalarray['nbfield']++;
1979}
1980if (!empty($arrayfields['state.nom']['checked'])) {
1981 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1982 $totalarray['nbfield']++;
1983}
1984if (!empty($arrayfields['country.code_iso']['checked'])) {
1985 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1986 $totalarray['nbfield']++;
1987}
1988if (!empty($arrayfields['typent.code']['checked'])) {
1989 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1990 $totalarray['nbfield']++;
1991}
1992if (!empty($arrayfields['c.date_commande']['checked'])) {
1993 print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
1994 $totalarray['nbfield']++;
1995}
1996if (!empty($arrayfields['c.date_delivery']['checked'])) {
1997 print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1998 $totalarray['nbfield']++;
1999}
2000if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
2001 print_liste_field_titre($arrayfields['c.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "c.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
2002 $totalarray['nbfield']++;
2003}
2004if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
2005 print_liste_field_titre($arrayfields['c.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
2006 $totalarray['nbfield']++;
2007}
2008if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
2009 print_liste_field_titre($arrayfields['c.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
2010 $totalarray['nbfield']++;
2011}
2012if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
2013 print_liste_field_titre($arrayfields['c.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "c.fk_input_reason", "", $param, '', $sortfield, $sortorder);
2014 $totalarray['nbfield']++;
2015}
2016if (!empty($arrayfields['c.total_ht']['checked'])) {
2017 print_liste_field_titre($arrayfields['c.total_ht']['label'], $_SERVER["PHP_SELF"], 'c.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
2018 $totalarray['nbfield']++;
2019}
2020if (!empty($arrayfields['c.total_vat']['checked'])) {
2021 print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'c.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
2022 $totalarray['nbfield']++;
2023}
2024if (!empty($arrayfields['c.total_ttc']['checked'])) {
2025 print_liste_field_titre($arrayfields['c.total_ttc']['label'], $_SERVER["PHP_SELF"], 'c.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
2026 $totalarray['nbfield']++;
2027}
2028if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
2029 print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
2030 $totalarray['nbfield']++;
2031}
2032if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
2033 print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
2034 $totalarray['nbfield']++;
2035}
2036if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
2037 print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
2038 $totalarray['nbfield']++;
2039}
2040if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
2041 print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
2042 $totalarray['nbfield']++;
2043}
2044if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
2045 print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
2046 $totalarray['nbfield']++;
2047}
2048if (!empty($arrayfields['u.login']['checked'])) {
2049 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
2050 $totalarray['nbfield']++;
2051}
2052if (!empty($arrayfields['sale_representative']['checked'])) {
2053 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
2054 $totalarray['nbfield']++;
2055}
2056if (!empty($arrayfields['total_pa']['checked'])) {
2057 print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
2058 $totalarray['nbfield']++;
2059}
2060if (!empty($arrayfields['total_margin']['checked'])) {
2061 print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
2062 $totalarray['nbfield']++;
2063}
2064if (!empty($arrayfields['total_margin_rate']['checked'])) {
2065 print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
2066 $totalarray['nbfield']++;
2067}
2068if (!empty($arrayfields['total_mark_rate']['checked'])) {
2069 print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
2070 $totalarray['nbfield']++;
2071}
2072
2073if (!empty($arrayfields['c.datec']['checked'])) {
2074 print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2075 $totalarray['nbfield']++;
2076}
2077if (!empty($arrayfields['c.tms']['checked'])) {
2078 print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2079 $totalarray['nbfield']++;
2080}
2081if (!empty($arrayfields['c.date_cloture']['checked'])) {
2082 print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
2083 $totalarray['nbfield']++;
2084}
2085if (!empty($arrayfields['c.note_public']['checked'])) {
2086 print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
2087 $totalarray['nbfield']++;
2088}
2089if (!empty($arrayfields['c.note_private']['checked'])) {
2090 print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
2091 $totalarray['nbfield']++;
2092}
2093if (!empty($arrayfields['shippable']['checked'])) {
2094 print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
2095 $totalarray['nbfield']++;
2096}
2097// Extra fields
2098include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
2099
2100// Hook fields
2101$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
2102$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2103print $hookmanager->resPrint;
2104
2105// Status billed
2106if (!empty($arrayfields['c.facture']['checked'])) {
2107 print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
2108 $totalarray['nbfield']++;
2109}
2110// Import key
2111if (!empty($arrayfields['c.import_key']['checked'])) {
2112 print_liste_field_titre($arrayfields['c.import_key']['label'], $_SERVER["PHP_SELF"], "c.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
2113 $totalarray['nbfield']++;
2114}
2115// Status
2116if (!empty($arrayfields['c.fk_statut']['checked'])) {
2117 print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
2118 $totalarray['nbfield']++;
2119}
2120// Action column
2121if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2122 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
2123 $totalarray['nbfield']++;
2124}
2125print '</tr>'."\n";
2126
2127$total = 0;
2128$subtotal = 0;
2129$productstat_cache = array();
2130$productstat_cachevirtual = array();
2131$getNomUrl_cache = array();
2132
2133$generic_commande = new Commande($db);
2134$generic_product = new Product($db);
2135$userstatic = new User($db);
2136
2137$with_margin_info = false;
2138if (isModEnabled('margin') && (
2139 !empty($arrayfields['total_pa']['checked'])
2140 || !empty($arrayfields['total_margin']['checked'])
2141 || !empty($arrayfields['total_margin_rate']['checked'])
2142 || !empty($arrayfields['total_mark_rate']['checked'])
2143)
2144) {
2145 $with_margin_info = true;
2146}
2147
2148$total_ht = 0;
2149$total_margin = 0;
2150
2151// Loop on record
2152// --------------------------------------------------------------------
2153$i = 0;
2154$savnbfield = $totalarray['nbfield'];
2155$totalarray = array();
2156$totalarray['nbfield'] = 0;
2157$imaxinloop = ($limit ? min($num, $limit) : $num);
2158while ($i < $imaxinloop) {
2159 $obj = $db->fetch_object($resql);
2160 if (empty($obj)) {
2161 break; // Should not happen
2162 }
2163
2164 $notshippable = 0;
2165 $warning = 0;
2166 $text_info = '';
2167 $text_warning = '';
2168 $nbprod = 0;
2169
2170 $companystatic->id = $obj->socid;
2171 $companystatic->name = $obj->name;
2172 $companystatic->name_alias = $obj->alias;
2173 $companystatic->client = $obj->client;
2174 $companystatic->fournisseur = $obj->fournisseur;
2175 $companystatic->code_client = $obj->code_client;
2176 $companystatic->email = $obj->email;
2177 $companystatic->phone = $obj->phone;
2178 $companystatic->address = $obj->address;
2179 $companystatic->zip = $obj->zip;
2180 $companystatic->town = $obj->town;
2181 $companystatic->country_code = $obj->country_code;
2182 if (!isset($getNomUrl_cache[$obj->socid])) {
2183 $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2184 }
2185
2186 $generic_commande->id = $obj->rowid;
2187 $generic_commande->ref = $obj->ref;
2188 $generic_commande->statut = $obj->fk_statut;
2189 $generic_commande->billed = $obj->billed;
2190 $generic_commande->date = $db->jdate($obj->date_commande);
2191 $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
2192 $generic_commande->ref_client = $obj->ref_client;
2193 $generic_commande->total_ht = $obj->total_ht;
2194 $generic_commande->total_tva = $obj->total_tva;
2195 $generic_commande->total_ttc = $obj->total_ttc;
2196 $generic_commande->note_public = $obj->note_public;
2197 $generic_commande->note_private = $obj->note_private;
2198
2199 $generic_commande->thirdparty = $companystatic;
2200
2201
2202 $projectstatic->id = $obj->project_id;
2203 $projectstatic->ref = $obj->project_ref;
2204 $projectstatic->title = $obj->project_label;
2205
2206 $marginInfo = array();
2207 if ($with_margin_info) {
2208 $generic_commande->fetch_lines();
2209 $marginInfo = $formmargin->getMarginInfosArray($generic_commande);
2210 $total_ht += $obj->total_ht;
2211 $total_margin += $marginInfo['total_margin'];
2212 }
2213
2214 if ($mode == 'kanban') {
2215 if ($i == 0) {
2216 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
2217 print '<div class="box-flex-container kanban">';
2218 }
2219
2220 // Output Kanban
2221 $selected = -1;
2222 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2223 $selected = 0;
2224 if (in_array($object->id, $arrayofselected)) {
2225 $selected = 1;
2226 }
2227 }
2228 print $generic_commande->getKanbanView('', array('selected' => $selected));
2229 if ($i == ($imaxinloop - 1)) {
2230 print '</div>';
2231 print '</td></tr>';
2232 }
2233 } else {
2234 // Show line of result
2235 $j = 0;
2236 print '<tr data-rowid="'.$object->id.'" class="oddeven '.((getDolGlobalInt('MAIN_FINISHED_LINES_OPACITY') == 1 && $obj->billed == 1) ? 'opacitymedium' : '').'">';
2237
2238 // Action column
2239 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2240 print '<td class="nowrap center">';
2241 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2242 $selected = 0;
2243 if (in_array($obj->rowid, $arrayofselected)) {
2244 $selected = 1;
2245 }
2246 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2247 }
2248 print '</td>';
2249 if (!$i) {
2250 $totalarray['nbfield']++;
2251 }
2252 }
2253
2254 // Technical ID
2255 if (!empty($arrayfields['c.rowid']['checked'])) {
2256 print '<td class="center" data-key="id">'.$obj->rowid.'</td>';
2257 if (!$i) {
2258 $totalarray['nbfield']++;
2259 }
2260 }
2261
2262 // Ref
2263 if (!empty($arrayfields['c.ref']['checked'])) {
2264 print '<td class="nowraponall">';
2265 $getNomUrlOption = $search_status != 2 ? 0 : $obj->fk_statut;
2266 if (getDolGlobalInt('MAIN_LIST_ORDER_LINK_DONT_USE_STATUS')) {
2267 // TODO : This hidden conf must be added to the user's individual conf.
2268 // The user must be able to manage this behavior to adapt it to his use of the software, because depending on the employee's workstation, his use differs.
2269 // This hidden configuration ensures that users are not confused by keeping the same behavior of click, whatever the current filter.
2270 // If the aim is to use a different url when the filter is applied via the link in the left-hand menu, then this detection should be adapted instead.
2271 $getNomUrlOption = '';
2272 }
2273 print $generic_commande->getNomUrl(1, $getNomUrlOption, 0, 0, 0, 1, 1);
2274
2275 $filename = dol_sanitizeFileName($obj->ref);
2276 $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
2277 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
2278 print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
2279
2280 print '</td>';
2281 if (!$i) {
2282 $totalarray['nbfield']++;
2283 }
2284 }
2285
2286 // Ref customer
2287 if (!empty($arrayfields['c.ref_client']['checked'])) {
2288 print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_client).'">';
2289 print dol_escape_htmltag($obj->ref_client);
2290 print '</td>';
2291 if (!$i) {
2292 $totalarray['nbfield']++;
2293 }
2294 }
2295
2296 // Project ref
2297 if (!empty($arrayfields['p.ref']['checked'])) {
2298 print '<td class="nowrap">';
2299 if ($obj->project_id > 0) {
2300 print $projectstatic->getNomUrl(1);
2301 }
2302 print '</td>';
2303 if (!$i) {
2304 $totalarray['nbfield']++;
2305 }
2306 }
2307
2308 // Project label
2309 if (!empty($arrayfields['p.title']['checked'])) {
2310 print '<td class="nowrap">';
2311 if ($obj->project_id > 0) {
2312 print $projectstatic->title;
2313 }
2314 print '</td>';
2315 if (!$i) {
2316 $totalarray['nbfield']++;
2317 }
2318 }
2319
2320 // Third party
2321 if (!empty($arrayfields['s.nom']['checked'])) {
2322 print '<td class="tdoverflowmax150">';
2323 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2324 print $companystatic->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2325 } else {
2326 print $getNomUrl_cache[$obj->socid];
2327 }
2328
2329 // If module invoices enabled and user with invoice creation permissions
2330 if (isModEnabled('invoice') && getDolGlobalString('ORDER_BILLING_ALL_CUSTOMER')) {
2331 if ($user->hasRight('facture', 'creer')) {
2332 if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0)) {
2333 print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
2334 print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
2335 }
2336 }
2337 }
2338 print '</td>';
2339 if (!$i) {
2340 $totalarray['nbfield']++;
2341 }
2342 }
2343
2344 // Alias name
2345 if (!empty($arrayfields['s.name_alias']['checked'])) {
2346 print '<td class="nocellnopadd tdoverflowmax100" title="'.dolPrintHTMLForTextArea($obj->alias).'">';
2347 print dolPrintLabel($obj->alias);
2348 print '</td>';
2349 if (!$i) {
2350 $totalarray['nbfield']++;
2351 }
2352 }
2353
2354 // Parent company
2355 if (!empty($arrayfields['s2.nom']['checked'])) {
2356 print '<td class="tdoverflowmax200">';
2357 if ($obj->fk_parent > 0) {
2358 if (!isset($company_url_list[$obj->fk_parent])) {
2359 $companyparent = new Societe($db);
2360 $res = $companyparent->fetch($obj->fk_parent);
2361 if ($res > 0) {
2362 $company_url_list[$obj->fk_parent] = $companyparent->getNomUrl(1);
2363 }
2364 }
2365 if (isset($company_url_list[$obj->fk_parent])) {
2366 print $company_url_list[$obj->fk_parent];
2367 }
2368 }
2369 print "</td>";
2370 if (!$i) {
2371 $totalarray['nbfield']++;
2372 }
2373 }
2374
2375 // Town
2376 if (!empty($arrayfields['s.town']['checked'])) {
2377 print '<td class="tdoverflowmax100" title="'.dolPrintHTMLForTextArea($obj->town).'">';
2378 print dolPrintLabel($obj->town);
2379 print '</td>';
2380 if (!$i) {
2381 $totalarray['nbfield']++;
2382 }
2383 }
2384
2385 // Zip
2386 if (!empty($arrayfields['s.zip']['checked'])) {
2387 print '<td class="tdoverflowmax100" title="'.dolPrintHTMLForTextArea($obj->zip).'">';
2388 print dolPrintLabel($obj->zip);
2389 print '</td>';
2390 if (!$i) {
2391 $totalarray['nbfield']++;
2392 }
2393 }
2394
2395 // State
2396 if (!empty($arrayfields['state.nom']['checked'])) {
2397 print '<td class="tdoverflowmax100" title="'.dolPrintHTMLForTextArea($obj->state_name).'">'.dolPrintLabel($obj->state_name)."</td>\n";
2398 if (!$i) {
2399 $totalarray['nbfield']++;
2400 }
2401 }
2402
2403 // Country
2404 if (!empty($arrayfields['country.code_iso']['checked'])) {
2405 print '<td class="center">';
2406 $tmparray = getCountry($obj->fk_pays, 'all');
2407 print $tmparray['label'];
2408 print '</td>';
2409 if (!$i) {
2410 $totalarray['nbfield']++;
2411 }
2412 }
2413
2414 // Type ent
2415 if (!empty($arrayfields['typent.code']['checked'])) {
2416 print '<td class="center">';
2417 if (empty($typenArray)) {
2418 $typenArray = $formcompany->typent_array(1);
2419 }
2420 print $typenArray[$obj->typent_code] ?? '';
2421 print '</td>';
2422 if (!$i) {
2423 $totalarray['nbfield']++;
2424 }
2425 }
2426
2427 // Order date
2428 if (!empty($arrayfields['c.date_commande']['checked'])) {
2429 print '<td class="center nowraponall">';
2430 print dol_print_date($db->jdate($obj->date_commande), 'day');
2431 // Warning late icon and note
2432 if ($generic_commande->hasDelay()) {
2433 print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
2434 }
2435 print '</td>';
2436 if (!$i) {
2437 $totalarray['nbfield']++;
2438 }
2439 }
2440
2441 // Plannned date of delivery
2442 if (!empty($arrayfields['c.date_delivery']['checked'])) {
2443 print '<td class="center nowraponall">';
2444 print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
2445 print '</td>';
2446 if (!$i) {
2447 $totalarray['nbfield']++;
2448 }
2449 }
2450
2451 // Shipping Method
2452 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
2453 print '<td>';
2454 $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
2455 print '</td>';
2456 if (!$i) {
2457 $totalarray['nbfield']++;
2458 }
2459 }
2460
2461 // Payment terms
2462 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
2463 print '<td>';
2464 $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
2465 print '</td>';
2466 if (!$i) {
2467 $totalarray['nbfield']++;
2468 }
2469 }
2470
2471 // Payment mode
2472 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
2473 print '<td>';
2474 $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
2475 print '</td>';
2476 if (!$i) {
2477 $totalarray['nbfield']++;
2478 }
2479 }
2480
2481 // Channel
2482 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
2483 print '<td>';
2484 $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', 0);
2485 print '</td>';
2486 if (!$i) {
2487 $totalarray['nbfield']++;
2488 }
2489 }
2490
2491 // Amount HT/net
2492 if (!empty($arrayfields['c.total_ht']['checked'])) {
2493 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
2494 if (!$i) {
2495 $totalarray['nbfield']++;
2496 }
2497 if (!$i) {
2498 $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ht';
2499 }
2500 if (isset($totalarray['val']['c.total_ht'])) {
2501 $totalarray['val']['c.total_ht'] += $obj->total_ht;
2502 } else {
2503 $totalarray['val']['c.total_ht'] = $obj->total_ht;
2504 }
2505 }
2506
2507 // Amount VAT
2508 if (!empty($arrayfields['c.total_vat']['checked'])) {
2509 print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
2510 if (!$i) {
2511 $totalarray['nbfield']++;
2512 }
2513 if (!$i) {
2514 $totalarray['pos'][$totalarray['nbfield']] = 'c.total_tva';
2515 }
2516 if (isset($totalarray['val']['c.total_tva'])) {
2517 $totalarray['val']['c.total_tva'] += $obj->total_tva;
2518 } else {
2519 $totalarray['val']['c.total_tva'] = $obj->total_tva;
2520 }
2521 }
2522
2523 // Amount TTC / gross
2524 if (!empty($arrayfields['c.total_ttc']['checked'])) {
2525 print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
2526 if (!$i) {
2527 $totalarray['nbfield']++;
2528 }
2529 if (!$i) {
2530 $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ttc';
2531 }
2532 if (isset($totalarray['val']['c.total_ttc'])) {
2533 $totalarray['val']['c.total_ttc'] += $obj->total_ttc;
2534 } else {
2535 $totalarray['val']['c.total_ttc'] = $obj->total_ttc;
2536 }
2537 }
2538
2539 // Currency
2540 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
2541 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
2542 if (!$i) {
2543 $totalarray['nbfield']++;
2544 }
2545 }
2546
2547 // Currency rate
2548 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
2549 print '<td class="nowrap">';
2550 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
2551 print "</td>\n";
2552 if (!$i) {
2553 $totalarray['nbfield']++;
2554 }
2555 }
2556
2557 // Amount HT/net in foreign currency
2558 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
2559 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
2560 if (!$i) {
2561 $totalarray['nbfield']++;
2562 }
2563 }
2564 // Amount VAT in foreign currency
2565 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
2566 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
2567 if (!$i) {
2568 $totalarray['nbfield']++;
2569 }
2570 }
2571 // Amount TTC / gross in foreign currency
2572 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
2573 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
2574 if (!$i) {
2575 $totalarray['nbfield']++;
2576 }
2577 }
2578
2579 $userstatic->id = $obj->fk_user_author;
2580 $userstatic->login = $obj->login;
2581 $userstatic->lastname = $obj->lastname;
2582 $userstatic->firstname = $obj->firstname;
2583 $userstatic->email = $obj->user_email;
2584 $userstatic->status = $obj->user_statut;
2585 $userstatic->entity = $obj->entity;
2586 $userstatic->photo = $obj->photo;
2587 $userstatic->office_phone = $obj->office_phone;
2588 $userstatic->office_fax = $obj->office_fax;
2589 $userstatic->user_mobile = $obj->user_mobile;
2590 $userstatic->job = $obj->job;
2591 $userstatic->gender = $obj->gender;
2592
2593 // Author
2594 if (!empty($arrayfields['u.login']['checked'])) {
2595 print '<td class="tdoverflowmax125">';
2596 if ($userstatic->id) {
2597 print $userstatic->getNomUrl(-1);
2598 } else {
2599 print '&nbsp;';
2600 }
2601 print "</td>\n";
2602 if (!$i) {
2603 $totalarray['nbfield']++;
2604 }
2605 }
2606
2607 // Sales representatives
2608 if (!empty($arrayfields['sale_representative']['checked'])) {
2609 print '<td>';
2610 if ($obj->socid > 0) {
2611 $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
2612 if ($listsalesrepresentatives < 0) {
2613 dol_print_error($db);
2614 }
2615 $nbofsalesrepresentative = count($listsalesrepresentatives);
2616 if ($nbofsalesrepresentative > 6) {
2617 // We print only number
2618 print $nbofsalesrepresentative;
2619 } elseif ($nbofsalesrepresentative > 0) {
2620 $j = 0;
2621 foreach ($listsalesrepresentatives as $val) {
2622 $userstatic->id = $val['id'];
2623 $userstatic->lastname = $val['lastname'];
2624 $userstatic->firstname = $val['firstname'];
2625 $userstatic->email = $val['email'];
2626 $userstatic->status = $val['statut'];
2627 $userstatic->entity = $val['entity'];
2628 $userstatic->photo = $val['photo'];
2629 $userstatic->login = $val['login'];
2630 $userstatic->office_phone = $val['office_phone'];
2631 $userstatic->office_fax = $val['office_fax'];
2632 $userstatic->user_mobile = $val['user_mobile'];
2633 $userstatic->job = $val['job'];
2634 $userstatic->gender = $val['gender'];
2635 //print '<div class="float">':
2636 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2637 $j++;
2638 if ($j < $nbofsalesrepresentative) {
2639 print ' ';
2640 }
2641 //print '</div>';
2642 }
2643 }
2644 //else print $langs->trans("NoSalesRepresentativeAffected");
2645 } else {
2646 print '&nbsp;';
2647 }
2648 print '</td>';
2649 if (!$i) {
2650 $totalarray['nbfield']++;
2651 }
2652 }
2653
2654 // Total buying or cost price
2655 if (!empty($arrayfields['total_pa']['checked'])) {
2656 print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
2657 if (!$i) {
2658 $totalarray['nbfield']++;
2659 }
2660 }
2661
2662 // Total margin
2663 if (!empty($arrayfields['total_margin']['checked'])) {
2664 print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
2665 if (!$i) {
2666 $totalarray['nbfield']++;
2667 }
2668 if (!$i) {
2669 $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
2670 }
2671
2672 if (!isset($totalarray['val']['total_margin'])) {
2673 $totalarray['val']['total_margin'] = 0;
2674 }
2675
2676 $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
2677 }
2678
2679 // Total margin rate
2680 if (!empty($arrayfields['total_margin_rate']['checked'])) {
2681 print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], 0, '', 0, 0, 2).'%').'</td>';
2682 if (!$i) {
2683 $totalarray['nbfield']++;
2684 }
2685 }
2686
2687 // Total mark rate
2688 if (!empty($arrayfields['total_mark_rate']['checked'])) {
2689 print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], 0, '', 0, 0, 2).'%').'</td>';
2690 if (!$i) {
2691 $totalarray['nbfield']++;
2692 }
2693 if (!$i) {
2694 $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
2695 }
2696 if ($i >= $imaxinloop - 1) {
2697 if (!empty($total_ht)) {
2698 $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
2699 } else {
2700 $totalarray['val']['total_mark_rate'] = '';
2701 }
2702 }
2703 }
2704
2705 // Date creation
2706 if (!empty($arrayfields['c.datec']['checked'])) {
2707 print '<td align="center" class="nowrap">';
2708 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2709 print '</td>';
2710 if (!$i) {
2711 $totalarray['nbfield']++;
2712 }
2713 }
2714
2715 // Date modification
2716 if (!empty($arrayfields['c.tms']['checked'])) {
2717 print '<td align="center" class="nowrap">';
2718 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2719 print '</td>';
2720 if (!$i) {
2721 $totalarray['nbfield']++;
2722 }
2723 }
2724
2725 // Date cloture
2726 if (!empty($arrayfields['c.date_cloture']['checked'])) {
2727 print '<td align="center" class="nowrap">';
2728 print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
2729 print '</td>';
2730 if (!$i) {
2731 $totalarray['nbfield']++;
2732 }
2733 }
2734
2735 // Note public
2736 if (!empty($arrayfields['c.note_public']['checked'])) {
2737 print '<td class="sensiblehtmlcontent center">';
2738 print dolPrintHTML($obj->note_public);
2739 print '</td>';
2740 if (!$i) {
2741 $totalarray['nbfield']++;
2742 }
2743 }
2744
2745 // Note private
2746 if (!empty($arrayfields['c.note_private']['checked'])) {
2747 print '<td class="sensiblehtmlcontent center">';
2748 print dolPrintHTML($obj->note_private);
2749 print '</td>';
2750 if (!$i) {
2751 $totalarray['nbfield']++;
2752 }
2753 }
2754
2755 // Show shippable Icon (this creates subloops, so may be slow)
2756 if (!empty($arrayfields['shippable']['checked'])) {
2757 print '<td class="center">';
2758 if (!empty($show_shippable_command) && isModEnabled('stock')) {
2759 $text_icon = '';
2760 if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
2761 $generic_commande->getLinesArray(); // Load array ->lines
2762 $generic_commande->loadExpeditions(); // Load array ->expeditions
2763
2764 $numlines = count($generic_commande->lines); // Loop on each line of order
2765 for ($lig = 0; $lig < $numlines; $lig++) {
2766 $orderLine = $generic_commande->lines[$lig];
2767 '@phan-var-force OrderLine $orderLine';
2768 if (isset($generic_commande->expeditions[$orderLine->id])) {
2769 $reliquat = $orderLine->qty - $generic_commande->expeditions[$orderLine->id];
2770 } else {
2771 $reliquat = $orderLine->qty;
2772 }
2773 if ($orderLine->product_type == 0 && $orderLine->fk_product > 0) { // If line is a product and not a service
2774 $nbprod++; // order contains real products
2775 $generic_product->id = $orderLine->fk_product;
2776
2777 // Get local and virtual stock and store it into cache
2778 if (empty($productstat_cache[$orderLine->fk_product])) {
2779 $generic_product->load_stock('nobatch,warehouseopen'); // ->load_virtual_stock() is already included into load_stock()
2780 $productstat_cache[$orderLine->fk_product]['stock_reel'] = $generic_product->stock_reel;
2781 $productstat_cachevirtual[$orderLine->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2782 } else {
2783 $generic_product->stock_reel = $productstat_cache[$orderLine->fk_product]['stock_reel'];
2784 // @phan-suppress-next-line PhanTypeInvalidDimOffset
2785 $generic_product->stock_theorique = $productstat_cachevirtual[$orderLine->fk_product]['stock_reel'];
2786 }
2787
2788 if ($reliquat > $generic_product->stock_reel) {
2789 $notshippable++;
2790 }
2791 if (!getDolGlobalString('SHIPPABLE_ORDER_ICON_IN_LIST')) { // Default code. Default should be this case.
2792 $text_info .= $reliquat.' x '.$orderLine->product_ref.'&nbsp;'.dol_trunc($orderLine->product_label, 20);
2793 $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
2794 $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
2795 $text_info .= ($reliquat != $orderLine->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($orderLine->qty - $reliquat).')</span>' : '');
2796 $text_info .= '<br>';
2797 } else { // BUGGED CODE.
2798 // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
2799 // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
2800 // Detailed virtual stock, looks bugged, incomplete and need heavy load.
2801 // stock order and stock order_supplier
2802 $stock_order = 0;
2803 $stock_order_supplier = 0;
2804 if (getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT') || getDolGlobalString('STOCK_CALCULATE_ON_SHIPMENT_CLOSE')) { // What about other options ?
2805 if (isModEnabled('order')) {
2806 if (empty($productstat_cache[$orderLine->fk_product]['stats_order_customer'])) {
2807 $generic_product->load_stats_commande(0, '1,2');
2808 $productstat_cache[$orderLine->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
2809 } else {
2810 // @phan-suppress-next-line PhanTypeInvalidDimOffset
2811 $generic_product->stats_commande['qty'] = $productstat_cache[$orderLine->fk_product]['stats_order_customer'];
2812 }
2813 $stock_order = $generic_product->stats_commande['qty'];
2814 }
2815 if (isModEnabled("supplier_order")) {
2816 if (empty($productstat_cache[$orderLine->fk_product]['stats_order_supplier'])) {
2817 $generic_product->load_stats_commande_fournisseur(0, '3');
2818 $productstat_cache[$orderLine->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
2819 } else {
2820 // @phan-suppress-next-line PhanTypeInvalidDimOffset
2821 $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$orderLine->fk_product]['stats_order_supplier'];
2822 }
2823 $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
2824 }
2825 }
2826 $text_info .= $reliquat.' x '.$orderLine->ref.'&nbsp;'.dol_trunc($orderLine->product_label, 20);
2827 $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
2828 if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $orderLine->qty)) {
2829 $warning++;
2830 $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2831 }
2832 if ($reliquat > $generic_product->stock_reel) {
2833 $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2834 } else {
2835 $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2836 }
2837 if (isModEnabled("supplier_order")) {
2838 $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier;
2839 }
2840 $text_info .= ($reliquat != $orderLine->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($orderLine->qty - $reliquat).')</span>' : '');
2841 $text_info .= '<br>';
2842 }
2843 }
2844 }
2845 if ($notshippable == 0) {
2846 $text_icon = img_picto('', 'dolly', '', 0, 0, 0, '', 'green paddingleft');
2847 $text_info = $text_icon.' '.$langs->trans('Shippable').'<br>'.$text_info;
2848 } else {
2849 $text_icon = img_picto('', 'dolly', '', 0, 0, 0, '', 'error paddingleft');
2850 $text_info = $text_icon.' '.$langs->trans('NonShippable').'<br>'.$text_info;
2851 }
2852 }
2853
2854 if ($nbprod) {
2855 print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
2856 }
2857 if ($warning) { // Always false in default mode
2858 print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
2859 }
2860 }
2861 print '</td>';
2862 if (!$i) {
2863 $totalarray['nbfield']++;
2864 }
2865 }
2866
2867 // Extra fields
2868 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2869 // Fields from hook
2870 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2871 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2872 print $hookmanager->resPrint;
2873
2874 // Billed
2875 if (!empty($arrayfields['c.facture']['checked'])) {
2876 print '<td class="center">';
2877 if ($obj->billed) {
2878 print yn($obj->billed, $langs->trans("Billed"));
2879 }
2880 print '</td>';
2881 if (!$i) {
2882 $totalarray['nbfield']++;
2883 }
2884 }
2885
2886 // Import key
2887 if (!empty($arrayfields['c.import_key']['checked'])) {
2888 print '<td class="nowrap center">'.dol_escape_htmltag($obj->import_key).'</td>';
2889 if (!$i) {
2890 $totalarray['nbfield']++;
2891 }
2892 }
2893
2894 // Status
2895 if (!empty($arrayfields['c.fk_statut']['checked'])) {
2896 print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
2897 if (!$i) {
2898 $totalarray['nbfield']++;
2899 }
2900 }
2901
2902 // Action column
2903 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2904 print '<td class="nowrap center">';
2905 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2906 $selected = 0;
2907 if (in_array($obj->rowid, $arrayofselected)) {
2908 $selected = 1;
2909 }
2910 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2911 }
2912 print '</td>';
2913 if (!$i) {
2914 $totalarray['nbfield']++;
2915 }
2916 }
2917
2918 print "</tr>\n";
2919
2920 $total += $obj->total_ht;
2921 $subtotal += $obj->total_ht;
2922 }
2923 $i++;
2924}
2925
2926// Show total line
2927include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2928
2929// If no record found
2930if ($num == 0) {
2931 $colspan = 1;
2932 foreach ($arrayfields as $key => $val) {
2933 if (!empty($val['checked'])) {
2934 $colspan++;
2935 }
2936 }
2937 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2938}
2939
2940$db->free($resql);
2941
2942$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2943$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2944print $hookmanager->resPrint;
2945
2946print '</table>'."\n";
2947print '</div>'."\n";
2948
2949print '</form>'."\n";
2950
2951if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2952 $hidegeneratedfilelistifempty = 1;
2953 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2954 $hidegeneratedfilelistifempty = 0;
2955 }
2956
2957 // Show list of available documents
2958 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2959 $urlsource .= str_replace('&amp;', '&', $param);
2960
2961 $filedir = $diroutputmassaction;
2962 $genallowed = $permissiontoread;
2963 $delallowed = $permissiontoadd;
2964
2965 print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2966}
2967
2968// End of page
2969llxFooter();
2970$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage customers orders.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
const STATUS_CLOSED
Closed (Sent, billed or not)
const STATUS_CANCELED
Canceled status.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class to manage absolute discounts.
Class to manage standard extra fields.
Class to manage 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 permettant la generation de composants html autre Only common components are here.
Class permettant la generation de composants html autre Only common components are here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage products or services.
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
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.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dolPrintLabel($s)
Return a string label (so on 1 line only and that should not contains any HTML) ready to be output on...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.