index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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@open-dsi.fr>
  6. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  7. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  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 <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/hrm/index.php
  24. * \ingroup hrm
  25. * \brief Home page for HRM area.
  26. */
  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) {
  36. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  37. }
  38. if ($conf->expensereport->enabled) {
  39. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  40. }
  41. if ($conf->recruitment->enabled) {
  42. require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentcandidature.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/recruitment/class/recruitmentjobposition.class.php';
  44. }
  45. if ($conf->holiday->enabled) {
  46. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  47. }
  48. $hookmanager = new HookManager($db);
  49. $hookmanager->initHooks('hrmindex');
  50. // Load translation files required by the page
  51. $langs->loadLangs(array('users', 'holidays', 'trips', 'boxes'));
  52. $socid = GETPOST("socid", "int");
  53. // Protection if external user
  54. if ($user->socid > 0) {
  55. accessforbidden();
  56. }
  57. if (empty($conf->global->MAIN_INFO_SOCIETE_NOM) || empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY)) {
  58. $setupcompanynotcomplete = 1;
  59. }
  60. $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
  61. /*
  62. * Actions
  63. */
  64. // Update sold
  65. if (!empty($conf->holiday->enabled) && !empty($setupcompanynotcomplete)) {
  66. $holidaystatic = new Holiday($db);
  67. $result = $holidaystatic->updateBalance();
  68. }
  69. /*
  70. * View
  71. */
  72. $childids = $user->getAllChildIds();
  73. $childids[] = $user->id;
  74. $title = $langs->trans('HRMArea');
  75. llxHeader('', $title, '');
  76. print load_fiche_titre($langs->trans("HRMArea"), '', 'hrm');
  77. if (!empty($setupcompanynotcomplete)) {
  78. $langs->load("errors");
  79. $warnpicto = img_warning($langs->trans("WarningMandatorySetupNotComplete"));
  80. 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>';
  81. llxFooter();
  82. exit;
  83. }
  84. print '<div class="fichecenter"><div class="fichethirdleft">';
  85. if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo
  86. if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) {
  87. $langs->load("holiday");
  88. $listofsearchfields['search_holiday'] = array('text'=>'TitreRequestCP');
  89. }
  90. if (!empty($conf->deplacement->enabled) && $user->rights->deplacement->lire) {
  91. $langs->load("trips");
  92. $listofsearchfields['search_deplacement'] = array('text'=>'ExpenseReport');
  93. }
  94. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) {
  95. $langs->load("trips");
  96. $listofsearchfields['search_expensereport'] = array('text'=>'ExpenseReport');
  97. }
  98. if (count($listofsearchfields)) {
  99. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  100. print '<input type="hidden" name="token" value="'.newToken().'">';
  101. print '<div class="div-table-responsive-no-min">';
  102. print '<table class="noborder nohover centpercent">';
  103. $i = 0;
  104. foreach ($listofsearchfields as $key => $value) {
  105. if ($i == 0) {
  106. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  107. }
  108. print '<tr '.$bc[false].'>';
  109. 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>';
  110. if ($i == 0) {
  111. print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  112. }
  113. print '</tr>';
  114. $i++;
  115. }
  116. print '</table>';
  117. print '</div>';
  118. print '</form>';
  119. print '<br>';
  120. }
  121. }
  122. if (!empty($conf->holiday->enabled)) {
  123. if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) {
  124. $holidaystatic = new Holiday($db);
  125. $user_id = $user->id;
  126. print '<div class="div-table-responsive-no-min">';
  127. print '<table class="noborder nohover centpercent">';
  128. print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Holidays").'</th></tr>';
  129. print '<tr class="oddeven">';
  130. print '<td colspan="3">';
  131. $out = '';
  132. $nb_holiday = 0;
  133. $typeleaves = $holidaystatic->getTypes(1, 1);
  134. foreach ($typeleaves as $key => $val) {
  135. $nb_type = $holidaystatic->getCPforUser($user->id, $val['rowid']);
  136. $nb_holiday += $nb_type;
  137. $out .= ' - '.($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']).': <strong>'.($nb_type ? price2num($nb_type) : 0).'</strong><br>';
  138. }
  139. print $langs->trans('SoldeCPUser', round($nb_holiday, 5)).'<br>';
  140. print $out;
  141. print '</td>';
  142. print '</tr>';
  143. print '</table></div><br>';
  144. } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
  145. print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
  146. }
  147. }
  148. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  149. // Latest leave requests
  150. if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) {
  151. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,";
  152. $sql .= " x.rowid, x.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";
  153. $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
  154. $sql .= " WHERE u.rowid = x.fk_user";
  155. $sql .= " AND x.entity = ".$conf->entity;
  156. if (empty($user->rights->holiday->readall)) {
  157. $sql .= ' AND x.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  158. }
  159. //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  160. //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
  161. $sql .= $db->order("x.tms", "DESC");
  162. $sql .= $db->plimit($max, 0);
  163. $result = $db->query($sql);
  164. if ($result) {
  165. $var = false;
  166. $num = $db->num_rows($result);
  167. $holidaystatic = new Holiday($db);
  168. $userstatic = new User($db);
  169. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  170. $typeleaves = $holidaystatic->getTypes(1, -1);
  171. $i = 0;
  172. print '<div class="div-table-responsive-no-min">';
  173. print '<table class="noborder centpercent">';
  174. print '<tr class="liste_titre">';
  175. print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests", min($max, $num)).'</th>';
  176. print '<th>'.$langs->trans("from").'</th>';
  177. print '<th>'.$langs->trans("to").'</th>';
  178. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  179. print '</tr>';
  180. if ($num) {
  181. while ($i < $num && $i < $max) {
  182. $obj = $db->fetch_object($result);
  183. $holidaystatic->id = $obj->rowid;
  184. $holidaystatic->ref = $obj->ref;
  185. $holidaystatic->statut = $obj->status;
  186. $userstatic->id = $obj->uid;
  187. $userstatic->lastname = $obj->lastname;
  188. $userstatic->firstname = $obj->firstname;
  189. $userstatic->login = $obj->login;
  190. $userstatic->photo = $obj->photo;
  191. $userstatic->email = $obj->email;
  192. $userstatic->statut = $obj->user_status;
  193. print '<tr class="oddeven">';
  194. print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
  195. print '<td class="tdoverflowmax125">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
  196. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($langs->trans($typeleaves[$obj->fk_type]['code'])).'">'.dol_escape_htmltag($langs->trans($typeleaves[$obj->fk_type]['code'])).'</td>';
  197. $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
  198. $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
  199. print '<td>'.dol_print_date($db->jdate($obj->date_start), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
  200. print '<td>'.dol_print_date($db->jdate($obj->date_end), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
  201. print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
  202. print '<td class="right nowrap" width="16">'.$holidaystatic->LibStatut($obj->status, 3).'</td>';
  203. print '</tr>';
  204. $i++;
  205. }
  206. } else {
  207. print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  208. }
  209. print '</table>';
  210. print '</div>';
  211. print '<br>';
  212. } else {
  213. dol_print_error($db);
  214. }
  215. }
  216. // Latest expense report
  217. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) {
  218. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,";
  219. $sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
  220. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
  221. //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  222. $sql .= " WHERE u.rowid = x.fk_user_author";
  223. $sql .= " AND x.entity = ".$conf->entity;
  224. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
  225. $sql .= ' AND x.fk_user_author IN ('.$db->sanitize(join(',', $childids)).')';
  226. }
  227. //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= " AND x.fk_soc = s. rowid AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  228. //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
  229. $sql .= $db->order("x.tms", "DESC");
  230. $sql .= $db->plimit($max, 0);
  231. $result = $db->query($sql);
  232. if ($result) {
  233. $num = $db->num_rows($result);
  234. $i = 0;
  235. print '<div class="div-table-responsive-no-min">';
  236. print '<table class="noborder centpercent">';
  237. print '<tr class="liste_titre">';
  238. print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
  239. print '<th class="right">'.$langs->trans("TotalTTC").'</th>';
  240. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  241. print '</tr>';
  242. if ($num) {
  243. $total_ttc = $totalam = $total = 0;
  244. $expensereportstatic = new ExpenseReport($db);
  245. $userstatic = new User($db);
  246. while ($i < $num && $i < $max) {
  247. $obj = $db->fetch_object($result);
  248. $expensereportstatic->id = $obj->rowid;
  249. $expensereportstatic->ref = $obj->ref;
  250. $expensereportstatic->statut = $obj->status;
  251. $expensereportstatic->status = $obj->status;
  252. $userstatic->id = $obj->uid;
  253. $userstatic->lastname = $obj->lastname;
  254. $userstatic->firstname = $obj->firstname;
  255. $userstatic->email = $obj->email;
  256. $userstatic->login = $obj->login;
  257. $userstatic->statut = $obj->user_status;
  258. $userstatic->photo = $obj->photo;
  259. print '<tr class="oddeven">';
  260. print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
  261. print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
  262. print '<td class="right amount">'.price($obj->total_ttc).'</td>';
  263. print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
  264. print '<td class="right nowraponall" width="16">'.$expensereportstatic->LibStatut($obj->status, 3).'</td>';
  265. print '</tr>';
  266. $i++;
  267. }
  268. } else {
  269. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  270. }
  271. print '</table>';
  272. print '</div>';
  273. print '<br>';
  274. } else {
  275. dol_print_error($db);
  276. }
  277. }
  278. // Last modified job position
  279. if (!empty($conf->recruitment->enabled) && $user->rights->recruitment->recruitmentjobposition->read) {
  280. $staticrecruitmentcandidature = new RecruitmentCandidature($db);
  281. $staticrecruitmentjobposition = new RecruitmentJobPosition($db);
  282. $sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status,";
  283. $sql.= " rp.rowid as jobid, rp.ref as jobref, rp.label";
  284. $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc";
  285. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as rp ON rc.fk_recruitmentjobposition = rp.rowid";
  286. if ($conf->societe->enabled && !$user->rights->societe->client->voir && !$socid) {
  287. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  288. }
  289. $sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentcandidature->element).")";
  290. if ($conf->societe->enabled && !$user->rights->societe->client->voir && !$socid) {
  291. $sql .= " AND rp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  292. }
  293. if ($socid) {
  294. $sql .= " AND rp.fk_soc = $socid";
  295. }
  296. $sql .= $db->order("rc.tms", "DESC");
  297. $sql .= $db->plimit($max, 0);
  298. $resql = $db->query($sql);
  299. if ($resql) {
  300. $num = $db->num_rows($resql);
  301. $i = 0;
  302. print '<div class="div-table-responsive-no-min">';
  303. print '<table class="noborder centpercent">';
  304. print '<tr class="liste_titre">';
  305. print '<th colspan="3">';
  306. print $langs->trans("BoxTitleLatestModifiedCandidatures", min($max, $num));
  307. print '</th>';
  308. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  309. print '</tr>';
  310. if ($num) {
  311. while ($i < $num) {
  312. $objp = $db->fetch_object($resql);
  313. $staticrecruitmentcandidature->id = $objp->rowid;
  314. $staticrecruitmentcandidature->ref = $objp->ref;
  315. $staticrecruitmentcandidature->email = $objp->email;
  316. $staticrecruitmentcandidature->status = $objp->status;
  317. $staticrecruitmentcandidature->date_creation = $objp->date_creation;
  318. $staticrecruitmentcandidature->firstname = $objp->firstname;
  319. $staticrecruitmentcandidature->lastname = $objp->lastname;
  320. $staticrecruitmentjobposition->id = $objp->jobid;
  321. $staticrecruitmentjobposition->ref = $objp->jobref;
  322. $staticrecruitmentjobposition->label = $objp->label;
  323. print '<tr class="oddeven">';
  324. print '<td class="nowraponall">'.$staticrecruitmentcandidature->getNomUrl(1, '').'</td>';
  325. print '<td class="tdoverflowmax150">'.$staticrecruitmentcandidature->getFullName($langs).'</td>';
  326. print '<td class="nowraponall">'.$staticrecruitmentjobposition->getNomUrl(1).'</td>';
  327. print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day').'</td>';
  328. print '<td class="right nowrap" width="16">';
  329. print $staticrecruitmentcandidature->getLibStatut(3);
  330. print "</td>";
  331. print '</tr>';
  332. $i++;
  333. }
  334. $db->free($resql);
  335. } else {
  336. print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  337. }
  338. print "</table>";
  339. print "</div>";
  340. print "<br>";
  341. } else {
  342. dol_print_error($db);
  343. }
  344. }
  345. print '</div></div></div>';
  346. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  347. $parameters = array('user' => $user);
  348. $reshook = $hookmanager->executeHooks('dashboardHRM', $parameters, $object); // Note that $action and $object may have been modified by hook
  349. // End of page
  350. llxFooter();
  351. $db->close();