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