dolibarr  9.0.0
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-2016 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  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
35 require '../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
46 
47 // Load translation files required by the page
48 $langs->loadLangs(array("orders",'sendings','deliveries','companies','compta','bills'));
49 
50 $action=GETPOST('action','aZ09');
51 $massaction=GETPOST('massaction','alpha');
52 $show_files=GETPOST('show_files','int');
53 $confirm=GETPOST('confirm','alpha');
54 $toselect = GETPOST('toselect', 'array');
55 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'orderlist';
56 
57 $search_orderyear=GETPOST("search_orderyear","int");
58 $search_ordermonth=GETPOST("search_ordermonth","int");
59 $search_orderday=GETPOST("search_orderday","int");
60 $search_deliveryyear=GETPOST("search_deliveryyear","int");
61 $search_deliverymonth=GETPOST("search_deliverymonth","int");
62 $search_deliveryday=GETPOST("search_deliveryday","int");
63 $search_product_category=GETPOST('search_product_category','int');
64 $search_ref=GETPOST('search_ref','alpha')!=''?GETPOST('search_ref','alpha'):GETPOST('sref','alpha');
65 $search_ref_customer=GETPOST('search_ref_customer','alpha');
66 $search_company=GETPOST('search_company','alpha');
67 $search_town=GETPOST('search_town','alpha');
68 $search_zip=GETPOST('search_zip','alpha');
69 $search_state=trim(GETPOST("search_state"));
70 $search_country=GETPOST("search_country",'int');
71 $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
72 $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
73 $socid=GETPOST('socid','int');
74 $search_user=GETPOST('search_user','int');
75 $search_sale=GETPOST('search_sale','int');
76 $search_total_ht=GETPOST('search_total_ht','alpha');
77 $search_total_ttc=GETPOST('search_total_ttc','alpha');
78 $search_categ_cus=trim(GETPOST("search_categ_cus",'int'));
79 $optioncss = GETPOST('optioncss','alpha');
80 $billed = GETPOST('billed','int');
81 $viewstatut=GETPOST('viewstatut');
82 $search_btn=GETPOST('button_search','alpha');
83 $search_remove_btn=GETPOST('button_removefilter','alpha');
84 $search_project_ref=GETPOST('search_project_ref','alpha');
85 
86 // Security check
87 $id = (GETPOST('orderid')?GETPOST('orderid','int'):GETPOST('id','int'));
88 if ($user->societe_id) $socid=$user->societe_id;
89 $result = restrictedArea($user, 'commande', $id,'');
90 
91 $diroutputmassaction=$conf->commande->dir_output . '/temp/massgeneration/'.$user->id;
92 
93 // Load variable for pagination
94 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
95 $sortfield = GETPOST("sortfield",'alpha');
96 $sortorder = GETPOST("sortorder",'alpha');
97 $page = GETPOST("page",'int');
98 if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1
99 $offset = $limit * $page;
100 $pageprev = $page - 1;
101 $pagenext = $page + 1;
102 if (! $sortfield) $sortfield='c.ref';
103 if (! $sortorder) $sortorder='DESC';
104 
105 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
106 $object = new Commande($db);
107 $hookmanager->initHooks(array('orderlist'));
108 $extrafields = new ExtraFields($db);
109 
110 // fetch optionals attributes and labels
111 $extralabels = $extrafields->fetch_name_optionals_label('commande');
112 $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
113 
114 // List of fields to search into when doing a "search in all"
115 $fieldstosearchall = array(
116  'c.ref'=>'Ref',
117  'c.ref_client'=>'RefCustomerOrder',
118  'pd.description'=>'Description',
119  's.nom'=>"ThirdParty",
120  'c.note_public'=>'NotePublic',
121 );
122 if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
123 
124 $checkedtypetiers=0;
125 $arrayfields=array(
126  'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
127  'c.ref_client'=>array('label'=>$langs->trans("RefCustomerOrder"), 'checked'=>1),
128  'p.project_ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0, 'enabled'=>1),
129  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
130  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
131  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
132  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
133  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
134  'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
135  'c.date_commande'=>array('label'=>$langs->trans("OrderDateShort"), 'checked'=>1),
136  'c.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)),
137  'c.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
138  'c.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
139  'c.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
140  'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
141  'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
142  'c.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
143  'c.facture'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
144 );
145 // Extra fields
146 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
147 {
148  foreach($extrafields->attribute_label as $key => $val)
149  {
150  if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
151  }
152 }
153 
154 
155 
156 /*
157  * Actions
158  */
159 
160 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
161 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
162 
163 $parameters=array('socid'=>$socid);
164 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
165 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
166 
167 if (empty($reshook))
168 {
169  // Selection of new fields
170  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
171 
172  // Purge search criteria
173  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
174  {
175  $search_categ='';
176  $search_user='';
177  $search_sale='';
178  $search_product_category='';
179  $search_ref='';
180  $search_ref_customer='';
181  $search_company='';
182  $search_town='';
183  $search_zip="";
184  $search_state="";
185  $search_type='';
186  $search_country='';
187  $search_type_thirdparty='';
188  $search_total_ht='';
189  $search_total_vat='';
190  $search_total_ttc='';
191  $search_orderyear='';
192  $search_ordermonth='';
193  $search_orderday='';
194  $search_deliveryday='';
195  $search_deliverymonth='';
196  $search_deliveryyear='';
197  $search_project_ref='';
198  $viewstatut='';
199  $billed='';
200  $toselect='';
201  $search_array_options=array();
202  $search_categ_cus=0;
203  }
204  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
205  || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
206  {
207  $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation
208  }
209 
210  // Mass actions
211  $objectclass='Commande';
212  $objectlabel='Orders';
213  $permtoread = $user->rights->commande->lire;
214  $permtodelete = $user->rights->commande->supprimer;
215  $uploaddir = $conf->commande->dir_output;
216  $trigger_name='ORDER_SENTBYMAIL';
217  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
218 }
219 
220 
221 /*
222  * View
223  */
224 
225 $now=dol_now();
226 
227 $form = new Form($db);
228 $formother = new FormOther($db);
229 $formfile = new FormFile($db);
230 $companystatic = new Societe($db);
231 $formcompany=new FormCompany($db);
232 $projectstatic=new Project($db);
233 
234 $title=$langs->trans("Orders");
235 $help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
236 // llxHeader('',$title,$help_url);
237 
238 $sql = 'SELECT';
239 if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
240 $sql.= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
241 $sql.= " typent.code as typent_code,";
242 $sql.= " state.code_departement as state_code, state.nom as state_name,";
243 $sql.= ' c.rowid, c.ref, c.total_ht, c.tva as total_tva, c.total_ttc, c.ref_client,';
244 $sql.= ' c.date_valid, c.date_commande, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as billed,';
245 $sql.= ' c.date_creation as date_creation, c.tms as date_update,';
246 $sql.= " p.rowid as project_id, p.ref as project_ref";
247 if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc";
248 
249 // Add fields from extrafields
250 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
251 // Add fields from hooks
252 $parameters=array();
253 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
254 $sql.=$hookmanager->resPrint;
255 $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
256 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
257 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
258 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
259 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
260 $sql.= ', '.MAIN_DB_PREFIX.'commande as c';
261 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
262 if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
263 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
264 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet";
265 // We'll need this table joined to the select in order to filter by sale
266 if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
267 if ($search_user > 0)
268 {
269  $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
270  $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
271 }
272 $sql.= ' WHERE c.fk_soc = s.rowid';
273 $sql.= ' AND c.entity IN ('.getEntity('commande').')';
274 if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
275 if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
276 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
277 if ($search_ref) $sql .= natural_search('c.ref', $search_ref);
278 if ($search_ref_customer) $sql.= natural_search('c.ref_client', $search_ref_customer);
279 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
280 if ($billed != '' && $billed >= 0) $sql.=' AND c.facture = '.$billed;
281 if ($viewstatut <> '')
282 {
283  if ($viewstatut < 4 && $viewstatut > -3)
284  {
285  if ($viewstatut == 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'
286  else $sql.= ' AND c.fk_statut = '.$viewstatut; // brouillon, validee, en cours, annulee
287  }
288  if ($viewstatut == 4)
289  {
290  $sql.= ' AND c.facture = 1'; // invoice created
291  }
292  if ($viewstatut == -2) // To process
293  {
294  //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
295  $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
296  }
297  if ($viewstatut == -3) // To bill
298  {
299  //$sql.= ' AND c.fk_statut in (1,2,3)';
300  //$sql.= ' AND c.facture = 0'; // invoice not created
301  $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
302  }
303 }
304 if ($search_ordermonth > 0)
305 {
306  if ($search_orderyear > 0 && empty($search_orderday))
307  $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($search_orderyear,$search_ordermonth,false))."' AND '".$db->idate(dol_get_last_day($search_orderyear,$search_ordermonth,false))."'";
308  else if ($search_orderyear > 0 && ! empty($search_orderday))
309  $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_ordermonth, $search_orderday, $search_orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_ordermonth, $search_orderday, $search_orderyear))."'";
310  else
311  $sql.= " AND date_format(c.date_commande, '%m') = '".$search_ordermonth."'";
312 }
313 else if ($search_orderyear > 0)
314 {
315  $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($search_orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_orderyear,12,false))."'";
316 }
317 if ($search_deliverymonth > 0)
318 {
319  if ($search_deliveryyear > 0 && empty($search_deliveryday))
320  $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_deliveryyear,$search_deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($search_deliveryyear,$search_deliverymonth,false))."'";
321  else if ($search_deliveryyear > 0 && ! empty($search_deliveryday))
322  $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_deliverymonth, $search_deliveryday, $search_deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_deliverymonth, $search_deliveryday, $search_deliveryyear))."'";
323  else
324  $sql.= " AND date_format(c.date_livraison, '%m') = '".$search_deliverymonth."'";
325 }
326 else if ($search_deliveryyear > 0)
327 {
328  $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_deliveryyear,12,false))."'";
329 }
330 if ($search_town) $sql.= natural_search('s.town', $search_town);
331 if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
332 if ($search_state) $sql.= natural_search("state.nom",$search_state);
333 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
334 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
335 if ($search_company) $sql .= natural_search('s.nom', $search_company);
336 if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
337 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;
338 if ($search_total_ht != '') $sql.= natural_search('c.total_ht', $search_total_ht, 1);
339 if ($search_total_ttc != '') $sql.= natural_search('c.total_ttc', $search_total_ttc, 1);
340 if ($search_project_ref != '') $sql.= natural_search("p.ref",$search_project_ref);
341 if ($search_categ_cus > 0) $sql.= " AND cc.fk_categorie = ".$db->escape($search_categ_cus);
342 if ($search_categ_cus == -2) $sql.= " AND cc.fk_categorie IS NULL";
343 // Add where from extra fields
344 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
345 // Add where from hooks
346 $parameters=array();
347 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
348 $sql.=$hookmanager->resPrint;
349 
350 $sql.= $db->order($sortfield,$sortorder);
351 
352 // Count total nb of records
353 $nbtotalofrecords = '';
354 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
355 {
356  $result = $db->query($sql);
357  $nbtotalofrecords = $db->num_rows($result);
358 
359  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
360  {
361  $page = 0;
362  $offset = 0;
363  }
364 }
365 
366 $sql.= $db->plimit($limit + 1,$offset);
367 //print $sql;
368 
369 $resql = $db->query($sql);
370 if ($resql)
371 {
372  if ($socid > 0)
373  {
374  $soc = new Societe($db);
375  $soc->fetch($socid);
376  $title = $langs->trans('ListOfOrders') . ' - '.$soc->name;
377  if (empty($search_company)) $search_company = $soc->name;
378  }
379  else
380  {
381  $title = $langs->trans('ListOfOrders');
382  }
383  if (strval($viewstatut) == '0')
384  $title.=' - '.$langs->trans('StatusOrderDraftShort');
385  if ($viewstatut == 1)
386  $title.=' - '.$langs->trans('StatusOrderValidatedShort');
387  if ($viewstatut == 2)
388  $title.=' - '.$langs->trans('StatusOrderSentShort');
389  if ($viewstatut == 3)
390  $title.=' - '.$langs->trans('StatusOrderToBillShort');
391  if ($viewstatut == 4)
392  $title.=' - '.$langs->trans('StatusOrderProcessedShort');
393  if ($viewstatut == -1)
394  $title.=' - '.$langs->trans('StatusOrderCanceledShort');
395  if ($viewstatut == -2)
396  $title.=' - '.$langs->trans('StatusOrderToProcessShort');
397  if ($viewstatut == -3)
398  $title.=' - '.$langs->trans('StatusOrderValidated').', '.(empty($conf->expedition->enabled)?'':$langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
399 
400  $num = $db->num_rows($resql);
401 
402  $arrayofselected=is_array($toselect)?$toselect:array();
403 
404  if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall)
405  {
406  $obj = $db->fetch_object($resql);
407  $id = $obj->rowid;
408  header("Location: ".DOL_URL_ROOT.'/commande/card.php?id='.$id);
409  exit;
410  }
411 
412  llxHeader('',$title,$help_url);
413 
414  $param='';
415 
416  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
417  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
418  if ($sall) $param.='&sall='.urlencode($sall);
419  if ($socid > 0) $param.='&socid='.urlencode($socid);
420  if ($viewstatut != '') $param.='&viewstatut='.urlencode($viewstatut);
421  if ($search_orderday) $param.='&search_orderday='.urlencode($search_orderday);
422  if ($search_ordermonth) $param.='&search_ordermonth='.urlencode($search_ordermonth);
423  if ($search_orderyear) $param.='&search_orderyear='.urlencode($search_orderyear);
424  if ($search_deliveryday) $param.='&search_deliveryday='.urlencode($search_deliveryday);
425  if ($search_deliverymonth) $param.='&search_deliverymonth='.urlencode($search_deliverymonth);
426  if ($search_deliveryyear) $param.='&search_deliveryyear='.urlencode($search_deliveryyear);
427  if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
428  if ($search_company) $param.='&search_company='.urlencode($search_company);
429  if ($search_ref_customer) $param.='&search_ref_customer='.urlencode($search_ref_customer);
430  if ($search_user > 0) $param.='&search_user='.urlencode($search_user);
431  if ($search_sale > 0) $param.='&search_sale='.urlencode($search_sale);
432  if ($search_total_ht != '') $param.='&search_total_ht='.urlencode($search_total_ht);
433  if ($search_total_vat != '') $param.='&search_total_vat='.urlencode($search_total_vat);
434  if ($search_total_ttc != '') $param.='&search_total_ttc='.urlencode($search_total_ttc);
435  if ($search_project_ref >= 0) $param.="&search_project_ref=".urlencode($search_project_ref);
436  if ($search_town != '') $param.='&search_town='.urlencode($search_town);
437  if ($search_zip != '') $param.='&search_zip='.urlencode($search_zip);
438  if ($search_state != '') $param.='&search_state='.urlencode($search_state);
439  if ($search_country != '') $param.='&search_country='.urlencode($search_country);
440  if ($search_type_thirdparty != '') $param.='&search_type_thirdparty='.urlencode($search_type_thirdparty);
441  if ($search_product_category != '') $param.='&search_product_category='.urlencode($search_product_category);
442  if ($search_categ_cus > 0) $param.='&search_categ_cus='.urlencode($search_categ_cus);
443  if ($show_files) $param.='&show_files=' .urlencode($show_files);
444  if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
445  if ($billed != '') $param.='&billed='.urlencode($billed);
446 
447  // Add $param from extra fields
448  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
449 
450  // List of mass actions available
451  $arrayofmassactions = array(
452  'presend'=>$langs->trans("SendByMail"),
453  'builddoc'=>$langs->trans("PDFMerge"),
454  'cancelorders'=>$langs->trans("Cancel"),
455 
456  );
457  if($user->rights->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
458  if ($user->rights->commande->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
459  if (in_array($massaction, array('presend','predelete','createbills'))) $arrayofmassactions=array();
460  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
461 
462  $newcardbutton='';
463  if ($contextpage == 'orderlist' && $user->rights->commande->creer)
464  {
465  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/commande/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewOrder').'</span>';
466  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
467  $newcardbutton.= '</a>';
468  }
469 
470  // Lines of title fields
471  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
472  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
473  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
474  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
475  print '<input type="hidden" name="action" value="list">';
476  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
477  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
478  print '<input type="hidden" name="page" value="'.$page.'">';
479  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
480  print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
481  print '<input type="hidden" name="socid" value="'.$socid.'">';
482 
483 
484  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, $newcardbutton, '', $limit);
485 
486  $topicmail="SendOrderRef";
487  $modelmail="order_send";
488  $objecttmp=new Commande($db);
489  $trackid='ord'.$object->id;
490  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
491 
492  if ($massaction == 'createbills')
493  {
494  //var_dump($_REQUEST);
495  print '<input type="hidden" name="massaction" value="confirm_createbills">';
496 
497  print '<table class="noborder" width="100%" >';
498  print '<tr>';
499  print '<td class="titlefield">';
500  print $langs->trans('DateInvoice');
501  print '</td>';
502  print '<td>';
503  print $form->selectDate('', '', '', '', '', '', 1, 1);
504  print '</td>';
505  print '</tr>';
506  print '<tr>';
507  print '<td>';
508  print $langs->trans('CreateOneBillByThird');
509  print '</td>';
510  print '<td>';
511  print $form->selectyesno('createbills_onebythird', '', 1);
512  print '</td>';
513  print '</tr>';
514  print '<tr>';
515  print '<td>';
516  print $langs->trans('ValidateInvoices');
517  print '</td>';
518  print '<td>';
519  if (! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
520  {
521  print $form->selectyesno('valdate_invoices', 0, 1, 1);
522  print ' ('.$langs->trans("AutoValidationNotPossibleWhenStockIsDecreasedOnInvoiceValidation").')';
523  }
524  else
525  {
526  print $form->selectyesno('valdate_invoices', 0, 1);
527  }
528  if (! empty($conf->workflow->enabled) && ! empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("IfValidateInvoiceIsNoOrderStayUnbilled").'</span>';
529  else print ' &nbsp; &nbsp; <span class="opacitymedium">'.$langs->trans("OptionToSetOrderBilledNotEnabled").'</span>';
530  print '</td>';
531  print '</tr>';
532  print '</table>';
533 
534  print '<br>';
535  print '<div class="center">';
536  print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
537  print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
538  print '</div>';
539  print '<br>';
540  }
541 
542  if ($sall)
543  {
544  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
545  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
546  }
547 
548  $moreforfilter='';
549 
550  // If the user can view prospects other than his'
551  if ($user->rights->societe->client->voir || $socid)
552  {
553  $langs->load("commercial");
554  $moreforfilter.='<div class="divsearchfield">';
555  $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
556  $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200');
557  $moreforfilter.='</div>';
558  }
559  // If the user can view other users
560  if ($user->rights->user->user->lire)
561  {
562  $moreforfilter.='<div class="divsearchfield">';
563  $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
564  $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
565  $moreforfilter.='</div>';
566  }
567  // If the user can view prospects other than his'
568  if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
569  {
570  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
571  $moreforfilter.='<div class="divsearchfield">';
572  $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
573  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
574  $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
575  $moreforfilter.='</div>';
576  }
577  if (! empty($conf->categorie->enabled))
578  {
579  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
580  $moreforfilter.='<div class="divsearchfield">';
581  $moreforfilter.=$langs->trans('CustomersProspectsCategoriesShort').': ';
582  $moreforfilter.=$formother->select_categories('customer',$search_categ_cus,'search_categ_cus',1);
583  $moreforfilter.='</div>';
584  }
585  $parameters=array();
586  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
587  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
588  else $moreforfilter = $hookmanager->resPrint;
589 
590  if (! empty($moreforfilter))
591  {
592  print '<div class="liste_titre liste_titre_bydiv centpercent">';
593  print $moreforfilter;
594  print '</div>';
595  }
596 
597  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
598  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
599  $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
600 
601  print '<div class="div-table-responsive">';
602  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
603 
604  print '<tr class="liste_titre_filter">';
605  // Ref
606  if (! empty($arrayfields['c.ref']['checked']))
607  {
608  print '<td class="liste_titre">';
609  print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
610  print '</td>';
611  }
612  // Ref customer
613  if (! empty($arrayfields['c.ref_client']['checked']))
614  {
615  print '<td class="liste_titre" align="left">';
616  print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.$search_ref_customer.'">';
617  print '</td>';
618  }
619  // Project ref
620  if (! empty($arrayfields['p.project_ref']['checked']))
621  {
622  print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_project_ref" value="'.$search_project_ref.'"></td>';
623  }
624  // Thirpdarty
625  if (! empty($arrayfields['s.nom']['checked']))
626  {
627  print '<td class="liste_titre" align="left">';
628  print '<input class="flat" type="text" name="search_company" value="'.$search_company.'">';
629  print '</td>';
630  }
631  // Town
632  if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_town" value="'.$search_town.'"></td>';
633  // Zip
634  if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.$search_zip.'"></td>';
635  // State
636  if (! empty($arrayfields['state.nom']['checked']))
637  {
638  print '<td class="liste_titre">';
639  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
640  print '</td>';
641  }
642  // Country
643  if (! empty($arrayfields['country.code_iso']['checked']))
644  {
645  print '<td class="liste_titre" align="center">';
646  print $form->select_country($search_country,'search_country','',0,'maxwidth100');
647  print '</td>';
648  }
649  // Company type
650  if (! empty($arrayfields['typent.code']['checked']))
651  {
652  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
653  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));
654  print '</td>';
655  }
656  // Date order
657  if (! empty($arrayfields['c.date_commande']['checked']))
658  {
659  print '<td class="liste_titre nowraponall" align="center">';
660  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_orderday" value="'.$search_orderday.'">';
661  print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_ordermonth" value="'.$search_ordermonth.'">';
662  $formother->select_year($search_orderyear?$search_orderyear:-1,'search_orderyear',1, 20, 5);
663  print '</td>';
664  }
665  if (! empty($arrayfields['c.date_delivery']['checked']))
666  {
667  print '<td class="liste_titre nowraponall" align="center">';
668  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_deliveryday" value="'.$search_deliveryday.'">';
669  print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_deliverymonth" value="'.$search_deliverymonth.'">';
670  $formother->select_year($search_deliveryyear?$search_deliveryyear:-1,'search_deliveryyear',1, 20, 5);
671  print '</td>';
672  }
673  if (! empty($arrayfields['c.total_ht']['checked']))
674  {
675  // Amount
676  print '<td class="liste_titre" align="right">';
677  print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.$search_total_ht.'">';
678  print '</td>';
679  }
680  if (! empty($arrayfields['c.total_vat']['checked']))
681  {
682  // Amount
683  print '<td class="liste_titre" align="right">';
684  print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.$search_total_vat.'">';
685  print '</td>';
686  }
687  if (! empty($arrayfields['c.total_ttc']['checked']))
688  {
689  // Amount
690  print '<td class="liste_titre" align="right">';
691  print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
692  print '</td>';
693  }
694  // Extra fields
695  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
696  // Fields from hook
697  $parameters=array('arrayfields'=>$arrayfields);
698  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
699  print $hookmanager->resPrint;
700  // Date creation
701  if (! empty($arrayfields['c.datec']['checked']))
702  {
703  print '<td class="liste_titre">';
704  print '</td>';
705  }
706  // Date modification
707  if (! empty($arrayfields['c.tms']['checked']))
708  {
709  print '<td class="liste_titre">';
710  print '</td>';
711  }
712  // Status
713  if (! empty($arrayfields['c.fk_statut']['checked']))
714  {
715  print '<td class="liste_titre maxwidthonsmartphone" align="right">';
716  $liststatus=array(
717  Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
718  Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
719  Commande::STATUS_SHIPMENTONPROCESS=>$langs->trans("StatusOrderSentShort"),
720  Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
721  -3=>$langs->trans("StatusOrderValidatedShort").'+'.$langs->trans("StatusOrderSentShort").'+'.$langs->trans("StatusOrderDelivered"),
722  Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
723  );
724  print $form->selectarray('viewstatut', $liststatus, $viewstatut, -4, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
725  print '</td>';
726  }
727  // Status billed
728  if (! empty($arrayfields['c.facture']['checked']))
729  {
730  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
731  print $form->selectyesno('billed', $billed, 1, 0, 1);
732  print '</td>';
733  }
734  // Action column
735  print '<td class="liste_titre" align="middle">';
736  $searchpicto=$form->showFilterButtons();
737  print $searchpicto;
738  print '</td>';
739 
740  print "</tr>\n";
741 
742  // Fields title
743  print '<tr class="liste_titre">';
744  if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'],$_SERVER["PHP_SELF"],'c.ref','',$param,'',$sortfield,$sortorder);
745  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);
746  if (! empty($arrayfields['p.project_ref']['checked'])) print_liste_field_titre($arrayfields['p.project_ref']['label'],$_SERVER["PHP_SELF"],"p.ref","",$param,'',$sortfield,$sortorder);
747  if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
748  if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
749  if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
750  if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
751  if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
752  if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
753  if (! empty($arrayfields['c.date_commande']['checked'])) print_liste_field_titre($arrayfields['c.date_commande']['label'],$_SERVER["PHP_SELF"],'c.date_commande','',$param, 'align="center"',$sortfield,$sortorder);
754  if (! empty($arrayfields['c.date_delivery']['checked'])) print_liste_field_titre($arrayfields['c.date_delivery']['label'],$_SERVER["PHP_SELF"],'c.date_livraison','',$param, 'align="center"',$sortfield,$sortorder);
755  if (! empty($arrayfields['c.total_ht']['checked'])) print_liste_field_titre($arrayfields['c.total_ht']['label'],$_SERVER["PHP_SELF"],'c.total_ht','',$param, 'align="right"',$sortfield,$sortorder);
756  if (! empty($arrayfields['c.total_vat']['checked'])) print_liste_field_titre($arrayfields['c.total_vat']['label'],$_SERVER["PHP_SELF"],'c.tva','',$param, 'align="right"',$sortfield,$sortorder);
757  if (! empty($arrayfields['c.total_ttc']['checked'])) print_liste_field_titre($arrayfields['c.total_ttc']['label'],$_SERVER["PHP_SELF"],'c.total_ttc','',$param, 'align="right"',$sortfield,$sortorder);
758  // Extra fields
759  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
760  // Hook fields
761  $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
762  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
763  print $hookmanager->resPrint;
764  if (! empty($arrayfields['c.datec']['checked'])) print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
765  if (! empty($arrayfields['c.tms']['checked'])) print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
766  if (! empty($arrayfields['c.fk_statut']['checked'])) print_liste_field_titre($arrayfields['c.fk_statut']['label'],$_SERVER["PHP_SELF"],"c.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
767  if (! empty($arrayfields['c.facture']['checked'])) print_liste_field_titre($arrayfields['c.facture']['label'],$_SERVER["PHP_SELF"],'c.facture','',$param,'align="center"',$sortfield,$sortorder,'');
768  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'',$param,'align="center"',$sortfield,$sortorder,'maxwidthsearch ');
769  print '</tr>'."\n";
770 
771  $total=0;
772  $subtotal=0;
773  $productstat_cache=array();
774 
775  $generic_commande = new Commande($db);
776  $generic_product = new Product($db);
777 
778  $i=0;
779  $totalarray=array();
780  while ($i < min($num,$limit))
781  {
782  $obj = $db->fetch_object($resql);
783 
784  $notshippable=0;
785  $warning = 0;
786  $text_info='';
787  $text_warning='';
788  $nbprod=0;
789 
790  $companystatic->id=$obj->socid;
791  $companystatic->code_client = $obj->code_client;
792  $companystatic->name=$obj->name;
793  $companystatic->client=$obj->client;
794  $companystatic->email=$obj->email;
795 
796  $generic_commande->id=$obj->rowid;
797  $generic_commande->ref=$obj->ref;
798  $generic_commande->statut = $obj->fk_statut;
799  $generic_commande->date_commande = $db->jdate($obj->date_commande);
800  $generic_commande->date_livraison = $db->jdate($obj->date_delivery);
801  $generic_commande->ref_client = $obj->ref_client;
802  $generic_commande->total_ht = $obj->total_ht;
803  $generic_commande->total_tva = $obj->total_tva;
804  $generic_commande->total_ttc = $obj->total_ttc;
805 
806  print '<tr class="oddeven">';
807 
808  // Ref
809  if (! empty($arrayfields['c.ref']['checked']))
810  {
811  print '<td class="nowrap">';
812 
813  $generic_commande->lines=array();
814  $generic_commande->getLinesArray();
815 
816  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
817  print '<td class="nobordernopadding nowrap">';
818  print $generic_commande->getNomUrl(1, ($viewstatut != 2?0:$obj->fk_statut), 0, 0, 0, 1);
819  print '</td>';
820 
821  // Show shippable Icon (create subloop, so may be slow)
822  if ($conf->stock->enabled)
823  {
824  $langs->load("stocks");
825  if (($obj->fk_statut > 0) && ($obj->fk_statut < 3))
826  {
827  $numlines = count($generic_commande->lines); // Loop on each line of order
828  for ($lig=0; $lig < $numlines; $lig++)
829  {
830  if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) // If line is a product and not a service
831  {
832  $nbprod++; // order contains real products
833  $generic_product->id = $generic_commande->lines[$lig]->fk_product;
834 
835  // Get local and virtual stock and store it into cache
836  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
837  $generic_product->load_stock('nobatch');
838  //$generic_product->load_virtual_stock(); Already included into load_stock
839  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
840  $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
841  } else {
842  $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
843  $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
844  }
845 
846  if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) // Default code. Default is when this option is not set, setting it create strange result
847  {
848  $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 25);
849  $text_info .= ' - '.$langs->trans("Stock").': '.$generic_product->stock_reel;
850  $text_info .= ' - '.$langs->trans("VirtualStock").': '.$generic_product->stock_theorique;
851  $text_info .= '<br>';
852 
853  if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel)
854  {
855  $notshippable++;
856  }
857  }
858  else { // Detailed code, looks bugged
859  // stock order and stock order_supplier
860  $stock_order=0;
861  $stock_order_supplier=0;
862  if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) // What about other options ?
863  {
864  if (! empty($conf->commande->enabled))
865  {
866  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
867  $generic_product->load_stats_commande(0,'1,2');
868  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
869  } else {
870  $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
871  }
872  $stock_order=$generic_product->stats_commande['qty'];
873  }
874  if (! empty($conf->fournisseur->enabled))
875  {
876  if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
877  $generic_product->load_stats_commande_fournisseur(0,'3');
878  $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
879  } else {
880  $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
881  }
882  $stock_order_supplier=$generic_product->stats_commande_fournisseur['qty'];
883  }
884  }
885  $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 25);
886  $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
887  if ($stock_order > $generic_product->stock_reel && ! ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) {
888  $warning++;
889  $text_warning.='<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
890  }
891  if ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty) {
892  $notshippable++;
893  $text_info.='<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
894  } else {
895  $text_info.='<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
896  }
897  if (! empty($conf->fournisseur->enabled)) {
898  $text_info.= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier.'<br>';
899  } else {
900  $text_info.= '<br>';
901  }
902  }
903  }
904  }
905  if ($notshippable==0) {
906  $text_icon = img_picto('', 'object_sending');
907  $text_info = $langs->trans('Shippable').'<br>'.$text_info;
908  } else {
909  $text_icon = img_picto('', 'error');
910  $text_info = $langs->trans('NonShippable').'<br>'.$text_info;
911  }
912  }
913 
914  print '<td>';
915  if ($nbprod)
916  {
917  print $form->textwithtooltip('',$text_info,2,1,$text_icon,'',2);
918  }
919  if ($warning) { // Always false in default mode
920  print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'),'',2);
921  }
922  print '</td>';
923  }
924 
925  // Warning late icon and note
926  print '<td class="nobordernopadding nowrap">';
927  if ($generic_commande->hasDelay()) {
928  print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
929  }
930  if (!empty($obj->note_private) || !empty($obj->note_public))
931  {
932  print ' <span class="note">';
933  print '<a href="'.DOL_URL_ROOT.'/commande/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
934  print '</span>';
935  }
936  print '</td>';
937 
938  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
939  $filename=dol_sanitizeFileName($obj->ref);
940  $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
941  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
942  print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
943  print '</td>';
944  print '</tr></table>';
945 
946  print '</td>';
947  if (! $i) $totalarray['nbfield']++;
948  }
949 
950  // Ref customer
951  if (! empty($arrayfields['c.ref_client']['checked']))
952  {
953  print '<td>'.$obj->ref_client.'</td>';
954  if (! $i) $totalarray['nbfield']++;
955  }
956 
957  // Project
958  if (! empty($arrayfields['p.project_ref']['checked']))
959  {
960  $projectstatic->id=$obj->project_id;
961  $projectstatic->ref=$obj->project_ref;
962  print '<td>';
963  if ($obj->project_id > 0) print $projectstatic->getNomUrl(1);
964  print '</td>';
965  if (! $i) $totalarray['nbfield']++;
966  }
967 
968  // Third party
969  if (! empty($arrayfields['s.nom']['checked']))
970  {
971  print '<td class="tdoverflowmax200">';
972  print $companystatic->getNomUrl(1,'customer');
973 
974  // If module invoices enabled and user with invoice creation permissions
975  if (! empty($conf->facture->enabled) && ! empty($conf->global->ORDER_BILLING_ALL_CUSTOMER))
976  {
977  if ($user->rights->facture->creer)
978  {
979  if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0))
980  {
981  print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$companystatic->id.'">';
982  print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
983  }
984  }
985  }
986  print '</td>';
987  if (! $i) $totalarray['nbfield']++;
988  }
989  // Town
990  if (! empty($arrayfields['s.town']['checked']))
991  {
992  print '<td class="nocellnopadd">';
993  print $obj->town;
994  print '</td>';
995  if (! $i) $totalarray['nbfield']++;
996  }
997  // Zip
998  if (! empty($arrayfields['s.zip']['checked']))
999  {
1000  print '<td class="nocellnopadd">';
1001  print $obj->zip;
1002  print '</td>';
1003  if (! $i) $totalarray['nbfield']++;
1004  }
1005  // State
1006  if (! empty($arrayfields['state.nom']['checked']))
1007  {
1008  print "<td>".$obj->state_name."</td>\n";
1009  if (! $i) $totalarray['nbfield']++;
1010  }
1011  // Country
1012  if (! empty($arrayfields['country.code_iso']['checked']))
1013  {
1014  print '<td align="center">';
1015  $tmparray=getCountry($obj->fk_pays,'all');
1016  print $tmparray['label'];
1017  print '</td>';
1018  if (! $i) $totalarray['nbfield']++;
1019  }
1020  // Type ent
1021  if (! empty($arrayfields['typent.code']['checked']))
1022  {
1023  print '<td align="center">';
1024  if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
1025  print $typenArray[$obj->typent_code];
1026  print '</td>';
1027  if (! $i) $totalarray['nbfield']++;
1028  }
1029 
1030  // Order date
1031  if (! empty($arrayfields['c.date_commande']['checked']))
1032  {
1033  print '<td align="center">';
1034  print dol_print_date($db->jdate($obj->date_commande), 'day');
1035  print '</td>';
1036  if (! $i) $totalarray['nbfield']++;
1037  }
1038  // Plannned date of delivery
1039  if (! empty($arrayfields['c.date_delivery']['checked']))
1040  {
1041  print '<td align="center">';
1042  print dol_print_date($db->jdate($obj->date_delivery), 'day');
1043  print '</td>';
1044  if (! $i) $totalarray['nbfield']++;
1045  }
1046  // Amount HT
1047  if (! empty($arrayfields['c.total_ht']['checked']))
1048  {
1049  print '<td align="right">'.price($obj->total_ht)."</td>\n";
1050  if (! $i) $totalarray['nbfield']++;
1051  if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
1052  $totalarray['totalht'] += $obj->total_ht;
1053  }
1054  // Amount VAT
1055  if (! empty($arrayfields['c.total_vat']['checked']))
1056  {
1057  print '<td align="right">'.price($obj->total_tva)."</td>\n";
1058  if (! $i) $totalarray['nbfield']++;
1059  if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
1060  $totalarray['totalvat'] += $obj->total_tva;
1061  }
1062  // Amount TTC
1063  if (! empty($arrayfields['c.total_ttc']['checked']))
1064  {
1065  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
1066  if (! $i) $totalarray['nbfield']++;
1067  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
1068  $totalarray['totalttc'] += $obj->total_ttc;
1069  }
1070 
1071  // Extra fields
1072  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1073  // Fields from hook
1074  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
1075  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
1076  print $hookmanager->resPrint;
1077  // Date creation
1078  if (! empty($arrayfields['c.datec']['checked']))
1079  {
1080  print '<td align="center" class="nowrap">';
1081  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1082  print '</td>';
1083  if (! $i) $totalarray['nbfield']++;
1084  }
1085  // Date modification
1086  if (! empty($arrayfields['c.tms']['checked']))
1087  {
1088  print '<td align="center" class="nowrap">';
1089  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1090  print '</td>';
1091  if (! $i) $totalarray['nbfield']++;
1092  }
1093  // Status
1094  if (! empty($arrayfields['c.fk_statut']['checked']))
1095  {
1096  print '<td align="right" class="nowrap">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
1097  if (! $i) $totalarray['nbfield']++;
1098  }
1099  // Billed
1100  if (! empty($arrayfields['c.facture']['checked']))
1101  {
1102  print '<td align="center">'.yn($obj->billed).'</td>';
1103  if (! $i) $totalarray['nbfield']++;
1104  }
1105 
1106  // Action column
1107  print '<td class="nowrap" align="center">';
1108  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1109  {
1110  $selected=0;
1111  if (in_array($obj->rowid, $arrayofselected)) $selected=1;
1112  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
1113  }
1114  print '</td>';
1115  if (! $i) $totalarray['nbfield']++;
1116 
1117  print "</tr>\n";
1118 
1119  $total+=$obj->total_ht;
1120  $subtotal+=$obj->total_ht;
1121  $i++;
1122  }
1123 
1124  // Show total line
1125  if (isset($totalarray['totalhtfield'])
1126  || isset($totalarray['totalvatfield'])
1127  || isset($totalarray['totalttcfield'])
1128  || isset($totalarray['totalamfield'])
1129  || isset($totalarray['totalrtpfield'])
1130  )
1131  {
1132  print '<tr class="liste_total">';
1133  $i=0;
1134  while ($i < $totalarray['nbfield'])
1135  {
1136  $i++;
1137  if ($i == 1)
1138  {
1139  if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
1140  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
1141  }
1142  elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
1143  elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
1144  elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
1145  else print '<td></td>';
1146  }
1147  print '</tr>';
1148  }
1149 
1150  $db->free($resql);
1151 
1152  $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1153  $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
1154  print $hookmanager->resPrint;
1155 
1156  print '</table>'."\n";
1157  print '</div>';
1158 
1159  print '</form>'."\n";
1160 
1161  $hidegeneratedfilelistifempty=1;
1162  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
1163 
1164  // Show list of available documents
1165  $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1166  $urlsource.=str_replace('&amp;','&',$param);
1167 
1168  $filedir=$diroutputmassaction;
1169  $genallowed=$user->rights->commande->lire;
1170  $delallowed=$user->rights->commande->creer;
1171 
1172  print $formfile->showdocuments('massfilesarea_orders','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty);
1173 }
1174 else
1175 {
1176  dol_print_error($db);
1177 }
1178 
1179 // End of page
1180 llxFooter();
1181 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
GETPOST($paramname, $check='none', $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)
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Class to manage products or services.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:453
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage projects.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
dol_now($mode='gmt')
Return date for now.
Class to offer components to list and upload files.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
const STATUS_VALIDATED
Validated status.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:467
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.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
const STATUS_CANCELED
Canceled status.