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