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