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