dolibarr  9.0.0
index.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2011 Dimitri Mouillard <dmouillard@teclib.com>
3  * Copyright (C) 2013-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2012-2014 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
35 if ($conf->deplacement->enabled) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
36 if ($conf->expensereport->enabled) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
38 
39 // Load translation files required by the page
40 $langs->loadLangs(array('users', 'holidays', 'trips'));
41 
42 $socid=GETPOST("socid","int");
43 
44 // Protection if external user
45 if ($user->societe_id > 0) accessforbidden();
46 
47 if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) $setupcompanynotcomplete=1;
48 
49 $holiday = new Holiday($db);
50 $holidaystatic=new Holiday($db);
51 
52 
53 
54 /*
55  * Actions
56  */
57 
58 // Update sold
59 if (! empty($conf->holiday->enabled) && ! empty($setupcompanynotcomplete))
60 {
61  $result = $holiday->updateBalance();
62 }
63 
64 
65 /*
66  * View
67  */
68 
69 $childids = $user->getAllChildIds();
70 $childids[]=$user->id;
71 
72 llxHeader('', $langs->trans('HRMArea'));
73 
74 print load_fiche_titre($langs->trans("HRMArea"),'', 'title_hrm.png');
75 
76 
77 if (! empty($setupcompanynotcomplete))
78 {
79  $langs->load("errors");
80  $warnpicto=img_warning($langs->trans("WarningMandatorySetupNotComplete"));
81  print '<br><div class="warning"><a href="'.DOL_URL_ROOT.'/admin/company.php?mainmenu=home'.(empty($setupcompanynotcomplete)?'':'&action=edit').'">'.$warnpicto.' '.$langs->trans("WarningMandatorySetupNotComplete").'</a></div>';
82 
83  llxFooter();
84  exit;
85 }
86 
87 
88 print '<div class="fichecenter"><div class="fichethirdleft">';
89 
90 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
91 {
92  if (! empty($conf->holiday->enabled) && $user->rights->holiday->read)
93  {
94  $langs->load("holiday");
95  $listofsearchfields['search_holiday']=array('text'=>'TitreRequestCP');
96  }
97  if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
98  {
99  $langs->load("trips");
100  $listofsearchfields['search_deplacement']=array('text'=>'ExpenseReport');
101  }
102  if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
103  {
104  $langs->load("trips");
105  $listofsearchfields['search_expensereport']=array('text'=>'ExpenseReport');
106  }
107  if (count($listofsearchfields))
108  {
109  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
110  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
111  print '<table class="noborder nohover centpercent">';
112  $i=0;
113  foreach($listofsearchfields as $key => $value)
114  {
115  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
116  print '<tr '.$bc[false].'>';
117  print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
118  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
119  print '</tr>';
120  $i++;
121  }
122  print '</table>';
123  print '</form>';
124  print '<br>';
125  }
126 }
127 
128 
129 if (! empty($conf->holiday->enabled))
130 {
131  if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
132  {
133  $user_id = $user->id;
134 
135  print '<table class="noborder nohover" width="100%">';
136  print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Holidays").'</th></tr>';
137  print "<tr ".$bc[0].">";
138  print '<td colspan="3">';
139 
140  $out='';
141  $typeleaves=$holiday->getTypes(1,1);
142  foreach($typeleaves as $key => $val)
143  {
144  $nb_type = $holiday->getCPforUser($user->id, $val['rowid']);
145  $nb_holiday += $nb_type;
146  $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
147  }
148  print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
149  print $out;
150 
151  print '</td>';
152  print '</tr>';
153  print '</table><br>';
154  }
155  elseif (! is_numeric($conf->global->HOLIDAY_HIDE_BALANCE))
156  {
157  print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
158  }
159 }
160 
161 
162 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
163 
164 $max=10;
165 
166 $langs->load("boxes");
167 
168 
169 
170 // Latest leave requests
171 if (! empty($conf->holiday->enabled) && $user->rights->holiday->read)
172 {
173  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut, x.rowid, x.rowid as ref, x.fk_type, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.tms as dm, x.statut as status";
174  $sql.= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
175  $sql.= " WHERE u.rowid = x.fk_user";
176  $sql.= " AND x.entity = ".$conf->entity;
177  if (empty($user->rights->holiday->read_all)) $sql.=' AND x.fk_user IN ('.join(',',$childids).')';
178  //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
179  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
180  $sql.= $db->order("x.tms","DESC");
181  $sql.= $db->plimit($max, 0);
182 
183  $result = $db->query($sql);
184  if ($result)
185  {
186  $var=false;
187  $num = $db->num_rows($result);
188 
189  $holidaystatic=new Holiday($db);
190  $userstatic=new User($db);
191 
192  $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
193  $typeleaves=$holidaystatic->getTypes(1,-1);
194 
195  $i = 0;
196 
197  print '<div class="div-table-responsive">';
198  print '<table class="noborder" width="100%">';
199  print '<tr class="liste_titre">';
200  print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests",min($max,$num)).'</th>';
201  print '<th>'.$langs->trans("from").'</th>';
202  print '<th>'.$langs->trans("to").'</th>';
203  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
204  print '<th width="16">&nbsp;</th>';
205  print '</tr>';
206  if ($num)
207  {
208  while ($i < $num && $i < $max)
209  {
210  $obj = $db->fetch_object($result);
211 
212  $holidaystatic->id=$obj->rowid;
213  $holidaystatic->ref=$obj->ref;
214 
215  $userstatic->id=$obj->uid;
216  $userstatic->lastname=$obj->lastname;
217  $userstatic->firstname=$obj->firstname;
218  $userstatic->login=$obj->login;
219  $userstatic->photo=$obj->photo;
220  $userstatic->email=$obj->email;
221  $userstatic->statut=$obj->statut;
222 
223  print '<tr class="oddeven">';
224  print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
225  print '<td>'.$userstatic->getNomUrl(-1, 'leave').'</td>';
226  print '<td>'.$typeleaves[$obj->fk_type]['label'].'</td>';
227 
228  $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning';
229  $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon';
230 
231  print '<td>'.dol_print_date($obj->date_start,'day').' '.$langs->trans($listhalfday[$starthalfday]);
232  print '<td>'.dol_print_date($obj->date_end,'day').' '.$langs->trans($listhalfday[$endhalfday]);
233  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
234  print '<td>'.$holidaystatic->LibStatut($obj->status,3).'</td>';
235  print '</tr>';
236 
237  $i++;
238  }
239  }
240  else
241  {
242  print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
243  }
244  print '</table></div><br>';
245  }
246  else dol_print_error($db);
247 }
248 
249 
250 // Last expense report (old module)
251 if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
252 {
253  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut, u.photo, d.rowid, d.dated as date, d.tms as dm, d.km, d.fk_statut";
254  $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
255  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
256  $sql.= " WHERE u.rowid = d.fk_user";
257  $sql.= " AND d.entity = ".$conf->entity;
258  if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
259  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND d.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
260  if (!empty($socid)) $sql.= " AND d.fk_soc = ".$socid;
261  $sql.= $db->order("d.tms","DESC");
262  $sql.= $db->plimit($max, 0);
263 
264  $result = $db->query($sql);
265  if ($result)
266  {
267  $var=false;
268  $num = $db->num_rows($result);
269 
270  $i = 0;
271 
272  print '<div class="div-table-responsive">';
273  print '<table class="noborder" width="100%">';
274  print '<tr class="liste_titre">';
275  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
276  print '<th align="right">'.$langs->trans("FeesKilometersOrAmout").'</th>';
277  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
278  print '<th width="16">&nbsp;</th>';
279  print '</tr>';
280  if ($num)
281  {
282  $total_ttc = $totalam = $total = 0;
283 
284  $deplacementstatic=new Deplacement($db);
285  $userstatic=new User($db);
286  while ($i < $num && $i < $max)
287  {
288  $obj = $db->fetch_object($result);
289 
290  $deplacementstatic->ref=$obj->rowid;
291  $deplacementstatic->id=$obj->rowid;
292 
293  $userstatic->id=$obj->uid;
294  $userstatic->lastname=$obj->lastname;
295  $userstatic->firstname=$obj->firstname;
296  $userstatic->login=$obj->login;
297  $userstatic->email=$obj->email;
298  $userstatic->statut=$obj->statut;
299  $userstatic->photo=$obj->photo;
300 
301  print '<tr class="oddeven">';
302  print '<td class="nowraponall">'.$deplacementstatic->getNomUrl(1).'</td>';
303  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
304  print '<td align="right">'.$obj->km.'</td>';
305  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
306  print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut,3).'</td>';
307  print '</tr>';
308 
309  $i++;
310  }
311  }
312  else
313  {
314  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
315  }
316  print '</table>';
317  print '</div>';
318  }
319  else dol_print_error($db);
320 }
321 
322 // Last expense report (new module)
323 if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
324 {
325  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut, u.photo, x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
326  $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
327  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
328  $sql.= " WHERE u.rowid = x.fk_user_author";
329  $sql.= " AND x.entity = ".$conf->entity;
330  if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $sql.=' AND x.fk_user_author IN ('.join(',',$childids).')';
331  //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
332  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
333  $sql.= $db->order("x.tms","DESC");
334  $sql.= $db->plimit($max, 0);
335 
336  $result = $db->query($sql);
337  if ($result)
338  {
339  $var=false;
340  $num = $db->num_rows($result);
341 
342  $i = 0;
343 
344  print '<div class="div-table-responsive">';
345  print '<table class="noborder" width="100%">';
346  print '<tr class="liste_titre">';
347  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
348  print '<th align="right">'.$langs->trans("TotalTTC").'</th>';
349  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
350  print '<th width="16">&nbsp;</th>';
351  print '</tr>';
352  if ($num)
353  {
354  $total_ttc = $totalam = $total = 0;
355 
356  $expensereportstatic=new ExpenseReport($db);
357  $userstatic=new User($db);
358  while ($i < $num && $i < $max)
359  {
360  $obj = $db->fetch_object($result);
361 
362  $expensereportstatic->id=$obj->rowid;
363  $expensereportstatic->ref=$obj->ref;
364 
365  $userstatic->id=$obj->uid;
366  $userstatic->lastname=$obj->lastname;
367  $userstatic->firstname=$obj->firstname;
368  $userstatic->email=$obj->email;
369  $userstatic->login=$obj->login;
370  $userstatic->statut=$obj->statut;
371  $userstatic->photo=$obj->photo;
372 
373  print '<tr class="oddeven">';
374  print '<td class="nowraponall">'.$expensereportstatic->getNomUrl(1).'</td>';
375  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
376  print '<td align="right">'.price($obj->total_ttc).'</td>';
377  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
378  print '<td>'.$expensereportstatic->LibStatut($obj->status,3).'</td>';
379  print '</tr>';
380 
381  $i++;
382  }
383  }
384  else
385  {
386  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
387  }
388  print '</table>';
389  print '</div>';
390  }
391  else dol_print_error($db);
392 }
393 
394 
395 print '</div></div></div>';
396 
397 // End of page
398 llxFooter();
399 $db->close();
llxFooter()
Footer empty.
Definition: index.php:44
img_warning($titlealt='default', $moreatt='')
Show warning logo.
Class of the module paid holiday.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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
Class to manage trips and working credit notes.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
llxHeader()
Header empty.
Definition: index.php:36
Class to manage Trips and Expenses.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...