index.php 17 KB

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