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