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