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