index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. /**
  21. * \file htdocs/hrm/index.php
  22. * \ingroup hrm
  23. * \brief Home page for HRM area.
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  33. if ($conf->deplacement->enabled) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  34. if ($conf->expensereport->enabled) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  36. // Load translation files required by the page
  37. $langs->loadLangs(array('users', 'holidays', 'trips'));
  38. $socid=GETPOST("socid","int");
  39. // Protection if external user
  40. if ($user->societe_id > 0) accessforbidden();
  41. if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) $setupcompanynotcomplete=1;
  42. $holiday = new Holiday($db);
  43. $holidaystatic=new Holiday($db);
  44. /*
  45. * Actions
  46. */
  47. // Update sold
  48. if (! empty($conf->holiday->enabled) && ! empty($setupcompanynotcomplete))
  49. {
  50. $result = $holiday->updateBalance();
  51. }
  52. /*
  53. * View
  54. */
  55. $childids = $user->getAllChildIds();
  56. $childids[]=$user->id;
  57. llxHeader('', $langs->trans('HRMArea'));
  58. print load_fiche_titre($langs->trans("HRMArea"),'', 'title_hrm.png');
  59. if (! empty($setupcompanynotcomplete))
  60. {
  61. $langs->load("errors");
  62. $warnpicto=img_warning($langs->trans("WarningMandatorySetupNotComplete"));
  63. 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>';
  64. llxFooter();
  65. exit;
  66. }
  67. print '<div class="fichecenter"><div class="fichethirdleft">';
  68. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  69. {
  70. if (! empty($conf->holiday->enabled) && $user->rights->holiday->read)
  71. {
  72. $langs->load("holiday");
  73. $listofsearchfields['search_holiday']=array('text'=>'TitreRequestCP');
  74. }
  75. if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
  76. {
  77. $langs->load("trips");
  78. $listofsearchfields['search_deplacement']=array('text'=>'ExpenseReport');
  79. }
  80. if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
  81. {
  82. $langs->load("trips");
  83. $listofsearchfields['search_expensereport']=array('text'=>'ExpenseReport');
  84. }
  85. if (count($listofsearchfields))
  86. {
  87. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  88. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  89. print '<table class="noborder nohover centpercent">';
  90. $i=0;
  91. foreach($listofsearchfields as $key => $value)
  92. {
  93. if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  94. print '<tr '.$bc[false].'>';
  95. 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>';
  96. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  97. print '</tr>';
  98. $i++;
  99. }
  100. print '</table>';
  101. print '</form>';
  102. print '<br>';
  103. }
  104. }
  105. if (! empty($conf->holiday->enabled))
  106. {
  107. if (empty($conf->global->HOLIDAY_HIDE_BALANCE))
  108. {
  109. $user_id = $user->id;
  110. print '<table class="noborder nohover" width="100%">';
  111. print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Holidays").'</th></tr>';
  112. print "<tr ".$bc[0].">";
  113. print '<td colspan="3">';
  114. $out='';
  115. $typeleaves=$holiday->getTypes(1,1);
  116. foreach($typeleaves as $key => $val)
  117. {
  118. $nb_type = $holiday->getCPforUser($user->id, $val['rowid']);
  119. $nb_holiday += $nb_type;
  120. $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
  121. }
  122. print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
  123. print $out;
  124. print '</td>';
  125. print '</tr>';
  126. print '</table><br>';
  127. }
  128. elseif (! is_numeric($conf->global->HOLIDAY_HIDE_BALANCE))
  129. {
  130. print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
  131. }
  132. }
  133. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  134. $max=10;
  135. $langs->load("boxes");
  136. // Latest leave requests
  137. if (! empty($conf->holiday->enabled) && $user->rights->holiday->read)
  138. {
  139. $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";
  140. $sql.= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
  141. $sql.= " WHERE u.rowid = x.fk_user";
  142. $sql.= " AND x.entity = ".$conf->entity;
  143. if (empty($user->rights->holiday->read_all)) $sql.=' AND x.fk_user IN ('.join(',',$childids).')';
  144. //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;
  145. //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
  146. $sql.= $db->order("x.tms","DESC");
  147. $sql.= $db->plimit($max, 0);
  148. $result = $db->query($sql);
  149. if ($result)
  150. {
  151. $var=false;
  152. $num = $db->num_rows($result);
  153. $holidaystatic=new Holiday($db);
  154. $userstatic=new User($db);
  155. $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
  156. $typeleaves=$holidaystatic->getTypes(1,-1);
  157. $i = 0;
  158. print '<div class="div-table-responsive">';
  159. print '<table class="noborder" width="100%">';
  160. print '<tr class="liste_titre">';
  161. print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests",min($max,$num)).'</th>';
  162. print '<th>'.$langs->trans("from").'</th>';
  163. print '<th>'.$langs->trans("to").'</th>';
  164. print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
  165. print '<th width="16">&nbsp;</th>';
  166. print '</tr>';
  167. if ($num)
  168. {
  169. while ($i < $num && $i < $max)
  170. {
  171. $obj = $db->fetch_object($result);
  172. $holidaystatic->id=$obj->rowid;
  173. $holidaystatic->ref=$obj->ref;
  174. $userstatic->id=$obj->uid;
  175. $userstatic->lastname=$obj->lastname;
  176. $userstatic->firstname=$obj->firstname;
  177. $userstatic->login=$obj->login;
  178. $userstatic->photo=$obj->photo;
  179. $userstatic->email=$obj->email;
  180. $userstatic->statut=$obj->statut;
  181. print '<tr class="oddeven">';
  182. print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
  183. print '<td>'.$userstatic->getNomUrl(-1, 'leave').'</td>';
  184. print '<td>'.$typeleaves[$obj->fk_type]['label'].'</td>';
  185. $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning';
  186. $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon';
  187. print '<td>'.dol_print_date($obj->date_start,'day').' '.$langs->trans($listhalfday[$starthalfday]);
  188. print '<td>'.dol_print_date($obj->date_end,'day').' '.$langs->trans($listhalfday[$endhalfday]);
  189. print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
  190. print '<td>'.$holidaystatic->LibStatut($obj->status,3).'</td>';
  191. print '</tr>';
  192. $i++;
  193. }
  194. }
  195. else
  196. {
  197. print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  198. }
  199. print '</table></div><br>';
  200. }
  201. else dol_print_error($db);
  202. }
  203. // Last expense report (old module)
  204. if (! empty($conf->deplacement->enabled) && $user->rights->deplacement->lire)
  205. {
  206. $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";
  207. $sql.= " FROM ".MAIN_DB_PREFIX."deplacement as d, ".MAIN_DB_PREFIX."user as u";
  208. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  209. $sql.= " WHERE u.rowid = d.fk_user";
  210. $sql.= " AND d.entity = ".$conf->entity;
  211. if (empty($user->rights->deplacement->readall) && empty($user->rights->deplacement->lire_tous)) $sql.=' AND d.fk_user IN ('.join(',',$childids).')';
  212. 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;
  213. if (!empty($socid)) $sql.= " AND d.fk_soc = ".$socid;
  214. $sql.= $db->order("d.tms","DESC");
  215. $sql.= $db->plimit($max, 0);
  216. $result = $db->query($sql);
  217. if ($result)
  218. {
  219. $var=false;
  220. $num = $db->num_rows($result);
  221. $i = 0;
  222. print '<div class="div-table-responsive">';
  223. print '<table class="noborder" width="100%">';
  224. print '<tr class="liste_titre">';
  225. print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
  226. print '<th align="right">'.$langs->trans("FeesKilometersOrAmout").'</th>';
  227. print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
  228. print '<th width="16">&nbsp;</th>';
  229. print '</tr>';
  230. if ($num)
  231. {
  232. $total_ttc = $totalam = $total = 0;
  233. $deplacementstatic=new Deplacement($db);
  234. $userstatic=new User($db);
  235. while ($i < $num && $i < $max)
  236. {
  237. $obj = $db->fetch_object($result);
  238. $deplacementstatic->ref=$obj->rowid;
  239. $deplacementstatic->id=$obj->rowid;
  240. $userstatic->id=$obj->uid;
  241. $userstatic->lastname=$obj->lastname;
  242. $userstatic->firstname=$obj->firstname;
  243. $userstatic->login=$obj->login;
  244. $userstatic->email=$obj->email;
  245. $userstatic->statut=$obj->statut;
  246. $userstatic->photo=$obj->photo;
  247. print '<tr class="oddeven">';
  248. print '<td class="nowraponall">'.$deplacementstatic->getNomUrl(1).'</td>';
  249. print '<td>'.$userstatic->getNomUrl(-1).'</td>';
  250. print '<td align="right">'.$obj->km.'</td>';
  251. print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
  252. print '<td>'.$deplacementstatic->LibStatut($obj->fk_statut,3).'</td>';
  253. print '</tr>';
  254. $i++;
  255. }
  256. }
  257. else
  258. {
  259. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  260. }
  261. print '</table>';
  262. print '</div>';
  263. }
  264. else dol_print_error($db);
  265. }
  266. // Last expense report (new module)
  267. if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->lire)
  268. {
  269. $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";
  270. $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
  271. if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  272. $sql.= " WHERE u.rowid = x.fk_user_author";
  273. $sql.= " AND x.entity = ".$conf->entity;
  274. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) $sql.=' AND x.fk_user_author IN ('.join(',',$childids).')';
  275. //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;
  276. //if (!empty($socid)) $sql.= " AND x.fk_soc = ".$socid;
  277. $sql.= $db->order("x.tms","DESC");
  278. $sql.= $db->plimit($max, 0);
  279. $result = $db->query($sql);
  280. if ($result)
  281. {
  282. $var=false;
  283. $num = $db->num_rows($result);
  284. $i = 0;
  285. print '<div class="div-table-responsive">';
  286. print '<table class="noborder" width="100%">';
  287. print '<tr class="liste_titre">';
  288. print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses",min($max,$num)).'</th>';
  289. print '<th align="right">'.$langs->trans("TotalTTC").'</th>';
  290. print '<th align="right">'.$langs->trans("DateModificationShort").'</th>';
  291. print '<th width="16">&nbsp;</th>';
  292. print '</tr>';
  293. if ($num)
  294. {
  295. $total_ttc = $totalam = $total = 0;
  296. $expensereportstatic=new ExpenseReport($db);
  297. $userstatic=new User($db);
  298. while ($i < $num && $i < $max)
  299. {
  300. $obj = $db->fetch_object($result);
  301. $expensereportstatic->id=$obj->rowid;
  302. $expensereportstatic->ref=$obj->ref;
  303. $userstatic->id=$obj->uid;
  304. $userstatic->lastname=$obj->lastname;
  305. $userstatic->firstname=$obj->firstname;
  306. $userstatic->email=$obj->email;
  307. $userstatic->login=$obj->login;
  308. $userstatic->statut=$obj->statut;
  309. $userstatic->photo=$obj->photo;
  310. print '<tr class="oddeven">';
  311. print '<td class="nowraponall">'.$expensereportstatic->getNomUrl(1).'</td>';
  312. print '<td>'.$userstatic->getNomUrl(-1).'</td>';
  313. print '<td align="right">'.price($obj->total_ttc).'</td>';
  314. print '<td align="right">'.dol_print_date($db->jdate($obj->dm),'day').'</td>';
  315. print '<td>'.$expensereportstatic->LibStatut($obj->status,3).'</td>';
  316. print '</tr>';
  317. $i++;
  318. }
  319. }
  320. else
  321. {
  322. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  323. }
  324. print '</table>';
  325. print '</div>';
  326. }
  327. else dol_print_error($db);
  328. }
  329. print '</div></div></div>';
  330. // End of page
  331. llxFooter();
  332. $db->close();