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