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