dolibarr  13.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 Ferran Marcet <fmarcet@2byte.es>
13  * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
36 require '../main.inc.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
47 
48 // Load translation files required by the page
49 $langs->loadLangs(array("orders", 'sendings', 'deliveries', 'companies', 'compta', 'bills', 'stocks', 'products'));
50 
51 $action = GETPOST('action', 'aZ09');
52 $massaction = GETPOST('massaction', 'alpha');
53 $show_files = GETPOST('show_files', 'int');
54 $confirm = GETPOST('confirm', 'alpha');
55 $toselect = GETPOST('toselect', 'array');
56 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'orderlist';
57 
58 $search_datecloture_start = GETPOST('search_datecloture_start', 'int');
59 if (empty($search_datecloture_start)) $search_datecloture_start = dol_mktime(0, 0, 0, GETPOST('search_datecloture_startmonth', 'int'), GETPOST('search_datecloture_startday', 'int'), GETPOST('search_datecloture_startyear', 'int'));
60 $search_datecloture_end = GETPOST('search_datecloture_end', 'int');
61 if (empty($search_datecloture_end)) $search_datecloture_end = dol_mktime(23, 59, 59, GETPOST('search_datecloture_endmonth', 'int'), GETPOST('search_datecloture_endday', 'int'), GETPOST('search_datecloture_endyear', 'int'));
62 $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'));
63 $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'));
64 $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'));
65 $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'));
66 $search_product_category = GETPOST('search_product_category', 'int');
67 $search_ref = GETPOST('search_ref', 'alpha') != '' ?GETPOST('search_ref', 'alpha') : GETPOST('sref', 'alpha');
68 $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
69 $search_company = GETPOST('search_company', 'alpha');
70 $search_town = GETPOST('search_town', 'alpha');
71 $search_zip = GETPOST('search_zip', 'alpha');
72 $search_state = GETPOST("search_state", 'alpha');
73 $search_country = GETPOST("search_country", 'int');
74 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
75 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
76 $socid = GETPOST('socid', 'int');
77 $search_user = GETPOST('search_user', 'int');
78 $search_sale = GETPOST('search_sale', 'int');
79 $search_total_ht = GETPOST('search_total_ht', 'alpha');
80 $search_total_vat = GETPOST('search_total_vat', 'alpha');
81 $search_total_ttc = GETPOST('search_total_ttc', 'alpha');
82 $search_warehouse = GETPOST('search_warehouse', 'int');
83 $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
84 $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
85 $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
86 $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
87 $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
88 $search_login = GETPOST('search_login', 'alpha');
89 $search_categ_cus = GETPOST("search_categ_cus", 'int');
90 $optioncss = GETPOST('optioncss', 'alpha');
91 $search_billed = GETPOSTISSET('search_billed') ? GETPOST('search_billed', 'int') : GETPOST('billed', 'int');
92 $search_status = GETPOST('search_status', 'int');
93 $search_btn = GETPOST('button_search', 'alpha');
94 $search_remove_btn = GETPOST('button_removefilter', 'alpha');
95 $search_project_ref = GETPOST('search_project_ref', 'alpha');
96 $search_project = GETPOST('search_project', 'alpha');
97 $search_shippable = GETPOST('search_shippable', 'aZ09');
98 
99 
100 // Security check
101 $id = (GETPOST('orderid') ?GETPOST('orderid', 'int') : GETPOST('id', 'int'));
102 if ($user->socid) $socid = $user->socid;
103 $result = restrictedArea($user, 'commande', $id, '');
104 
105 $diroutputmassaction = $conf->commande->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
106 
107 // Load variable for pagination
108 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
109 $sortfield = GETPOST("sortfield", 'alpha');
110 $sortorder = GETPOST("sortorder", 'alpha');
111 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
112 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters
113 $offset = $limit * $page;
114 $pageprev = $page - 1;
115 $pagenext = $page + 1;
116 if (!$sortfield) $sortfield = 'c.ref';
117 if (!$sortorder) $sortorder = 'DESC';
118 
119 $show_shippable_command = GETPOST('show_shippable_command', 'aZ09');
120 
121 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
122 $object = new Commande($db);
123 $hookmanager->initHooks(array('orderlist'));
124 $extrafields = new ExtraFields($db);
125 
126 // fetch optionals attributes and labels
127 $extrafields->fetch_name_optionals_label($object->table_element);
128 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
129 
130 // List of fields to search into when doing a "search in all"
131 $fieldstosearchall = array(
132  'c.ref'=>'Ref',
133  'c.ref_client'=>'RefCustomerOrder',
134  'pd.description'=>'Description',
135  's.nom'=>"ThirdParty",
136  's.name_alias'=>"AliasNameShort",
137  's.zip'=>"Zip",
138  's.town'=>"Town",
139  'c.note_public'=>'NotePublic',
140 );
141 if (empty($user->socid)) $fieldstosearchall["c.note_private"] = "NotePrivate";
142 
143 $checkedtypetiers = 0;
144 $arrayfields = array(
145  'c.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>5),
146  'c.ref_client'=>array('label'=>"RefCustomerOrder", 'checked'=>-1, 'position'=>10),
147  'p.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1), 'position'=>20),
148  'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1), 'position'=>25),
149  's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>30),
150  's.town'=>array('label'=>"Town", 'checked'=>1, 'position'=>35),
151  's.zip'=>array('label'=>"Zip", 'checked'=>1, 'position'=>40),
152  'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>45),
153  'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>50),
154  'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>55),
155  'c.date_commande'=>array('label'=>"OrderDateShort", 'checked'=>1, 'position'=>60),
156  'c.date_delivery'=>array('label'=>"DateDeliveryPlanned", 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE), 'position'=>65),
157  'c.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>75),
158  'c.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>80),
159  'c.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>85),
160  'c.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>90),
161  'c.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>95),
162  'c.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>100),
163  'c.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>105),
164  'c.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>110),
165  'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>10, 'position'=>115),
166  'c.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500, 'position'=>120),
167  'c.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500, 'position'=>125),
168  'c.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>500, 'position'=>130),
169  'c.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES)), 'position'=>135),
170  'c.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES)), 'position'=>140),
171  'c.facture'=>array('label'=>"Billed", 'checked'=>1, 'position'=>990, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)), 'position'=>145),
172  'shippable'=>array('label'=>"Shippable", 'checked'=>1, 'position'=>995, 'enabled'=>(!empty($conf->expedition->enabled)), 'position'=>150),
173  'c.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000, 'position'=>155)
174 );
175 // Extra fields
176 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
177 
178 $object->fields = dol_sort_array($object->fields, 'position');
179 $arrayfields = dol_sort_array($arrayfields, 'position');
180 
181 
182 
183 /*
184  * Actions
185  */
186 
187 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
188 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction = ''; }
189 
190 $parameters = array('socid'=>$socid);
191 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
192 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
193 
194 if (empty($reshook))
195 {
196  // Selection of new fields
197  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
198 
199  // Purge search criteria
200  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
201  {
202  $search_categ = '';
203  $search_user = '';
204  $search_sale = '';
205  $search_product_category = '';
206  $search_ref = '';
207  $search_ref_customer = '';
208  $search_company = '';
209  $search_town = '';
210  $search_zip = "";
211  $search_state = "";
212  $search_type = '';
213  $search_country = '';
214  $search_type_thirdparty = '';
215  $search_total_ht = '';
216  $search_total_vat = '';
217  $search_total_ttc = '';
218  $search_warehouse = '';
219  $search_multicurrency_code = '';
220  $search_multicurrency_tx = '';
221  $search_multicurrency_montant_ht = '';
222  $search_multicurrency_montant_vat = '';
223  $search_multicurrency_montant_ttc = '';
224  $search_login = '';
225  $search_dateorder_start = '';
226  $search_dateorder_end = '';
227  $search_datedelivery_start = '';
228  $search_datedelivery_end = '';
229  $search_project_ref = '';
230  $search_project = '';
231  $search_status = '';
232  $search_billed = '';
233  $toselect = '';
234  $search_array_options = array();
235  $search_categ_cus = 0;
236  $search_datecloture_start = '';
237  $search_datecloture_end = '';
238  }
239  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
240  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
241  {
242  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
243  }
244 
245  // Mass actions
246  $objectclass = 'Commande';
247  $objectlabel = 'Orders';
248  $permissiontoread = $user->rights->commande->lire;
249  $permissiontodelete = $user->rights->commande->supprimer;
250  $uploaddir = $conf->commande->multidir_output[$conf->entity];
251  $triggersendname = 'ORDER_SENTBYMAIL';
252  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
253 }
254 
255 
256 /*
257  * View
258  */
259 
260 $now = dol_now();
261 
262 $form = new Form($db);
263 $formother = new FormOther($db);
264 $formfile = new FormFile($db);
265 $companystatic = new Societe($db);
266 $formcompany = new FormCompany($db);
267 $projectstatic = new Project($db);
268 
269 $title = $langs->trans("Orders");
270 $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
271 // llxHeader('',$title,$help_url);
272 
273 $sql = 'SELECT';
274 if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT';
275 $sql .= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
276 $sql .= " typent.code as typent_code,";
277 $sql .= " state.code_departement as state_code, state.nom as state_name,";
278 $sql .= ' c.rowid, c.ref, c.total_ht, c.tva as total_tva, c.total_ttc, c.ref_client, c.fk_user_author,';
279 $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,';
280 $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,';
281 $sql .= ' c.date_creation as date_creation, c.tms as date_update, c.date_cloture as date_cloture,';
282 $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
283 $sql .= " u.login";
284 if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc";
285 // Add fields from extrafields
286 if (!empty($extrafields->attributes[$object->table_element]['label']))
287  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
288 // Add fields from hooks
289 $parameters = array();
290 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
291 $sql .= $hookmanager->resPrint;
292 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
293 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
294 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
295 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
296 if (!empty($search_categ_cus)) $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
297 $sql .= ', '.MAIN_DB_PREFIX.'commande as c';
298 if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
299 if ($sall || $search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
300 if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
301 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
302 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid';
303 
304 // We'll need this table joined to the select in order to filter by sale
305 if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
306 if ($search_user > 0)
307 {
308  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
309  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
310 }
311 $sql .= ' WHERE c.fk_soc = s.rowid';
312 $sql .= ' AND c.entity IN ('.getEntity('commande').')';
313 if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category;
314 if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;
315 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
316 if ($search_ref) $sql .= natural_search('c.ref', $search_ref);
317 if ($search_ref_customer) $sql .= natural_search('c.ref_client', $search_ref_customer);
318 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
319 if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND c.facture = '.$search_billed;
320 if ($search_status <> '')
321 {
322  if ($search_status < 4 && $search_status > -3)
323  {
324  if ($search_status == 1 && empty($conf->expedition->enabled)) $sql .= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status 'sending in process' into 'validated'
325  else $sql .= ' AND c.fk_statut = '.$search_status; // brouillon, validee, en cours, annulee
326  }
327  if ($search_status == 4)
328  {
329  $sql .= ' AND c.facture = 1'; // invoice created
330  }
331  if ($search_status == -2) // To process
332  {
333  //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
334  $sql .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected
335  }
336  if ($search_status == -3) // To bill
337  {
338  //$sql.= ' AND c.fk_statut in (1,2,3)';
339  //$sql.= ' AND c.facture = 0'; // invoice not created
340  $sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))'; // validated, in process or closed but not billed
341  }
342 }
343 
344 if ($search_datecloture_start) $sql .= " AND c.date_cloture >= '".$db->idate($search_datecloture_start)."'";
345 if ($search_datecloture_end) $sql .= " AND c.date_cloture <= '".$db->idate($search_datecloture_end)."'";
346 if ($search_dateorder_start) $sql .= " AND c.date_commande >= '".$db->idate($search_dateorder_start)."'";
347 if ($search_dateorder_end) $sql .= " AND c.date_commande <= '".$db->idate($search_dateorder_end)."'";
348 if ($search_datedelivery_start) $sql .= " AND c.date_livraison >= '".$db->idate($search_datedelivery_start)."'";
349 if ($search_datedelivery_end) $sql .= " AND c.date_livraison <= '".$db->idate($search_datedelivery_end)."'";
350 if ($search_town) $sql .= natural_search('s.town', $search_town);
351 if ($search_zip) $sql .= natural_search("s.zip", $search_zip);
352 if ($search_state) $sql .= natural_search("state.nom", $search_state);
353 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
354 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
355 if ($search_company) $sql .= natural_search('s.nom', $search_company);
356 if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale;
357 if ($search_user > 0) $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 = ".$search_user;
358 if ($search_total_ht != '') $sql .= natural_search('c.total_ht', $search_total_ht, 1);
359 if ($search_total_vat != '') $sql .= natural_search('c.tva', $search_total_vat, 1);
360 if ($search_total_ttc != '') $sql .= natural_search('c.total_ttc', $search_total_ttc, 1);
361 if ($search_warehouse != '' && $search_warehouse != '-1') $sql .= natural_search('c.fk_warehouse', $search_warehouse, 1);
362 if ($search_multicurrency_code != '') $sql .= ' AND c.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"';
363 if ($search_multicurrency_tx != '') $sql .= natural_search('c.multicurrency_tx', $search_multicurrency_tx, 1);
364 if ($search_multicurrency_montant_ht != '') $sql .= natural_search('c.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
365 if ($search_multicurrency_montant_vat != '') $sql .= natural_search('c.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
366 if ($search_multicurrency_montant_ttc != '') $sql .= natural_search('c.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
367 if ($search_login) $sql .= natural_search("u.login", $search_login);
368 if ($search_project_ref != '') $sql .= natural_search("p.ref", $search_project_ref);
369 if ($search_project != '') $sql .= natural_search("p.title", $search_project);
370 if ($search_categ_cus > 0) $sql .= " AND cc.fk_categorie = ".$db->escape($search_categ_cus);
371 if ($search_categ_cus == -2) $sql .= " AND cc.fk_categorie IS NULL";
372 
373 // Add where from extra fields
374 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
375 // Add where from hooks
376 $parameters = array();
377 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
378 $sql .= $hookmanager->resPrint;
379 
380 $sql .= $db->order($sortfield, $sortorder);
381 
382 // Count total nb of records
383 $nbtotalofrecords = '';
384 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
385 {
386  $result = $db->query($sql);
387  $nbtotalofrecords = $db->num_rows($result);
388 
389  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
390  {
391  $page = 0;
392  $offset = 0;
393  }
394 }
395 
396 $sql .= $db->plimit($limit + 1, $offset);
397 //print $sql;
398 
399 $resql = $db->query($sql);
400 if ($resql)
401 {
402  if ($socid > 0)
403  {
404  $soc = new Societe($db);
405  $soc->fetch($socid);
406  $title = $langs->trans('ListOfOrders').' - '.$soc->name;
407  if (empty($search_company)) $search_company = $soc->name;
408  } else {
409  $title = $langs->trans('ListOfOrders');
410  }
411  if (strval($search_status) == '0')
412  $title .= ' - '.$langs->trans('StatusOrderDraftShort');
413  if ($search_status == 1)
414  $title .= ' - '.$langs->trans('StatusOrderValidatedShort');
415  if ($search_status == 2)
416  $title .= ' - '.$langs->trans('StatusOrderSentShort');
417  if ($search_status == 3)
418  $title .= ' - '.$langs->trans('StatusOrderToBillShort');
419  if ($search_status == 4)
420  $title .= ' - '.$langs->trans('StatusOrderProcessedShort');
421  if ($search_status == -1)
422  $title .= ' - '.$langs->trans('StatusOrderCanceledShort');
423  if ($search_status == -2)
424  $title .= ' - '.$langs->trans('StatusOrderToProcessShort');
425  if ($search_status == -3)
426  $title .= ' - '.$langs->trans('StatusOrderValidated').', '.(empty($conf->expedition->enabled) ? '' : $langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
427 
428  $num = $db->num_rows($resql);
429 
430  $arrayofselected = is_array($toselect) ? $toselect : array();
431 
432  if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
433  {
434  $obj = $db->fetch_object($resql);
435  $id = $obj->rowid;
436  header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
437  exit;
438  }
439 
440  llxHeader('', $title, $help_url);
441 
442  $param = '';
443 
444  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
445  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
446  if ($sall) $param .= '&sall='.urlencode($sall);
447  if ($socid > 0) $param .= '&socid='.urlencode($socid);
448  if ($search_status != '') $param .= '&search_status='.urlencode($search_status);
449  if ($search_datecloture_start) $param .= '&search_datecloture_start='.urlencode($search_datecloture_start);
450  if ($search_datecloture_end) $param .= '&search_datecloture_end='.urlencode($search_datecloture_end);
451  if ($search_dateorder_start) $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');
452  if ($search_dateorder_end) $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');
453  if ($search_datedelivery_start) $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');
454  if ($search_datedelivery_end) $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');
455  if ($search_ref) $param .= '&search_ref='.urlencode($search_ref);
456  if ($search_company) $param .= '&search_company='.urlencode($search_company);
457  if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
458  if ($search_user > 0) $param .= '&search_user='.urlencode($search_user);
459  if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale);
460  if ($search_total_ht != '') $param .= '&search_total_ht='.urlencode($search_total_ht);
461  if ($search_total_vat != '') $param .= '&search_total_vat='.urlencode($search_total_vat);
462  if ($search_total_ttc != '') $param .= '&search_total_ttc='.urlencode($search_total_ttc);
463  if ($search_warehouse != '') $param .= '&search_warehouse='.urlencode($search_warehouse);
464  if ($search_login) $param .= '&search_login='.urlencode($search_login);
465  if ($search_multicurrency_code != '') $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
466  if ($search_multicurrency_tx != '') $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
467  if ($search_multicurrency_montant_ht != '') $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
468  if ($search_multicurrency_montant_vat != '') $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
469  if ($search_multicurrency_montant_ttc != '') $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
470  if ($search_project_ref >= 0) $param .= "&search_project_ref=".urlencode($search_project_ref);
471  if ($search_town != '') $param .= '&search_town='.urlencode($search_town);
472  if ($search_zip != '') $param .= '&search_zip='.urlencode($search_zip);
473  if ($search_state != '') $param .= '&search_state='.urlencode($search_state);
474  if ($search_country != '') $param .= '&search_country='.urlencode($search_country);
475  if ($search_type_thirdparty != '') $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
476  if ($search_product_category != '') $param .= '&search_product_category='.urlencode($search_product_category);
477  if ($search_categ_cus > 0) $param .= '&search_categ_cus='.urlencode($search_categ_cus);
478  if ($show_files) $param .= '&show_files='.urlencode($show_files);
479  if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
480  if ($search_billed != '') $param .= '&search_billed='.urlencode($search_billed);
481 
482  // Add $param from extra fields
483  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
484 
485  // List of mass actions available
486  $arrayofmassactions = array(
487  'generate_doc'=>$langs->trans("ReGeneratePDF"),
488  'builddoc'=>$langs->trans("PDFMerge"),
489  'cancelorders'=>$langs->trans("Cancel"),
490  'presend'=>$langs->trans("SendByMail"),
491  );
492  if ($user->rights->facture->creer) $arrayofmassactions['createbills'] = $langs->trans("CreateInvoiceForThisCustomer");
493  if ($user->rights->commande->supprimer) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
494  if (in_array($massaction, array('presend', 'predelete', 'createbills'))) $arrayofmassactions = array();
495  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
496 
497  $url = DOL_URL_ROOT.'/commande/card.php?action=create';
498  if (!empty($socid)) $url .= '&socid='.$socid;
499  $newcardbutton = dolGetButtonTitle($langs->trans('NewOrder'), '', 'fa fa-plus-circle', $url, '', $contextpage == 'orderlist' && $user->rights->commande->creer);
500 
501  // Lines of title fields
502  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
503  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
504  print '<input type="hidden" name="token" value="'.newToken().'">';
505  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
506  print '<input type="hidden" name="action" value="list">';
507  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
508  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
509  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
510  print '<input type="hidden" name="search_status" value="'.$search_status.'">';
511  print '<input type="hidden" name="socid" value="'.$socid.'">';
512 
513  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'order', 0, $newcardbutton, '', $limit, 0, 0, 1);
514 
515  $topicmail = "SendOrderRef";
516  $modelmail = "order_send";
517  $objecttmp = new Commande($db);
518  $trackid = 'ord'.$object->id;
519  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
520 
521  if ($massaction == 'createbills')
522  {
523  //var_dump($_REQUEST);
524  print '<input type="hidden" name="massaction" value="confirm_createbills">';
525 
526  print '<table class="noborder" width="100%" >';
527  print '<tr>';
528  print '<td class="titlefield">';
529  print $langs->trans('DateInvoice');
530  print '</td>';
531  print '<td>';
532  print $form->selectDate('', '', '', '', '', '', 1, 1);
533  print '</td>';
534  print '</tr>';
535  print '<tr>';
536  print '<td>';
537  print $langs->trans('CreateOneBillByThird');
538  print '</td>';
539  print '<td>';
540  print $form->selectyesno('createbills_onebythird', '', 1);
541  print '</td>';
542  print '</tr>';
543  print '<tr>';
544  print '<td>';
545  print $langs->trans('ValidateInvoices');
546  print '</td>';
547  print '<td>';
548  if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL))
549  {
550  print $form->selectyesno('validate_invoices', 0, 1, 1);
551  print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
552  } else {
553  print $form->selectyesno('validate_invoices', 0, 1);
554  }
555  if (!empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoOrderStayUnbilled").'</span>';
556  else print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetOrderBilledNotEnabled").'</span>';
557  print '</td>';
558  print '</tr>';
559  print '</table>';
560 
561  print '<br>';
562  print '<div class="center">';
563  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
564  print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
565  print '</div>';
566  print '<br>';
567  }
568 
569  if ($sall)
570  {
571  foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
572  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
573  }
574 
575  $moreforfilter = '';
576 
577  // If the user can view prospects other than his'
578  if ($user->rights->societe->client->voir || $socid)
579  {
580  $langs->load("commercial");
581  $moreforfilter .= '<div class="divsearchfield">';
582  $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': ';
583  $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
584  $moreforfilter .= '</div>';
585  }
586  // If the user can view other users
587  if ($user->rights->user->user->lire)
588  {
589  $moreforfilter .= '<div class="divsearchfield">';
590  $moreforfilter .= $langs->trans('LinkedToSpecificUsers').': ';
591  $moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
592  $moreforfilter .= '</div>';
593  }
594  // If the user can view prospects other than his'
595  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire))
596  {
597  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
598  $moreforfilter .= '<div class="divsearchfield">';
599  $moreforfilter .= $langs->trans('IncludingProductWithTag').': ';
600  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
601  $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
602  $moreforfilter .= '</div>';
603  }
604  if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire)
605  {
606  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
607  $moreforfilter .= '<div class="divsearchfield">';
608  $moreforfilter .= $langs->trans('CustomersProspectsCategoriesShort').': ';
609  $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1);
610  $moreforfilter .= '</div>';
611  }
612  if (!empty($conf->expedition->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) {
613  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
614  $formproduct = new FormProduct($db);
615  $moreforfilter .= '<div class="divsearchfield">';
616  $moreforfilter .= $langs->trans('Warehouse').': ';
617  $moreforfilter .= $formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', 1);
618  $moreforfilter .= '</div>';
619  }
620  $parameters = array();
621  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
622  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
623  else $moreforfilter = $hookmanager->resPrint;
624 
625  if (!empty($moreforfilter))
626  {
627  print '<div class="liste_titre liste_titre_bydiv centpercent">';
628  print $moreforfilter;
629  print '</div>';
630  }
631 
632  $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
633  $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
634  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
635 
636  if (GETPOST('autoselectall', 'int')) {
637  $selectedfields .= '<script>';
638  $selectedfields .= ' $(document).ready(function() {';
639  $selectedfields .= ' console.log("Autoclick on checkforselects");';
640  $selectedfields .= ' $("#checkforselects").click();';
641  $selectedfields .= ' $("#massaction").val("createbills").change();';
642  $selectedfields .= ' });';
643  $selectedfields .= '</script>';
644  }
645 
646  print '<div class="div-table-responsive">';
647  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
648 
649  print '<tr class="liste_titre_filter">';
650  // Ref
651  if (!empty($arrayfields['c.ref']['checked']))
652  {
653  print '<td class="liste_titre">';
654  print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
655  print '</td>';
656  }
657  // Ref customer
658  if (!empty($arrayfields['c.ref_client']['checked']))
659  {
660  print '<td class="liste_titre" align="left">';
661  print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
662  print '</td>';
663  }
664  // Project ref
665  if (!empty($arrayfields['p.ref']['checked']))
666  {
667  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.dol_escape_htmltag($search_project_ref).'"></td>';
668  }
669  // Project title
670  if (!empty($arrayfields['p.title']['checked']))
671  {
672  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
673  }
674  // Thirpdarty
675  if (!empty($arrayfields['s.nom']['checked']))
676  {
677  print '<td class="liste_titre" align="left">';
678  print '<input class="flat maxwidth100" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
679  print '</td>';
680  }
681  // Town
682  if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
683  // Zip
684  if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
685  // State
686  if (!empty($arrayfields['state.nom']['checked']))
687  {
688  print '<td class="liste_titre">';
689  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
690  print '</td>';
691  }
692  // Country
693  if (!empty($arrayfields['country.code_iso']['checked']))
694  {
695  print '<td class="liste_titre" align="center">';
696  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
697  print '</td>';
698  }
699  // Company type
700  if (!empty($arrayfields['typent.code']['checked']))
701  {
702  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
703  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
704  print '</td>';
705  }
706  // Date order
707  if (!empty($arrayfields['c.date_commande']['checked']))
708  {
709  print '<td class="liste_titre center">';
710  print '<div class="nowrap">';
711  print $form->selectDate($search_dateorder_start ? $search_dateorder_start : -1, 'search_dateorder_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
712  print '</div>';
713  print '<div class="nowrap">';
714  print $form->selectDate($search_dateorder_end ? $search_dateorder_end : -1, 'search_dateorder_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
715  print '</div>';
716  print '</td>';
717  }
718  if (!empty($arrayfields['c.date_delivery']['checked']))
719  {
720  print '<td class="liste_titre center">';
721  print '<div class="nowrap">';
722  print $form->selectDate($search_datedelivery_start ? $search_datedelivery_start : -1, 'search_datedelivery_start_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
723  print '</div>';
724  print '<div class="nowrap">';
725  print $form->selectDate($search_datedelivery_end ? $search_datedelivery_end : -1, 'search_datedelivery_end_', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
726  print '</div>';
727  print '</td>';
728  }
729  if (!empty($arrayfields['c.total_ht']['checked']))
730  {
731  // Amount
732  print '<td class="liste_titre right">';
733  print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.dol_escape_htmltag($search_total_ht).'">';
734  print '</td>';
735  }
736  if (!empty($arrayfields['c.total_vat']['checked']))
737  {
738  // Amount
739  print '<td class="liste_titre right">';
740  print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.dol_escape_htmltag($search_total_vat).'">';
741  print '</td>';
742  }
743  if (!empty($arrayfields['c.total_ttc']['checked']))
744  {
745  // Amount
746  print '<td class="liste_titre right">';
747  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
748  print '</td>';
749  }
750  if (!empty($arrayfields['c.multicurrency_code']['checked']))
751  {
752  // Currency
753  print '<td class="liste_titre">';
754  print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
755  print '</td>';
756  }
757  if (!empty($arrayfields['c.multicurrency_tx']['checked']))
758  {
759  // Currency rate
760  print '<td class="liste_titre">';
761  print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
762  print '</td>';
763  }
764  if (!empty($arrayfields['c.multicurrency_total_ht']['checked']))
765  {
766  // Amount
767  print '<td class="liste_titre right">';
768  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
769  print '</td>';
770  }
771  if (!empty($arrayfields['c.multicurrency_total_vat']['checked']))
772  {
773  // Amount VAT
774  print '<td class="liste_titre right">';
775  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
776  print '</td>';
777  }
778  if (!empty($arrayfields['c.multicurrency_total_ttc']['checked']))
779  {
780  // Amount
781  print '<td class="liste_titre right">';
782  print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
783  print '</td>';
784  }
785  if (!empty($arrayfields['u.login']['checked']))
786  {
787  // Author
788  print '<td class="liste_titre" align="center">';
789  print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
790  print '</td>';
791  }
792  // Extra fields
793  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
794  // Fields from hook
795  $parameters = array('arrayfields'=>$arrayfields);
796  $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
797  print $hookmanager->resPrint;
798  // Date creation
799  if (!empty($arrayfields['c.datec']['checked']))
800  {
801  print '<td class="liste_titre">';
802  print '</td>';
803  }
804  // Date modification
805  if (!empty($arrayfields['c.tms']['checked']))
806  {
807  print '<td class="liste_titre">';
808  print '</td>';
809  }
810  // Date cloture
811  if (!empty($arrayfields['c.date_cloture']['checked']))
812  {
813  print '<td class="liste_titre center">';
814  print '<div class="nowrap">';
815  print $form->selectDate($search_datecloture_start ? $search_datecloture_start : -1, 'search_datecloture_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
816  print '</div>';
817  print '<div class="nowrap">';
818  print $form->selectDate($search_datecloture_end ? $search_datecloture_end : -1, 'search_datecloture_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
819  print '</div>';
820  print '</td>';
821  }
822  // Note public
823  if (!empty($arrayfields['c.note_public']['checked']))
824  {
825  print '<td class="liste_titre">';
826  print '</td>';
827  }
828  // Note private
829  if (!empty($arrayfields['c.note_private']['checked']))
830  {
831  print '<td class="liste_titre">';
832  print '</td>';
833  }
834  // Shippable
835  if (!empty($arrayfields['shippable']['checked']))
836  {
837  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
838  //print $form->selectyesno('search_shippable', $search_shippable, 1, 0, 1, 1);
839  if (!empty($conf->global->ORDER_SHIPABLE_STATUS_DISABLED_BY_DEFAULT)) {
840  print '<input type="checkbox" name="show_shippable_command" value="1"'.($show_shippable_command ? ' checked' : '').'>';
841  print $langs->trans('ShowShippableStatus');
842  } else {
843  $show_shippable_command = 1;
844  }
845  print '</td>';
846  }
847  // Status billed
848  if (!empty($arrayfields['c.facture']['checked']))
849  {
850  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
851  print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
852  print '</td>';
853  }
854  // Status
855  if (!empty($arrayfields['c.fk_statut']['checked']))
856  {
857  print '<td class="liste_titre maxwidthonsmartphone center">';
858  $liststatus = array(
859  Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
860  Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
861  Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSentShort"),
862  Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
863  -3=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
864  Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
865  );
866  print $form->selectarray('search_status', $liststatus, $search_status, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100', 1);
867  print '</td>';
868  }
869  // Action column
870  print '<td class="liste_titre" align="middle">';
871  $searchpicto = $form->showFilterButtons();
872  print $searchpicto;
873  print '</td>';
874 
875  print "</tr>\n";
876 
877  // Fields title
878  print '<tr class="liste_titre">';
879  if (!empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], 'c.ref', '', $param, '', $sortfield, $sortorder);
880  if (!empty($arrayfields['c.ref_client']['checked'])) print_liste_field_titre($arrayfields['c.ref_client']['label'], $_SERVER["PHP_SELF"], 'c.ref_client', '', $param, '', $sortfield, $sortorder);
881  if (!empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
882  if (!empty($arrayfields['p.title']['checked'])) print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER["PHP_SELF"], "p.title", "", $param, '', $sortfield, $sortorder);
883  if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
884  if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
885  if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
886  if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
887  if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
888  if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
889  if (!empty($arrayfields['c.date_commande']['checked'])) print_liste_field_titre($arrayfields['c.date_commande']['label'], $_SERVER["PHP_SELF"], 'c.date_commande', '', $param, '', $sortfield, $sortorder, 'center ');
890  if (!empty($arrayfields['c.date_delivery']['checked'])) print_liste_field_titre($arrayfields['c.date_delivery']['label'], $_SERVER["PHP_SELF"], 'c.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
891  if (!empty($arrayfields['c.total_ht']['checked'])) print_liste_field_titre($arrayfields['c.total_ht']['label'], $_SERVER["PHP_SELF"], 'c.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
892  if (!empty($arrayfields['c.total_vat']['checked'])) print_liste_field_titre($arrayfields['c.total_vat']['label'], $_SERVER["PHP_SELF"], 'c.tva', '', $param, '', $sortfield, $sortorder, 'right ');
893  if (!empty($arrayfields['c.total_ttc']['checked'])) print_liste_field_titre($arrayfields['c.total_ttc']['label'], $_SERVER["PHP_SELF"], 'c.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
894  if (!empty($arrayfields['c.multicurrency_code']['checked'])) print_liste_field_titre($arrayfields['c.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_code', '', $param, '', $sortfield, $sortorder);
895  if (!empty($arrayfields['c.multicurrency_tx']['checked'])) print_liste_field_titre($arrayfields['c.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
896  if (!empty($arrayfields['c.multicurrency_total_ht']['checked'])) print_liste_field_titre($arrayfields['c.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
897  if (!empty($arrayfields['c.multicurrency_total_vat']['checked'])) print_liste_field_titre($arrayfields['c.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
898  if (!empty($arrayfields['c.multicurrency_total_ttc']['checked'])) print_liste_field_titre($arrayfields['c.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'c.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
899  if (!empty($arrayfields['u.login']['checked'])) print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
900 
901  // Extra fields
902  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
903  // Hook fields
904  $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
905  $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
906  print $hookmanager->resPrint;
907  if (!empty($arrayfields['c.datec']['checked'])) print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
908  if (!empty($arrayfields['c.tms']['checked'])) print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
909  if (!empty($arrayfields['c.date_cloture']['checked'])) print_liste_field_titre($arrayfields['c.date_cloture']['label'], $_SERVER["PHP_SELF"], "c.date_cloture", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
910  if (!empty($arrayfields['c.note_public']['checked'])) print_liste_field_titre($arrayfields['c.note_public']['label'], $_SERVER["PHP_SELF"], "c.note_public", "", $param, '', $sortfield, $sortorder, 'right ');
911  if (!empty($arrayfields['c.note_private']['checked'])) print_liste_field_titre($arrayfields['c.note_private']['label'], $_SERVER["PHP_SELF"], "c.note_private", "", $param, '', $sortfield, $sortorder, 'right ');
912  if (!empty($arrayfields['shippable']['checked'])) print_liste_field_titre($arrayfields['shippable']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
913  if (!empty($arrayfields['c.facture']['checked'])) print_liste_field_titre($arrayfields['c.facture']['label'], $_SERVER["PHP_SELF"], 'c.facture', '', $param, '', $sortfield, $sortorder, 'center ');
914  if (!empty($arrayfields['c.fk_statut']['checked'])) print_liste_field_titre($arrayfields['c.fk_statut']['label'], $_SERVER["PHP_SELF"], "c.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
915  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder, 'maxwidthsearch center ');
916  print '</tr>'."\n";
917 
918  $total = 0;
919  $subtotal = 0;
920  $productstat_cache = array();
921  $productstat_cachevirtual = array();
922  $getNomUrl_cache = array();
923 
924  $generic_commande = new Commande($db);
925  $generic_product = new Product($db);
926  $userstatic = new User($db);
927  $i = 0;
928  $totalarray = array();
929  while ($i < min($num, $limit))
930  {
931  $obj = $db->fetch_object($resql);
932 
933  $notshippable = 0;
934  $warning = 0;
935  $text_info = '';
936  $text_warning = '';
937  $nbprod = 0;
938 
939  $companystatic->id = $obj->socid;
940  $companystatic->code_client = $obj->code_client;
941  $companystatic->name = $obj->name;
942  $companystatic->client = $obj->client;
943  $companystatic->email = $obj->email;
944  if (!isset($getNomUrl_cache[$obj->socid])) {
945  $getNomUrl_cache[$obj->socid] = $companystatic->getNomUrl(1, 'customer');
946  }
947 
948  $generic_commande->id = $obj->rowid;
949  $generic_commande->ref = $obj->ref;
950  $generic_commande->statut = $obj->fk_statut;
951  $generic_commande->billed = $obj->billed;
952  $generic_commande->date = $db->jdate($obj->date_commande);
953  $generic_commande->date_livraison = $db->jdate($obj->date_delivery); // deprecated
954  $generic_commande->delivery_date = $db->jdate($obj->date_delivery);
955  $generic_commande->ref_client = $obj->ref_client;
956  $generic_commande->total_ht = $obj->total_ht;
957  $generic_commande->total_tva = $obj->total_tva;
958  $generic_commande->total_ttc = $obj->total_ttc;
959  $generic_commande->note_public = $obj->note_public;
960  $generic_commande->note_private = $obj->note_private;
961 
962  $projectstatic->id = $obj->project_id;
963  $projectstatic->ref = $obj->project_ref;
964  $projectstatic->title = $obj->project_label;
965 
966  print '<tr class="oddeven">';
967 
968  // Ref
969  if (!empty($arrayfields['c.ref']['checked']))
970  {
971  print '<td class="nowraponall">';
972  print $generic_commande->getNomUrl(1, ($search_status != 2 ? 0 : $obj->fk_statut), 0, 0, 0, 1, 1);
973 
974  // Warning late icon and note
975  if ($generic_commande->hasDelay()) {
976  print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
977  }
978 
979  $filename = dol_sanitizeFileName($obj->ref);
980  $filedir = $conf->commande->multidir_output[$conf->entity].'/'.dol_sanitizeFileName($obj->ref);
981  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
982  print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
983 
984  print '</td>';
985  if (!$i) $totalarray['nbfield']++;
986  }
987 
988  // Ref customer
989  if (!empty($arrayfields['c.ref_client']['checked']))
990  {
991  print '<td class="nowrap tdoverflowmax200">'.$obj->ref_client.'</td>';
992  if (!$i) $totalarray['nbfield']++;
993  }
994 
995  // Project ref
996  if (!empty($arrayfields['p.ref']['checked']))
997  {
998  print '<td class="nowrap">';
999  if ($obj->project_id > 0)
1000  {
1001  print $projectstatic->getNomUrl(1);
1002  }
1003  print '</td>';
1004  if (!$i) $totalarray['nbfield']++;
1005  }
1006 
1007  // Project label
1008  if (!empty($arrayfields['p.title']['checked']))
1009  {
1010  print '<td class="nowrap">';
1011  if ($obj->project_id > 0)
1012  {
1013  print $projectstatic->title;
1014  }
1015  print '</td>';
1016  if (!$i) $totalarray['nbfield']++;
1017  }
1018 
1019  // Third party
1020  if (!empty($arrayfields['s.nom']['checked']))
1021  {
1022  print '<td class="tdoverflowmax200">';
1023  print $getNomUrl_cache[$obj->socid];
1024 
1025  // If module invoices enabled and user with invoice creation permissions
1026  if (!empty($conf->facture->enabled) && !empty($conf->global->ORDER_BILLING_ALL_CUSTOMER))
1027  {
1028  if ($user->rights->facture->creer)
1029  {
1030  if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0))
1031  {
1032  print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$companystatic->id.'&search_billed=0&autoselectall=1">';
1033  print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
1034  }
1035  }
1036  }
1037  print '</td>';
1038  if (!$i) $totalarray['nbfield']++;
1039  }
1040  // Town
1041  if (!empty($arrayfields['s.town']['checked']))
1042  {
1043  print '<td class="nocellnopadd">';
1044  print $obj->town;
1045  print '</td>';
1046  if (!$i) $totalarray['nbfield']++;
1047  }
1048  // Zip
1049  if (!empty($arrayfields['s.zip']['checked']))
1050  {
1051  print '<td class="nocellnopadd">';
1052  print $obj->zip;
1053  print '</td>';
1054  if (!$i) $totalarray['nbfield']++;
1055  }
1056  // State
1057  if (!empty($arrayfields['state.nom']['checked']))
1058  {
1059  print "<td>".$obj->state_name."</td>\n";
1060  if (!$i) $totalarray['nbfield']++;
1061  }
1062  // Country
1063  if (!empty($arrayfields['country.code_iso']['checked']))
1064  {
1065  print '<td class="center">';
1066  $tmparray = getCountry($obj->fk_pays, 'all');
1067  print $tmparray['label'];
1068  print '</td>';
1069  if (!$i) $totalarray['nbfield']++;
1070  }
1071  // Type ent
1072  if (!empty($arrayfields['typent.code']['checked']))
1073  {
1074  print '<td class="center">';
1075  if (empty($typenArray)) $typenArray = $formcompany->typent_array(1);
1076  print $typenArray[$obj->typent_code];
1077  print '</td>';
1078  if (!$i) $totalarray['nbfield']++;
1079  }
1080 
1081  // Order date
1082  if (!empty($arrayfields['c.date_commande']['checked']))
1083  {
1084  print '<td class="center">';
1085  print dol_print_date($db->jdate($obj->date_commande), 'day');
1086  print '</td>';
1087  if (!$i) $totalarray['nbfield']++;
1088  }
1089  // Plannned date of delivery
1090  if (!empty($arrayfields['c.date_delivery']['checked']))
1091  {
1092  print '<td class="center">';
1093  print dol_print_date($db->jdate($obj->date_delivery), 'dayhour');
1094  print '</td>';
1095  if (!$i) $totalarray['nbfield']++;
1096  }
1097  // Amount HT
1098  if (!empty($arrayfields['c.total_ht']['checked']))
1099  {
1100  print '<td class="nowrap right">'.price($obj->total_ht)."</td>\n";
1101  if (!$i) $totalarray['nbfield']++;
1102  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ht';
1103  $totalarray['val']['c.total_ht'] += $obj->total_ht;
1104  }
1105  // Amount VAT
1106  if (!empty($arrayfields['c.total_vat']['checked']))
1107  {
1108  print '<td class="nowrap right">'.price($obj->total_tva)."</td>\n";
1109  if (!$i) $totalarray['nbfield']++;
1110  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'c.total_tva';
1111  $totalarray['val']['c.total_tva'] += $obj->total_tva;
1112  }
1113  // Amount TTC
1114  if (!empty($arrayfields['c.total_ttc']['checked']))
1115  {
1116  print '<td class="nowrap right">'.price($obj->total_ttc)."</td>\n";
1117  if (!$i) $totalarray['nbfield']++;
1118  if (!$i) $totalarray['pos'][$totalarray['nbfield']] = 'c.total_ttc';
1119  $totalarray['val']['c.total_ttc'] += $obj->total_ttc;
1120  }
1121 
1122  // Currency
1123  if (!empty($arrayfields['c.multicurrency_code']['checked']))
1124  {
1125  print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1126  if (!$i) $totalarray['nbfield']++;
1127  }
1128 
1129  // Currency rate
1130  if (!empty($arrayfields['c.multicurrency_tx']['checked']))
1131  {
1132  print '<td class="nowrap">';
1133  $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1134  print "</td>\n";
1135  if (!$i) $totalarray['nbfield']++;
1136  }
1137  // Amount HT
1138  if (!empty($arrayfields['c.multicurrency_total_ht']['checked']))
1139  {
1140  print '<td class="right nowrap">'.price($obj->multicurrency_total_ht)."</td>\n";
1141  if (!$i) $totalarray['nbfield']++;
1142  }
1143  // Amount VAT
1144  if (!empty($arrayfields['c.multicurrency_total_vat']['checked']))
1145  {
1146  print '<td class="right nowrap">'.price($obj->multicurrency_total_vat)."</td>\n";
1147  if (!$i) $totalarray['nbfield']++;
1148  }
1149  // Amount TTC
1150  if (!empty($arrayfields['c.multicurrency_total_ttc']['checked']))
1151  {
1152  print '<td class="right nowrap">'.price($obj->multicurrency_total_ttc)."</td>\n";
1153  if (!$i) $totalarray['nbfield']++;
1154  }
1155 
1156  $userstatic->id = $obj->fk_user_author;
1157  $userstatic->login = $obj->login;
1158 
1159  // Author
1160  if (!empty($arrayfields['u.login']['checked']))
1161  {
1162  print '<td align="center">';
1163  if ($userstatic->id) print $userstatic->getLoginUrl(1);
1164  else print '&nbsp;';
1165  print "</td>\n";
1166  if (!$i) $totalarray['nbfield']++;
1167  }
1168 
1169  // Extra fields
1170  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1171  // Fields from hook
1172  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1173  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1174  print $hookmanager->resPrint;
1175 
1176  // Date creation
1177  if (!empty($arrayfields['c.datec']['checked']))
1178  {
1179  print '<td align="center" class="nowrap">';
1180  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1181  print '</td>';
1182  if (!$i) $totalarray['nbfield']++;
1183  }
1184 
1185  // Date modification
1186  if (!empty($arrayfields['c.tms']['checked']))
1187  {
1188  print '<td align="center" class="nowrap">';
1189  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1190  print '</td>';
1191  if (!$i) $totalarray['nbfield']++;
1192  }
1193 
1194  // Date cloture
1195  if (!empty($arrayfields['c.date_cloture']['checked']))
1196  {
1197  print '<td align="center" class="nowrap">';
1198  print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
1199  print '</td>';
1200  if (!$i) $totalarray['nbfield']++;
1201  }
1202 
1203  // Note public
1204  if (!empty($arrayfields['c.note_public']['checked']))
1205  {
1206  print '<td align="center" class="nowrap">';
1207  print dol_escape_htmltag($obj->note_public);
1208  print '</td>';
1209  if (!$i) $totalarray['nbfield']++;
1210  }
1211 
1212  // Note private
1213  if (!empty($arrayfields['c.note_private']['checked']))
1214  {
1215  print '<td align="center" class="nowrap">';
1216  print dol_escape_htmltag($obj->note_private);
1217  print '</td>';
1218  if (!$i) $totalarray['nbfield']++;
1219  }
1220 
1221  // Show shippable Icon (this creates subloops, so may be slow)
1222  if (!empty($arrayfields['shippable']['checked']))
1223  {
1224  print '<td class="center">';
1225  if (!empty($show_shippable_command) && !empty($conf->stock->enabled)) {
1226  if (($obj->fk_statut > $generic_commande::STATUS_DRAFT) && ($obj->fk_statut < $generic_commande::STATUS_CLOSED)) {
1227  $generic_commande->getLinesArray(); // This set ->lines
1228 
1229  $numlines = count($generic_commande->lines); // Loop on each line of order
1230  for ($lig = 0; $lig < $numlines; $lig++) {
1231  if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) // If line is a product and not a service
1232  {
1233  $nbprod++; // order contains real products
1234  $generic_product->id = $generic_commande->lines[$lig]->fk_product;
1235 
1236  // Get local and virtual stock and store it into cache
1237  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
1238  $generic_product->load_stock('nobatch'); // ->load_virtual_stock() is already included into load_stock()
1239  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
1240  $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
1241  } else {
1242  $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
1243  $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
1244  }
1245 
1246  if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) // Default code. Default should be this case.
1247  {
1248  $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->product_ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 25);
1249  $text_info .= ' - '.$langs->trans("Stock").': <span class="'.($generic_product->stock_reel > 0 ? 'ok' : 'error').'">'.$generic_product->stock_reel.'</span>';
1250  $text_info .= ' - '.$langs->trans("VirtualStock").': <span class="'.($generic_product->stock_theorique > 0 ? 'ok' : 'error').'">'.$generic_product->stock_theorique.'</span>';
1251  $text_info .= '<br>';
1252 
1253  if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel) {
1254  $notshippable++;
1255  }
1256  } else { // BUGGED CODE.
1257  // DOES NOT TAKE INTO ACCOUNT MANUFACTURING. THIS CODE SHOULD BE USELESS. PREVIOUS CODE SEEMS COMPLETE.
1258  // COUNT STOCK WHEN WE SHOULD ALREADY HAVE VALUE
1259  // Detailed virtual stock, looks bugged, uncomplete and need heavy load.
1260  // stock order and stock order_supplier
1261  $stock_order = 0;
1262  $stock_order_supplier = 0;
1263  if (!empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) // What about other options ?
1264  {
1265  if (!empty($conf->commande->enabled)) {
1266  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
1267  $generic_product->load_stats_commande(0, '1,2');
1268  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
1269  } else {
1270  $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
1271  }
1272  $stock_order = $generic_product->stats_commande['qty'];
1273  }
1274  if (!empty($conf->fournisseur->enabled)) {
1275  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
1276  $generic_product->load_stats_commande_fournisseur(0, '3');
1277  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
1278  } else {
1279  $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
1280  }
1281  $stock_order_supplier = $generic_product->stats_commande_fournisseur['qty'];
1282  }
1283  }
1284  $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 25);
1285  $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
1286  if ($stock_order > $generic_product->stock_reel && !($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) {
1287  $warning++;
1288  $text_warning .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
1289  }
1290  if ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty) {
1291  $notshippable++;
1292  $text_info .= '<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
1293  } else {
1294  $text_info .= '<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
1295  }
1296  if (!empty($conf->fournisseur->enabled)) {
1297  $text_info .= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier.'<br>';
1298  } else {
1299  $text_info .= '<br>';
1300  }
1301  }
1302  }
1303  }
1304  if ($notshippable == 0) {
1305  $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'green paddingleft');
1306  $text_info = $langs->trans('Shippable').'<br>'.$text_info;
1307  } else {
1308  $text_icon = img_picto('', 'dolly', '', false, 0, 0, '', 'error paddingleft');
1309  $text_info = $langs->trans('NonShippable').'<br>'.$text_info;
1310  }
1311  }
1312 
1313  if ($nbprod) {
1314  print $form->textwithtooltip('', $text_info, 2, 1, $text_icon, '', 2);
1315  }
1316  if ($warning) { // Always false in default mode
1317  print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'), '', 2);
1318  }
1319  }
1320  print '</td>';
1321  }
1322 
1323  // Billed
1324  if (!empty($arrayfields['c.facture']['checked']))
1325  {
1326  print '<td class="center">'.yn($obj->billed).'</td>';
1327  if (!$i) $totalarray['nbfield']++;
1328  }
1329 
1330  // Status
1331  if (!empty($arrayfields['c.fk_statut']['checked']))
1332  {
1333  print '<td class="nowrap center">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
1334  if (!$i) $totalarray['nbfield']++;
1335  }
1336 
1337  // Action column
1338  print '<td class="nowrap center">';
1339  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1340  {
1341  $selected = 0;
1342  if (in_array($obj->rowid, $arrayofselected)) $selected = 1;
1343  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1344  }
1345  print '</td>';
1346  if (!$i) $totalarray['nbfield']++;
1347 
1348  print "</tr>\n";
1349 
1350  $total += $obj->total_ht;
1351  $subtotal += $obj->total_ht;
1352  $i++;
1353  }
1354 
1355  // Show total line
1356  include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1357 
1358  $db->free($resql);
1359 
1360  $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1361  $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1362  print $hookmanager->resPrint;
1363 
1364  print '</table>'."\n";
1365  print '</div>';
1366 
1367  print '</form>'."\n";
1368 
1369  $hidegeneratedfilelistifempty = 1;
1370  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0;
1371 
1372  // Show list of available documents
1373  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1374  $urlsource .= str_replace('&amp;', '&', $param);
1375 
1376  $filedir = $diroutputmassaction;
1377  $genallowed = $user->rights->commande->lire;
1378  $delallowed = $user->rights->commande->creer;
1379 
1380  print $formfile->showdocuments('massfilesarea_orders', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1381 } else {
1382  dol_print_error($db);
1383 }
1384 
1385 // End of page
1386 llxFooter();
1387 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
const STATUS_CLOSED
Closed (Sent, billed or not)
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...
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.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
const STATUS_SHIPMENTONPROCESS
Shipment on process.
Class with static methods for building HTML components related to products Only components common to ...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Class to manage projects.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
Classe permettant la generation de composants html autre Only common components are here...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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...
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
Class to offer components to list and upload files.
print $_SERVER["PHP_SELF"]
Edit parameters.
const STATUS_VALIDATED
Validated status.
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
llxFooter()
Empty footer.
Definition: wrapper.php:59
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
const STATUS_CANCELED
Canceled status.