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