dolibarr  13.0.2
month_report.php
Go to the documentation of this file.
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 2 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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 
34 // Load translation files required by the page
35 $langs->loadLangs(array("holiday"));
36 
37 // Security check
38 $socid = 0;
39 if ($user->socid > 0) // Protection if external user
40 {
41  //$socid = $user->socid;
43 }
44 $result = restrictedArea($user, 'holiday', $id, '');
45 
46 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view';
47 $massaction = GETPOST('massaction', 'alpha');
48 $contextpage = GETPOST('contextpage', 'aZ');
49 $optioncss = GETPOST('optioncss', 'aZ');
50 
51 $search_ref = GETPOST('search_ref', 'alphanohtml');
52 $search_employee = GETPOST('search_employee', 'int');
53 $search_type = GETPOST('search_type', 'int');
54 $search_description = GETPOST('search_description', 'alphanohtml');
55 
56 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST('sortfield', 'aZ09comma');
58 $sortorder = GETPOST('sortorder', 'alpha');
59 
60 if (!$sortfield) $sortfield = "cp.rowid";
61 if (!$sortorder) $sortorder = "ASC";
62 
63 $hookmanager->initHooks(array('leavemovementlist'));
64 
65 $arrayfields = array();
66 $arrayofmassactions = array();
67 
68 /*
69  * Actions
70  */
71 
72 if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
73 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
74 
75 $parameters = array();
76 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
77 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
78 
79 if (empty($reshook))
80 {
81  // Selection of new fields
82  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
83 
84  // Purge search criteria
85  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
86  {
87  $search_ref = '';
88  $search_employee = '';
89  $search_type = '';
90  $search_description = '';
91  $toselect = '';
92  $search_array_options = array();
93  }
94 
95  if (GETPOST('button_removefilter_x', 'alpha')
96  || GETPOST('button_removefilter.x', 'alpha')
97  || GETPOST('button_removefilter', 'alpha')
98  || GETPOST('button_search_x', 'alpha')
99  || GETPOST('button_search.x', 'alpha')
100  || GETPOST('button_search', 'alpha'))
101  {
102  $massaction = '';
103  }
104 }
105 
106 $arrayfields = array(
107  'cp.ref'=>array('label'=>$langs->trans('Ref'), 'checked'=>1),
108  'cp.fk_user'=>array('label'=>$langs->trans('Employee'), 'checked'=>1),
109  'ct.label'=>array('label'=>$langs->trans('Type'), 'checked'=>1),
110  'cp.date_debut'=>array('label'=>$langs->trans('DateDebCP'), 'checked'=>1),
111  'cp.date_fin'=>array('label'=>$langs->trans('DateFinCP'), 'checked'=>1),
112  'used_days'=>array('label'=>$langs->trans('NbUseDaysCPShort'), 'checked'=>1),
113  'date_start_month'=>array('label'=>$langs->trans('DateStartInMonth'), 'checked'=>1),
114  'date_end_month'=>array('label'=>$langs->trans('DateEndInMonth'), 'checked'=>1),
115  'used_days_month'=>array('label'=>$langs->trans('NbUseDaysCPShortInMonth'), 'checked'=>1),
116  'cp.description'=>array('label'=>$langs->trans('DescCP'), 'checked'=>1),
117 );
118 
119 
120 /*
121  * View
122  */
123 
124 $form = new Form($db);
125 $formother = new FormOther($db);
126 $holidaystatic = new Holiday($db);
127 
128 $listhalfday = array('morning'=>$langs->trans("Morning"), "afternoon"=>$langs->trans("Afternoon"));
129 
130 llxHeader('', $langs->trans('CPTitreMenu'));
131 
132 $search_month = GETPOST("remonth", 'int') ?GETPOST("remonth", 'int') : date("m", time());
133 $search_year = GETPOST("reyear", 'int') ?GETPOST("reyear", 'int') : date("Y", time());
134 $year_month = sprintf("%04d", $search_year).'-'.sprintf("%02d", $search_month);
135 
136 $sql = "SELECT cp.rowid, cp.ref, cp.fk_user, cp.date_debut, cp.date_fin, ct.label, cp.description, cp.halfday";
137 $sql .= " FROM ".MAIN_DB_PREFIX."holiday cp";
138 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user u ON cp.fk_user = u.rowid";
139 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_holiday_types ct ON cp.fk_type = ct.rowid";
140 $sql .= " WHERE cp.rowid > 0";
141 $sql .= " AND cp.statut = 3"; // 3 = Approved
142 $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)."')";
143 
144 if (!empty($search_ref)) $sql .= natural_search('cp.ref', $search_ref);
145 if (!empty($search_employee)) $sql .= " AND cp.fk_user = '".$db->escape($search_employee)."'";
146 if (!empty($search_type)) $sql .= ' AND cp.fk_type IN ('.$db->escape($search_type).')';
147 if (!empty($search_description)) $sql .= natural_search('cp.description', $search_description);
148 
149 $sql .= $db->order($sortfield, $sortorder);
150 
151 $resql = $db->query($sql);
152 if (empty($resql))
153 {
154  dol_print_error($db);
155  exit;
156 }
157 
158 $num = $db->num_rows($resql);
159 
160 $param = '';
161 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
162 if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
163 if (!empty($search_ref)) $param .= '&search_ref='.urlencode($search_ref);
164 if (!empty($search_employee)) $param .= '&search_employee='.urlencode($search_employee);
165 if (!empty($search_type)) $param .= '&search_type='.urlencode($search_type);
166 if (!empty($search_description)) $param .= '&search_description='.urlencode($search_description);
167 
168 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
169 if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
170 print '<input type="hidden" name="token" value="'.newToken().'">';
171 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
172 print '<input type="hidden" name="action" value="list">';
173 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
174 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
175 print '<input type="hidden" name="page" value="'.$page.'">';
176 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
177 
178 print load_fiche_titre($langs->trans('MenuReportMonth'), '', 'title_hrm');
179 
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 
188 $moreforfilter = '';
189 
190 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
191 $selectedfields = '';
192 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
193 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
194 
195 print '<div class="div-table-responsive">';
196 print '<table class="noborder centpercent">';
197 
198 print '<tr class="liste_titre">';
199 
200 // Filter: Ref
201 if (!empty($arrayfields['cp.ref']['checked'])) {
202  print '<td class="liste_titre">';
203  print '<input class="flat maxwidth100" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
204  print '</td>';
205 }
206 
207 // Filter: Employee
208 if (!empty($arrayfields['cp.fk_user']['checked'])) {
209  print '<td class="liste_titre">';
210  print $form->select_dolusers($search_employee, "search_employee", 1, null, 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
211  print '</td>';
212 }
213 
214 // Filter: Type
215 if (!empty($arrayfields['ct.label']['checked'])) {
216  $typeleaves = $holidaystatic->getTypes(1, -1);
217  $arraytypeleaves = array();
218  foreach ($typeleaves as $key => $val)
219  {
220  $labeltoshow = ($langs->trans($val['code']) != $val['code'] ? $langs->trans($val['code']) : $val['label']);
221  $arraytypeleaves[$val['rowid']] = $labeltoshow;
222  }
223 
224  print '<td class="liste_titre">';
225  print $form->selectarray('search_type', $arraytypeleaves, $search_type, 1, 0, 0, '', 0, 0, 0, '', '', 1);
226  print '</td>';
227 }
228 
229 if (!empty($arrayfields['cp.date_debut']['checked'])) print '<td class="liste_titre"></td>';
230 if (!empty($arrayfields['cp.date_fin']['checked'])) print '<td class="liste_titre"></td>';
231 if (!empty($arrayfields['used_days']['checked'])) print '<td class="liste_titre"></td>';
232 if (!empty($arrayfields['date_start_month']['checked'])) print '<td class="liste_titre"></td>';
233 if (!empty($arrayfields['date_end_month']['checked'])) print '<td class="liste_titre"></td>';
234 if (!empty($arrayfields['used_days_month']['checked'])) print '<td class="liste_titre"></td>';
235 
236 // Filter: Description
237 if (!empty($arrayfields['cp.description']['checked'])) {
238  print '<td class="liste_titre">';
239  print '<input type="text" class="maxwidth100" name="search_description" value="'.$search_description.'">';
240  print '</td>';
241 }
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 
250 print '<tr class="liste_titre">';
251 if (!empty($arrayfields['cp.ref']['checked'])) print_liste_field_titre($arrayfields['cp.ref']['label'], $_SERVER["PHP_SELF"], 'cp.ref', '', '', '', $sortfield, $sortorder);
252 if (!empty($arrayfields['cp.fk_user']['checked'])) print_liste_field_titre($arrayfields['cp.fk_user']['label'], $_SERVER["PHP_SELF"], 'cp.fk_user', '', '', '', $sortfield, $sortorder);
253 if (!empty($arrayfields['ct.label']['checked'])) print_liste_field_titre($arrayfields['ct.label']['label'], $_SERVER["PHP_SELF"], 'ct.label', '', '', '', $sortfield, $sortorder);
254 if (!empty($arrayfields['cp.date_debut']['checked'])) print_liste_field_titre($arrayfields['cp.date_debut']['label'], $_SERVER["PHP_SELF"], 'cp.date_debut', '', '', '', $sortfield, $sortorder);
255 if (!empty($arrayfields['cp.date_fin']['checked'])) print_liste_field_titre($arrayfields['cp.date_fin']['label'], $_SERVER["PHP_SELF"], 'cp.date_fin', '', '', '', $sortfield, $sortorder);
256 if (!empty($arrayfields['used_days']['checked'])) print_liste_field_titre($arrayfields['used_days']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
257 if (!empty($arrayfields['date_start_month']['checked'])) print_liste_field_titre($arrayfields['date_start_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
258 if (!empty($arrayfields['date_end_month']['checked'])) print_liste_field_titre($arrayfields['date_end_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
259 if (!empty($arrayfields['used_days_month']['checked'])) print_liste_field_titre($arrayfields['used_days_month']['label'], $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder);
260 if (!empty($arrayfields['cp.description']['checked'])) print_liste_field_titre($arrayfields['cp.description']['label'], $_SERVER["PHP_SELF"], 'cp.description', '', '', '', $sortfield, $sortorder);
261 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
262 print '</tr>';
263 
264 if ($num == 0)
265 {
266  print '<tr><td colspan="10" class="opacitymedium">'.$langs->trans('None').'</td></tr>';
267 }
268 else {
269  while ($obj = $db->fetch_object($resql))
270  {
271  $user = new User($db);
272  $user->fetch($obj->fk_user);
273 
274  $date_start = $db->jdate($obj->date_debut, true);
275  $date_end = $db->jdate($obj->date_fin, true);
276 
277  $tmpstart = dol_getdate($date_start);
278  $tmpend = dol_getdate($date_end);
279 
280  $starthalfday = ($obj->halfday == -1 || $obj->halfday == 2) ? 'afternoon' : 'morning';
281  $endhalfday = ($obj->halfday == 1 || $obj->halfday == 2) ? 'morning' : 'afternoon';
282 
283  $halfdayinmonth = $obj->halfday;
284  $starthalfdayinmonth = $starthalfday;
285  $endhalfdayinmonth = $endhalfday;
286 
287  //0:Full days, 2:Start afternoon end morning, -1:Start afternoon end afternoon, 1:Start morning end morning
288 
289  // Set date_start_gmt and date_end_gmt that are date to show for the selected month
290  $date_start_inmonth = $db->jdate($obj->date_debut, true);
291  $date_end_inmonth = $db->jdate($obj->date_fin, true);
292  if ($tmpstart['year'] < $search_year || $tmpstart['mon'] < $search_month)
293  {
294  $date_start_inmonth = dol_get_first_day($search_year, $search_month, true);
295  $starthalfdayinmonth = 'morning';
296  if ($halfdayinmonth == 2) $halfdayinmonth = 1;
297  if ($halfdayinmonth == -1) $halfdayinmonth = 0;
298  }
299  if ($tmpend['year'] > $search_year || $tmpend['mon'] > $search_month)
300  {
301  $date_end_inmonth = dol_get_last_day($search_year, $search_month, true) - ((24 * 3600) - 1);
302  $endhalfdayinmonth = 'afternoon';
303  if ($halfdayinmonth == 2) $halfdayinmonth = -1;
304  if ($halfdayinmonth == 1) $halfdayinmonth = 0;
305  }
306 
307  // Leave request
308  $holidaystatic->id = $obj->rowid;
309  $holidaystatic->ref = $obj->ref;
310 
311  print '<tr class="oddeven">';
312 
313  if (!empty($arrayfields['cp.ref']['checked'])) print '<td>'.$holidaystatic->getNomUrl(1, 1).'</td>';
314  if (!empty($arrayfields['cp.fk_user']['checked'])) print '<td>'.$user->getFullName($langs).'</td>';
315  if (!empty($arrayfields['ct.label']['checked'])) print '<td>'.$obj->label.'</td>';
316 
317  if (!empty($arrayfields['cp.date_debut']['checked']))
318  {
319  print '<td class="center">'.dol_print_date($db->jdate($obj->date_debut), 'day');
320  print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfday]).')</span>';
321  print '</td>';
322  }
323 
324  if (!empty($arrayfields['cp.date_fin']['checked']))
325  {
326  print '<td class="center">'.dol_print_date($db->jdate($obj->date_fin), 'day');
327  print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfday]).')</span>';
328  print '</td>';
329  }
330 
331  if (!empty($arrayfields['used_days']['checked'])) print '<td class="right">'.num_open_day($date_start, $date_end, 0, 1, $obj->halfday).'</td>';
332 
333  if (!empty($arrayfields['date_start_month']['checked']))
334  {
335  print '<td class="center">'.dol_print_date($date_start_inmonth, 'day');
336  print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$starthalfdayinmonth]).')</span>';
337  print '</td>';
338  }
339 
340  if (!empty($arrayfields['date_end_month']['checked']))
341  {
342  print '<td class="center">'.dol_print_date($date_end_inmonth, 'day');
343  print ' <span class="opacitymedium">('.$langs->trans($listhalfday[$endhalfdayinmonth]).')</span>';
344  print '</td>';
345  }
346 
347  if (!empty($arrayfields['used_days_month']['checked'])) print '<td class="right">'.num_open_day($date_start_inmonth, $date_end_inmonth, 0, 1, $halfdayinmonth).'</td>';
348  if (!empty($arrayfields['cp.description']['checked'])) print '<td class="maxwidth300">'.dol_escape_htmltag(dolGetFirstLineOfText($obj->description)).'</td>';
349 
350  print '<td></td>';
351  print '</tr>';
352  }
353 }
354 print '</table>';
355 print '</div>';
356 print '</form>';
357 
358 // End of page
359 llxFooter();
360 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class of the module paid holiday.
Class to manage Dolibarr users.
Definition: user.class.php:44
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:481
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
Classe permettant la generation de composants html autre Only common components are here...
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
print $_SERVER["PHP_SELF"]
Edit parameters.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:498
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip= '', $forcenowrapcolumntitle=0)
Get title line of an array.
llxFooter()
Empty footer.
Definition: wrapper.php:59