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