month_report.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <?php
  2. /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2011 François Legastelois <flegastelois@teclib.com>
  4. * Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
  5. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file month_report.php
  22. * \ingroup holiday
  23. * \brief Monthly report of leave requests.
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("holiday"));
  33. // Security check
  34. $socid = 0;
  35. if ($user->socid > 0) { // Protection if external user
  36. //$socid = $user->socid;
  37. accessforbidden();
  38. }
  39. $result = restrictedArea($user, 'holiday', $id, '');
  40. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
  41. $massaction = GETPOST('massaction', 'alpha');
  42. $contextpage = GETPOST('contextpage', 'aZ');
  43. $optioncss = GETPOST('optioncss', 'aZ');
  44. $search_ref = GETPOST('search_ref', 'alphanohtml');
  45. $search_employee = GETPOST('search_employee', 'int');
  46. $search_type = GETPOST('search_type', 'int');
  47. $search_description = GETPOST('search_description', 'alphanohtml');
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. if (!$sortfield) {
  52. $sortfield = "cp.rowid";
  53. }
  54. if (!$sortorder) {
  55. $sortorder = "ASC";
  56. }
  57. $hookmanager->initHooks(array('leavemovementlist'));
  58. $arrayfields = array();
  59. $arrayofmassactions = array();
  60. /*
  61. * Actions
  62. */
  63. if (GETPOST('cancel', 'alpha')) {
  64. $action = 'list'; $massaction = '';
  65. }
  66. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  67. $massaction = '';
  68. }
  69. $parameters = array();
  70. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  71. if ($reshook < 0) {
  72. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  73. }
  74. if (empty($reshook)) {
  75. // Selection of new fields
  76. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  77. // Purge search criteria
  78. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  79. $search_ref = '';
  80. $search_employee = '';
  81. $search_type = '';
  82. $search_description = '';
  83. $toselect = '';
  84. $search_array_options = array();
  85. }
  86. if (GETPOST('button_removefilter_x', 'alpha')
  87. || GETPOST('button_removefilter.x', 'alpha')
  88. || GETPOST('button_removefilter', 'alpha')
  89. || GETPOST('button_search_x', 'alpha')
  90. || GETPOST('button_search.x', 'alpha')
  91. || GETPOST('button_search', 'alpha')) {
  92. $massaction = '';
  93. }
  94. }
  95. $arrayfields = array(
  96. 'cp.ref'=>array('label'=>$langs->trans('Ref'), 'checked'=>1),
  97. 'cp.fk_user'=>array('label'=>$langs->trans('Employee'), 'checked'=>1),
  98. 'ct.label'=>array('label'=>$langs->trans('Type'), 'checked'=>1),
  99. 'cp.date_debut'=>array('label'=>$langs->trans('DateDebCP'), 'checked'=>1),
  100. 'cp.date_fin'=>array('label'=>$langs->trans('DateFinCP'), 'checked'=>1),
  101. 'used_days'=>array('label'=>$langs->trans('NbUseDaysCPShort'), 'checked'=>1),
  102. 'date_start_month'=>array('label'=>$langs->trans('DateStartInMonth'), 'checked'=>1),
  103. 'date_end_month'=>array('label'=>$langs->trans('DateEndInMonth'), 'checked'=>1),
  104. 'used_days_month'=>array('label'=>$langs->trans('NbUseDaysCPShortInMonth'), 'checked'=>1),
  105. 'cp.description'=>array('label'=>$langs->trans('DescCP'), 'checked'=>1),
  106. );
  107. /*
  108. * View
  109. */
  110. $form = new Form($db);
  111. $formother = new FormOther($db);
  112. $holidaystatic = new Holiday($db);
  113. $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
  114. $title = $langs->trans('CPTitreMenu');
  115. llxHeader('', $title);
  116. $search_month = GETPOST("remonth", 'int') ?GETPOST("remonth", 'int') : date("m", time());
  117. $search_year = GETPOST("reyear", 'int') ?GETPOST("reyear", 'int') : date("Y", time());
  118. $year_month = sprintf("%04d", $search_year).'-'.sprintf("%02d", $search_month);
  119. $sql = "SELECT cp.rowid, cp.ref, cp.fk_user, cp.date_debut, cp.date_fin, ct.label, cp.description, cp.halfday";
  120. $sql .= " FROM ".MAIN_DB_PREFIX."holiday cp";
  121. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON cp.fk_user = u.rowid";
  122. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_holiday_types ct ON cp.fk_type = ct.rowid";
  123. $sql .= " WHERE cp.rowid > 0";
  124. $sql .= " AND cp.statut = ".Holiday::STATUS_APPROVED;
  125. $sql .= " AND (";
  126. $sql .= " (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')";
  127. $sql .= " OR"; // For leave over several months
  128. $sql .= " (date_format(cp.date_debut, '%Y-%m') < '".$db->escape($year_month)."' AND date_format(cp.date_fin, '%Y-%m') > '".$db->escape($year_month)."') ";
  129. $sql .= " )";
  130. if (!empty($search_ref)) {
  131. $sql .= natural_search('cp.ref', $search_ref);
  132. }
  133. if (!empty($search_employee) && $search_employee > 0) {
  134. $sql .= " AND cp.fk_user = ".((int) $search_employee);
  135. }
  136. if (!empty($search_type) && $search_type != '-1') {
  137. $sql .= ' AND cp.fk_type IN ('.$db->sanitize($search_type).')';
  138. }
  139. if (!empty($search_description)) {
  140. $sql .= natural_search('cp.description', $search_description);
  141. }
  142. $sql .= $db->order($sortfield, $sortorder);
  143. $resql = $db->query($sql);
  144. if (empty($resql)) {
  145. dol_print_error($db);
  146. exit;
  147. }
  148. $num = $db->num_rows($resql);
  149. $param = '';
  150. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  151. $param .= '&contextpage='.urlencode($contextpage);
  152. }
  153. if ($limit > 0 && $limit != $conf->liste_limit) {
  154. $param .= '&limit='.urlencode($limit);
  155. }
  156. if (!empty($search_ref)) {
  157. $param .= '&search_ref='.urlencode($search_ref);
  158. }
  159. if (!empty($search_employee)) {
  160. $param .= '&search_employee='.urlencode($search_employee);
  161. }
  162. if (!empty($search_type)) {
  163. $param .= '&search_type='.urlencode($search_type);
  164. }
  165. if (!empty($search_description)) {
  166. $param .= '&search_description='.urlencode($search_description);
  167. }
  168. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  169. if ($optioncss != '') {
  170. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  171. }
  172. print '<input type="hidden" name="token" value="'.newToken().'">';
  173. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  174. print '<input type="hidden" name="action" value="list">';
  175. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  176. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  177. print '<input type="hidden" name="page" value="'.$page.'">';
  178. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  179. print load_fiche_titre($langs->trans('MenuReportMonth'), '', 'title_hrm');
  180. // Selection filter
  181. print '<div class="tabBar">';
  182. print $formother->select_month($search_month, 'remonth', 0, 0, 'minwidth50 maxwidth75imp valignmiddle', true);
  183. print $formother->selectyear($search_year, 'reyear', 0, 10, 5, 0, 0, '', 'valignmiddle width75', true);
  184. print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Search")).'" />';
  185. print '</div>';
  186. print '<br>';
  187. $moreforfilter = '';
  188. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  189. $selectedfields = '';
  190. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  191. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  192. print '<div class="div-table-responsive">';
  193. print '<table class="noborder centpercent">';
  194. print '<tr class="liste_titre">';
  195. // Filter: Ref
  196. if (!empty($arrayfields['cp.ref']['checked'])) {
  197. print '<td class="liste_titre">';
  198. print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  199. print '</td>';
  200. }
  201. // Filter: Employee
  202. if (!empty($arrayfields['cp.fk_user']['checked'])) {
  203. print '<td class="liste_titre">';
  204. print $form->select_dolusers($search_employee, "search_employee", 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  205. print '</td>';
  206. }
  207. // Filter: Type
  208. if (!empty($arrayfields['ct.label']['checked'])) {
  209. $typeleaves = $holidaystatic->getTypes(1, -1);
  210. $arraytypeleaves = array();
  211. foreach ($typeleaves as $key => $val) {
  212. $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
  213. $arraytypeleaves[$val['rowid']] = $labeltoshow;
  214. }
  215. print '<td class="liste_titre">';
  216. print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', '', 1);
  217. print '</td>';
  218. }
  219. if (!empty($arrayfields['cp.date_debut']['checked'])) {
  220. print '<td class="liste_titre"></td>';
  221. }
  222. if (!empty($arrayfields['cp.date_fin']['checked'])) {
  223. print '<td class="liste_titre"></td>';
  224. }
  225. if (!empty($arrayfields['used_days']['checked'])) {
  226. print '<td class="liste_titre"></td>';
  227. }
  228. if (!empty($arrayfields['date_start_month']['checked'])) {
  229. print '<td class="liste_titre"></td>';
  230. }
  231. if (!empty($arrayfields['date_end_month']['checked'])) {
  232. print '<td class="liste_titre"></td>';
  233. }
  234. if (!empty($arrayfields['used_days_month']['checked'])) {
  235. print '<td class="liste_titre"></td>';
  236. }
  237. // Filter: Description
  238. if (!empty($arrayfields['cp.description']['checked'])) {
  239. print '<td class="liste_titre">';
  240. print '<input type="text" class="maxwidth100" name="search_description" value="'.$search_description.'">';
  241. print '</td>';
  242. }
  243. // Action column
  244. print '<td class="liste_titre maxwidthsearch">';
  245. $searchpicto = $form->showFilterButtons();
  246. print $searchpicto;
  247. print '</td>';
  248. print '</tr>';
  249. print '<tr class="liste_titre">';
  250. if (!empty($arrayfields['cp.ref']['checked'])) {
  251. print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], 'cp.ref', '', '', '', $sortfield, $sortorder);
  252. }
  253. if (!empty($arrayfields['cp.fk_user']['checked'])) {
  254. print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], 'cp.fk_user', '', '', '', $sortfield, $sortorder);
  255. }
  256. if (!empty($arrayfields['ct.label']['checked'])) {
  257. print_liste_field_titre($arrayfields['ct.label']['label'], $_SERVER["PHP_SELF"], 'ct.label', '', '', '', $sortfield, $sortorder);
  258. }
  259. if (!empty($arrayfields['cp.date_debut']['checked'])) {
  260. print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], 'cp.date_debut', '', '', '', $sortfield, $sortorder);
  261. }
  262. if (!empty($arrayfields['cp.date_fin']['checked'])) {
  263. print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], 'cp.date_fin', '', '', '', $sortfield, $sortorder);
  264. }
  265. if (!empty($arrayfields['used_days']['checked'])) {
  266. print_liste_field_titre($arrayfields['used_days']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
  267. }
  268. if (!empty($arrayfields['date_start_month']['checked'])) {
  269. print_liste_field_titre($arrayfields['date_start_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
  270. }
  271. if (!empty($arrayfields['date_end_month']['checked'])) {
  272. print_liste_field_titre($arrayfields['date_end_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
  273. }
  274. if (!empty($arrayfields['used_days_month']['checked'])) {
  275. print_liste_field_titre($arrayfields['used_days_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
  276. }
  277. if (!empty($arrayfields['cp.description']['checked'])) {
  278. print_liste_field_titre($arrayfields['cp.description']['label'], $_SERVER["PHP_SELF"], 'cp.description', '', '', '', $sortfield, $sortorder);
  279. }
  280. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  281. print '</tr>';
  282. if ($num == 0) {
  283. print '<tr><td colspan="10" class="opacitymedium">'.$langs->trans('None').'</td></tr>';
  284. } else {
  285. while ($obj = $db->fetch_object($resql)) {
  286. $user = new User($db);
  287. $user->fetch($obj->fk_user);
  288. $date_start = $db->jdate($obj->date_debut, true);
  289. $date_end = $db->jdate($obj->date_fin, true);
  290. $tmpstart = dol_getdate($date_start);
  291. $tmpend = dol_getdate($date_end);
  292. $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
  293. $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
  294. $halfdayinmonth = $obj->halfday;
  295. $starthalfdayinmonth = $starthalfday;
  296. $endhalfdayinmonth = $endhalfday;
  297. //0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning
  298. // Set date_start_gmt and date_end_gmt that are date to show for the selected month
  299. $date_start_inmonth = $db->jdate($obj->date_debut, true);
  300. $date_end_inmonth = $db->jdate($obj->date_fin, true);
  301. if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month) {
  302. $date_start_inmonth = dol_get_first_day($search_year, $search_month, true);
  303. $starthalfdayinmonth = 'morning';
  304. if ($halfdayinmonth == 2) {
  305. $halfdayinmonth = 1;
  306. }
  307. if ($halfdayinmonth == -1) {
  308. $halfdayinmonth = 0;
  309. }
  310. }
  311. if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month) {
  312. $date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1);
  313. $endhalfdayinmonth = 'afternoon';
  314. if ($halfdayinmonth == 2) {
  315. $halfdayinmonth = -1;
  316. }
  317. if ($halfdayinmonth == 1) {
  318. $halfdayinmonth = 0;
  319. }
  320. }
  321. // Leave request
  322. $holidaystatic->id = $obj->rowid;
  323. $holidaystatic->ref = $obj->ref;
  324. print '<tr class="oddeven">';
  325. if (!empty($arrayfields['cp.ref']['checked'])) {
  326. print '<td>'.$holidaystatic->getNomUrl(1, 1).'</td>';
  327. }
  328. if (!empty($arrayfields['cp.fk_user']['checked'])) {
  329. print '<td>'.$user->getFullName($langs).'</td>';
  330. }
  331. if (!empty($arrayfields['ct.label']['checked'])) {
  332. print '<td>'.$obj->label.'</td>';
  333. }
  334. if (!empty($arrayfields['cp.date_debut']['checked'])) {
  335. print '<td class="center">'.dol_print_date($db->jdate($obj->date_debut), 'day');
  336. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
  337. print '</td>';
  338. }
  339. if (!empty($arrayfields['cp.date_fin']['checked'])) {
  340. print '<td class="center">'.dol_print_date($db->jdate($obj->date_fin), 'day');
  341. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
  342. print '</td>';
  343. }
  344. if (!empty($arrayfields['used_days']['checked'])) {
  345. print '<td class="right">'.num_open_day($date_start, $date_end, 0, 1, $obj->halfday).'</td>';
  346. }
  347. if (!empty($arrayfields['date_start_month']['checked'])) {
  348. print '<td class="center">'.dol_print_date($date_start_inmonth, 'day');
  349. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfdayinmonth]).')</span>';
  350. print '</td>';
  351. }
  352. if (!empty($arrayfields['date_end_month']['checked'])) {
  353. print '<td class="center">'.dol_print_date($date_end_inmonth, 'day');
  354. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfdayinmonth]).')</span>';
  355. print '</td>';
  356. }
  357. if (!empty($arrayfields['used_days_month']['checked'])) {
  358. print '<td class="right">'.num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth).'</td>';
  359. }
  360. if (!empty($arrayfields['cp.description']['checked'])) {
  361. print '<td class="maxwidth300 small">'.dol_escape_htmltag(dolGetFirstLineOfText($obj->description)).'</td>';
  362. }
  363. print '<td></td>';
  364. print '</tr>';
  365. }
  366. }
  367. print '</table>';
  368. print '</div>';
  369. print '</form>';
  370. // End of page
  371. llxFooter();
  372. $db->close();