index.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 (!empty($conf->deplacement->enabled)) {
  36. require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  37. }
  38. if (!empty($conf->expensereport->enabled)) {
  39. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  40. }
  41. if (!empty($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 (!empty($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', 'holiday', '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&token='.newToken()).'">'.$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>';
  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. $balancetoshow = $langs->trans('SoldeCPUser', '{s1}');
  140. print '<div class="valignmiddle div-balanceofleave">'.str_replace('{s1}', img_picto('', 'holiday', 'class="paddingleft pictofixedwidth"').'<span class="balanceofleave valignmiddle'.($nb_holiday > 0 ? ' amountpaymentcomplete' : ($nb_holiday < 0 ? ' amountremaintopay' : ' amountpaymentneutral')).'">'.round($nb_holiday, 5).'</span>', $balancetoshow).'</div>';
  141. print '<span class="opacitymedium">'.$out.'</span>';
  142. print '</td>';
  143. print '</tr>';
  144. print '</table></div><br>';
  145. } elseif (!is_numeric($conf->global->HOLIDAY_HIDE_BALANCE)) {
  146. print $langs->trans($conf->global->HOLIDAY_HIDE_BALANCE).'<br>';
  147. }
  148. }
  149. print '</div><div class="fichetwothirdright">';
  150. // Latest leave requests
  151. if (!empty($conf->holiday->enabled) && $user->rights->holiday->read) {
  152. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.photo, u.statut as user_status,";
  153. $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";
  154. $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
  155. $sql .= " WHERE u.rowid = x.fk_user";
  156. $sql .= " AND x.entity = ".$conf->entity;
  157. if (empty($user->rights->holiday->readall)) {
  158. $sql .= ' AND x.fk_user IN ('.$db->sanitize(join(',', $childids)).')';
  159. }
  160. //if (empty($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);
  161. //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
  162. $sql .= $db->order("x.tms", "DESC");
  163. $sql .= $db->plimit($max, 0);
  164. $result = $db->query($sql);
  165. if ($result) {
  166. $var = false;
  167. $num = $db->num_rows($result);
  168. $holidaystatic = new Holiday($db);
  169. $userstatic = new User($db);
  170. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  171. $typeleaves = $holidaystatic->getTypes(1, -1);
  172. $i = 0;
  173. print '<div class="div-table-responsive-no-min">';
  174. print '<table class="noborder centpercent">';
  175. print '<tr class="liste_titre">';
  176. print '<th colspan="3">'.$langs->trans("BoxTitleLastLeaveRequests", min($max, $num)).'</th>';
  177. print '<th>'.$langs->trans("from").'</th>';
  178. print '<th>'.$langs->trans("to").'</th>';
  179. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/holiday/list.php?sortfield=cp.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  180. print '</tr>';
  181. if ($num) {
  182. while ($i < $num && $i < $max) {
  183. $obj = $db->fetch_object($result);
  184. $holidaystatic->id = $obj->rowid;
  185. $holidaystatic->ref = $obj->ref;
  186. $holidaystatic->statut = $obj->status;
  187. $holidaystatic->date_debut = $db->jdate($obj->date_start);
  188. $userstatic->id = $obj->uid;
  189. $userstatic->lastname = $obj->lastname;
  190. $userstatic->firstname = $obj->firstname;
  191. $userstatic->login = $obj->login;
  192. $userstatic->photo = $obj->photo;
  193. $userstatic->email = $obj->email;
  194. $userstatic->statut = $obj->user_status;
  195. print '<tr class="oddeven">';
  196. print '<td class="nowraponall">'.$holidaystatic->getNomUrl(1).'</td>';
  197. print '<td class="tdoverflowmax100">'.$userstatic->getNomUrl(-1, 'leave').'</td>';
  198. $leavecode = empty($typeleaves[$obj->fk_type]) ? 'Undefined' : $typeleaves[$obj->fk_type]['code'];
  199. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($langs->trans($leavecode)).'">'.dol_escape_htmltag($langs->trans($leavecode)).'</td>';
  200. $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
  201. $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
  202. print '<td>'.dol_print_date($db->jdate($obj->date_start), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$starthalfday]).'</span>';
  203. print '<td>'.dol_print_date($db->jdate($obj->date_end), 'day').' <span class="opacitymedium">'.$langs->trans($listhalfday[$endhalfday]).'</span>';
  204. print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
  205. print '<td class="right nowrap" width="16">'.$holidaystatic->LibStatut($obj->status, 3, $holidaystatic->date_debut).'</td>';
  206. print '</tr>';
  207. $i++;
  208. }
  209. } else {
  210. print '<tr class="oddeven"><td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  211. }
  212. print '</table>';
  213. print '</div>';
  214. print '<br>';
  215. } else {
  216. dol_print_error($db);
  217. }
  218. }
  219. // Latest expense report
  220. if (!empty($conf->expensereport->enabled) && $user->rights->expensereport->lire) {
  221. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.login, u.email, u.statut as user_status, u.photo,";
  222. $sql .= " x.rowid, x.ref, x.date_debut as date, x.tms as dm, x.total_ttc, x.fk_statut as status";
  223. $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as x, ".MAIN_DB_PREFIX."user as u";
  224. //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  225. $sql .= " WHERE u.rowid = x.fk_user_author";
  226. $sql .= " AND x.entity = ".$conf->entity;
  227. if (empty($user->rights->expensereport->readall) && empty($user->rights->expensereport->lire_tous)) {
  228. $sql .= ' AND x.fk_user_author IN ('.$db->sanitize(join(',', $childids)).')';
  229. }
  230. //if (empty($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);
  231. //if (!empty($socid)) $sql.= " AND x.fk_soc = ".((int) $socid);
  232. $sql .= $db->order("x.tms", "DESC");
  233. $sql .= $db->plimit($max, 0);
  234. $result = $db->query($sql);
  235. if ($result) {
  236. $num = $db->num_rows($result);
  237. $i = 0;
  238. print '<div class="div-table-responsive-no-min">';
  239. print '<table class="noborder centpercent">';
  240. print '<tr class="liste_titre">';
  241. print '<th colspan="2">'.$langs->trans("BoxTitleLastModifiedExpenses", min($max, $num)).'</th>';
  242. print '<th class="right">'.$langs->trans("TotalTTC").'</th>';
  243. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/expensereport/list.php?sortfield=d.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  244. print '</tr>';
  245. if ($num) {
  246. $total_ttc = $totalam = $total = 0;
  247. $expensereportstatic = new ExpenseReport($db);
  248. $userstatic = new User($db);
  249. while ($i < $num && $i < $max) {
  250. $obj = $db->fetch_object($result);
  251. $expensereportstatic->id = $obj->rowid;
  252. $expensereportstatic->ref = $obj->ref;
  253. $expensereportstatic->statut = $obj->status;
  254. $expensereportstatic->status = $obj->status;
  255. $userstatic->id = $obj->uid;
  256. $userstatic->lastname = $obj->lastname;
  257. $userstatic->firstname = $obj->firstname;
  258. $userstatic->email = $obj->email;
  259. $userstatic->login = $obj->login;
  260. $userstatic->statut = $obj->user_status;
  261. $userstatic->photo = $obj->photo;
  262. print '<tr class="oddeven">';
  263. print '<td class="tdoverflowmax200">'.$expensereportstatic->getNomUrl(1).'</td>';
  264. print '<td class="tdoverflowmax150">'.$userstatic->getNomUrl(-1).'</td>';
  265. print '<td class="right amount">'.price($obj->total_ttc).'</td>';
  266. print '<td class="right">'.dol_print_date($db->jdate($obj->dm), 'day').'</td>';
  267. print '<td class="right nowraponall" width="16">'.$expensereportstatic->LibStatut($obj->status, 3).'</td>';
  268. print '</tr>';
  269. $i++;
  270. }
  271. } else {
  272. print '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  273. }
  274. print '</table>';
  275. print '</div>';
  276. print '<br>';
  277. } else {
  278. dol_print_error($db);
  279. }
  280. }
  281. // Last modified job position
  282. if (!empty($conf->recruitment->enabled) && $user->rights->recruitment->recruitmentjobposition->read) {
  283. $staticrecruitmentcandidature = new RecruitmentCandidature($db);
  284. $staticrecruitmentjobposition = new RecruitmentJobPosition($db);
  285. $sql = "SELECT rc.rowid, rc.ref, rc.email, rc.lastname, rc.firstname, rc.date_creation, rc.tms, rc.status,";
  286. $sql.= " rp.rowid as jobid, rp.ref as jobref, rp.label";
  287. $sql .= " FROM ".MAIN_DB_PREFIX."recruitment_recruitmentcandidature as rc";
  288. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."recruitment_recruitmentjobposition as rp ON rc.fk_recruitmentjobposition = rp.rowid";
  289. if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$socid) {
  290. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  291. }
  292. $sql .= " WHERE rc.entity IN (".getEntity($staticrecruitmentcandidature->element).")";
  293. if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$socid) {
  294. $sql .= " AND rp.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  295. }
  296. if ($socid) {
  297. $sql .= " AND rp.fk_soc = $socid";
  298. }
  299. $sql .= $db->order("rc.tms", "DESC");
  300. $sql .= $db->plimit($max, 0);
  301. $resql = $db->query($sql);
  302. if ($resql) {
  303. $num = $db->num_rows($resql);
  304. $i = 0;
  305. print '<div class="div-table-responsive-no-min">';
  306. print '<table class="noborder centpercent">';
  307. print '<tr class="liste_titre">';
  308. print '<th colspan="3">';
  309. print $langs->trans("BoxTitleLatestModifiedCandidatures", min($max, $num));
  310. print '</th>';
  311. print '<th class="right" colspan="2"><a href="'.DOL_URL_ROOT.'/recruitment/recruitmentcandidature_list.php?sortfield=t.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  312. print '</tr>';
  313. if ($num) {
  314. while ($i < $num) {
  315. $objp = $db->fetch_object($resql);
  316. $staticrecruitmentcandidature->id = $objp->rowid;
  317. $staticrecruitmentcandidature->ref = $objp->ref;
  318. $staticrecruitmentcandidature->email = $objp->email;
  319. $staticrecruitmentcandidature->status = $objp->status;
  320. $staticrecruitmentcandidature->date_creation = $objp->date_creation;
  321. $staticrecruitmentcandidature->firstname = $objp->firstname;
  322. $staticrecruitmentcandidature->lastname = $objp->lastname;
  323. $staticrecruitmentjobposition->id = $objp->jobid;
  324. $staticrecruitmentjobposition->ref = $objp->jobref;
  325. $staticrecruitmentjobposition->label = $objp->label;
  326. print '<tr class="oddeven">';
  327. print '<td class="nowraponall">'.$staticrecruitmentcandidature->getNomUrl(1, '').'</td>';
  328. print '<td class="tdoverflowmax150">'.$staticrecruitmentcandidature->getFullName($langs).'</td>';
  329. print '<td class="nowraponall">'.$staticrecruitmentjobposition->getNomUrl(1).'</td>';
  330. print '<td class="right nowrap">'.dol_print_date($db->jdate($objp->tms), 'day').'</td>';
  331. print '<td class="right nowrap" width="16">';
  332. print $staticrecruitmentcandidature->getLibStatut(3);
  333. print "</td>";
  334. print '</tr>';
  335. $i++;
  336. }
  337. $db->free($resql);
  338. } else {
  339. print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
  340. }
  341. print "</table>";
  342. print "</div>";
  343. print "<br>";
  344. } else {
  345. dol_print_error($db);
  346. }
  347. }
  348. print '</div></div>';
  349. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  350. $parameters = array('user' => $user);
  351. $reshook = $hookmanager->executeHooks('dashboardHRM', $parameters, $object); // Note that $action and $object may have been modified by hook
  352. // End of page
  353. llxFooter();
  354. $db->close();