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