list.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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-2016 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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 htdocs/holiday/list.php
  21. * \ingroup holiday
  22. * \brief List of holiday.
  23. */
  24. require('../main.inc.php');
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  33. $langs->load('users');
  34. $langs->load('holidays');
  35. $langs->load('hrm');
  36. // Protection if external user
  37. if ($user->societe_id > 0) accessforbidden();
  38. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  39. $sortfield = GETPOST("sortfield",'alpha');
  40. $sortorder = GETPOST("sortorder",'alpha');
  41. $page = GETPOST("page",'int');
  42. $page = is_numeric($page) ? $page : 0;
  43. $page = $page == -1 ? 0 : $page;
  44. if (! $sortfield) $sortfield="cp.rowid";
  45. if (! $sortorder) $sortorder="DESC";
  46. $offset = $limit * $page;
  47. $pageprev = $page - 1;
  48. $pagenext = $page + 1;
  49. $id = GETPOST('id','int');
  50. $sall = GETPOST('sall');
  51. $search_ref = GETPOST('search_ref');
  52. $month_create = GETPOST('month_create');
  53. $year_create = GETPOST('year_create');
  54. $month_start = GETPOST('month_start');
  55. $year_start = GETPOST('year_start');
  56. $month_end = GETPOST('month_end');
  57. $year_end = GETPOST('year_end');
  58. $search_employe = GETPOST('search_employe');
  59. $search_valideur = GETPOST('search_valideur');
  60. $search_statut = GETPOST('select_statut');
  61. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers
  62. {
  63. $search_ref="";
  64. $month_create="";
  65. $year_create="";
  66. $month_start="";
  67. $year_start="";
  68. $month_end="";
  69. $year_end="";
  70. $search_employe="";
  71. $search_valideur="";
  72. $search_statut="";
  73. }
  74. // List of fields to search into when doing a "search in all"
  75. $fieldstosearchall = array(
  76. 'cp.rowid'=>'Ref',
  77. 'cp.description'=>'Description',
  78. 'uu.lastname'=>'EmployeeLastname',
  79. 'uu.firstname'=>'EmployeeFirstname'
  80. );
  81. /*
  82. * Actions
  83. */
  84. // None
  85. /*
  86. * View
  87. */
  88. $holiday = new Holiday($db);
  89. $holidaystatic=new Holiday($db);
  90. $fuser = new User($db);
  91. $childids = $user->getAllChildIds();
  92. $childids[]=$user->id;
  93. // Update sold
  94. $result = $holiday->updateBalance();
  95. $max_year = 5;
  96. $min_year = 10;
  97. $filter='';
  98. llxHeader('', $langs->trans('CPTitreMenu'));
  99. $order = $db->order($sortfield,$sortorder).$db->plimit($limit + 1, $offset);
  100. // WHERE
  101. if(!empty($search_ref))
  102. {
  103. $filter.= " AND cp.rowid LIKE '%".$db->escape($search_ref)."%'\n";
  104. }
  105. // DATE START
  106. if($year_start > 0) {
  107. if($month_start > 0) {
  108. $filter .= " AND (cp.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,$month_start,1))."' AND '".$db->idate(dol_get_last_day($year_start,$month_start,1))."')";
  109. //$filter.= " AND date_format(cp.date_debut, '%Y-%m') = '$year_start-$month_start'";
  110. } else {
  111. $filter .= " AND (cp.date_debut BETWEEN '".$db->idate(dol_get_first_day($year_start,1,1))."' AND '".$db->idate(dol_get_last_day($year_start,12,1))."')";
  112. //$filter.= " AND date_format(cp.date_debut, '%Y') = '$year_start'";
  113. }
  114. } else {
  115. if($month_start > 0) {
  116. $filter.= " AND date_format(cp.date_debut, '%m') = '$month_start'";
  117. }
  118. }
  119. // DATE FIN
  120. if($year_end > 0) {
  121. if($month_end > 0) {
  122. $filter .= " AND (cp.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,$month_end,1))."' AND '".$db->idate(dol_get_last_day($year_end,$month_end,1))."')";
  123. //$filter.= " AND date_format(cp.date_fin, '%Y-%m') = '$year_end-$month_end'";
  124. } else {
  125. $filter .= " AND (cp.date_fin BETWEEN '".$db->idate(dol_get_first_day($year_end,1,1))."' AND '".$db->idate(dol_get_last_day($year_end,12,1))."')";
  126. //$filter.= " AND date_format(cp.date_fin, '%Y') = '$year_end'";
  127. }
  128. } else {
  129. if($month_end > 0) {
  130. $filter.= " AND date_format(cp.date_fin, '%m') = '$month_end'";
  131. }
  132. }
  133. // DATE CREATE
  134. if($year_create > 0) {
  135. if($month_create > 0) {
  136. $filter .= " AND (cp.date_create BETWEEN '".$db->idate(dol_get_first_day($year_create,$month_create,1))."' AND '".$db->idate(dol_get_last_day($year_create,$month_create,1))."')";
  137. //$filter.= " AND date_format(cp.date_create, '%Y-%m') = '$year_create-$month_create'";
  138. } else {
  139. $filter .= " AND (cp.date_create BETWEEN '".$db->idate(dol_get_first_day($year_create,1,1))."' AND '".$db->idate(dol_get_last_day($year_create,12,1))."')";
  140. //$filter.= " AND date_format(cp.date_create, '%Y') = '$year_create'";
  141. }
  142. } else {
  143. if($month_create > 0) {
  144. $filter.= " AND date_format(cp.date_create, '%m') = '$month_create'";
  145. }
  146. }
  147. // EMPLOYE
  148. if(!empty($search_employe) && $search_employe != -1) {
  149. $filter.= " AND cp.fk_user = '".$db->escape($search_employe)."'\n";
  150. }
  151. // VALIDEUR
  152. if(!empty($search_valideur) && $search_valideur != -1) {
  153. $filter.= " AND cp.fk_validator = '".$db->escape($search_valideur)."'\n";
  154. }
  155. // STATUT
  156. if(!empty($search_statut) && $search_statut != -1) {
  157. $filter.= " AND cp.statut = '".$db->escape($search_statut)."'\n";
  158. }
  159. // Search all
  160. if (!empty($sall))
  161. {
  162. $filter.= natural_search(array_keys($fieldstosearchall), $sall);
  163. }
  164. if (empty($user->rights->holiday->read_all)) $filter.=' AND cp.fk_user IN ('.join(',',$childids).')';
  165. // Récupération de l'ID de l'utilisateur
  166. $user_id = $user->id;
  167. if ($id > 0)
  168. {
  169. // Charge utilisateur edite
  170. $fuser->fetch($id);
  171. $fuser->getrights();
  172. $user_id = $fuser->id;
  173. }
  174. // Récupération des congés payés de l'utilisateur ou de tous les users
  175. if (empty($user->rights->holiday->read_all) || $id > 0)
  176. {
  177. $holiday_payes = $holiday->fetchByUser($user_id,$order,$filter); // Load array $holiday->holiday
  178. }
  179. else
  180. {
  181. $holiday_payes = $holiday->fetchAll($order,$filter); // Load array $holiday->holiday
  182. }
  183. // Si erreur SQL
  184. if ($holiday_payes == '-1')
  185. {
  186. print load_fiche_titre($langs->trans('CPTitreMenu'), '', 'title_hrm.png');
  187. dol_print_error($db, $langs->trans('Error').' '.$holiday->error);
  188. exit();
  189. }
  190. // Show table of vacations
  191. $var=true;
  192. $num = count($holiday->holiday);
  193. $form = new Form($db);
  194. $formother = new FormOther($db);
  195. if ($id > 0)
  196. {
  197. $title = $langs->trans("User");
  198. $linkback = '<a href="'.DOL_URL_ROOT.'/user/index.php">'.$langs->trans("BackToList").'</a>';
  199. $head = user_prepare_head($fuser);
  200. dol_fiche_head($head, 'paidholidays', $title, 0, 'user');
  201. dol_banner_tab($fuser,'id',$linkback,$user->rights->user->user->lire || $user->admin);
  202. print '<div class="underbanner clearboth"></div>';
  203. print '<br>';
  204. }
  205. else
  206. {
  207. //print $num;
  208. //print count($holiday->holiday);
  209. print_barre_liste($langs->trans("ListeCP"), $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, "", $num, count($holiday->holiday), 'title_hrm.png', 0, '', '', $limit);
  210. dol_fiche_head('');
  211. }
  212. $alltypeleaves=$holiday->getTypes(1,-1); // To have labels
  213. $out='';
  214. $typeleaves=$holiday->getTypes(1,1);
  215. foreach($typeleaves as $key => $val)
  216. {
  217. $nb_type = $holiday->getCPforUser($user_id, $val['rowid']);
  218. $nb_holiday += $nb_type;
  219. $out .= ' - '.$val['label'].': <strong>'.($nb_type?price2num($nb_type):0).'</strong><br>';
  220. }
  221. print $langs->trans('SoldeCPUser', round($nb_holiday,5)).'<br>';
  222. print $out;
  223. dol_fiche_end();
  224. if ($id > 0) print '</br>';
  225. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  226. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  227. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  228. print '<input type="hidden" name="action" value="list">';
  229. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  230. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  231. if ($sall)
  232. {
  233. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  234. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  235. }
  236. print '<table class="noborder" width="100%;">';
  237. print "<tr class=\"liste_titre\">";
  238. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"cp.rowid","",'','',$sortfield,$sortorder);
  239. print_liste_field_titre($langs->trans("DateCreateCP"),$_SERVER["PHP_SELF"],"cp.date_create","",'','align="center"',$sortfield,$sortorder);
  240. print_liste_field_titre($langs->trans("Employee"),$_SERVER["PHP_SELF"],"cp.fk_user","",'','',$sortfield,$sortorder);
  241. print_liste_field_titre($langs->trans("ValidatorCP"),$_SERVER["PHP_SELF"],"cp.fk_validator","",'','',$sortfield,$sortorder);
  242. print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],'','','','',$sortfield,$sortorder);
  243. print_liste_field_titre($langs->trans("Duration"),$_SERVER["PHP_SELF"],'','','','align="right"',$sortfield,$sortorder);
  244. print_liste_field_titre($langs->trans("DateDebCP"),$_SERVER["PHP_SELF"],"cp.date_debut","",'','align="center"',$sortfield,$sortorder);
  245. print_liste_field_titre($langs->trans("DateFinCP"),$_SERVER["PHP_SELF"],"cp.date_fin","",'','align="center"',$sortfield,$sortorder);
  246. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cp.statut","",'','align="center"',$sortfield,$sortorder);
  247. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  248. print "</tr>\n";
  249. // FILTRES
  250. print '<tr class="liste_titre">';
  251. print '<td class="liste_titre" align="left" width="50">';
  252. print '<input class="flat" size="4" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  253. print '</td>';
  254. // DATE CREATE
  255. print '<td class="liste_titre" colspan="1" align="center">';
  256. print '<input class="flat" type="text" size="1" maxlength="2" name="month_create" value="'.$month_create.'">';
  257. $formother->select_year($year_create,'year_create',1, $min_year, 0);
  258. print '</td>';
  259. // UTILISATEUR
  260. if ($user->rights->holiday->write_all)
  261. {
  262. print '<td class="liste_titre" align="left">';
  263. print $form->select_dolusers($search_employe,"search_employe",1,"",0,'','',0,32);
  264. print '</td>';
  265. }
  266. else
  267. {
  268. //print '<td class="liste_titre">&nbsp;</td>';
  269. print '<td class="liste_titre" align="left">';
  270. print $form->select_dolusers($user->id,"search_employe",1,"",1,'','',0,32);
  271. print '</td>';
  272. }
  273. // VALIDEUR
  274. if($user->rights->holiday->write_all)
  275. {
  276. print '<td class="liste_titre" align="left">';
  277. $validator = new UserGroup($db);
  278. $excludefilter=$user->admin?'':'u.rowid <> '.$user->id;
  279. $valideurobjects = $validator->listUsersForGroup($excludefilter);
  280. $valideurarray = array();
  281. foreach($valideurobjects as $val) $valideurarray[$val->id]=$val->id;
  282. print $form->select_dolusers($search_valideur,"search_valideur",1,"",0,$valideurarray,'', 0, 32);
  283. print '</td>';
  284. }
  285. else
  286. {
  287. print '<td class="liste_titre">&nbsp;</td>';
  288. }
  289. // Type
  290. print '<td class="liste_titre" colspan="1" align="center">';
  291. print '</td>';
  292. // DUREE
  293. print '<td>&nbsp;</td>';
  294. // DATE DEBUT
  295. print '<td class="liste_titre" colspan="1" align="center">';
  296. print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="'.$month_start.'">';
  297. $formother->select_year($year_start,'year_start',1, $min_year, $max_year);
  298. print '</td>';
  299. // DATE FIN
  300. print '<td class="liste_titre" colspan="1" align="center">';
  301. print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="'.$month_end.'">';
  302. $formother->select_year($year_end,'year_end',1, $min_year, $max_year);
  303. print '</td>';
  304. // STATUT
  305. print '<td class="liste_titre" width="70px;" align="center">';
  306. $holiday->selectStatutCP($search_statut);
  307. print '</td>';
  308. // ACTION
  309. print '<td class="liste_titre" align="right">';
  310. $searchpitco=$form->showFilterAndCheckAddButtons(0);
  311. print $searchpitco;
  312. print '</td>';
  313. print "</tr>\n";
  314. // Lines
  315. if (! empty($holiday->holiday))
  316. {
  317. $userstatic = new User($db);
  318. $approbatorstatic = new User($db);
  319. foreach($holiday->holiday as $infos_CP)
  320. {
  321. $var=!$var;
  322. // Utilisateur
  323. $userstatic->id=$infos_CP['fk_user'];
  324. $userstatic->lastname=$infos_CP['user_lastname'];
  325. $userstatic->firstname=$infos_CP['user_firstname'];
  326. // Valideur
  327. $approbatorstatic->id=$infos_CP['fk_validator'];
  328. $approbatorstatic->lastname=$infos_CP['validator_lastname'];
  329. $approbatorstatic->firstname=$infos_CP['validator_firstname'];
  330. $date = $infos_CP['date_create'];
  331. print '<tr '.$bc[$var].'>';
  332. print '<td>';
  333. $holidaystatic->id=$infos_CP['rowid'];
  334. $holidaystatic->ref=$infos_CP['rowid'];
  335. print $holidaystatic->getNomUrl(1);
  336. print '</td>';
  337. print '<td style="text-align: center;">'.dol_print_date($date,'day').'</td>';
  338. print '<td>'.$userstatic->getNomUrl('1', 'leave').'</td>';
  339. print '<td>'.$approbatorstatic->getNomUrl('1').'</td>';
  340. print '<td>';
  341. $label=$alltypeleaves[$infos_CP['fk_type']]['label'];
  342. print $label?$label:$infos_CP['fk_type'];
  343. print '</td>';
  344. print '<td align="right">';
  345. $nbopenedday=num_open_day($infos_CP['date_debut_gmt'], $infos_CP['date_fin_gmt'], 0, 1, $infos_CP['halfday']);
  346. print $nbopenedday.' '.$langs->trans('DurationDays');
  347. print '</td>';
  348. print '<td align="center">'.dol_print_date($infos_CP['date_debut'],'day').'</td>';
  349. print '<td align="center">'.dol_print_date($infos_CP['date_fin'],'day').'</td>';
  350. print '<td align="right">'.$holidaystatic->LibStatut($infos_CP['statut'],5).'</td>';
  351. print '<td></td>';
  352. print '</tr>'."\n";
  353. }
  354. }
  355. // Si il n'y a pas d'enregistrement suite à une recherche
  356. if($holiday_payes == '2')
  357. {
  358. print '<tr>';
  359. print '<td colspan="10" class="opacitymedium">'.$langs->trans('NoRecordFound').'</td>';
  360. print '</tr>';
  361. }
  362. print '</table>';
  363. print '</form>';
  364. /*if ($user_id == $user->id)
  365. {
  366. print '<br>';
  367. print '<div style="float: right; margin-top: 8px;">';
  368. print '<a href="./card.php?action=request" class="butAction">'.$langs->trans('AddCP').'</a>';
  369. print '</div>';
  370. }*/
  371. llxFooter();
  372. $db->close();