2012-09-05 03:26:57 +02:00
< ? php
2016-03-14 21:22:49 +01:00
/* Copyright ( C ) 2007 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2016-03-03 08:41:39 +01:00
* Copyright ( C ) 2011 Dimitri Mouillard < dmouillard @ teclib . com >
* Copyright ( C ) 2013 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2016 Regis Houssin < regis . houssin @ capnetworks . com >
2013-05-04 20:09:39 +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
* the Free Software Foundation ; either version 3 of the License , or
* ( 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 .
*
2012-09-05 03:57:26 +02:00
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2017-08-02 13:31:53 +02:00
*/
2012-09-05 03:26:57 +02:00
/**
* File that defines the balance of paid holiday of users .
*
2012-12-20 20:16:10 +01:00
* \file htdocs / holiday / define_holiday . php
2012-09-05 03:26:57 +02:00
* \ingroup holiday
* \brief File that defines the balance of paid holiday of users .
*/
2012-09-06 10:39:25 +02:00
require ( '../main.inc.php' );
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/holiday/common.inc.php' ;
2012-09-05 03:26:57 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
$langs -> loadlangs ( array ( 'users' , 'hrm' ));
2017-06-13 15:34:18 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2018-03-31 18:48:27 +02:00
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'defineholidaylist' ;
2017-06-13 15:34:18 +02:00
$search_name = GETPOST ( 'search_name' , 'alpha' );
2017-10-02 17:45:01 +02:00
$search_supervisor = GETPOST ( 'search_supervisor' , 'int' );
2017-06-13 15:34:18 +02:00
// Load variable for pagination
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
$sortfield = GETPOST ( 'sortfield' , 'alpha' );
$sortorder = GETPOST ( 'sortorder' , 'alpha' );
$page = GETPOST ( 'page' , 'int' );
if ( empty ( $page ) || $page == - 1 ) { $page = 0 ; } // If $page is not defined, or '' or -1
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
if ( ! $sortfield ) $sortfield = " t.rowid " ; // Set here default search field
if ( ! $sortorder ) $sortorder = " ASC " ;
2012-09-05 03:26:57 +02:00
// Protection if external user
if ( $user -> societe_id > 0 ) accessforbidden ();
2013-05-04 20:09:39 +02:00
// If the user does not have perm to read the page
2017-10-02 18:17:16 +02:00
if ( ! $user -> rights -> holiday -> read ) accessforbidden ();
2012-09-05 03:26:57 +02:00
2012-09-05 03:57:26 +02:00
2017-06-13 15:34:18 +02:00
// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
$hookmanager -> initHooks ( array ( 'defineholidaylist' ));
$extrafields = new ExtraFields ( $db );
$holiday = new Holiday ( $db );
2015-06-27 11:45:23 +02:00
2012-09-05 12:59:33 +02:00
2015-06-21 03:19:15 +02:00
/*
* Actions
*/
2012-09-05 03:26:57 +02:00
2017-09-15 10:50:50 +02:00
if ( GETPOST ( 'cancel' , 'alpha' )) { $action = 'list' ; $massaction = '' ; }
if ( ! GETPOST ( 'confirmmassaction' , 'alpha' ) && $massaction != 'presend' && $massaction != 'confirm_presend' ) { $massaction = '' ; }
2015-06-21 03:19:15 +02:00
2017-06-13 15:34:18 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2015-06-21 03:19:15 +02:00
2017-06-13 15:34:18 +02:00
if ( empty ( $reshook ))
{
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
2012-09-05 03:26:57 +02:00
2017-06-13 15:34:18 +02:00
// Purge search criteria
2017-07-13 00:35:10 +02:00
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
2015-06-21 03:19:15 +02:00
{
2017-06-13 15:34:18 +02:00
$search_name = '' ;
2017-10-02 17:45:01 +02:00
$search_supervisor = '' ;
2017-06-13 15:34:18 +02:00
$toselect = '' ;
$search_array_options = array ();
2012-09-05 03:26:57 +02:00
}
2017-06-13 15:34:18 +02:00
// Mass actions
/*
$objectclass = 'Skeleton' ;
$objectlabel = 'Skeleton' ;
$permtoread = $user -> rights -> skeleton -> read ;
$permtodelete = $user -> rights -> skeleton -> delete ;
$uploaddir = $conf -> skeleton -> dir_output ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
*/
// Si il y a une action de mise à jour
if ( $action == 'update' && isset ( $_POST [ 'update_cp' ]))
{
$error = 0 ;
$typeleaves = $holiday -> getTypes ( 1 , 1 );
$userID = array_keys ( $_POST [ 'update_cp' ]);
$userID = $userID [ 0 ];
foreach ( $typeleaves as $key => $val )
{
$userValue = $_POST [ 'nb_holiday_' . $val [ 'rowid' ]];
$userValue = $userValue [ $userID ];
2018-02-20 14:53:19 +01:00
if ( ! empty ( $userValue ) || ( string ) $userValue == '0' )
2017-06-13 15:34:18 +02:00
{
$userValue = price2num ( $userValue , 5 );
} else {
$userValue = '' ;
}
//If the user set a comment, we add it to the log comment
$comment = (( isset ( $_POST [ 'note_holiday' ][ $userID ]) && ! empty ( $_POST [ 'note_holiday' ][ $userID ])) ? ' (' . $_POST [ 'note_holiday' ][ $userID ] . ')' : '' );
2018-02-26 15:03:09 +01:00
//print 'holiday: '.$val['rowid'].'-'.$userValue;
2017-06-13 15:34:18 +02:00
if ( $userValue != '' )
{
// We add the modification to the log (must be before update of sold because we read current value of sold)
$result = $holiday -> addLogCP ( $user -> id , $userID , $langs -> transnoentitiesnoconv ( 'ManualUpdate' ) . $comment , $userValue , $val [ 'rowid' ]);
if ( $result < 0 )
{
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
$error ++ ;
}
// Update of the days of the employee
$result = $holiday -> updateSoldeCP ( $userID , $userValue , $val [ 'rowid' ]);
if ( $result < 0 )
{
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
$error ++ ;
}
// If it first update of balance, we set date to avoid to have sold incremented by new month
/*
$now = dol_now ();
$sql = " UPDATE " . MAIN_DB_PREFIX . " holiday_config SET " ;
$sql .= " value = ' " . dol_print_date ( $now , '%Y%m%d%H%M%S' ) . " ' " ;
$sql .= " WHERE name = 'lastUpdate' and value IS NULL " ; // Add value IS NULL to be sure to update only at init.
dol_syslog ( 'define_holiday update lastUpdate entry' , LOG_DEBUG );
$result = $db -> query ( $sql );
*/
}
}
if ( ! $error ) setEventMessages ( 'UpdateConfCPOK' , '' , 'mesgs' );
}
2012-09-05 03:57:26 +02:00
}
2012-09-05 03:26:57 +02:00
2015-06-21 03:19:15 +02:00
/*
* View
*/
$form = new Form ( $db );
$userstatic = new User ( $db );
2016-04-09 16:04:07 +02:00
llxHeader ( '' , $langs -> trans ( 'CPTitreMenu' ));
2015-06-21 03:19:15 +02:00
2017-06-13 15:34:18 +02:00
2018-02-20 14:53:19 +01:00
$typeleaves = $holiday -> getTypes ( 1 , 1 );
2017-06-13 15:34:18 +02:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
if ( $optioncss != '' ) print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">' ;
2018-02-20 14:53:19 +01:00
print '<input type="hidden" name="action" value="update">' ;
2017-06-13 15:34:18 +02:00
print '<input type="hidden" name="sortfield" value="' . $sortfield . '">' ;
print '<input type="hidden" name="sortorder" value="' . $sortorder . '">' ;
print '<input type="hidden" name="page" value="' . $page . '">' ;
print '<input type="hidden" name="contextpage" value="' . $contextpage . '">' ;
2015-09-24 18:33:48 +02:00
print load_fiche_titre ( $langs -> trans ( 'MenuConfCP' ), '' , 'title_hrm.png' );
2015-06-21 03:19:15 +02:00
2015-06-27 11:45:23 +02:00
print '<div class="info">' . $langs -> trans ( 'LastUpdateCP' ) . ': ' . " \n " ;
2016-01-10 11:31:22 +01:00
$lastUpdate = $holiday -> getConfCP ( 'lastUpdate' );
2016-03-03 08:41:39 +01:00
if ( $lastUpdate )
2016-01-09 01:54:10 +01:00
{
$monthLastUpdate = $lastUpdate [ 4 ] . $lastUpdate [ 5 ];
$yearLastUpdate = $lastUpdate [ 0 ] . $lastUpdate [ 1 ] . $lastUpdate [ 2 ] . $lastUpdate [ 3 ];
print '<strong>' . dol_print_date ( $db -> jdate ( $holiday -> getConfCP ( 'lastUpdate' )), 'dayhour' , 'tzuser' ) . '</strong>' ;
print '<br>' . $langs -> trans ( " MonthOfLastMonthlyUpdate " ) . ': <strong>' . $yearLastUpdate . '-' . $monthLastUpdate . '</strong>' . " \n " ;
}
2015-06-27 11:45:23 +02:00
else print $langs -> trans ( 'None' );
print " </div><br> \n " ;
$result = $holiday -> updateBalance (); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user.
if ( $result < 0 )
{
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
}
2015-06-21 03:19:15 +02:00
2017-10-02 18:17:16 +02:00
$filters = '' ;
// Filter on array of ids of all childs
$userchilds = array ();
if ( empty ( $user -> rights -> holiday -> read_all ))
{
$userchilds = $user -> getAllChildIds ( 1 );
$filters .= ' AND u.rowid IN (' . join ( ', ' , $userchilds ) . ')' ;
}
2018-03-09 11:37:23 +01:00
if ( ! empty ( $search_name )) {
$filters .= natural_search ( array ( 'u.firstname' , 'u.lastname' ), $search_name );
}
2017-10-02 17:45:01 +02:00
if ( $search_supervisor > 0 ) $filters .= natural_search ( array ( 'u.fk_user' ), $search_supervisor , 2 );
2018-03-21 11:13:28 +01:00
$filters .= ' AND employee = 1' ; // Only employee users are visible
2017-06-13 15:34:18 +02:00
2017-10-02 17:45:01 +02:00
$listUsers = $holiday -> fetchUsers ( false , true , $filters );
2016-04-23 17:35:33 +02:00
if ( is_numeric ( $listUsers ) && $listUsers < 0 )
{
2017-06-13 15:34:18 +02:00
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
2016-04-23 17:35:33 +02:00
}
2015-06-21 03:19:15 +02:00
2012-09-05 03:26:57 +02:00
$i = 0 ;
2015-06-21 03:19:15 +02:00
2016-01-09 01:18:53 +01:00
if ( count ( $typeleaves ) == 0 )
2015-06-21 03:19:15 +02:00
{
2016-01-09 01:18:53 +01:00
//print '<div class="info">';
print $langs -> trans ( " NoLeaveWithCounterDefined " ) . " <br> \n " ;
print $langs -> trans ( " GoIntoDictionaryHolidayTypes " );
//print '</div>';
2015-06-21 03:19:15 +02:00
}
2016-01-09 01:18:53 +01:00
else
2012-09-05 03:26:57 +02:00
{
2016-03-14 21:31:22 +01:00
$canedit = 0 ;
if ( ! empty ( $user -> rights -> holiday -> define_holiday )) $canedit = 1 ;
2017-06-13 15:34:18 +02:00
2016-11-27 13:49:46 +01:00
$moreforfilter = '' ;
2017-06-13 15:34:18 +02:00
2016-11-27 13:49:46 +01:00
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '" id="tablelines3">' . " \n " ;
2017-06-13 15:34:18 +02:00
print '<tr class="liste_titre_filter">' ;
2017-10-02 17:45:01 +02:00
// User
2017-06-13 15:34:18 +02:00
print '<td class="liste_titre"><input type="text" name="search_name" value="' . dol_escape_htmltag ( $search_name ) . '"></td>' ;
2017-10-02 17:45:01 +02:00
// Supervisor
print '<td class="liste_titre">' ;
print $form -> select_dolusers ( $search_supervisor , 'search_supervisor' , 1 , null , 0 , null , null , 0 , 0 , 0 , '' , 0 , '' , 'maxwidth200' );
print '</td>' ;
// Type of leave request
2016-01-09 01:18:53 +01:00
if ( count ( $typeleaves ))
{
foreach ( $typeleaves as $key => $val )
{
2017-06-13 15:34:18 +02:00
print '<td class="liste_titre" style="text-align:center"></td>' ;
2016-01-09 01:18:53 +01:00
}
}
else
{
2017-06-13 15:34:18 +02:00
print '<td class="liste_titre"></td>' ;
2016-01-09 01:18:53 +01:00
}
2017-06-13 15:34:18 +02:00
print '<td class="liste_titre"></td>' ;
// Action column
print '<td class="liste_titre" align="right">' ;
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
print '</td>' ;
2012-09-05 03:26:57 +02:00
print '</tr>' ;
2017-06-13 15:34:18 +02:00
2016-12-22 16:09:12 +01:00
print '<tr class="liste_titre">' ;
2017-08-02 13:31:53 +02:00
print_liste_field_titre ( 'Employee' , $_SERVER [ " PHP_SELF " ]);
2017-10-02 17:45:01 +02:00
print_liste_field_titre ( 'Supervisor' , $_SERVER [ " PHP_SELF " ]);
2016-12-22 16:09:12 +01:00
if ( count ( $typeleaves ))
{
foreach ( $typeleaves as $key => $val )
{
2018-03-19 13:55:26 +01:00
$labeltype = ( $langs -> trans ( $val [ 'code' ]) != $val [ 'code' ]) ? $langs -> trans ( $val [ 'code' ]) : $langs -> trans ( $val [ 'label' ]);
print_liste_field_titre ( $labeltype , $_SERVER [ " PHP_SELF " ], '' , '' , '' , 'align="center"' );
2016-12-22 16:09:12 +01:00
}
}
else
{
2017-10-03 10:08:25 +02:00
print_liste_field_titre ( 'NoLeaveWithCounterDefined' , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' );
2016-12-22 16:09:12 +01:00
}
2017-10-03 10:08:25 +02:00
print_liste_field_titre (( empty ( $user -> rights -> holiday -> define_holiday ) ? '' : 'Note' ), $_SERVER [ " PHP_SELF " ]);
2017-06-13 15:34:18 +02:00
print_liste_field_titre ( '' );
2016-12-22 16:09:12 +01:00
print '</tr>' ;
2017-06-13 15:34:18 +02:00
2017-10-02 17:45:01 +02:00
$usersupervisor = new User ( $db );
2017-06-13 15:34:18 +02:00
2016-01-09 01:18:53 +01:00
foreach ( $listUsers as $users )
{
2016-03-14 21:22:49 +01:00
// If user has not permission to edit/read all, we must see only subordinates
2017-06-13 15:34:18 +02:00
if ( empty ( $user -> rights -> holiday -> read_all ))
2016-03-14 21:22:49 +01:00
{
if (( $users [ 'rowid' ] != $user -> id ) && ( ! in_array ( $users [ 'rowid' ], $userchilds ))) continue ; // This user is not into hierarchy of current user, we hide it.
}
2017-06-13 15:34:18 +02:00
2016-01-09 01:18:53 +01:00
$userstatic -> id = $users [ 'rowid' ];
2016-04-23 17:35:33 +02:00
$userstatic -> lastname = $users [ 'lastname' ];
2016-01-09 01:18:53 +01:00
$userstatic -> firstname = $users [ 'firstname' ];
2016-04-23 17:35:33 +02:00
$userstatic -> gender = $users [ 'gender' ];
$userstatic -> photo = $users [ 'photo' ];
$userstatic -> statut = $users [ 'status' ];
$userstatic -> employee = $users [ 'employee' ];
2017-10-02 17:45:01 +02:00
$userstatic -> fk_user = $users [ 'fk_user' ];
if ( $userstatic -> fk_user > 0 ) $usersupervisor -> fetch ( $userstatic -> fk_user );
print '<tr class="oddeven">' ;
// User
print '<td>' ;
2016-04-23 17:35:33 +02:00
print $userstatic -> getNomUrl ( - 1 );
2016-01-09 01:18:53 +01:00
print '</td>' ;
2016-03-03 08:41:39 +01:00
2017-10-02 17:45:01 +02:00
// Supervisor
print '<td>' ;
if ( $userstatic -> fk_user > 0 ) print $usersupervisor -> getNomUrl ( - 1 );
print '</td>' ;
2017-01-22 16:03:08 +01:00
// Amount for each type
2016-01-09 01:18:53 +01:00
if ( count ( $typeleaves ))
{
foreach ( $typeleaves as $key => $val )
{
$nbtoshow = '' ;
if ( $holiday -> getCPforUser ( $users [ 'rowid' ], $val [ 'rowid' ]) != '' ) $nbtoshow = price2num ( $holiday -> getCPforUser ( $users [ 'rowid' ], $val [ 'rowid' ]), 5 );
2017-10-02 17:45:01 +02:00
//var_dump($users['rowid'].' - '.$val['rowid']);
2016-01-09 01:18:53 +01:00
print '<td style="text-align:center">' ;
2016-03-14 21:31:22 +01:00
if ( $canedit ) print '<input type="text"' . ( $canedit ? '' : ' disabled="disabled"' ) . ' value="' . $nbtoshow . '" name="nb_holiday_' . $val [ 'rowid' ] . '[' . $users [ 'rowid' ] . ']" size="5" style="text-align: center;"/>' ;
else print $nbtoshow ;
2016-01-09 01:18:53 +01:00
//print ' '.$langs->trans('days');
print '</td>' . " \n " ;
}
}
else
{
2016-03-03 08:41:39 +01:00
print '<td></td>' ;
2016-01-09 01:18:53 +01:00
}
2017-06-13 15:34:18 +02:00
2017-01-22 16:03:08 +01:00
// Note
2017-10-02 17:45:01 +02:00
print '<td>' ;
2017-01-22 16:03:08 +01:00
if ( $canedit ) print '<input type="text"' . ( $canedit ? '' : ' disabled="disabled"' ) . ' class="maxwidthonsmartphone" value="" name="note_holiday[' . $users [ 'rowid' ] . ']" size="30"/>' ;
2016-03-14 21:31:22 +01:00
print '</td>' ;
2018-03-31 18:48:27 +02:00
2018-03-21 11:13:28 +01:00
// Button modify
2016-03-14 21:31:22 +01:00
print '<td>' ;
2018-03-21 11:13:28 +01:00
if ( ! empty ( $user -> rights -> holiday -> define_holiday )) // Allowed to set the balance of any user
2016-03-14 21:31:22 +01:00
{
print '<input type="submit" name="update_cp[' . $users [ 'rowid' ] . ']" value="' . dol_escape_htmltag ( $langs -> trans ( " Update " )) . '" class="button"/>' ;
}
print '</td>' . " \n " ;
2016-01-09 01:18:53 +01:00
print '</tr>' ;
2016-03-03 08:41:39 +01:00
2016-01-09 01:18:53 +01:00
$i ++ ;
}
2016-03-03 08:41:39 +01:00
2016-01-09 01:18:53 +01:00
print '</table>' ;
2016-11-27 13:49:46 +01:00
print '</div>' ;
2012-09-05 03:26:57 +02:00
}
2017-06-13 15:34:18 +02:00
print '</form>' ;
2012-09-05 12:59:33 +02:00
llxFooter ();
2012-09-05 03:26:57 +02:00
$db -> close ();