dolibarr  19.0.0-dev
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'];
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('PassedInClosedStatus', $objecttmp->ref), null, 'mesgs');
722  } else {
723  setEventMessages($langs->trans('CantBeClosed'), 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 progress"
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 progress + shipped"
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 }
915 
916 if ($search_datecloture_start) {
917  $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
918 }
919 if ($search_datecloture_end) {
920  $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
921 }
922 if ($search_dateorder_start) {
923  $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
924 }
925 if ($search_dateorder_end) {
926  $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
927 }
928 if ($search_datedelivery_start) {
929  $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
930 }
931 if ($search_datedelivery_end) {
932  $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
933 }
934 if ($search_town) {
935  $sql .= natural_search('s.town', $search_town);
936 }
937 if ($search_zip) {
938  $sql .= natural_search("s.zip", $search_zip);
939 }
940 if ($search_state) {
941  $sql .= natural_search("state.nom", $search_state);
942 }
943 if ($search_country) {
944  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
945 }
946 if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
947  $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
948 }
949 if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
950  $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
951 } else {
952  if ($search_company) {
953  $sql .= natural_search('s.nom', $search_company);
954  }
955  if ($search_company_alias) {
956  $sql .= natural_search('s.name_alias', $search_company_alias);
957  }
958 }
959 if ($search_parent_name) {
960  $sql .= natural_search('s2.nom', $search_parent_name);
961 }
962 if ($search_sale > 0) {
963  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
964 }
965 if ($search_user > 0) {
966  $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);
967 }
968 if ($search_total_ht != '') {
969  $sql .= natural_search('c.total_ht', $search_total_ht, 1);
970 }
971 if ($search_total_vat != '') {
972  $sql .= natural_search('c.total_tva', $search_total_vat, 1);
973 }
974 if ($search_total_ttc != '') {
975  $sql .= natural_search('c.total_ttc', $search_total_ttc, 1);
976 }
977 if ($search_warehouse != '' && $search_warehouse > 0) {
978  $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
979 }
980 if ($search_multicurrency_code != '') {
981  $sql .= " AND c.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
982 }
983 if ($search_multicurrency_tx != '') {
984  $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
985 }
986 if ($search_multicurrency_montant_ht != '') {
987  $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
988 }
989 if ($search_multicurrency_montant_vat != '') {
990  $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
991 }
992 if ($search_multicurrency_montant_ttc != '') {
993  $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
994 }
995 if ($search_login) {
996  $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
997 }
998 if ($search_project_ref != '') {
999  $sql .= natural_search("p.ref", $search_project_ref);
1000 }
1001 if ($search_project != '') {
1002  $sql .= natural_search("p.title", $search_project);
1003 }
1004 if ($search_categ_cus > 0) {
1005  $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
1006 }
1007 if ($search_categ_cus == -2) {
1008  $sql .= " AND cc.fk_categorie IS NULL";
1009 }
1010 if ($search_fk_cond_reglement > 0) {
1011  $sql .= " AND c.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
1012 }
1013 if ($search_fk_shipping_method > 0) {
1014  $sql .= " AND c.fk_shipping_method = ".((int) $search_fk_shipping_method);
1015 }
1016 if ($search_fk_mode_reglement > 0) {
1017  $sql .= " AND c.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
1018 }
1019 if ($search_fk_input_reason > 0) {
1020  $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason);
1021 }
1022 // Search for tag/category ($searchCategoryProductList is an array of ID)
1023 $searchCategoryProductOperator = -1;
1024 $searchCategoryProductList = array($search_product_category);
1025 if (!empty($searchCategoryProductList)) {
1026  $searchCategoryProductSqlList = array();
1027  $listofcategoryid = '';
1028  foreach ($searchCategoryProductList as $searchCategoryProduct) {
1029  if (intval($searchCategoryProduct) == -2) {
1030  $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)";
1031  } elseif (intval($searchCategoryProduct) > 0) {
1032  if ($searchCategoryProductOperator == 0) {
1033  $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).")";
1034  } else {
1035  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
1036  }
1037  }
1038  }
1039  if ($listofcategoryid) {
1040  $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)."))";
1041  }
1042  if ($searchCategoryProductOperator == 1) {
1043  if (!empty($searchCategoryProductSqlList)) {
1044  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
1045  }
1046  } else {
1047  if (!empty($searchCategoryProductSqlList)) {
1048  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
1049  }
1050  }
1051 }
1052 // Add where from extra fields
1053 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
1054 // Add where from hooks
1055 $parameters = array();
1056 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1057 $sql .= $hookmanager->resPrint;
1058 
1059 // Add HAVING from hooks
1060 $parameters = array();
1061 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1062 $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
1063 
1064 // Count total nb of records
1065 $nbtotalofrecords = '';
1066 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
1067  /* The fast and low memory method to get and count full list converts the sql into a sql count */
1068  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
1069  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
1070  $resql = $db->query($sqlforcount);
1071  if ($resql) {
1072  $objforcount = $db->fetch_object($resql);
1073  $nbtotalofrecords = $objforcount->nbtotalofrecords;
1074  } else {
1075  dol_print_error($db);
1076  }
1077 
1078  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than paging size (filtering), goto and load page 0
1079  $page = 0;
1080  $offset = 0;
1081  }
1082  $db->free($resql);
1083 }
1084 
1085 $sql .= $db->order($sortfield, $sortorder);
1086 if ($limit) {
1087  $sql .= $db->plimit($limit + 1, $offset);
1088 }
1089 //print $sql;
1090 
1091 $resql = $db->query($sql);
1092 if (!$resql) {
1093  dol_print_error($db);
1094  exit;
1095 }
1096 
1097 if ($socid > 0) {
1098  $soc = new Societe($db);
1099  $soc->fetch($socid);
1100  $title = $langs->trans('CustomersOrders').' - '.$soc->name;
1101  if (empty($search_company)) {
1102  $search_company = $soc->name;
1103  }
1104 } else {
1105  $title = $langs->trans('CustomersOrders');
1106 }
1107 if (strval($search_status) == '0') {
1108  $title .= ' - '.$langs->trans('StatusOrderDraftShort');
1109 }
1110 if ($search_status == 1) {
1111  $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
1112 }
1113 if ($search_status == 2) {
1114  $title .= ' - '.$langs->trans('StatusOrderSentShort');
1115 }
1116 if ($search_status == 3) {
1117  $title .= ' - '.$langs->trans('StatusOrderToBillShort');
1118 }
1119 if ($search_status == -1) {
1120  $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
1121 }
1122 if ($search_status == -2) {
1123  $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
1124 }
1125 if ($search_status == -3) {
1126  $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(!isModEnabled('expedition') ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
1127 }
1128 if ($search_status == -4) {
1129  $title .= ' - '.$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort");
1130 }
1131 
1132 $num = $db->num_rows($resql);
1133 
1134 $arrayofselected = is_array($toselect) ? $toselect : array();
1135 
1136 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
1137  $obj = $db->fetch_object($resql);
1138  $id = $obj->rowid;
1139  header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
1140  exit;
1141 }
1142 
1143 // Output page
1144 // --------------------------------------------------------------------
1145 
1146 llxHeader('', $title, $help_url);
1147 
1148 $arrayofselected = is_array($toselect) ? $toselect : array();
1149 
1150 $param = '';
1151 if (!empty($mode)) {
1152  $param .= '&mode='.urlencode($mode);
1153 }
1154 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
1155  $param .= '&contextpage='.urlencode($contextpage);
1156 }
1157 if ($limit > 0 && $limit != $conf->liste_limit) {
1158  $param .= '&limit='.((int) $limit);
1159 }
1160 if ($sall) {
1161  $param .= '&sall='.urlencode($sall);
1162 }
1163 if ($socid > 0) {
1164  $param .= '&socid='.urlencode($socid);
1165 }
1166 if ($search_status != '') {
1167  $param .= '&search_status='.urlencode($search_status);
1168 }
1169 if ($search_datecloture_start) {
1170  $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');
1171 }
1172 if ($search_datecloture_end) {
1173  $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');
1174 }
1175 if ($search_dateorder_start) {
1176  $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');
1177 }
1178 if ($search_dateorder_end) {
1179  $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');
1180 }
1181 if ($search_datedelivery_start) {
1182  $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');
1183 }
1184 if ($search_datedelivery_end) {
1185  $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');
1186 }
1187 if ($search_ref) {
1188  $param .= '&search_ref='.urlencode($search_ref);
1189 }
1190 if ($search_company) {
1191  $param .= '&search_company='.urlencode($search_company);
1192 }
1193 if ($search_company_alias) {
1194  $param .= '&search_company_alias='.urlencode($search_company_alias);
1195 }
1196 if ($search_parent_name != '') {
1197  $param .= '&search_parent_name='.urlencode($search_parent_name);
1198 }
1199 if ($search_ref_customer) {
1200  $param .= '&search_ref_customer='.urlencode($search_ref_customer);
1201 }
1202 if ($search_user > 0) {
1203  $param .= '&search_user='.urlencode($search_user);
1204 }
1205 if ($search_sale > 0) {
1206  $param .= '&search_sale='.urlencode($search_sale);
1207 }
1208 if ($search_total_ht != '') {
1209  $param .= '&search_total_ht='.urlencode($search_total_ht);
1210 }
1211 if ($search_total_vat != '') {
1212  $param .= '&search_total_vat='.urlencode($search_total_vat);
1213 }
1214 if ($search_total_ttc != '') {
1215  $param .= '&search_total_ttc='.urlencode($search_total_ttc);
1216 }
1217 if ($search_warehouse != '') {
1218  $param .= '&search_warehouse='.urlencode($search_warehouse);
1219 }
1220 if ($search_login) {
1221  $param .= '&search_login='.urlencode($search_login);
1222 }
1223 if ($search_multicurrency_code != '') {
1224  $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
1225 }
1226 if ($search_multicurrency_tx != '') {
1227  $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
1228 }
1229 if ($search_multicurrency_montant_ht != '') {
1230  $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
1231 }
1232 if ($search_multicurrency_montant_vat != '') {
1233  $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
1234 }
1235 if ($search_multicurrency_montant_ttc != '') {
1236  $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
1237 }
1238 if ($search_project_ref >= 0) {
1239  $param .= "&search_project_ref=".urlencode($search_project_ref);
1240 }
1241 if ($search_town != '') {
1242  $param .= '&search_town='.urlencode($search_town);
1243 }
1244 if ($search_zip != '') {
1245  $param .= '&search_zip='.urlencode($search_zip);
1246 }
1247 if ($search_state != '') {
1248  $param .= '&search_state='.urlencode($search_state);
1249 }
1250 if ($search_country != '') {
1251  $param .= '&search_country='.urlencode($search_country);
1252 }
1253 if ($search_type_thirdparty && $search_type_thirdparty != '-1') {
1254  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
1255 }
1256 if ($search_product_category != '') {
1257  $param .= '&search_product_category='.urlencode($search_product_category);
1258 }
1259 if (($search_categ_cus > 0) || ($search_categ_cus == -2)) {
1260  $param .= '&search_categ_cus='.urlencode($search_categ_cus);
1261 }
1262 if ($show_files) {
1263  $param .= '&show_files='.urlencode($show_files);
1264 }
1265 if ($optioncss != '') {
1266  $param .= '&optioncss='.urlencode($optioncss);
1267 }
1268 if ($search_billed != '') {
1269  $param .= '&search_billed='.urlencode($search_billed);
1270 }
1271 if ($search_fk_cond_reglement > 0) {
1272  $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
1273 }
1274 if ($search_fk_shipping_method > 0) {
1275  $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
1276 }
1277 if ($search_fk_mode_reglement > 0) {
1278  $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
1279 }
1280 if ($search_fk_input_reason > 0) {
1281  $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
1282 }
1283 
1284 // Add $param from extra fields
1285 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1286 
1287 // Add $param from hooks
1288 $parameters = array();
1289 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1290 $param .= $hookmanager->resPrint;
1291 
1292 // List of mass actions available
1293 $arrayofmassactions = array(
1294  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
1295  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1296 );
1297 if ($permissiontovalidate) {
1298  $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
1299 }
1300 if ($permissiontoclose) {
1301  $arrayofmassactions['preshipped'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').$langs->trans("ClassifyShipped");
1302 }
1303 if ($permissiontoclose) {
1304  $arrayofmassactions['setbilled'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
1305 }
1306 if ($permissiontocancel) {
1307  $arrayofmassactions['cancelorders'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Cancel");
1308 }
1309 if (!empty($permissiontodelete)) {
1310  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1311 }
1312 if (isModEnabled('facture') && $user->hasRight("facture", "creer")) {
1313  $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisCustomer");
1314 }
1315 if ($permissiontosendbymail) {
1316  $arrayofmassactions['presend'] = img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
1317 }
1318 if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
1319  $arrayofmassactions = array();
1320 }
1321 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1322 
1323 $url = DOL_URL_ROOT.'/commande/card.php?action=create';
1324 if (!empty($socid)) {
1325  $url .= '&socid='.$socid;
1326 }
1327 $newcardbutton = '';
1328 $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'));
1329 $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'));
1330 $newcardbutton .= dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', $contextpage == 'orderlist' && $permissiontoadd);
1331 
1332 // Lines of title fields
1333 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
1334 if ($optioncss != '') {
1335  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1336 }
1337 print '<input type="hidden" name="token" value="'.newToken().'">';
1338 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1339 print '<input type="hidden" name="action" value="list">';
1340 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1341 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1342 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1343 print '<input type="hidden" name="search_status" value="'.$search_status.'">';
1344 print '<input type="hidden" name="socid" value="'.$socid.'">';
1345 print '<input type="hidden" name="page_y" value="">';
1346 print '<input type="hidden" name="mode" value="'.$mode.'">';
1347 
1348 
1349 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
1350 
1351 $topicmail = "SendOrderRef";
1352 $modelmail = "order_send";
1353 $objecttmp = new Commande($db);
1354 $trackid = 'ord'.$object->id;
1355 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1356 
1357 if ($massaction == 'prevalidate') {
1358  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
1359 }
1360 if ($massaction == 'preshipped') {
1361  print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("CloseOrder"), $langs->trans("ConfirmCloseOrder"), "shipped", null, '', 0, 200, 500, 1);
1362 }
1363 
1364 if ($massaction == 'createbills') {
1365  print '<input type="hidden" name="massaction" value="confirm_createbills">';
1366 
1367  print '<table class="noborder centpercent">';
1368  print '<tr>';
1369  print '<td>';
1370  print $langs->trans('DateInvoice');
1371  print '</td>';
1372  print '<td>';
1373  print $form->selectDate('', '', '', '', '', '', 1, 1);
1374  print '</td>';
1375  print '</tr>';
1376  print '<tr>';
1377  print '<td>';
1378  print $langs->trans('CreateOneBillByThird');
1379  print '</td>';
1380  print '<td>';
1381  print $form->selectyesno('createbills_onebythird', '', 1);
1382  print '</td>';
1383  print '</tr>';
1384  print '<tr>';
1385  print '<td>';
1386  print $langs->trans('ValidateInvoices');
1387  print '</td>';
1388  print '<td>';
1389  if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_BILL)) {
1390  print $form->selectyesno('validate_invoices', 0, 1, 1);
1391  $langs->load("errors");
1392  print ' ('.$langs->trans("WarningAutoValNotPossibleWhenStockIsDecreasedOnInvoiceVal").')';
1393  } else {
1394  print $form->selectyesno('validate_invoices', 0, 1);
1395  }
1396  if (!empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) {
1397  print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoOrderStayUnbilled").'</span>';
1398  } else {
1399  print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetOrderBilledNotEnabled").'</span>';
1400  }
1401  print '</td>';
1402  print '</tr>';
1403  print '</table>';
1404 
1405  print '<div class="center">';
1406  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
1407  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1408  print '</div>';
1409  print '<br><br>';
1410 }
1411 
1412 if ($sall) {
1413  $setupstring = '';
1414  foreach ($fieldstosearchall as $key => $val) {
1415  $fieldstosearchall[$key] = $langs->trans($val);
1416  $setupstring .= $key."=".$val.";";
1417  }
1418  print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1419  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
1420 }
1421 
1422 $moreforfilter = '';
1423 
1424 // If the user can view prospects? sales other than his own
1425 if ($user->hasRight("user", "user", "lire")) {
1426  $langs->load("commercial");
1427  $moreforfilter .= '<div class="divsearchfield">';
1428  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1429  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
1430  $moreforfilter .= '</div>';
1431 }
1432 // If the user can view other users
1433 if ($user->hasRight("user", "user", "lire")) {
1434  $moreforfilter .= '<div class="divsearchfield">';
1435  $tmptitle = $langs->trans('LinkedToSpecificUsers');
1436  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
1437  $moreforfilter .= '</div>';
1438 }
1439 
1440 // If the user can view other products/services than his own
1441 if (isModEnabled('categorie') && $user->hasRight("categorie", "lire") && ($user->hasRight("produit", "lire") || $user->hasRight("service", "lire"))) {
1442  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1443  $moreforfilter .= '<div class="divsearchfield">';
1444  $tmptitle = $langs->trans('IncludingProductWithTag');
1445  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
1446  $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);
1447  $moreforfilter .= '</div>';
1448 }
1449 // If Categories are enabled & user has rights to see
1450 if (isModEnabled('categorie') && $user->hasRight("categorie", "lire")) {
1451  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1452  $moreforfilter .= '<div class="divsearchfield">';
1453  $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1454  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, 'maxwidth300 widthcentpercentminusx');
1455  $moreforfilter .= '</div>';
1456 }
1457 // If Stock is enabled
1458 if (isModEnabled('stock') && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
1459  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1460  $formproduct = new FormProduct($db);
1461  $moreforfilter .= '<div class="divsearchfield">';
1462  $tmptitle = $langs->trans('Warehouse');
1463  $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1, 0, 0, $tmptitle, 0, 0, array(), 'maxwidth250 widthcentpercentminusx');
1464  $moreforfilter .= '</div>';
1465 }
1466 $parameters = array();
1467 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1468 if (empty($reshook)) {
1469  $moreforfilter .= $hookmanager->resPrint;
1470 } else {
1471  $moreforfilter = $hookmanager->resPrint;
1472 }
1473 
1474 if (!empty($moreforfilter)) {
1475  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1476  print $moreforfilter;
1477  $parameters = array();
1478  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1479  print $hookmanager->resPrint;
1480  print '</div>';
1481 }
1482 
1483 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1484 $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
1485 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1486 
1487 if (GETPOST('autoselectall', 'int')) {
1488  $selectedfields .= '<script>';
1489  $selectedfields .= ' $(document).ready(function() {';
1490  $selectedfields .= ' console.log("Autoclick on checkforselects");';
1491  $selectedfields .= ' $("#checkforselects").click();';
1492  $selectedfields .= ' $("#massaction").val("createbills").change();';
1493  $selectedfields .= ' });';
1494  $selectedfields .= '</script>';
1495 }
1496 
1497 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
1498 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1499 
1500 // Fields title search
1501 // --------------------------------------------------------------------
1502 print '<tr class="liste_titre_filter">';
1503 // Action column
1504 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1505  print '<td class="liste_titre center maxwidthsearch">';
1506  $searchpicto = $form->showFilterButtons('left');
1507  print $searchpicto;
1508  print '</td>';
1509 }
1510 
1511 // Ref
1512 if (!empty($arrayfields['c.ref']['checked'])) {
1513  print '<td class="liste_titre">';
1514  print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1515  print '</td>';
1516 }
1517 // Ref customer
1518 if (!empty($arrayfields['c.ref_client']['checked'])) {
1519  print '<td class="liste_titre" align="left">';
1520  print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
1521  print '</td>';
1522 }
1523 // Project ref
1524 if (!empty($arrayfields['p.ref']['checked'])) {
1525  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
1526 }
1527 // Project title
1528 if (!empty($arrayfields['p.title']['checked'])) {
1529  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
1530 }
1531 // Thirpdarty
1532 if (!empty($arrayfields['s.nom']['checked'])) {
1533  print '<td class="liste_titre" align="left">';
1534  print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
1535  print '</td>';
1536 }
1537 // Alias
1538 if (!empty($arrayfields['s.name_alias']['checked'])) {
1539  print '<td class="liste_titre" align="left">';
1540  print '<input class="flat maxwidth100" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'">';
1541  print '</td>';
1542 }
1543 // Parent company
1544 if (!empty($arrayfields['s2.nom']['checked'])) {
1545  print '<td class="liste_titre">';
1546  print '<input class="flat maxwidth100" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
1547  print '</td>';
1548 }
1549 // Town
1550 if (!empty($arrayfields['s.town']['checked'])) {
1551  print '<td class="liste_titre"><input class="flat width50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
1552 }
1553 // Zip
1554 if (!empty($arrayfields['s.zip']['checked'])) {
1555  print '<td class="liste_titre"><input class="flat width50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
1556 }
1557 // State
1558 if (!empty($arrayfields['state.nom']['checked'])) {
1559  print '<td class="liste_titre">';
1560  print '<input class="flat width50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1561  print '</td>';
1562 }
1563 // Country
1564 if (!empty($arrayfields['country.code_iso']['checked'])) {
1565  print '<td class="liste_titre" align="center">';
1566  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1567  print '</td>';
1568 }
1569 // Company type
1570 if (!empty($arrayfields['typent.code']['checked'])) {
1571  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1572  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);
1573  print '</td>';
1574 }
1575 // Date order
1576 if (!empty($arrayfields['c.date_commande']['checked'])) {
1577  print '<td class="liste_titre center">';
1578  print '<div class="nowrap">';
1579  print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1580  print '</div>';
1581  print '<div class="nowrap">';
1582  print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1583  print '</div>';
1584  print '</td>';
1585 }
1586 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1587  print '<td class="liste_titre center">';
1588  print '<div class="nowrap">';
1589  print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1590  print '</div>';
1591  print '<div class="nowrap">';
1592  print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1593  print '</div>';
1594  print '</td>';
1595 }
1596 // Shipping Method
1597 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1598  print '<td class="liste_titre">';
1599  $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
1600  print '</td>';
1601 }
1602 // Payment term
1603 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1604  print '<td class="liste_titre">';
1605  print $form->getSelectConditionsPaiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
1606  print '</td>';
1607 }
1608 // Payment mode
1609 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1610  print '<td class="liste_titre">';
1611  print $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1, '', 1);
1612  print '</td>';
1613 }
1614 // Channel
1615 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1616  print '<td class="liste_titre">';
1617  $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, '', 1);
1618  print '</td>';
1619 }
1620 // Amount HT / net
1621 if (!empty($arrayfields['c.total_ht']['checked'])) {
1622  print '<td class="liste_titre right">';
1623  print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
1624  print '</td>';
1625 }
1626 // Amount of VAT
1627 if (!empty($arrayfields['c.total_vat']['checked'])) {
1628  print '<td class="liste_titre right">';
1629  print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
1630  print '</td>';
1631 }
1632 // Total Amount (TTC / gross)
1633 if (!empty($arrayfields['c.total_ttc']['checked'])) {
1634  print '<td class="liste_titre right">';
1635  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
1636  print '</td>';
1637 }
1638 // Currency
1639 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1640  print '<td class="liste_titre">';
1641  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1642  print '</td>';
1643 }
1644 // Currency rate
1645 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1646  print '<td class="liste_titre">';
1647  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1648  print '</td>';
1649 }
1650 // Amount HT/net in foreign currency
1651 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1652  print '<td class="liste_titre right">';
1653  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1654  print '</td>';
1655 }
1656 // VAT in foreign currency
1657 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1658  print '<td class="liste_titre right">';
1659  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1660  print '</td>';
1661 }
1662 // Amount/Total (TTC / gross) in foreign currency
1663 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1664  print '<td class="liste_titre right">';
1665  print '<input class="flat width75" type="text" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1666  print '</td>';
1667 }
1668 // Author
1669 if (!empty($arrayfields['u.login']['checked'])) {
1670  print '<td class="liste_titre">';
1671  print '<input class="flat width75" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1672  print '</td>';
1673 }
1674 // Sales Representative
1675 if (!empty($arrayfields['sale_representative']['checked'])) {
1676  print '<td class="liste_titre"></td>';
1677 }
1678 if (!empty($arrayfields['total_pa']['checked'])) {
1679  print '<td class="liste_titre right">';
1680  print '</td>';
1681 }
1682 if (!empty($arrayfields['total_margin']['checked'])) {
1683  print '<td class="liste_titre right">';
1684  print '</td>';
1685 }
1686 if (!empty($arrayfields['total_margin_rate']['checked'])) {
1687  print '<td class="liste_titre right">';
1688  print '</td>';
1689 }
1690 if (!empty($arrayfields['total_mark_rate']['checked'])) {
1691  print '<td class="liste_titre right">';
1692  print '</td>';
1693 }
1694 
1695 // Extra fields
1696 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1697 
1698 // Fields from hook
1699 $parameters = array('arrayfields'=>$arrayfields);
1700 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1701 print $hookmanager->resPrint;
1702 
1703 // Date creation
1704 if (!empty($arrayfields['c.datec']['checked'])) {
1705  print '<td class="liste_titre">';
1706  print '</td>';
1707 }
1708 // Date modification
1709 if (!empty($arrayfields['c.tms']['checked'])) {
1710  print '<td class="liste_titre">';
1711  print '</td>';
1712 }
1713 // Date cloture
1714 if (!empty($arrayfields['c.date_cloture']['checked'])) {
1715  print '<td class="liste_titre center">';
1716  print '<div class="nowrap">';
1717  print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1718  print '</div>';
1719  print '<div class="nowrap">';
1720  print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1721  print '</div>';
1722  print '</td>';
1723 }
1724 // Note public
1725 if (!empty($arrayfields['c.note_public']['checked'])) {
1726  print '<td class="liste_titre">';
1727  print '</td>';
1728 }
1729 // Note private
1730 if (!empty($arrayfields['c.note_private']['checked'])) {
1731  print '<td class="liste_titre">';
1732  print '</td>';
1733 }
1734 // Shippable
1735 if (!empty($arrayfields['shippable']['checked'])) {
1736  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
1737  //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
1738  if (!empty($conf->global->ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT)) {
1739  print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
1740  print $langs->trans('ShowShippableStatus');
1741  } else {
1742  $show_shippable_command = 1;
1743  }
1744  print '</td>';
1745 }
1746 // Status billed
1747 if (!empty($arrayfields['c.facture']['checked'])) {
1748  print '<td class="liste_titre maxwidthonsmartphone center">';
1749  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
1750  print '</td>';
1751 }
1752 // Import key
1753 if (!empty($arrayfields['c.import_key']['checked'])) {
1754  print '<td class="liste_titre maxwidthonsmartphone center">';
1755  print '</td>';
1756 }
1757 // Status
1758 if (!empty($arrayfields['c.fk_statut']['checked'])) {
1759  print '<td class="liste_titre right parentonrightofpage">';
1760  $liststatus = array(
1761  Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
1762  Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
1763  Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSentShort"),
1764  -2=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort"),
1765  -3=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
1766  Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
1767  Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
1768  );
1769  print $form->selectarray('search_status', $liststatus, $search_status, -5, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage', 1);
1770  print '</td>';
1771 }
1772 // Action column
1773 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1774  print '<td class="liste_titre center maxwidthsearch">';
1775  $searchpicto = $form->showFilterButtons();
1776  print $searchpicto;
1777  print '</td>';
1778 }
1779 print '</tr>'."\n";
1780 
1781 $totalarray = array(
1782  'nbfield' => 0,
1783  'val' => array(
1784  'c.total_ht' => 0,
1785  'c.total_tva' => 0,
1786  'c.total_ttc' => 0,
1787  ),
1788  'pos' => array(),
1789 );
1790 
1791 
1792 // Fields title label
1793 // --------------------------------------------------------------------
1794 print '<tr class="liste_titre">';
1795 
1796 // Action column
1797 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1798  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
1799  $totalarray['nbfield']++;
1800 }
1801 if (!empty($arrayfields['c.ref']['checked'])) {
1802  print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
1803  $totalarray['nbfield']++;
1804 }
1805 if (!empty($arrayfields['c.ref_client']['checked'])) {
1806  print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
1807  $totalarray['nbfield']++;
1808 }
1809 if (!empty($arrayfields['p.ref']['checked'])) {
1810  print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
1811  $totalarray['nbfield']++;
1812 }
1813 if (!empty($arrayfields['p.title']['checked'])) {
1814  print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
1815  $totalarray['nbfield']++;
1816 }
1817 if (!empty($arrayfields['s.nom']['checked'])) {
1818  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1819  $totalarray['nbfield']++;
1820 }
1821 if (!empty($arrayfields['s.name_alias']['checked'])) {
1822  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1823  $totalarray['nbfield']++;
1824 }
1825 if (!empty($arrayfields['s2.nom']['checked'])) {
1826  print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER['PHP_SELF'], 's2.nom', '', $param, '', $sortfield, $sortorder);
1827  $totalarray['nbfield']++;
1828 }
1829 if (!empty($arrayfields['s.town']['checked'])) {
1830  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1831  $totalarray['nbfield']++;
1832 }
1833 if (!empty($arrayfields['s.zip']['checked'])) {
1834  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1835  $totalarray['nbfield']++;
1836 }
1837 if (!empty($arrayfields['state.nom']['checked'])) {
1838  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1839  $totalarray['nbfield']++;
1840 }
1841 if (!empty($arrayfields['country.code_iso']['checked'])) {
1842  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1843  $totalarray['nbfield']++;
1844 }
1845 if (!empty($arrayfields['typent.code']['checked'])) {
1846  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1847  $totalarray['nbfield']++;
1848 }
1849 if (!empty($arrayfields['c.date_commande']['checked'])) {
1850  print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
1851  $totalarray['nbfield']++;
1852 }
1853 if (!empty($arrayfields['c.date_delivery']['checked'])) {
1854  print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
1855  $totalarray['nbfield']++;
1856 }
1857 if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
1858  print_liste_field_titre($arrayfields['c.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "c.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
1859  $totalarray['nbfield']++;
1860 }
1861 if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
1862  print_liste_field_titre($arrayfields['c.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
1863  $totalarray['nbfield']++;
1864 }
1865 if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
1866  print_liste_field_titre($arrayfields['c.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "c.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
1867  $totalarray['nbfield']++;
1868 }
1869 if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
1870  print_liste_field_titre($arrayfields['c.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "c.fk_input_reason", "", $param, '', $sortfield, $sortorder);
1871  $totalarray['nbfield']++;
1872 }
1873 if (!empty($arrayfields['c.total_ht']['checked'])) {
1874  print_liste_field_titre($arrayfields['c.total_ht']['label'], $_SERVER["PHP_SELF"], 'c.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
1875  $totalarray['nbfield']++;
1876 }
1877 if (!empty($arrayfields['c.total_vat']['checked'])) {
1878  print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'c.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
1879  $totalarray['nbfield']++;
1880 }
1881 if (!empty($arrayfields['c.total_ttc']['checked'])) {
1882  print_liste_field_titre($arrayfields['c.total_ttc']['label'], $_SERVER["PHP_SELF"], 'c.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
1883  $totalarray['nbfield']++;
1884 }
1885 if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
1886  print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1887  $totalarray['nbfield']++;
1888 }
1889 if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
1890  print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1891  $totalarray['nbfield']++;
1892 }
1893 if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
1894  print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1895  $totalarray['nbfield']++;
1896 }
1897 if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
1898  print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1899  $totalarray['nbfield']++;
1900 }
1901 if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
1902  print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1903  $totalarray['nbfield']++;
1904 }
1905 if (!empty($arrayfields['u.login']['checked'])) {
1906  print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
1907  $totalarray['nbfield']++;
1908 }
1909 if (!empty($arrayfields['sale_representative']['checked'])) {
1910  print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1911  $totalarray['nbfield']++;
1912 }
1913 if (!empty($arrayfields['total_pa']['checked'])) {
1914  print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1915  $totalarray['nbfield']++;
1916 }
1917 if (!empty($arrayfields['total_margin']['checked'])) {
1918  print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1919  $totalarray['nbfield']++;
1920 }
1921 if (!empty($arrayfields['total_margin_rate']['checked'])) {
1922  print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1923  $totalarray['nbfield']++;
1924 }
1925 if (!empty($arrayfields['total_mark_rate']['checked'])) {
1926  print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
1927  $totalarray['nbfield']++;
1928 }
1929 
1930 // Extra fields
1931 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1932 
1933 // Hook fields
1934 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
1935 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1936 print $hookmanager->resPrint;
1937 if (!empty($arrayfields['c.datec']['checked'])) {
1938  print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1939  $totalarray['nbfield']++;
1940 }
1941 if (!empty($arrayfields['c.tms']['checked'])) {
1942  print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1943  $totalarray['nbfield']++;
1944 }
1945 if (!empty($arrayfields['c.date_cloture']['checked'])) {
1946  print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1947  $totalarray['nbfield']++;
1948 }
1949 if (!empty($arrayfields['c.note_public']['checked'])) {
1950  print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
1951  $totalarray['nbfield']++;
1952 }
1953 if (!empty($arrayfields['c.note_private']['checked'])) {
1954  print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
1955  $totalarray['nbfield']++;
1956 }
1957 if (!empty($arrayfields['shippable']['checked'])) {
1958  print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
1959  $totalarray['nbfield']++;
1960 }
1961 if (!empty($arrayfields['c.facture']['checked'])) {
1962  print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
1963  $totalarray['nbfield']++;
1964 }
1965 if (!empty($arrayfields['c.import_key']['checked'])) {
1966  print_liste_field_titre($arrayfields['c.import_key']['label'], $_SERVER["PHP_SELF"], "c.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1967  $totalarray['nbfield']++;
1968 }
1969 if (!empty($arrayfields['c.fk_statut']['checked'])) {
1970  print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
1971  $totalarray['nbfield']++;
1972 }
1973 // Action column
1974 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1975  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
1976  $totalarray['nbfield']++;
1977 }
1978 print '</tr>'."\n";
1979 
1980 $total = 0;
1981 $subtotal = 0;
1982 $productstat_cache = array();
1983 $productstat_cachevirtual = array();
1984 $getNomUrl_cache = array();
1985 
1986 $generic_commande = new Commande($db);
1987 $generic_product = new Product($db);
1988 $userstatic = new User($db);
1989 
1990 $with_margin_info = false;
1991 if (isModEnabled('margin') && (
1992  !empty($arrayfields['total_pa']['checked'])
1993  || !empty($arrayfields['total_margin']['checked'])
1994  || !empty($arrayfields['total_margin_rate']['checked'])
1995  || !empty($arrayfields['total_mark_rate']['checked'])
1996  )
1997  ) {
1998  $with_margin_info = true;
1999 }
2000 
2001  $total_ht = 0;
2002  $total_margin = 0;
2003 
2004  // Loop on record
2005  // --------------------------------------------------------------------
2006  $i = 0;
2007  $savnbfield = $totalarray['nbfield'];
2008  $totalarray = array();
2009  $totalarray['nbfield'] = 0;
2010  $imaxinloop = ($limit ? min($num, $limit) : $num);
2011 while ($i < $imaxinloop) {
2012  $obj = $db->fetch_object($resql);
2013  if (empty($obj)) {
2014  break; // Should not happen
2015  }
2016 
2017  $notshippable = 0;
2018  $warning = 0;
2019  $text_info = '';
2020  $text_warning = '';
2021  $nbprod = 0;
2022 
2023  $companystatic->id = $obj->socid;
2024  $companystatic->name = $obj->name;
2025  $companystatic->name_alias = $obj->alias;
2026  $companystatic->client = $obj->client;
2027  $companystatic->fournisseur = $obj->fournisseur;
2028  $companystatic->code_client = $obj->code_client;
2029  $companystatic->email = $obj->email;
2030  $companystatic->phone = $obj->phone;
2031  $companystatic->address = $obj->address;
2032  $companystatic->zip = $obj->zip;
2033  $companystatic->town = $obj->town;
2034  $companystatic->country_code = $obj->country_code;
2035  if (!isset($getNomUrl_cache[$obj->socid])) {
2036  $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2037  }
2038 
2039  $generic_commande->id = $obj->rowid;
2040  $generic_commande->ref = $obj->ref;
2041  $generic_commande->statut = $obj->fk_statut;
2042  $generic_commande->billed = $obj->billed;
2043  $generic_commande->date = $db->jdate($obj->date_commande);
2044  $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
2045  $generic_commande->ref_client = $obj->ref_client;
2046  $generic_commande->total_ht = $obj->total_ht;
2047  $generic_commande->total_tva = $obj->total_tva;
2048  $generic_commande->total_ttc = $obj->total_ttc;
2049  $generic_commande->note_public = $obj->note_public;
2050  $generic_commande->note_private = $obj->note_private;
2051 
2052  $generic_commande->thirdparty = $companystatic;
2053 
2054 
2055  $projectstatic->id = $obj->project_id;
2056  $projectstatic->ref = $obj->project_ref;
2057  $projectstatic->title = $obj->project_label;
2058 
2059  $marginInfo = array();
2060  if ($with_margin_info === true) {
2061  $generic_commande->fetch_lines();
2062  $marginInfo = $formmargin->getMarginInfosArray($generic_commande);
2063  $total_ht += $obj->total_ht;
2064  $total_margin += $marginInfo['total_margin'];
2065  }
2066 
2067  if ($mode == 'kanban') {
2068  if ($i == 0) {
2069  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
2070  print '<div class="box-flex-container kanban">';
2071  }
2072 
2073  // Output Kanban
2074  $selected = -1;
2075  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2076  $selected = 0;
2077  if (in_array($object->id, $arrayofselected)) {
2078  $selected = 1;
2079  }
2080  }
2081  print $generic_commande->getKanbanView('', array('selected' => $selected));
2082  if ($i == ($imaxinloop - 1)) {
2083  print '</div>';
2084  print '</td></tr>';
2085  }
2086  } else {
2087  // Show line of result
2088  $j = 0;
2089  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
2090 
2091  // Action column
2092  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2093  print '<td class="nowrap center">';
2094  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2095  $selected = 0;
2096  if (in_array($obj->rowid, $arrayofselected)) {
2097  $selected = 1;
2098  }
2099  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2100  }
2101  print '</td>';
2102  if (!$i) {
2103  $totalarray['nbfield']++;
2104  }
2105  }
2106 
2107  // Ref
2108  if (!empty($arrayfields['c.ref']['checked'])) {
2109  print '<td class="nowraponall">';
2110  print $generic_commande->getNomUrl(1, ($search_status != 2 ? 0 : $obj->fk_statut), 0, 0, 0, 1, 1);
2111 
2112  $filename = dol_sanitizeFileName($obj->ref);
2113  $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
2114  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
2115  print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
2116 
2117  print '</td>';
2118  if (!$i) {
2119  $totalarray['nbfield']++;
2120  }
2121  }
2122 
2123  // Ref customer
2124  if (!empty($arrayfields['c.ref_client']['checked'])) {
2125  print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_client).'">';
2126  print dol_escape_htmltag($obj->ref_client);
2127  print '</td>';
2128  if (!$i) {
2129  $totalarray['nbfield']++;
2130  }
2131  }
2132 
2133  // Project ref
2134  if (!empty($arrayfields['p.ref']['checked'])) {
2135  print '<td class="nowrap">';
2136  if ($obj->project_id > 0) {
2137  print $projectstatic->getNomUrl(1);
2138  }
2139  print '</td>';
2140  if (!$i) {
2141  $totalarray['nbfield']++;
2142  }
2143  }
2144 
2145  // Project label
2146  if (!empty($arrayfields['p.title']['checked'])) {
2147  print '<td class="nowrap">';
2148  if ($obj->project_id > 0) {
2149  print $projectstatic->title;
2150  }
2151  print '</td>';
2152  if (!$i) {
2153  $totalarray['nbfield']++;
2154  }
2155  }
2156 
2157  // Third party
2158  if (!empty($arrayfields['s.nom']['checked'])) {
2159  print '<td class="tdoverflowmax150">';
2160  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
2161  print $companystatic->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
2162  } else {
2163  print $getNomUrl_cache[$obj->socid];
2164  }
2165 
2166  // If module invoices enabled and user with invoice creation permissions
2167  if (isModEnabled('facture') && !empty($conf->global->ORDER_BILLING_ALL_CUSTOMER)) {
2168  if ($user->hasRight('facture', 'creer')) {
2169  if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0)) {
2170  print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
2171  print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
2172  }
2173  }
2174  }
2175  print '</td>';
2176  if (!$i) {
2177  $totalarray['nbfield']++;
2178  }
2179  }
2180 
2181  // Alias name
2182  if (!empty($arrayfields['s.name_alias']['checked'])) {
2183  print '<td class="nocellnopadd">';
2184  print $obj->alias;
2185  print '</td>';
2186  if (!$i) {
2187  $totalarray['nbfield']++;
2188  }
2189  }
2190 
2191  // Parent company
2192  if (!empty($arrayfields['s2.nom']['checked'])) {
2193  print '<td class="tdoverflowmax200">';
2194  if ($obj->fk_parent > 0) {
2195  if (!isset($company_url_list[$obj->fk_parent])) {
2196  $companyparent = new Societe($db);
2197  $res = $companyparent->fetch($obj->fk_parent);
2198  if ($res > 0) {
2199  $company_url_list[$obj->fk_parent] = $companyparent->getNomUrl(1);
2200  }
2201  }
2202  if (isset($company_url_list[$obj->fk_parent])) {
2203  print $company_url_list[$obj->fk_parent];
2204  }
2205  }
2206  print "</td>";
2207  if (!$i) {
2208  $totalarray['nbfield']++;
2209  }
2210  }
2211 
2212  // Town
2213  if (!empty($arrayfields['s.town']['checked'])) {
2214  print '<td class="nocellnopadd">';
2215  print $obj->town;
2216  print '</td>';
2217  if (!$i) {
2218  $totalarray['nbfield']++;
2219  }
2220  }
2221 
2222  // Zip
2223  if (!empty($arrayfields['s.zip']['checked'])) {
2224  print '<td class="nocellnopadd">';
2225  print $obj->zip;
2226  print '</td>';
2227  if (!$i) {
2228  $totalarray['nbfield']++;
2229  }
2230  }
2231 
2232  // State
2233  if (!empty($arrayfields['state.nom']['checked'])) {
2234  print "<td>".$obj->state_name."</td>\n";
2235  if (!$i) {
2236  $totalarray['nbfield']++;
2237  }
2238  }
2239 
2240  // Country
2241  if (!empty($arrayfields['country.code_iso']['checked'])) {
2242  print '<td class="center">';
2243  $tmparray = getCountry($obj->fk_pays, 'all');
2244  print $tmparray['label'];
2245  print '</td>';
2246  if (!$i) {
2247  $totalarray['nbfield']++;
2248  }
2249  }
2250 
2251  // Type ent
2252  if (!empty($arrayfields['typent.code']['checked'])) {
2253  print '<td class="center">';
2254  if (empty($typenArray)) {
2255  $typenArray = $formcompany->typent_array(1);
2256  }
2257  print $typenArray[$obj->typent_code];
2258  print '</td>';
2259  if (!$i) {
2260  $totalarray['nbfield']++;
2261  }
2262  }
2263 
2264  // Order date
2265  if (!empty($arrayfields['c.date_commande']['checked'])) {
2266  print '<td class="center">';
2267  print dol_print_date($db->jdate($obj->date_commande), 'day');
2268  // Warning late icon and note
2269  if ($generic_commande->hasDelay()) {
2270  print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
2271  }
2272  print '</td>';
2273  if (!$i) {
2274  $totalarray['nbfield']++;
2275  }
2276  }
2277 
2278  // Plannned date of delivery
2279  if (!empty($arrayfields['c.date_delivery']['checked'])) {
2280  print '<td class="center">';
2281  print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
2282  print '</td>';
2283  if (!$i) {
2284  $totalarray['nbfield']++;
2285  }
2286  }
2287 
2288  // Shipping Method
2289  if (!empty($arrayfields['c.fk_shipping_method']['checked'])) {
2290  print '<td>';
2291  $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
2292  print '</td>';
2293  if (!$i) {
2294  $totalarray['nbfield']++;
2295  }
2296  }
2297 
2298  // Payment terms
2299  if (!empty($arrayfields['c.fk_cond_reglement']['checked'])) {
2300  print '<td>';
2301  $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
2302  print '</td>';
2303  if (!$i) {
2304  $totalarray['nbfield']++;
2305  }
2306  }
2307 
2308  // Payment mode
2309  if (!empty($arrayfields['c.fk_mode_reglement']['checked'])) {
2310  print '<td>';
2311  $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
2312  print '</td>';
2313  if (!$i) {
2314  $totalarray['nbfield']++;
2315  }
2316  }
2317 
2318  // Channel
2319  if (!empty($arrayfields['c.fk_input_reason']['checked'])) {
2320  print '<td>';
2321  $form->formInputReason($_SERVER['PHP_SELF'], $obj->fk_input_reason, 'none', '');
2322  print '</td>';
2323  if (!$i) {
2324  $totalarray['nbfield']++;
2325  }
2326  }
2327 
2328  // Amount HT/net
2329  if (!empty($arrayfields['c.total_ht']['checked'])) {
2330  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
2331  if (!$i) {
2332  $totalarray['nbfield']++;
2333  }
2334  if (!$i) {
2335  $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ht';
2336  }
2337  if (isset($totalarray['val']['c.total_ht'])) {
2338  $totalarray['val']['c.total_ht'] += $obj->total_ht;
2339  } else {
2340  $totalarray['val']['c.total_ht'] = $obj->total_ht;
2341  }
2342  }
2343 
2344  // Amount VAT
2345  if (!empty($arrayfields['c.total_vat']['checked'])) {
2346  print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
2347  if (!$i) {
2348  $totalarray['nbfield']++;
2349  }
2350  if (!$i) {
2351  $totalarray['pos'][$totalarray['nbfield']] = 'c.total_tva';
2352  }
2353  if (isset($totalarray['val']['c.total_tva'])) {
2354  $totalarray['val']['c.total_tva'] += $obj->total_tva;
2355  } else {
2356  $totalarray['val']['c.total_tva'] = $obj->total_tva;
2357  }
2358  }
2359 
2360  // Amount TTC / gross
2361  if (!empty($arrayfields['c.total_ttc']['checked'])) {
2362  print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
2363  if (!$i) {
2364  $totalarray['nbfield']++;
2365  }
2366  if (!$i) {
2367  $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ttc';
2368  }
2369  if (isset($totalarray['val']['c.total_ttc'])) {
2370  $totalarray['val']['c.total_ttc'] += $obj->total_ttc;
2371  } else {
2372  $totalarray['val']['c.total_ttc'] = $obj->total_ttc;
2373  }
2374  }
2375 
2376  // Currency
2377  if (!empty($arrayfields['c.multicurrency_code']['checked'])) {
2378  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
2379  if (!$i) {
2380  $totalarray['nbfield']++;
2381  }
2382  }
2383 
2384  // Currency rate
2385  if (!empty($arrayfields['c.multicurrency_tx']['checked'])) {
2386  print '<td class="nowrap">';
2387  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
2388  print "</td>\n";
2389  if (!$i) {
2390  $totalarray['nbfield']++;
2391  }
2392  }
2393 
2394  // Amount HT/net in foreign currency
2395  if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) {
2396  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
2397  if (!$i) {
2398  $totalarray['nbfield']++;
2399  }
2400  }
2401  // Amount VAT in foreign currency
2402  if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) {
2403  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
2404  if (!$i) {
2405  $totalarray['nbfield']++;
2406  }
2407  }
2408  // Amount TTC / gross in foreign currency
2409  if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) {
2410  print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
2411  if (!$i) {
2412  $totalarray['nbfield']++;
2413  }
2414  }
2415 
2416  $userstatic->id = $obj->fk_user_author;
2417  $userstatic->login = $obj->login;
2418  $userstatic->lastname = $obj->lastname;
2419  $userstatic->firstname = $obj->firstname;
2420  $userstatic->email = $obj->user_email;
2421  $userstatic->statut = $obj->user_statut;
2422  $userstatic->entity = $obj->entity;
2423  $userstatic->photo = $obj->photo;
2424  $userstatic->office_phone = $obj->office_phone;
2425  $userstatic->office_fax = $obj->office_fax;
2426  $userstatic->user_mobile = $obj->user_mobile;
2427  $userstatic->job = $obj->job;
2428  $userstatic->gender = $obj->gender;
2429 
2430  // Author
2431  if (!empty($arrayfields['u.login']['checked'])) {
2432  print '<td class="tdoverflowmax150">';
2433  if ($userstatic->id) {
2434  print $userstatic->getNomUrl(-1);
2435  } else {
2436  print '&nbsp;';
2437  }
2438  print "</td>\n";
2439  if (!$i) {
2440  $totalarray['nbfield']++;
2441  }
2442  }
2443 
2444  // Sales representatives
2445  if (!empty($arrayfields['sale_representative']['checked'])) {
2446  print '<td>';
2447  if ($obj->socid > 0) {
2448  $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
2449  if ($listsalesrepresentatives < 0) {
2450  dol_print_error($db);
2451  }
2452  $nbofsalesrepresentative = count($listsalesrepresentatives);
2453  if ($nbofsalesrepresentative > 6) {
2454  // We print only number
2455  print $nbofsalesrepresentative;
2456  } elseif ($nbofsalesrepresentative > 0) {
2457  $j = 0;
2458  foreach ($listsalesrepresentatives as $val) {
2459  $userstatic->id = $val['id'];
2460  $userstatic->lastname = $val['lastname'];
2461  $userstatic->firstname = $val['firstname'];
2462  $userstatic->email = $val['email'];
2463  $userstatic->statut = $val['statut'];
2464  $userstatic->entity = $val['entity'];
2465  $userstatic->photo = $val['photo'];
2466  $userstatic->login = $val['login'];
2467  $userstatic->office_phone = $val['office_phone'];
2468  $userstatic->office_fax = $val['office_fax'];
2469  $userstatic->user_mobile = $val['user_mobile'];
2470  $userstatic->job = $val['job'];
2471  $userstatic->gender = $val['gender'];
2472  //print '<div class="float">':
2473  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
2474  $j++;
2475  if ($j < $nbofsalesrepresentative) {
2476  print ' ';
2477  }
2478  //print '</div>';
2479  }
2480  }
2481  //else print $langs->trans("NoSalesRepresentativeAffected");
2482  } else {
2483  print '&nbsp;';
2484  }
2485  print '</td>';
2486  if (!$i) {
2487  $totalarray['nbfield']++;
2488  }
2489  }
2490 
2491  // Total buying or cost price
2492  if (!empty($arrayfields['total_pa']['checked'])) {
2493  print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
2494  if (!$i) {
2495  $totalarray['nbfield']++;
2496  }
2497  }
2498 
2499  // Total margin
2500  if (!empty($arrayfields['total_margin']['checked'])) {
2501  print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
2502  if (!$i) {
2503  $totalarray['nbfield']++;
2504  }
2505  if (!$i) {
2506  $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
2507  }
2508  $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
2509  }
2510 
2511  // Total margin rate
2512  if (!empty($arrayfields['total_margin_rate']['checked'])) {
2513  print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
2514  if (!$i) {
2515  $totalarray['nbfield']++;
2516  }
2517  }
2518 
2519  // Total mark rate
2520  if (!empty($arrayfields['total_mark_rate']['checked'])) {
2521  print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
2522  if (!$i) {
2523  $totalarray['nbfield']++;
2524  }
2525  if (!$i) {
2526  $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
2527  }
2528  if ($i >= $imaxinloop - 1) {
2529  if (!empty($total_ht)) {
2530  $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
2531  } else {
2532  $totalarray['val']['total_mark_rate'] = '';
2533  }
2534  }
2535  }
2536 
2537  // Extra fields
2538  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2539  // Fields from hook
2540  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
2541  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2542  print $hookmanager->resPrint;
2543 
2544  // Date creation
2545  if (!empty($arrayfields['c.datec']['checked'])) {
2546  print '<td align="center" class="nowrap">';
2547  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2548  print '</td>';
2549  if (!$i) {
2550  $totalarray['nbfield']++;
2551  }
2552  }
2553 
2554  // Date modification
2555  if (!empty($arrayfields['c.tms']['checked'])) {
2556  print '<td align="center" class="nowrap">';
2557  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
2558  print '</td>';
2559  if (!$i) {
2560  $totalarray['nbfield']++;
2561  }
2562  }
2563 
2564  // Date cloture
2565  if (!empty($arrayfields['c.date_cloture']['checked'])) {
2566  print '<td align="center" class="nowrap">';
2567  print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
2568  print '</td>';
2569  if (!$i) {
2570  $totalarray['nbfield']++;
2571  }
2572  }
2573 
2574  // Note public
2575  if (!empty($arrayfields['c.note_public']['checked'])) {
2576  print '<td class="center">';
2577  print dol_string_nohtmltag($obj->note_public);
2578  print '</td>';
2579  if (!$i) {
2580  $totalarray['nbfield']++;
2581  }
2582  }
2583 
2584  // Note private
2585  if (!empty($arrayfields['c.note_private']['checked'])) {
2586  print '<td class="center">';
2587  print dol_string_nohtmltag($obj->note_private);
2588  print '</td>';
2589  if (!$i) {
2590  $totalarray['nbfield']++;
2591  }
2592  }
2593 
2594  // Show shippable Icon (this creates subloops, so may be slow)
2595  if (!empty($arrayfields['shippable']['checked'])) {
2596  print '<td class="center">';
2597  if (!empty($show_shippable_command) && isModEnabled('stock')) {
2598  if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
2599  $generic_commande->getLinesArray(); // Load array ->lines
2600  $generic_commande->loadExpeditions(); // Load array ->expeditions
2601 
2602  $numlines = count($generic_commande->lines); // Loop on each line of order
2603  for ($lig = 0; $lig < $numlines; $lig++) {
2604  if (isset($generic_commande->expeditions[$generic_commande->lines[$lig]->id])) {
2605  $reliquat = $generic_commande->lines[$lig]->qty - $generic_commande->expeditions[$generic_commande->lines[$lig]->id];
2606  } else {
2607  $reliquat = $generic_commande->lines[$lig]->qty;
2608  }
2609  if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) { // If line is a product and not a service
2610  $nbprod++; // order contains real products
2611  $generic_product->id = $generic_commande->lines[$lig]->fk_product;
2612 
2613  // Get local and virtual stock and store it into cache
2614  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
2615  $generic_product->load_stock('nobatch,warehouseopen'); // ->load_virtual_stock() is already included into load_stock()
2616  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
2617  $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2618  } else {
2619  $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
2620  $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
2621  }
2622 
2623  if ($reliquat > $generic_product->stock_reel) {
2624  $notshippable++;
2625  }
2626  if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) { // Default code. Default should be this case.
2627  $text_info .= $reliquat.' x '.$generic_commande->lines[$lig]->product_ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 20);
2628  $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
2629  $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
2630  $text_info .= ($reliquat != $generic_commande->lines[$lig]->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($generic_commande->lines[$lig]->qty - $reliquat).')</span>' : '');
2631  $text_info .= '<br>';
2632  } else { // BUGGED CODE.
2633  // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
2634  // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
2635  // Detailed virtual stock, looks bugged, uncomplete and need heavy load.
2636  // stock order and stock order_supplier
2637  $stock_order = 0;
2638  $stock_order_supplier = 0;
2639  if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { // What about other options ?
2640  if (isModEnabled('commande')) {
2641  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
2642  $generic_product->load_stats_commande(0, '1,2');
2643  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
2644  } else {
2645  $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
2646  }
2647  $stock_order = $generic_product->stats_commande['qty'];
2648  }
2649  if (isModEnabled("supplier_order")) {
2650  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
2651  $generic_product->load_stats_commande_fournisseur(0, '3');
2652  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
2653  } else {
2654  $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
2655  }
2656  $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
2657  }
2658  }
2659  $text_info .= $reliquat.' x '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 20);
2660  $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
2661  if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) {
2662  $warning++;
2663  $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2664  }
2665  if ($reliquat > $generic_product->stock_reel) {
2666  $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2667  } else {
2668  $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
2669  }
2670  if (isModEnabled("supplier_order")) {
2671  $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier;
2672  }
2673  $text_info .= ($reliquat != $generic_commande->lines[$lig]->qty ? ' <span class="opacitymedium">('.$langs->trans("QtyInOtherShipments").' '.($generic_commande->lines[$lig]->qty - $reliquat).')</span>' : '');
2674  $text_info .= '<br>';
2675  }
2676  }
2677  }
2678  if ($notshippable == 0) {
2679  $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'green paddingleft');
2680  $text_info = $text_icon.' '.$langs->trans('Shippable').'<br>'.$text_info;
2681  } else {
2682  $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'error paddingleft');
2683  $text_info = $text_icon.' '.$langs->trans('NonShippable').'<br>'.$text_info;
2684  }
2685  }
2686 
2687  if ($nbprod) {
2688  print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
2689  }
2690  if ($warning) { // Always false in default mode
2691  print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
2692  }
2693  }
2694  print '</td>';
2695  if (!$i) {
2696  $totalarray['nbfield']++;
2697  }
2698  }
2699 
2700  // Billed
2701  if (!empty($arrayfields['c.facture']['checked'])) {
2702  print '<td class="center">'.yn($obj->billed).'</td>';
2703  if (!$i) {
2704  $totalarray['nbfield']++;
2705  }
2706  }
2707 
2708  // Import key
2709  if (!empty($arrayfields['c.import_key']['checked'])) {
2710  print '<td class="nowrap center">'.dol_escape_htmltag($obj->import_key).'</td>';
2711  if (!$i) {
2712  $totalarray['nbfield']++;
2713  }
2714  }
2715 
2716  // Status
2717  if (!empty($arrayfields['c.fk_statut']['checked'])) {
2718  print '<td class="nowrap right">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
2719  if (!$i) {
2720  $totalarray['nbfield']++;
2721  }
2722  }
2723 
2724  // Action column
2725  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2726  print '<td class="nowrap center">';
2727  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2728  $selected = 0;
2729  if (in_array($obj->rowid, $arrayofselected)) {
2730  $selected = 1;
2731  }
2732  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2733  }
2734  print '</td>';
2735  if (!$i) {
2736  $totalarray['nbfield']++;
2737  }
2738  }
2739 
2740  print "</tr>\n";
2741 
2742  $total += $obj->total_ht;
2743  $subtotal += $obj->total_ht;
2744  }
2745  $i++;
2746 }
2747 
2748  // Show total line
2749  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2750 
2751  // If no record found
2752 if ($num == 0) {
2753  $colspan = 1;
2754  foreach ($arrayfields as $key => $val) {
2755  if (!empty($val['checked'])) {
2756  $colspan++;
2757  }
2758  }
2759  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2760 }
2761 
2762  $db->free($resql);
2763 
2764  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
2765  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2766  print $hookmanager->resPrint;
2767 
2768  print '</table>'."\n";
2769  print '</div>'."\n";
2770 
2771  print '</form>'."\n";
2772 
2773 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
2774  $hidegeneratedfilelistifempty = 1;
2775  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
2776  $hidegeneratedfilelistifempty = 0;
2777  }
2778 
2779  // Show list of available documents
2780  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
2781  $urlsource .= str_replace('&amp;', '&', $param);
2782 
2783  $filedir = $diroutputmassaction;
2784  $genallowed = $permissiontoread;
2785  $delallowed = $permissiontoadd;
2786 
2787  print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2788 }
2789 
2790  // End of page
2791  llxFooter();
2792  $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.