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