dolibarr  9.0.0
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
5  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
7  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
37 
38 // Load translation files required by the page
39 $langs->loadLangs(array('companies', 'users', 'trips'));
40 
41 $action=GETPOST('action','aZ09');
42 $massaction=GETPOST('massaction','alpha');
43 $show_files=GETPOST('show_files','int');
44 $confirm=GETPOST('confirm','alpha');
45 $toselect = GETPOST('toselect', 'array');
46 $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'expensereportlist';
47 
48 // Security check
49 $socid = GETPOST('socid','int');
50 if ($user->societe_id) $socid=$user->societe_id;
51 $result = restrictedArea($user, 'expensereport','','');
52 
53 $diroutputmassaction=$conf->expensereport->dir_output . '/temp/massgeneration/'.$user->id;
54 
55 
56 // Load variable for pagination
57 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
58 $sortfield = GETPOST('sortfield','alpha');
59 $sortorder = GETPOST('sortorder','alpha');
60 $page = GETPOST('page','int');
61 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
62 $offset = $limit * $page;
63 $pageprev = $page - 1;
64 $pagenext = $page + 1;
65 if (!$sortorder) $sortorder="DESC";
66 if (!$sortfield) $sortfield="d.date_debut";
67 
68 $id = GETPOST('id', 'int');
69 
70 $sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
71 $search_ref = GETPOST('search_ref');
72 $search_user = GETPOST('search_user','int');
73 $search_amount_ht = GETPOST('search_amount_ht','alpha');
74 $search_amount_vat = GETPOST('search_amount_vat','alpha');
75 $search_amount_ttc = GETPOST('search_amount_ttc','alpha');
76 $search_status = (GETPOST('search_status','intcomma')!=''?GETPOST('search_status','intcomma'):GETPOST('statut','intcomma'));
77 $month_start = GETPOST("month_start","int");
78 $year_start = GETPOST("year_start","int");
79 $month_end = GETPOST("month_end","int");
80 $year_end = GETPOST("year_end","int");
81 $optioncss = GETPOST('optioncss','alpha');
82 
83 if ($search_status == '') $search_status=-1;
84 if ($search_user == '') $search_user=-1;
85 
86 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
87 $object = new ExpenseReport($db);
88 $hookmanager->initHooks(array('expensereportlist'));
89 $extrafields = new ExtraFields($db);
90 
91 // fetch optionals attributes and labels
92 $extralabels = $extrafields->fetch_name_optionals_label('expensereport');
93 $search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
94 
95 
96 // List of fields to search into when doing a "search in all"
97 $fieldstosearchall = array(
98  'd.ref'=>'Ref',
99  'd.note_public'=>"NotePublic",
100  'u.lastname'=>'Lastname',
101  'u.firstname'=>"Firstname",
102  'u.login'=>"Login",
103 );
104 if (empty($user->socid)) $fieldstosearchall["d.note_private"]="NotePrivate";
105 
106 $arrayfields=array(
107  'd.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
108  'user'=>array('label'=>$langs->trans("User"), 'checked'=>1),
109  'd.date_debut'=>array('label'=>$langs->trans("DateStart"), 'checked'=>1),
110  'd.date_fin'=>array('label'=>$langs->trans("DateEnd"), 'checked'=>1),
111  'd.date_valid'=>array('label'=>$langs->trans("DateValidation"), 'checked'=>1),
112  'd.date_approve'=>array('label'=>$langs->trans("DateApprove"), 'checked'=>1),
113  'd.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
114  'd.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
115  'd.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
116  'd.date_create'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
117  'd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
118  'd.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
119 );
120 // Extra fields
121 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
122 {
123  foreach($extrafields->attribute_label as $key => $val)
124  {
125  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]));
126  }
127 }
128 
129 $canedituser=(! empty($user->admin) || $user->rights->user->user->creer);
130 
131 $object = new ExpenseReport($db);
132 $objectuser = new User($db);
133 
134 
135 /*
136  * Actions
137  */
138 
139 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
140 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
141 
142 $parameters=array('socid'=>$socid);
143 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
144 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
145 
146 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
147 
148 if (empty($reshook))
149 {
150  // Purge search criteria
151  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test must be present to be compatible with all browsers
152  {
153  $search_ref="";
154  $search_user="";
155  $search_amount_ht="";
156  $search_amount_vat="";
157  $search_amount_ttc="";
158  $search_status="";
159  $month_start="";
160  $year_start="";
161  $month_end="";
162  $year_end="";
163  $toselect='';
164  $search_array_options=array();
165  }
166  if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
167  || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
168  {
169  $massaction=''; // Protection to avoid mass action if we force a new search during a mass action confirmation
170  }
171 
172  // Mass actions
173  $objectclass='ExpenseReport';
174  $objectlabel='ExpenseReport';
175  $permtoread = $user->rights->expensereport->lire;
176  $permtodelete = $user->rights->expensereport->supprimer;
177  $uploaddir = $conf->expensereport->dir_output;
178  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
179 
180  if ($action == 'update' && ! $cancel)
181  {
182  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
183 
184  if ($canedituser) // Case we can edit all field
185  {
186  $error = 0;
187 
188  if (!$error)
189  {
190  $objectuser->fetch($id);
191 
192  $objectuser->oldcopy = clone $objectuser;
193 
194  $db->begin();
195 
196  $objectuser->default_range = GETPOST('default_range');
197  $objectuser->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat');
198 
199  if (!$error) {
200  $ret = $objectuser->update($user);
201  if ($ret < 0) {
202  $error++;
203  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
204  $langs->load("errors");
205  setEventMessages($langs->trans("ErrorLoginAlreadyExists", $objectuser->login), null, 'errors');
206  }
207  else
208  {
209  setEventMessages($objectuser->error, $objectuser->errors, 'errors');
210  }
211  }
212  }
213 
214  if (!$error && !count($objectuser->errors)) {
215  setEventMessages($langs->trans("UserModified"), null, 'mesgs');
216  $db->commit();
217  }
218  else {
219  $db->rollback();
220  }
221  }
222  }
223  }
224 }
225 
226 
227 /*
228  * View
229  */
230 
231 $form = new Form($db);
232 $formother = new FormOther($db);
233 $formfile = new FormFile($db);
234 
235 $fuser = new User($db);
236 
237 $title = $langs->trans("ListOfTrips");
238 llxHeader('', $title);
239 
240 $max_year = 5;
241 $min_year = 5;
242 
243 // Récupération de l'ID de l'utilisateur
244 $user_id = $user->id;
245 
246 if ($id > 0)
247 {
248  // Charge utilisateur edite
249  $fuser->fetch($id, '', '', 1);
250  $fuser->getrights();
251  $user_id = $fuser->id;
252 
253  $search_user = $user_id;
254 }
255 
256 $sql = "SELECT d.rowid, d.ref, d.fk_user_author, d.total_ht, d.total_tva, d.total_ttc, d.fk_statut as status,";
257 $sql.= " d.date_debut, d.date_fin, d.date_create, d.tms as date_modif, d.date_valid, d.date_approve, d.note_private, d.note_public,";
258 $sql.= " u.rowid as id_user, u.firstname, u.lastname, u.login, u.email, u.statut, u.photo";
259 // Add fields from extrafields
260 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
261 // Add fields from hooks
262 $parameters=array();
263 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
264 $sql.=$hookmanager->resPrint;
265 $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d";
266 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_extrafields as ef on (d.rowid = ef.fk_object)";
267 $sql.= ", ".MAIN_DB_PREFIX."user as u";
268 $sql.= " WHERE d.fk_user_author = u.rowid AND d.entity IN (".getEntity('expensereport').")";
269 // Search all
270 if (!empty($sall)) $sql.= natural_search(array_keys($fieldstosearchall), $sall);
271 // Ref
272 if (!empty($search_ref)) $sql.= natural_search('d.ref', $search_ref);
273 // Date Start
274 if ($month_start > 0)
275 {
276  if ($year_start > 0 && empty($day))
277  $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,$month_start,false))."' AND '".$db->idate(dol_get_last_day($year_start,$month_start,false))."'";
278  else if ($year_start > 0 && ! empty($day))
279  $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_start, $day, $year_start))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_start, $day, $year_start))."'";
280  else
281  $sql.= " AND date_format(d.date_debut, '%m') = '".$month_start."'";
282 }
283 else if ($year_start > 0)
284 {
285  $sql.= " AND d.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,1,false))."' AND '".$db->idate(dol_get_last_day($year_start,12,false))."'";
286 }
287 // Date Start
288 if ($month_end > 0)
289 {
290  if ($year_end > 0 && empty($day))
291  $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,$month_end,false))."' AND '".$db->idate(dol_get_last_day($year_end,$month_end,false))."'";
292  else if ($year_end > 0 && ! empty($day))
293  $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_end, $day, $year_end))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_end, $day, $year_end))."'";
294  else
295  $sql.= " AND date_format(d.date_fin, '%m') = '".$month_end."'";
296 }
297 else if ($year_end > 0)
298 {
299  $sql.= " AND d.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,false))."' AND '".$db->idate(dol_get_last_day($year_end,12,false))."'";
300 }
301 // Amount
302 if ($search_amount_ht != '') $sql.= natural_search('d.total_ht', $search_amount_ht, 1);
303 if ($search_amount_ttc != '') $sql.= natural_search('d.total_ttc', $search_amount_ttc, 1);
304 // User
305 if ($search_user != '' && $search_user >= 0) $sql.= " AND u.rowid = '".$db->escape($search_user)."'";
306 // Status
307 if ($search_status != '' && $search_status >= 0) $sql.=" AND d.fk_statut IN (".$db->escape($search_status).")";
308 // RESTRICT RIGHTS
309 if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)
310  && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || empty($user->rights->expensereport->writeall_advance)))
311 {
312  $childids = $user->getAllChildIds(1);
313  $sql.= " AND d.fk_user_author IN (".join(',',$childids).")\n";
314 }
315 // Add where from extra fields
316 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
317 // Add where from hooks
318 $parameters=array();
319 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
320 $sql.=$hookmanager->resPrint;
321 
322 $sql.= $db->order($sortfield,$sortorder);
323 
324 // Count total nb of records
325 $nbtotalofrecords = '';
326 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
327 {
328  $result = $db->query($sql);
329  $nbtotalofrecords = $db->num_rows($result);
330  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
331  {
332  $page = 0;
333  $offset = 0;
334  }
335 }
336 
337 $sql.= $db->plimit($limit+1, $offset);
338 
339 //print $sql;
340 $resql = $db->query($sql);
341 if ($resql)
342 {
343  $num = $db->num_rows($resql);
344 
345  $arrayofselected=is_array($toselect)?$toselect:array();
346 
347  $param='';
348  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
349  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
350  if ($sall) $param.="&sall=".$sall;
351  if ($search_ref) $param.="&search_ref=".$search_ref;
352  if ($search_user) $param.="&search_user=".$search_user;
353  if ($search_amount_ht) $param.="&search_amount_ht=".$search_amount_ht;
354  if ($search_amount_ttc) $param.="&search_amount_ttc=".$search_amount_ttc;
355  if ($search_status >= 0) $param.="&search_status=".$search_status;
356  if ($optioncss != '') $param.='&optioncss='.$optioncss;
357  // Add $param from extra fields
358  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
359 
360  // List of mass actions available
361  $arrayofmassactions = array(
362  'presend'=>$langs->trans("SendByMail"),
363  'builddoc'=>$langs->trans("PDFMerge"),
364  );
365  if ($user->rights->expensereport->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
366  if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
367  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
368 
369  // Lines of title fields
370  print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST">'."\n";
371  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
372  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
373  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
374  print '<input type="hidden" name="action" value="'.($action=='edit'?'update':'list').'">';
375  print '<input type="hidden" name="page" value="'.$page.'">';
376  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
377  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
378  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
379  if ($id > 0) print '<input type="hidden" name="id" value="'.$id.'">';
380 
381  if ($id > 0) // For user tab
382  {
383  $title = $langs->trans("User");
384  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
385  $head = user_prepare_head($fuser);
386 
387  dol_fiche_head($head, 'expensereport', $title, -1, 'user');
388 
389  dol_banner_tab($fuser,'id',$linkback,$user->rights->user->user->lire || $user->admin);
390 
391  print '<div class="fichecenter">';
392  print '<div class="underbanner clearboth"></div>';
393 
394  if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
395  {
396  print '<table class="border centpercent">';
397 
398  if ($action == 'edit')
399  {
400  print '<tr><td class="titlefield">'.$langs->trans("DefaultCategoryCar").'</td>';
401  print '<td>';
402  print $form->selectExpenseCategories($fuser->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1);
403  print '</td></tr>';
404 
405  print '<tr><td>'.$langs->trans("DefaultRangeNumber").'</td>';
406  print '<td>';
407  $maxRangeNum = ExpenseReportIk::getMaxRangeNumber($fuser->default_c_exp_tax_cat);
408  print $form->selectarray('default_range', range(0, $maxRangeNum), $fuser->default_range);
409  print '</td></tr>';
410  }
411  else
412  {
413  print '<tr><td class="titlefield">'.$langs->trans("DefaultCategoryCar").'</td>';
414  print '<td class="fk_c_exp_tax_cat">';
415  print dol_getIdFromCode($db, $fuser->default_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label');
416  print '</td></tr>';
417 
418  print '<tr><td>'.$langs->trans("DefaultRangeNumber").'</td>';
419  print '<td>';
420  print $fuser->default_range;
421  print '</td></tr>';
422  }
423 
424  print '</table>';
425  }
426 
427  print '</div>';
428 
429  /*if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
430  {
431  print '<div class="underbanner clearboth"></div>';
432 
433  print '<br>';
434 
435  showMyBalance($holiday, $user_id);
436  }*/
437 
438  dol_fiche_end();
439 
440  if ($action != 'edit')
441  {
442  print '<div class="tabsAction">';
443 
444  if (!empty($conf->global->MAIN_USE_EXPENSE_IK))
445  {
446  print '<a href="'.$_SERVER["PHP_SELF"].'?action=edit&id='.$user_id.'" class="butAction">'.$langs->trans("Modify").'</a>';
447  }
448 
449  $childids = $user->getAllChildIds(1);
450 
451  $canedit=((in_array($user_id, $childids) && $user->rights->expensereport->creer)
452  || ($conf->global->MAIN_USE_ADVANCED_PERMS && $user->rights->expensereport->writeall_advance));
453 
454  // Boutons d'actions
455  if ($canedit)
456  {
457  print '<a href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create&fk_user_author='.$fuser->id.'" class="butAction">'.$langs->trans("AddTrip").'</a>';
458  }
459 
460  print '</div>';
461  }
462  else
463  {
464  print '<div class="center">';
465  print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
466  print '</div><br>';
467  }
468  }
469  else
470  {
471  $title = $langs->trans("ListTripsAndExpenses");
472 
473  $newcardbutton='';
474  if ($user->rights->expensereport->creer)
475  {
476  $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/expensereport/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewTrip').'</span>';
477  $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
478  $newcardbutton.= '</a>';
479  }
480 
481  print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_generic.png', 0, $newcardbutton, '', $limit);
482  }
483 
484  $topicmail="SendExpenseReport";
485  $modelmail="expensereport";
486  $objecttmp=new ExpenseReport($db);
487  $trackid='exp'.$object->id;
488  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
489 
490  if ($sall)
491  {
492  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
493  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
494  }
495 
496  $moreforfilter='';
497 
498  $parameters=array();
499  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
500  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
501  else $moreforfilter = $hookmanager->resPrint;
502 
503  if (! empty($moreforfilter))
504  {
505  print '<div class="liste_titre liste_titre_bydiv centpercent">';
506  print $moreforfilter;
507  print '</div>';
508  }
509 
510  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
511  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
512  if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
513 
514  print '<div class="div-table-responsive">';
515  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
516 
517  // Filters
518  print '<tr class="liste_titre_filter">';
519  if (! empty($arrayfields['d.ref']['checked']))
520  {
521  print '<td class="liste_titre" align="left">';
522  print '<input class="flat" size="15" type="text" name="search_ref" value="'.$search_ref.'">';
523  print '</td>';
524  }
525  // User
526  if (! empty($arrayfields['user']['checked']))
527  {
528  if ($user->rights->expensereport->readall || $user->rights->expensereport->lire_tous)
529  {
530  print '<td class="liste_titre maxwidthonspartphone" align="left">';
531  print $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
532  print '</td>';
533  } else {
534  print '<td class="liste_titre">&nbsp;</td>';
535  }
536  }
537  // Date start
538  if (! empty($arrayfields['d.date_debut']['checked']))
539  {
540  print '<td class="liste_titre" align="center">';
541  print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
542  $formother->select_year($year_start,'year_start',1, $min_year, $max_year);
543  print '</td>';
544  }
545  // Date end
546  if (! empty($arrayfields['d.date_fin']['checked']))
547  {
548  print '<td class="liste_titre" align="center">';
549  print '<input class="flat valignmiddle" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
550  $formother->select_year($year_end,'year_end',1, $min_year, $max_year);
551  print '</td>';
552  }
553  // Date valid
554  if (! empty($arrayfields['d.date_valid']['checked']))
555  {
556  print '<td class="liste_titre" align="center">';
557  //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
558  //$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
559  print '</td>';
560  }
561  // Date approve
562  if (! empty($arrayfields['d.date_approve']['checked']))
563  {
564  print '<td class="liste_titre" align="center">';
565  //print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
566  //$formother->select_year($year_end,'year_end',1, $min_year, $max_year);
567  print '</td>';
568  }
569  // Amount with no tax
570  if (! empty($arrayfields['d.total_ht']['checked']))
571  {
572  print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_ht" value="'.$search_amount_ht.'"></td>';
573  }
574  if (! empty($arrayfields['d.total_vat']['checked']))
575  {
576  print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_vat" value="'.$search_amount_vat.'"></td>';
577  }
578  // Amount with all taxes
579  if (! empty($arrayfields['d.total_ttc']['checked']))
580  {
581  print '<td class="liste_titre" align="right"><input class="flat" type="text" size="5" name="search_amount_ttc" value="'.$search_amount_ttc.'"></td>';
582  }
583  // Extra fields
584  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
585 
586  // Fields from hook
587  $parameters=array('arrayfields'=>$arrayfields);
588  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
589  print $hookmanager->resPrint;
590  // Date creation
591  if (! empty($arrayfields['d.date_create']['checked']))
592  {
593  print '<td class="liste_titre">';
594  print '</td>';
595  }
596  // Date modification
597  if (! empty($arrayfields['d.tms']['checked']))
598  {
599  print '<td class="liste_titre">';
600  print '</td>';
601  }
602  // Status
603  if (! empty($arrayfields['d.fk_statut']['checked']))
604  {
605  print '<td class="liste_titre" align="right">';
606  select_expensereport_statut($search_status,'search_status',1,1);
607  print '</td>';
608  }
609  // Action column
610  print '<td class="liste_titre" align="middle">';
611  $searchpicto=$form->showFilterButtons();
612  print $searchpicto;
613  print '</td>';
614 
615  print "</tr>\n";
616 
617  print '<tr class="liste_titre">';
618  if (! empty($arrayfields['d.ref']['checked'])) print_liste_field_titre($arrayfields['d.ref']['label'],$_SERVER["PHP_SELF"],"d.ref","",$param,'',$sortfield,$sortorder);
619  if (! empty($arrayfields['user']['checked'])) print_liste_field_titre($arrayfields['user']['label'],$_SERVER["PHP_SELF"],"u.lastname","",$param,'',$sortfield,$sortorder);
620  if (! empty($arrayfields['d.date_debut']['checked'])) print_liste_field_titre($arrayfields['d.date_debut']['label'],$_SERVER["PHP_SELF"],"d.date_debut","",$param,'align="center"',$sortfield,$sortorder);
621  if (! empty($arrayfields['d.date_fin']['checked'])) print_liste_field_titre($arrayfields['d.date_fin']['label'],$_SERVER["PHP_SELF"],"d.date_fin","",$param,'align="center"',$sortfield,$sortorder);
622  if (! empty($arrayfields['d.date_valid']['checked'])) print_liste_field_titre($arrayfields['d.date_valid']['label'],$_SERVER["PHP_SELF"],"d.date_valid","",$param,'align="center"',$sortfield,$sortorder);
623  if (! empty($arrayfields['d.date_approve']['checked'])) print_liste_field_titre($arrayfields['d.date_approve']['label'],$_SERVER["PHP_SELF"],"d.date_approve","",$param,'align="center"',$sortfield,$sortorder);
624  if (! empty($arrayfields['d.total_ht']['checked'])) print_liste_field_titre($arrayfields['d.total_ht']['label'],$_SERVER["PHP_SELF"],"d.total_ht","",$param,'align="right"',$sortfield,$sortorder);
625  if (! empty($arrayfields['d.total_vat']['checked'])) print_liste_field_titre($arrayfields['d.total_vat']['label'],$_SERVER["PHP_SELF"],"d.total_tva","",$param,'align="right"',$sortfield,$sortorder);
626  if (! empty($arrayfields['d.total_ttc']['checked'])) print_liste_field_titre($arrayfields['d.total_ttc']['label'],$_SERVER["PHP_SELF"],"d.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
627  // Extra fields
628  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
629  // Hook fields
630  $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
631  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
632  print $hookmanager->resPrint;
633  if (! empty($arrayfields['d.date_create']['checked'])) print_liste_field_titre($arrayfields['d.date_create']['label'],$_SERVER["PHP_SELF"],"d.date_create","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
634  if (! empty($arrayfields['d.tms']['checked'])) print_liste_field_titre($arrayfields['d.tms']['label'],$_SERVER["PHP_SELF"],"d.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
635  if (! empty($arrayfields['d.fk_statut']['checked'])) print_liste_field_titre($arrayfields['d.fk_statut']['label'],$_SERVER["PHP_SELF"],"d.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
636  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
637  print "</tr>\n";
638 
639  $total_total_ht = 0;
640  $total_total_ttc = 0;
641  $total_total_tva = 0;
642 
643  $expensereportstatic=new ExpenseReport($db);
644  $usertmp = new User($db);
645 
646  if ($num > 0)
647  {
648  $i=0;
649  $totalarray=array();
650  while ($i < min($num,$limit))
651  {
652  $obj = $db->fetch_object($resql);
653 
654  $expensereportstatic->id=$obj->rowid;
655  $expensereportstatic->ref=$obj->ref;
656  $expensereportstatic->status=$obj->status;
657  $expensereportstatic->date_debut=$db->jdate($obj->date_debut);
658  $expensereportstatic->date_fin=$db->jdate($obj->date_fin);
659  $expensereportstatic->date_create=$db->jdate($obj->date_create);
660  $expensereportstatic->date_modif=$db->jdate($obj->date_modif);
661  $expensereportstatic->date_valid=$db->jdate($obj->date_valid);
662  $expensereportstatic->date_approve=$db->jdate($obj->date_approve);
663  $expensereportstatic->note_private=$obj->note_private;
664  $expensereportstatic->note_public=$obj->note_public;
665 
666 
667  print '<tr class="oddeven">';
668  // Ref
669  if (! empty($arrayfields['d.ref']['checked'])) {
670  print '<td>';
671  print '<table class="nobordernopadding"><tr class="nocellnopadd">';
672  print '<td class="nobordernopadding nowrap">';
673  print $expensereportstatic->getNomUrl(1);
674  print '</td>';
675  // Warning late icon and note
676  print '<td class="nobordernopadding nowrap">';
677  if ($expensereportstatic->status == 2 && $expensereportstatic->hasDelay('toappove')) print img_warning($langs->trans("Late"));
678  if ($expensereportstatic->status == 5 && $expensereportstatic->hasDelay('topay')) print img_warning($langs->trans("Late"));
679  if (!empty($obj->note_private) || !empty($obj->note_public))
680  {
681  print ' <span class="note">';
682  print '<a href="'.DOL_URL_ROOT.'/expensereport/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
683  print '</span>';
684  }
685  print '</td>';
686  print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
687  $filename=dol_sanitizeFileName($obj->ref);
688  $filedir=$conf->expensereport->dir_output . '/' . dol_sanitizeFileName($obj->ref);
689  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
690  print $formfile->getDocumentsLink($expensereportstatic->element, $filename, $filedir);
691  print '</td>';
692  print '</tr></table>';
693  print '</td>';
694  if (! $i) $totalarray['nbfield']++;
695  }
696  // User
697  if (! empty($arrayfields['user']['checked'])) {
698  print '<td align="left">';
699  $usertmp->id=$obj->id_user;
700  $usertmp->lastname=$obj->lastname;
701  $usertmp->firstname=$obj->firstname;
702  $usertmp->login=$obj->login;
703  $usertmp->statut=$obj->statut;
704  $usertmp->photo=$obj->photo;
705  $usertmp->email=$obj->email;
706  print $usertmp->getNomUrl(-1);
707  print '</td>';
708  if (! $i) $totalarray['nbfield']++;
709  }
710  // Start date
711  if (! empty($arrayfields['d.date_debut']['checked'])) {
712  print '<td align="center">'.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').'</td>';
713  if (! $i) $totalarray['nbfield']++;
714  }
715  // End date
716  if (! empty($arrayfields['d.date_fin']['checked'])) {
717  print '<td align="center">'.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').'</td>';
718  if (! $i) $totalarray['nbfield']++;
719  }
720  // Date validation
721  if (! empty($arrayfields['d.date_valid']['checked'])) {
722  print '<td align="center">'.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').'</td>';
723  if (! $i) $totalarray['nbfield']++;
724  }
725  // Date approval
726  if (! empty($arrayfields['d.date_approve']['checked'])) {
727  print '<td align="center">'.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').'</td>';
728  if (! $i) $totalarray['nbfield']++;
729  }
730  // Amount HT
731  if (! empty($arrayfields['d.total_ht']['checked']))
732  {
733  print '<td align="right">'.price($obj->total_ht)."</td>\n";
734  if (! $i) $totalarray['nbfield']++;
735  if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
736  $totalarray['totalht'] += $obj->total_ht;
737  }
738  // Amount VAT
739  if (! empty($arrayfields['d.total_vat']['checked']))
740  {
741  print '<td align="right">'.price($obj->total_tva)."</td>\n";
742  if (! $i) $totalarray['nbfield']++;
743  if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
744  $totalarray['totalvat'] += $obj->total_tva;
745  }
746  // Amount TTC
747  if (! empty($arrayfields['d.total_ttc']['checked']))
748  {
749  print '<td align="right">'.price($obj->total_ttc)."</td>\n";
750  if (! $i) $totalarray['nbfield']++;
751  if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
752  $totalarray['totalttc'] += $obj->total_ttc;
753  }
754 
755  // Extra fields
756  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
757  // Fields from hook
758  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
759  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
760  print $hookmanager->resPrint;
761  // Date creation
762  if (! empty($arrayfields['d.date_create']['checked']))
763  {
764  print '<td align="center" class="nowrap">';
765  print dol_print_date($db->jdate($obj->date_create), 'dayhour');
766  print '</td>';
767  if (! $i) $totalarray['nbfield']++;
768  }
769  // Date modification
770  if (! empty($arrayfields['d.tms']['checked']))
771  {
772  print '<td align="center" class="nowrap">';
773  print dol_print_date($db->jdate($obj->date_modif), 'dayhour');
774  print '</td>';
775  if (! $i) $totalarray['nbfield']++;
776  }
777  // Status
778  if (! empty($arrayfields['d.fk_statut']['checked']))
779  {
780  print '<td align="right" class="nowrap">'.$expensereportstatic->getLibStatut(5).'</td>';
781  if (! $i) $totalarray['nbfield']++;
782  }
783  // Action column
784  print '<td class="nowrap" align="center">';
785  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
786  {
787  $selected=0;
788  if (in_array($obj->rowid, $arrayofselected)) $selected=1;
789  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
790  }
791  print '</td>';
792  if (! $i) $totalarray['nbfield']++;
793 
794  print "</tr>\n";
795 
796  $total_total_ht = $total_total_ht + $obj->total_ht;
797  $total_total_tva = $total_total_tva + $obj->total_tva;
798  $total_total_ttc = $total_total_ttc + $obj->total_ttc;
799 
800  $i++;
801  }
802  }
803  else
804  {
805  $colspan=1;
806  foreach($arrayfields as $key => $val) { if (! empty($val['checked'])) $colspan++; }
807 
808  print '<tr>'.'<td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
809  }
810 
811  // Show total line
812  if (isset($totalarray['totalhtfield']))
813  {
814  print '<tr class="liste_total">';
815  $i=0;
816  while ($i < $totalarray['nbfield'])
817  {
818  $i++;
819  if ($i == 1)
820  {
821  if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
822  else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
823  }
824  elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
825  elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
826  elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
827  else print '<td></td>';
828  }
829  print '</tr>';
830  }
831 
832  $db->free($resql);
833 
834  $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
835  $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
836  print $hookmanager->resPrint;
837 
838  print '</table>'."\n";
839  print '</div>';
840 
841  print '</form>'."\n";
842 
843  if (empty($id))
844  {
845  $hidegeneratedfilelistifempty=1;
846  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty=0;
847 
848  // Show list of available documents
849  $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
850  $urlsource.=str_replace('&amp;','&',$param);
851 
852  $filedir=$diroutputmassaction;
853  $genallowed=$user->rights->expensereport->lire;
854  $delallowed=$user->rights->expensereport->creer;
855 
856  print $formfile->showdocuments('massfilesarea_expensereport','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'','','',null,$hidegeneratedfilelistifempty);
857  }
858 }
859 else
860 {
861  dol_print_error($db);
862 }
863 
864 // End of page
865 llxFooter();
866 $db->close();
select_expensereport_statut($selected='', $htmlname='fk_statut', $useempty=1, $useshortlabel=0)
Retourne la liste deroulante des differents etats d&#39;une note de frais.
img_warning($titlealt='default', $moreatt='')
Show warning logo.
llxFooter()
Empty footer.
Definition: wrapper.php:56
static getMaxRangeNumber($default_c_exp_tax_cat=0)
Return the max number of range by a category.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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
user_prepare_head($object)
Prepare array with list of tabs.
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.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
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...
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.
dol_fiche_end($notab=0)
Show tab footer of a card.
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...
Class to manage Trips and Expenses.
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).
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)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.