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