dolibarr  7.0.0-beta
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@capnetworks.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 $langs->load('users');
40 $langs->load('holidays');
41 $langs->load('trips');
42 
43 $socid=GETPOST("socid");
44 
45 // Protection if external user
46 if ($user->societe_id > 0) accessforbidden();
47 
48 
49 
50 /*
51  * Actions
52  */
53 
54 // None
55 
56 
57 
58 /*
59  * View
60  */
61 
62 $holiday = new Holiday($db);
63 $holidaystatic=new Holiday($db);
64 
65 // Update sold
66 if (! empty($conf->holiday->enabled))
67 {
68  $result = $holiday->updateBalance();
69 }
70 
71 $childids = $user->getAllChildIds();
72 $childids[]=$user->id;
73 
74 llxHeader('', $langs->trans('HRMArea'));
75 
76 print load_fiche_titre($langs->trans("HRMArea"),'', 'title_hrm.png');
77 
78 
79 if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) $setupcompanynotcomplete=1;
80 if (! empty($setupcompanynotcomplete))
81 {
82  $langs->load("errors");
83  $warnpicto=img_warning($langs->trans("WarningMandatorySetupNotComplete"));
84  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>';
85 
86  exit;
87 }
88 
89 
90 print '<div class="fichecenter"><div class="fichethirdleft">';
91 
92 if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
93 {
94  if (! empty($conf->holiday->enabled) && $user->rights->holiday->read)
95  {
96  $langs->load("holiday");
97  $listofsearchfields['search_holiday']=array('text'=>'TitreRequestCP');
98  }
99  if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
100  {
101  $langs->load("trips");
102  $listofsearchfields['search_deplacement']=array('text'=>'ExpenseReport');
103  }
104  if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
105  {
106  $langs->load("trips");
107  $listofsearchfields['search_expensereport']=array('text'=>'ExpenseReport');
108  }
109  if (count($listofsearchfields))
110  {
111  print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
112  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
113  print '<table class="noborder nohover centpercent">';
114  $i=0;
115  foreach($listofsearchfields as $key => $value)
116  {
117  if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
118  print '<tr '.$bc[false].'>';
119  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>';
120  if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
121  print '</tr>';
122  $i++;
123  }
124  print '</table>';
125  print '</form>';
126  print '<br>';
127  }
128 }
129 
130 
131 if (! empty($conf->holiday->enabled))
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 
156 
157 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
158 
159 $max=10;
160 
161 $langs->load("boxes");
162 
163 
164 
165 // Latest leave requests
166 if (! empty($conf->holiday->enabled) && $user->rights->holiday->read)
167 {
168  $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";
169  $sql.= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
170  $sql.= " WHERE u.rowid = x.fk_user";
171  $sql.= " AND x.entity = ".$conf->entity;
172  if (empty($user->rights->holiday->read_all)) $sql.=' AND x.fk_user IN ('.join(',',$childids).')';
173  //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;
174  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
175  $sql.= $db->order("x.tms","DESC");
176  $sql.= $db->plimit($max, 0);
177 
178  $result = $db->query($sql);
179  if ($result)
180  {
181  $var=false;
182  $num = $db->num_rows($result);
183 
184  $holidaystatic=new Holiday($db);
185  $userstatic=new User($db);
186 
187  $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
188  $typeleaves=$holidaystatic->getTypes(1,-1);
189 
190  $i = 0;
191 
192  print '<div class="div-table-responsive">';
193  print '<table class="noborder" width="100%">';
194  print '<tr class="liste_titre">';
195  print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests",min($max,$num)).'</th>';
196  print '<th>'.$langs->trans("from").'</th>';
197  print '<th>'.$langs->trans("to").'</th>';
198  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
199  print '<th width="16">&nbsp;</th>';
200  print '</tr>';
201  if ($num)
202  {
203  while ($i < $num && $i < $max)
204  {
205  $obj = $db->fetch_object($result);
206 
207  $holidaystatic->id=$obj->rowid;
208  $holidaystatic->ref=$obj->ref;
209 
210  $userstatic->id=$obj->uid;
211  $userstatic->lastname=$obj->lastname;
212  $userstatic->firstname=$obj->firstname;
213  $userstatic->login=$obj->login;
214  $userstatic->photo=$obj->photo;
215  $userstatic->email=$obj->email;
216  $userstatic->statut=$obj->statut;
217 
218  print '<tr class="oddeven">';
219  print '<td>'.$holidaystatic->getNomUrl(1).'</td>';
220  print '<td>'.$userstatic->getNomUrl(-1, 'leave').'</td>';
221  print '<td>'.$typeleaves[$obj->fk_type]['label'].'</td>';
222 
223  $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning';
224  $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon';
225 
226  print '<td>'.dol_print_date($obj->date_start,'day').' '.$langs->trans($listhalfday[$starthalfday]);
227  print '<td>'.dol_print_date($obj->date_end,'day').' '.$langs->trans($listhalfday[$endhalfday]);
228  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
229  print '<td>'.$holidaystatic->LibStatut($obj->status,3).'</td>';
230  print '</tr>';
231 
232  $i++;
233  }
234 
235  }
236  else
237  {
238  print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
239  }
240  print '</table></div><br>';
241  }
242  else dol_print_error($db);
243 }
244 
245 
246 // Last expense report (old module)
247 if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
248 {
249  $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";
250  $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
251  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
252  $sql.= " WHERE u.rowid = d.fk_user";
253  $sql.= " AND d.entity = ".$conf->entity;
254  if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
255  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;
256  if (!empty($socid)) $sql.= " AND d.fk_soc = ".$socid;
257  $sql.= $db->order("d.tms","DESC");
258  $sql.= $db->plimit($max, 0);
259 
260  $result = $db->query($sql);
261  if ($result)
262  {
263  $var=false;
264  $num = $db->num_rows($result);
265 
266  $i = 0;
267 
268  print '<table class="noborder" width="100%">';
269  print '<tr class="liste_titre">';
270  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
271  print '<th align="right">'.$langs->trans("FeesKilometersOrAmout").'</th>';
272  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
273  print '<th width="16">&nbsp;</th>';
274  print '</tr>';
275  if ($num)
276  {
277  $total_ttc = $totalam = $total = 0;
278 
279  $deplacementstatic=new Deplacement($db);
280  $userstatic=new User($db);
281  while ($i < $num && $i < $max)
282  {
283  $obj = $db->fetch_object($result);
284 
285  $deplacementstatic->ref=$obj->rowid;
286  $deplacementstatic->id=$obj->rowid;
287 
288  $userstatic->id=$obj->uid;
289  $userstatic->lastname=$obj->lastname;
290  $userstatic->firstname=$obj->firstname;
291  $userstatic->login=$obj->login;
292  $userstatic->email=$obj->email;
293  $userstatic->statut=$obj->statut;
294  $userstatic->photo=$obj->photo;
295 
296  print '<tr class="oddeven">';
297  print '<td>'.$deplacementstatic->getNomUrl(1).'</td>';
298  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
299  print '<td align="right">'.$obj->km.'</td>';
300  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
301  print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut,3).'</td>';
302  print '</tr>';
303 
304  $i++;
305  }
306 
307  }
308  else
309  {
310  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
311  }
312  print '</table><br>';
313  }
314  else dol_print_error($db);
315 }
316 
317 // Last expense report (new module)
318 if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
319 {
320  $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";
321  $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
322  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
323  $sql.= " WHERE u.rowid = x.fk_user_author";
324  $sql.= " AND x.entity = ".$conf->entity;
325  if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $sql.=' AND x.fk_user_author IN ('.join(',',$childids).')';
326  //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;
327  //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
328  $sql.= $db->order("x.tms","DESC");
329  $sql.= $db->plimit($max, 0);
330 
331  $result = $db->query($sql);
332  if ($result)
333  {
334  $var=false;
335  $num = $db->num_rows($result);
336 
337  $i = 0;
338 
339  print '<table class="noborder" width="100%">';
340  print '<tr class="liste_titre">';
341  print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
342  print '<th align="right">'.$langs->trans("TotalTTC").'</th>';
343  print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
344  print '<th width="16">&nbsp;</th>';
345  print '</tr>';
346  if ($num)
347  {
348  $total_ttc = $totalam = $total = 0;
349 
350  $expensereportstatic=new ExpenseReport($db);
351  $userstatic=new User($db);
352  while ($i < $num && $i < $max)
353  {
354  $obj = $db->fetch_object($result);
355 
356  $expensereportstatic->id=$obj->rowid;
357  $expensereportstatic->ref=$obj->ref;
358 
359  $userstatic->id=$obj->uid;
360  $userstatic->lastname=$obj->lastname;
361  $userstatic->firstname=$obj->firstname;
362  $userstatic->email=$obj->email;
363  $userstatic->login=$obj->login;
364  $userstatic->statut=$obj->statut;
365  $userstatic->photo=$obj->photo;
366 
367  print '<tr class="oddeven">';
368  print '<td>'.$expensereportstatic->getNomUrl(1).'</td>';
369  print '<td>'.$userstatic->getNomUrl(-1).'</td>';
370  print '<td align="right">'.price($obj->total_ttc).'</td>';
371  print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
372  print '<td>'.$expensereportstatic->LibStatut($obj->status,3).'</td>';
373  print '</tr>';
374 
375  $i++;
376  }
377 
378  }
379  else
380  {
381  print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
382  }
383  print '</table>';
384  }
385  else dol_print_error($db);
386 }
387 
388 
389 print '</div></div></div>';
390 
391 
392 
393 llxFooter();
394 
395 $db->close();
llxFooter()
Footer empty.
Definition: index.php:43
Class of the module paid holiday.
Class to manage trips and working credit notes.
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
llxHeader()
Header empty.
Definition: index.php:37
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Class to manage Trips and Expenses.
print
Draft customers invoices.
Definition: index.php:91
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...