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