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