month_report.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file month_report.php
  21. * \ingroup holiday
  22. * \brief Monthly report of leave requests.
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("holiday"));
  31. // Security check
  32. $socid=0;
  33. if ($user->societe_id > 0) // Protection if external user
  34. {
  35. //$socid = $user->societe_id;
  36. accessforbidden();
  37. }
  38. $result = restrictedArea($user, 'holiday', $id, '');
  39. /*
  40. * View
  41. */
  42. $holidaystatic = new Holiday($db);
  43. $listhalfday=array('morning'=>$langs->trans("Morning"),"afternoon"=>$langs->trans("Afternoon"));
  44. llxHeader('', $langs->trans('CPTitreMenu'));
  45. print_fiche_titre($langs->trans('MenuReportMonth'));
  46. $html = new Form($db);
  47. $formother = new FormOther($db);
  48. // Selection filter
  49. print '<div class="tabBar">';
  50. print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  51. $search_month = GETPOST("remonth",'int')?GETPOST("remonth",'int'):date("m", time());
  52. $search_year = GETPOST("reyear",'int')?GETPOST("reyear",'int'):date("Y", time());
  53. $month_year = sprintf("%02d",$search_month).'-'.sprintf("%04d",$search_year);
  54. $year_month = sprintf("%04d",$search_year).'-'.sprintf("%02d",$search_month);
  55. print $formother->select_month($search_month,'remonth');
  56. print $formother->select_year($search_year,'reyear');
  57. print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Search")).'" />';
  58. print '</form>';
  59. $sql = "SELECT cp.rowid, cp.fk_user, cp.date_debut, cp.date_fin, ct.label, cp.description, cp.halfday";
  60. $sql .= " FROM ".MAIN_DB_PREFIX."holiday cp";
  61. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON cp.fk_user = u.rowid";
  62. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_holiday_types ct ON cp.fk_type = ct.rowid";
  63. $sql .= " WHERE cp.rowid > 0";
  64. $sql .= " AND cp.statut = 3"; // Approved
  65. $sql .= " AND (date_format(cp.date_debut, '%Y-%m') = '".$db->escape($year_month)."' OR date_format(cp.date_fin, '%Y-%m') = '".$db->escape($year_month)."')";
  66. $sql .= " ORDER BY u.lastname, cp.date_debut";
  67. $resql = $db->query($sql);
  68. if (empty($resql))
  69. {
  70. dol_print_error($db);
  71. exit;
  72. }
  73. $num = $db->num_rows($resql);
  74. print '</div>';
  75. print '<br>';
  76. print '<div class="div-table-responsive">';
  77. print '<table class="noborder" width="100%">';
  78. print '<tr class="liste_titre">';
  79. print '<td>' . $langs->trans('Ref') . '</td>';
  80. print '<td>' . $langs->trans('Employee') . '</td>';
  81. print '<td>' . $langs->trans('Type') . '</td>';
  82. print '<td align="center">' . $langs->trans('DateDebCP') . '</td>';
  83. print '<td align="center">' . $langs->trans('DateFinCP') . '</td>';
  84. print '<td align="right">' . $langs->trans('NbUseDaysCPShort') . '</td>';
  85. print '<td align="center">' . $langs->trans('DateStartInMonth') . '</td>';
  86. print '<td align="center">' . $langs->trans('DateEndInMonth') . '</td>';
  87. print '<td align="right">' . $langs->trans('NbUseDaysCPShortInMonth') . '</td>';
  88. print '<td class="maxwidth300">' . $langs->trans('DescCP') . '</td>';
  89. print '</tr>';
  90. if ($num == 0)
  91. {
  92. print '<tr><td colspan="10" class="opacitymedium">'.$langs->trans('None').'</td></tr>';
  93. }
  94. else
  95. {
  96. while ($obj = $db->fetch_object($resql))
  97. {
  98. $user = new User($db);
  99. $user->fetch($obj->fk_user);
  100. $date_start = $db->jdate($obj->date_debut, true);
  101. $date_end = $db->jdate($obj->date_fin, true);
  102. $tmpstart = dol_getdate($date_start);
  103. $tmpend = dol_getdate($date_end);
  104. $starthalfday=($obj->halfday == -1 || $obj->halfday == 2)?'afternoon':'morning';
  105. $endhalfday=($obj->halfday == 1 || $obj->halfday == 2)?'morning':'afternoon';
  106. $halfdayinmonth = $obj->halfday;
  107. $starthalfdayinmonth = $starthalfday;
  108. $endhalfdayinmonth = $endhalfday;
  109. //0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning
  110. // Set date_start_gmt and date_end_gmt that are date to show for the selected month
  111. $date_start_inmonth = $db->jdate($obj->date_debut, true);
  112. $date_end_inmonth = $db->jdate($obj->date_fin, true);
  113. if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month)
  114. {
  115. $date_start_inmonth = dol_get_first_day($search_year, $search_month, true);
  116. $starthalfdayinmonth = 'morning';
  117. if ($halfdayinmonth == 2) $halfdayinmonth=1;
  118. if ($halfdayinmonth == -1) $halfdayinmonth=0;
  119. }
  120. if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month)
  121. {
  122. $date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1);
  123. $endhalfdayinmonth = 'afternoon';
  124. if ($halfdayinmonth == 2) $halfdayinmonth=-1;
  125. if ($halfdayinmonth == 1) $halfdayinmonth=0;
  126. }
  127. // Leave request
  128. $holidaystatic->id=$obj->rowid;
  129. $holidaystatic->ref=$obj->rowid;
  130. print '<tr class="oddeven">';
  131. print '<td>';
  132. print $holidaystatic->getNomUrl(1, 1);
  133. print '</td>';
  134. print '<td>' . $user->getFullName($langs) . '</td>';
  135. print '<td>' . $obj->label . '</td>';
  136. print '<td align="center">' . dol_print_date($obj->date_debut, 'day');
  137. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
  138. print '</td>';
  139. print '<td align="center">' . dol_print_date($obj->date_fin, 'day');
  140. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
  141. print '</td>';
  142. print '<td align="right">' . num_open_day($date_start, $date_end, 0, 1, $obj->halfday) . '</td>';
  143. print '<td align="center">' . dol_print_date($date_start_inmonth, 'day');
  144. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfdayinmonth]).')</span>';
  145. print '</td>';
  146. print '<td align="center">' . dol_print_date($date_end_inmonth, 'day');
  147. print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfdayinmonth]).')</span>';
  148. print '</td>';
  149. print '<td align="right">' . num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth) . '</td>';
  150. print '<td class="maxwidth300">' . dol_escape_htmltag(dolGetFirstLineOfText($obj->description)) . '</td>';
  151. print '</tr>';
  152. }
  153. }
  154. print '</table>';
  155. print '</div>';
  156. // End of page
  157. llxFooter();
  158. $db->close();