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