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