2012-09-05 03:26:57 +02:00
< ? php
2012-11-14 11:29:22 +01:00
/* Copyright ( C ) 2011 Dimitri Mouillard < dmouillard @ teclib . com >
2013-04-21 17:56:29 +02:00
* Copyright ( C ) 2013 Laurent Destailleur < eldy @ users . sourceforge . net >
2012-12-30 15:11:07 +01:00
* Copyright ( C ) 2012 Regis Houssin < regis . houssin @ capnetworks . com >
2012-09-05 03:26:57 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2012-09-05 03:26:57 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2012-09-05 03:57:26 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2012-09-05 03:26:57 +02:00
*/
/**
2012-12-20 20:16:10 +01:00
* \file htdocs / holiday / index . php
2012-09-05 03:26:57 +02:00
* \ingroup holiday
* \brief List of holiday .
*/
2012-09-06 10:39:25 +02:00
require ( '../main.inc.php' );
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php' ;
2012-11-20 12:40:57 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
2012-09-06 10:39:25 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2012-09-07 17:23:16 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/holiday/common.inc.php' ;
2013-03-30 14:27:13 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php' ;
2013-02-17 19:25:55 +01:00
2013-03-30 14:27:13 +01:00
$langs -> load ( 'users' );
$langs -> load ( 'holidays' );
2012-09-05 03:26:57 +02:00
// Protection if external user
if ( $user -> societe_id > 0 ) accessforbidden ();
2012-10-13 14:47:46 +02:00
$sortfield = GETPOST ( " sortfield " , 'alpha' );
$sortorder = GETPOST ( " sortorder " , 'alpha' );
$page = GETPOST ( " page " , 'int' );
2012-09-07 17:23:16 +02:00
$page = is_numeric ( $page ) ? $page : 0 ;
$page = $page == - 1 ? 0 : $page ;
if ( ! $sortfield ) $sortfield = " cp.rowid " ;
if ( ! $sortorder ) $sortorder = " DESC " ;
$offset = $conf -> liste_limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2014-09-13 19:04:25 +02:00
$id = GETPOST ( 'id' , 'int' );
2013-02-17 19:25:55 +01:00
2012-09-07 17:23:16 +02:00
$search_ref = GETPOST ( 'search_ref' );
$month_create = GETPOST ( 'month_create' );
$year_create = GETPOST ( 'year_create' );
$month_start = GETPOST ( 'month_start' );
$year_start = GETPOST ( 'year_start' );
$month_end = GETPOST ( 'month_end' );
$year_end = GETPOST ( 'year_end' );
$search_employe = GETPOST ( 'search_employe' );
$search_valideur = GETPOST ( 'search_valideur' );
$search_statut = GETPOST ( 'select_statut' );
2012-09-05 12:59:33 +02:00
2014-11-23 09:30:32 +01:00
if ( GETPOST ( " button_removefilter_x " ) || GETPOST ( " button_removefilter " )) // Both test are required to be compatible with all browsers
2014-11-02 21:28:02 +01:00
{
$search_ref = " " ;
$month_create = " " ;
$year_create = " " ;
$month_start = " " ;
$year_start = " " ;
$month_end = " " ;
$year_end = " " ;
$search_employe = " " ;
$search_valideur = " " ;
$search_statut = " " ;
}
2012-09-05 03:26:57 +02:00
/*
* Actions
*/
// None
/*
* View
*/
2012-12-18 13:12:11 +01:00
$holiday = new Holiday ( $db );
$holidaystatic = new Holiday ( $db );
2013-03-30 14:27:13 +01:00
$fuser = new User ( $db );
2012-12-18 13:12:11 +01:00
2013-02-01 10:13:42 +01:00
// Update sold
$holiday -> updateSold ();
2012-09-05 03:26:57 +02:00
$max_year = 5 ;
2012-09-05 03:57:26 +02:00
$min_year = 10 ;
2012-11-14 11:29:22 +01:00
$filter = '' ;
2012-09-05 03:26:57 +02:00
2012-09-05 12:59:33 +02:00
llxHeader ( array (), $langs -> trans ( 'CPTitreMenu' ));
2012-09-07 17:23:16 +02:00
$order = $db -> order ( $sortfield , $sortorder ) . $db -> plimit ( $conf -> liste_limit + 1 , $offset );
2012-09-05 03:26:57 +02:00
// WHERE
2012-12-02 18:21:26 +01:00
if ( ! empty ( $search_ref ))
{
$filter .= " AND cp.rowid LIKE '% " . $db -> escape ( $search_ref ) . " %' \n " ;
2012-09-05 03:26:57 +02:00
}
// DATE START
if ( $year_start > 0 ) {
if ( $month_start > 0 ) {
2013-03-01 23:30:07 +01:00
$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 )) . " ') " ;
//$filter.= " AND date_format(cp.date_debut, '%Y-%m') = '$year_start-$month_start'";
2012-09-05 03:26:57 +02:00
} else {
2013-03-01 23:30:07 +01:00
$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 )) . " ') " ;
//$filter.= " AND date_format(cp.date_debut, '%Y') = '$year_start'";
2012-09-05 03:26:57 +02:00
}
} else {
if ( $month_start > 0 ) {
$filter .= " AND date_format(cp.date_debut, '%m') = ' $month_start ' " ;
}
}
// DATE FIN
if ( $year_end > 0 ) {
if ( $month_end > 0 ) {
2013-03-01 23:30:07 +01:00
$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 )) . " ') " ;
//$filter.= " AND date_format(cp.date_fin, '%Y-%m') = '$year_end-$month_end'";
2012-09-05 03:26:57 +02:00
} else {
2013-03-01 23:30:07 +01:00
$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 )) . " ') " ;
//$filter.= " AND date_format(cp.date_fin, '%Y') = '$year_end'";
2012-09-05 03:26:57 +02:00
}
} else {
if ( $month_end > 0 ) {
$filter .= " AND date_format(cp.date_fin, '%m') = ' $month_end ' " ;
}
}
// DATE CREATE
if ( $year_create > 0 ) {
if ( $month_create > 0 ) {
2013-03-01 23:30:07 +01:00
$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 )) . " ') " ;
//$filter.= " AND date_format(cp.date_create, '%Y-%m') = '$year_create-$month_create'";
2012-09-05 03:26:57 +02:00
} else {
2013-03-01 23:30:07 +01:00
$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 )) . " ') " ;
//$filter.= " AND date_format(cp.date_create, '%Y') = '$year_create'";
2012-09-05 03:26:57 +02:00
}
} else {
if ( $month_create > 0 ) {
$filter .= " AND date_format(cp.date_create, '%m') = ' $month_create ' " ;
}
}
// EMPLOYE
if ( ! empty ( $search_employe ) && $search_employe != - 1 ) {
2012-12-02 18:21:26 +01:00
$filter .= " AND cp.fk_user = ' " . $db -> escape ( $search_employe ) . " ' \n " ;
2012-09-05 03:26:57 +02:00
}
// VALIDEUR
if ( ! empty ( $search_valideur ) && $search_valideur != - 1 ) {
2012-12-02 18:21:26 +01:00
$filter .= " AND cp.fk_validator = ' " . $db -> escape ( $search_valideur ) . " ' \n " ;
2012-09-05 03:26:57 +02:00
}
// STATUT
if ( ! empty ( $search_statut ) && $search_statut != - 1 ) {
2012-12-02 18:21:26 +01:00
$filter .= " AND cp.statut = ' " . $db -> escape ( $search_statut ) . " ' \n " ;
2012-09-05 03:26:57 +02:00
}
/*************************************
* Fin des filtres de recherche
*************************************/
// Récupération de l'ID de l'utilisateur
$user_id = $user -> id ;
2013-03-30 14:27:13 +01:00
if ( $id > 0 )
{
// Charge utilisateur edite
$fuser -> fetch ( $id );
2013-02-17 19:25:55 +01:00
$fuser -> getrights ();
2013-03-30 14:27:13 +01:00
$user_id = $fuser -> id ;
2013-02-17 19:25:55 +01:00
}
2012-09-05 03:26:57 +02:00
// Récupération des congés payés de l'utilisateur ou de tous les users
2014-05-07 15:03:05 +02:00
if ( ! $user -> rights -> holiday -> write_all || $id > 0 )
2012-09-05 03:26:57 +02:00
{
2013-02-17 19:25:55 +01:00
$holiday_payes = $holiday -> fetchByUser ( $user_id , $order , $filter );
2012-09-05 03:26:57 +02:00
}
else
{
$holiday_payes = $holiday -> fetchAll ( $order , $filter );
}
// Si erreur SQL
2012-12-02 18:21:26 +01:00
if ( $holiday_payes == '-1' )
2012-09-05 03:26:57 +02:00
{
print_fiche_titre ( $langs -> trans ( 'CPTitreMenu' ));
2014-05-10 15:50:32 +02:00
dol_print_error ( $db , $langs -> trans ( 'Error' ) . ' ' . $holiday -> error );
2012-09-05 03:26:57 +02:00
exit ();
}
/*************************************
* Affichage du tableau des congés payés
*************************************/
2013-03-30 14:27:13 +01:00
$var = true ; $num = count ( $holiday -> holiday );
$form = new Form ( $db );
$formother = new FormOther ( $db );
2012-09-05 03:26:57 +02:00
2013-02-17 19:25:55 +01:00
if ( $id > 0 )
{
2013-03-30 14:27:13 +01:00
$head = user_prepare_head ( $fuser );
$title = $langs -> trans ( " User " );
2013-02-17 19:25:55 +01:00
dol_fiche_head ( $head , 'paidholidays' , $title , 0 , 'user' );
2013-03-30 14:27:13 +01:00
print '<table class="border" width="100%">' ;
// Ref
print '<tr><td width="25%" valign="top">' . $langs -> trans ( " Ref " ) . '</td>' ;
print '<td colspan="2">' ;
print $form -> showrefnav ( $fuser , 'id' , '' , $user -> rights -> user -> user -> lire || $user -> admin );
print '</td>' ;
print '</tr>' ;
// LastName
print '<tr><td width="25%" valign="top">' . $langs -> trans ( " LastName " ) . '</td>' ;
print '<td colspan="2">' . $fuser -> lastname . '</td>' ;
print " </tr> \n " ;
// FirstName
print '<tr><td width="25%" valign="top">' . $langs -> trans ( " FirstName " ) . '</td>' ;
print '<td colspan="2">' . $fuser -> firstname . '</td>' ;
print " </tr> \n " ;
print '</table><br>' ;
2013-02-17 19:25:55 +01:00
}
else
{
print_barre_liste ( $langs -> trans ( " ListeCP " ), $page , $_SERVER [ " PHP_SELF " ], '' , $sortfield , $sortorder , " " , $num );
2012-09-05 03:26:57 +02:00
2014-03-17 14:30:55 +01:00
dol_fiche_head ( '' );
2013-02-17 19:25:55 +01:00
}
$nbaquis = $holiday -> getCPforUser ( $user_id );
2012-09-05 03:26:57 +02:00
$nbdeduced = $holiday -> getConfCP ( 'nbHolidayDeducted' );
$nb_holiday = $nbaquis / $nbdeduced ;
print $langs -> trans ( 'SoldeCPUser' , round ( $nb_holiday , 2 )) . ( $nbdeduced != 1 ? ' (' . $nbaquis . ' / ' . $nbdeduced . ')' : '' );
2013-04-21 17:56:29 +02:00
if ( $id > 0 )
{
dol_fiche_end ();
print '</br>' ;
}
else {
2014-03-17 14:30:55 +01:00
dol_fiche_end ();
2014-03-05 20:52:27 +01:00
}
2012-09-05 03:26:57 +02:00
print '<form method="get" action="' . $_SERVER [ " PHP_SELF " ] . '">' . " \n " ;
print '<table class="noborder" width="100%;">' ;
print " <tr class= \" liste_titre \" > " ;
2012-09-05 03:57:26 +02:00
print_liste_field_titre ( $langs -> trans ( " Ref " ), $_SERVER [ " PHP_SELF " ], " cp.rowid " , " " , '' , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " DateCreateCP " ), $_SERVER [ " PHP_SELF " ], " cp.date_create " , " " , '' , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " Employe " ), $_SERVER [ " PHP_SELF " ], " cp.fk_user " , " " , '' , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " ValidatorCP " ), $_SERVER [ " PHP_SELF " ], " cp.fk_validator " , " " , '' , '' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " DateDebCP " ), $_SERVER [ " PHP_SELF " ], " cp.date_debut " , " " , '' , 'align="center"' , $sortfield , $sortorder );
print_liste_field_titre ( $langs -> trans ( " DateFinCP " ), $_SERVER [ " PHP_SELF " ], " cp.date_fin " , " " , '' , 'align="center"' , $sortfield , $sortorder );
2014-11-02 21:28:02 +01:00
print_liste_field_titre ( $langs -> trans ( " Duration " ), $_SERVER [ " PHP_SELF " ], '' , '' , '' , 'align="center"' , $sortfield , $sortorder );
2013-04-15 00:18:08 +02:00
print_liste_field_titre ( $langs -> trans ( " Status " ), $_SERVER [ " PHP_SELF " ], " cp.statut " , " " , '' , 'align="center"' , $sortfield , $sortorder );
2013-04-29 22:09:47 +02:00
print '<td></td>' ;
2012-09-05 03:26:57 +02:00
print " </tr> \n " ;
// FILTRES
print '<tr class="liste_titre">' ;
print '<td class="liste_titre" align="left" width="50">' ;
2012-09-05 12:59:33 +02:00
print '<input class="flat" size="4" type="text" name="search_ref" value="' . $search_ref . '">' ;
2013-09-13 10:40:49 +02:00
print '</td>' ;
2012-09-05 03:26:57 +02:00
// DATE CREATE
print '<td class="liste_titre" colspan="1" align="center">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="month_create" value="' . $month_create . '">' ;
2013-05-12 11:38:17 +02:00
$formother -> select_year ( $year_create , 'year_create' , 1 , $min_year , 0 );
2012-09-05 03:26:57 +02:00
print '</td>' ;
// UTILISATEUR
2014-05-07 15:03:05 +02:00
if ( $user -> rights -> holiday -> write_all ) {
2012-09-05 03:26:57 +02:00
print '<td class="liste_titre" align="left">' ;
2013-02-17 19:25:55 +01:00
$form -> select_users ( $search_employe , " search_employe " , 1 , " " , 0 , '' );
2012-09-05 03:26:57 +02:00
print '</td>' ;
} else {
print '<td class="liste_titre"> </td>' ;
}
// VALIDEUR
2014-05-07 15:03:05 +02:00
if ( $user -> rights -> holiday -> write_all )
2013-04-15 12:39:34 +02:00
{
2012-09-05 03:26:57 +02:00
print '<td class="liste_titre" align="left">' ;
2013-04-29 18:01:26 +02:00
$validator = new UserGroup ( $db );
$excludefilter = $user -> admin ? '' : 'u.rowid <> ' . $user -> id ;
$valideurobjects = $validator -> listUsersForGroup ( $excludefilter );
$valideurarray = array ();
foreach ( $valideurobjects as $val ) $valideurarray [ $val -> id ] = $val -> id ;
2013-04-15 12:39:34 +02:00
$form -> select_users ( $search_valideur , " search_valideur " , 1 , " " , 0 , $valideurarray , '' );
2012-09-05 03:26:57 +02:00
print '</td>' ;
2013-04-15 12:39:34 +02:00
}
2014-03-05 20:52:27 +01:00
else
2013-04-15 12:39:34 +02:00
{
2012-09-05 03:26:57 +02:00
print '<td class="liste_titre"> </td>' ;
}
// DATE DEBUT
print '<td class="liste_titre" colspan="1" align="center">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="month_start" value="' . $month_start . '">' ;
2013-02-17 19:25:55 +01:00
$formother -> select_year ( $year_start , 'year_start' , 1 , $min_year , $max_year );
2012-09-05 03:26:57 +02:00
print '</td>' ;
// DATE FIN
print '<td class="liste_titre" colspan="1" align="center">' ;
print '<input class="flat" type="text" size="1" maxlength="2" name="month_end" value="' . $month_end . '">' ;
2013-02-17 19:25:55 +01:00
$formother -> select_year ( $year_end , 'year_end' , 1 , $min_year , $max_year );
2012-09-05 03:26:57 +02:00
print '</td>' ;
// DUREE
print '<td> </td>' ;
// STATUT
print '<td class="liste_titre" width="70px;" align="center">' ;
$holiday -> selectStatutCP ( $search_statut );
2013-04-29 22:09:47 +02:00
print '</td>' ;
2013-09-13 10:40:49 +02:00
2013-04-29 22:09:47 +02:00
// ACTION
2013-09-13 10:40:49 +02:00
print '<td align="right">' ;
2014-11-02 21:28:02 +01:00
print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto ( $langs -> trans ( " Search " ), 'search.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " Search " )) . '">' ;
print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto ( $langs -> trans ( " Search " ), 'searchclear.png' , '' , '' , 1 ) . '" value="' . dol_escape_htmltag ( $langs -> trans ( " RemoveFilter " )) . '" title="' . dol_escape_htmltag ( $langs -> trans ( " RemoveFilter " )) . '">' ;
2013-09-13 10:40:49 +02:00
print '</td>' ;
print " </tr> \n " ;
2012-09-05 03:26:57 +02:00
2012-12-18 13:12:11 +01:00
// Lines
2012-09-05 03:26:57 +02:00
if ( ! empty ( $holiday -> holiday ))
{
2012-12-18 13:12:11 +01:00
$userstatic = new User ( $db );
$approbatorstatic = new User ( $db );
2012-12-19 20:59:08 +01:00
2012-09-05 03:26:57 +02:00
foreach ( $holiday -> holiday as $infos_CP )
{
$var =! $var ;
// Utilisateur
2012-12-18 13:12:11 +01:00
$userstatic -> id = $infos_CP [ 'fk_user' ];
$userstatic -> lastname = $infos_CP [ 'user_lastname' ];
$userstatic -> firstname = $infos_CP [ 'user_firstname' ];
2012-09-05 03:26:57 +02:00
// Valideur
2012-12-18 13:12:11 +01:00
$approbatorstatic -> id = $infos_CP [ 'fk_validator' ];
2013-01-10 08:27:12 +01:00
$approbatorstatic -> lastname = $infos_CP [ 'validator_lastname' ];
$approbatorstatic -> firstname = $infos_CP [ 'validator_firstname' ];
2012-12-19 20:59:08 +01:00
2012-11-20 13:14:16 +01:00
$date = $infos_CP [ 'date_create' ];
2012-09-05 03:26:57 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2012-09-24 21:37:19 +02:00
print '<td>' ;
2012-12-18 13:12:11 +01:00
$holidaystatic -> id = $infos_CP [ 'rowid' ];
$holidaystatic -> ref = $infos_CP [ 'rowid' ];
print $holidaystatic -> getNomUrl ( 1 );
print '</td>' ;
print '<td style="text-align: center;">' . dol_print_date ( $date , 'day' ) . '</td>' ;
print '<td>' . $userstatic -> getNomUrl ( '1' ) . '</td>' ;
print '<td>' . $approbatorstatic -> getNomUrl ( '1' ) . '</td>' ;
print '<td align="center">' . dol_print_date ( $infos_CP [ 'date_debut' ], 'day' ) . '</td>' ;
print '<td align="center">' . dol_print_date ( $infos_CP [ 'date_fin' ], 'day' ) . '</td>' ;
print '<td align="right">' ;
2014-03-05 20:52:27 +01:00
$nbopenedday = num_open_day ( $infos_CP [ 'date_debut_gmt' ], $infos_CP [ 'date_fin_gmt' ], 0 , 1 , $infos_CP [ 'halfday' ]);
2013-04-29 18:01:26 +02:00
print $nbopenedday . ' ' . $langs -> trans ( 'DurationDays' );
2013-09-13 10:40:49 +02:00
print '<td align="right" colspan="2">' . $holidaystatic -> LibStatut ( $infos_CP [ 'statut' ], 5 ) . '</td>' ;
2012-09-05 03:26:57 +02:00
print '</tr>' . " \n " ;
}
}
// Si il n'y a pas d'enregistrement suite à une recherche
if ( $holiday_payes == '2' )
{
print '<tr>' ;
2013-09-13 10:40:49 +02:00
print '<td colspan="9" class="pair" style="text-align: center; padding: 5px;">' . $langs -> trans ( 'None' ) . '</td>' ;
2012-09-05 03:26:57 +02:00
print '</tr>' ;
}
print '</table>' ;
print '</form>' ;
2013-02-17 19:25:55 +01:00
if ( $user_id == $user -> id )
{
print '<br>' ;
print '<div style="float: right; margin-top: 8px;">' ;
2014-09-18 21:18:25 +02:00
print '<a href="./card.php?action=request" class="butAction">' . $langs -> trans ( 'AddCP' ) . '</a>' ;
2013-02-17 19:25:55 +01:00
print '</div>' ;
}
2012-09-05 03:26:57 +02:00
llxFooter ();
2012-12-02 18:21:26 +01:00
$db -> close ();