2012-09-05 03:26:57 +02:00
< ? php
2022-08-12 15:07:15 +02:00
/* Copyright ( C ) 2007 - 2022 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 >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2016 Regis Houssin < regis . houssin @ inodbox . 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// 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 .
*/
2018-07-26 11:57:25 +02:00
require '../main.inc.php' ;
2012-09-06 10:39:25 +02:00
require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php' ;
2020-12-04 14:53:52 +01:00
require_once DOL_DOCUMENT_ROOT . '/holiday/class/holiday.class.php' ;
2012-09-05 03:26:57 +02:00
2018-05-26 21:11:25 +02:00
// Load translation files required by the page
2020-12-04 14:53:52 +01:00
$langs -> loadlangs ( array ( 'users' , 'other' , 'holiday' , 'hrm' ));
2017-06-13 15:34:18 +02:00
2020-04-10 10:59:32 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
$contextpage = GETPOST ( 'contextpage' , 'aZ' ) ? GETPOST ( 'contextpage' , 'aZ' ) : 'defineholidaylist' ;
2022-06-02 11:14:35 +02:00
$massaction = GETPOST ( 'massaction' , 'alpha' );
$optioncss = GETPOST ( 'optioncss' , 'alpha' );
2017-06-13 15:34:18 +02:00
2020-04-10 10:59:32 +02:00
$search_name = GETPOST ( 'search_name' , 'alpha' );
$search_supervisor = GETPOST ( 'search_supervisor' , 'int' );
2017-06-13 15:34:18 +02:00
// Load variable for pagination
2020-04-10 10:59:32 +02:00
$limit = GETPOST ( 'limit' , 'int' ) ? GETPOST ( 'limit' , 'int' ) : $conf -> liste_limit ;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-26 17:59:31 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2017-06-13 15:34:18 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-26 17:59:31 +01:00
if ( ! $sortfield ) {
$sortfield = " t.rowid " ; // Set here default search field
}
if ( ! $sortorder ) {
$sortorder = " ASC " ;
}
2017-06-13 15:34:18 +02:00
2012-09-05 03:26:57 +02:00
// Protection if external user
2021-02-26 17:59:31 +01:00
if ( $user -> socid > 0 ) {
accessforbidden ();
}
2012-09-05 03:26:57 +02:00
2013-05-04 20:09:39 +02:00
// If the user does not have perm to read the page
2021-02-26 17:59:31 +01:00
if ( empty ( $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
2021-02-26 17:59:31 +01:00
if ( empty ( $conf -> holiday -> enabled )) {
2020-12-04 14:53:52 +01:00
llxHeader ( '' , $langs -> trans ( 'CPTitreMenu' ));
print '<div class="tabBar">' ;
print '<span style="color: #FF0000;">' . $langs -> trans ( 'NotActiveModCP' ) . '</span>' ;
print '</div>' ;
llxFooter ();
exit ();
}
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
2021-02-26 17:59:31 +01: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
2020-04-10 10:59:32 +02:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-02-26 17:59:31 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2015-06-21 03:19:15 +02:00
2021-02-26 17:59:31 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
// Selection of new fields
include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php' ;
// Purge search criteria
2021-02-26 17:59:31 +01: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
2020-10-31 14:32:18 +01:00
$search_name = '' ;
$search_supervisor = '' ;
2022-05-08 18:25:22 +02:00
$toselect = array ();
2020-10-31 14:32:18 +01:00
$search_array_options = array ();
}
// Mass actions
/*
2021-02-26 17:59:31 +01:00
$objectclass = 'Skeleton' ;
$objectlabel = 'Skeleton' ;
$permissiontoread = $user -> rights -> skeleton -> read ;
$permissiontodelete = $user -> rights -> skeleton -> delete ;
$uploaddir = $conf -> skeleton -> dir_output ;
include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php' ;
*/
2017-06-13 15:34:18 +02:00
2020-10-31 14:32:18 +01:00
// Si il y a une action de mise à jour
2021-06-15 16:29:42 +02:00
if ( $action == 'update' && GETPOSTISSET ( 'update_cp' )) {
2020-10-31 14:32:18 +01:00
$error = 0 ;
2022-08-12 15:07:15 +02:00
$nbok = 0 ;
2020-10-31 14:32:18 +01:00
$typeleaves = $holiday -> getTypes ( 1 , 1 );
2021-06-15 16:29:42 +02:00
$userID = array_keys ( GETPOST ( 'update_cp' ));
2020-10-31 14:32:18 +01:00
$userID = $userID [ 0 ];
2022-08-12 15:07:15 +02:00
$db -> begin ();
2021-02-26 17:59:31 +01:00
foreach ( $typeleaves as $key => $val ) {
2021-06-15 16:29:42 +02:00
$userValue = GETPOST ( 'nb_holiday_' . $val [ 'rowid' ]);
2020-10-31 14:32:18 +01:00
$userValue = $userValue [ $userID ];
2021-02-26 17:59:31 +01:00
if ( ! empty ( $userValue ) || ( string ) $userValue == '0' ) {
2020-10-31 14:32:18 +01:00
$userValue = price2num ( $userValue , 5 );
} else {
$userValue = '' ;
}
//If the user set a comment, we add it to the log comment
2022-02-22 23:44:56 +01:00
$note_holiday = GETPOST ( 'note_holiday' );
$comment = (( isset ( $note_holiday [ $userID ]) && ! empty ( $note_holiday [ $userID ])) ? ' (' . $note_holiday [ $userID ] . ')' : '' );
2020-10-31 14:32:18 +01:00
2022-08-12 15:07:15 +02:00
//print 'holiday: '.$val['rowid'].'-'.$userValue;exit;
2021-02-26 17:59:31 +01:00
if ( $userValue != '' ) {
2022-08-12 15:07:15 +02:00
// We add the modification to the log (must be done before the update of balance because we read current value of balance inside this method)
2020-10-31 14:32:18 +01:00
$result = $holiday -> addLogCP ( $user -> id , $userID , $langs -> transnoentitiesnoconv ( 'ManualUpdate' ) . $comment , $userValue , $val [ 'rowid' ]);
2021-02-26 17:59:31 +01:00
if ( $result < 0 ) {
2020-10-31 14:32:18 +01:00
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
$error ++ ;
2022-08-12 15:07:15 +02:00
} elseif ( $result == 0 ) {
setEventMessages ( $langs -> trans ( " HolidayQtyNotModified " , $user -> login ), null , 'warnings' );
2020-10-31 14:32:18 +01:00
}
// Update of the days of the employee
2022-08-12 15:07:15 +02:00
if ( $result > 0 ) {
$nbok ++ ;
$result = $holiday -> updateSoldeCP ( $userID , $userValue , $val [ 'rowid' ]);
if ( $result < 0 ) {
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
$error ++ ;
}
2020-10-31 14:32:18 +01:00
}
// If it first update of balance, we set date to avoid to have sold incremented by new month
/*
2021-02-26 17:59:31 +01:00
$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 );
*/
2020-10-31 14:32:18 +01:00
}
}
2017-06-13 15:34:18 +02:00
2021-02-26 17:59:31 +01:00
if ( ! $error ) {
2022-08-12 15:07:15 +02:00
$db -> commit ();
if ( $nbok > 0 ) {
setEventMessages ( 'UpdateConfCPOK' , '' , 'mesgs' );
}
} else {
$db -> rollback ();
2021-02-26 17:59:31 +01:00
}
2020-10-31 14:32:18 +01:00
}
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 );
2020-04-10 10:59:32 +02:00
$userstatic = new User ( $db );
2015-06-21 03:19:15 +02:00
2021-06-17 09:08:59 +02:00
$title = $langs -> trans ( 'CPTitreMenu' );
llxHeader ( '' , $title );
2015-06-21 03:19:15 +02:00
2017-06-13 15:34:18 +02:00
2020-04-10 10:59:32 +02:00
$typeleaves = $holiday -> getTypes ( 1 , 1 );
$result = $holiday -> updateBalance (); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user.
2019-11-01 08:25:58 +01:00
if ( $result < 0 ) {
setEventMessages ( $holiday -> error , $holiday -> errors , 'errors' );
}
2018-02-20 14:53:19 +01:00
2017-06-13 15:34:18 +02:00
print '<form method="POST" id="searchFormList" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2021-02-26 17:59:31 +01:00
if ( $optioncss != '' ) {
print '<input type="hidden" name="optioncss" value="' . $optioncss . '">' ;
}
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2017-06-13 15:34:18 +02:00
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' );
2019-11-01 08:25:58 +01:00
if ( $lastUpdate ) {
2020-10-31 14:32:18 +01:00
print '<strong>' . dol_print_date ( $db -> jdate ( $lastUpdate ), 'dayhour' ) . '</strong>' ;
print '<br>' . $langs -> trans ( " MonthOfLastMonthlyUpdate " ) . ': <strong>' . $langs -> trans ( 'Month' . substr ( $lastUpdate , 4 , 2 )) . ' ' . substr ( $lastUpdate , 0 , 4 ) . '</strong>' . " \n " ;
2019-11-01 08:25:58 +01:00
} else {
2020-10-31 14:32:18 +01:00
print $langs -> trans ( 'None' );
2016-01-09 01:54:10 +01:00
}
2015-06-27 11:45:23 +02:00
print " </div><br> \n " ;
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
2020-04-10 10:59:32 +02:00
$userchilds = array ();
2021-02-26 17:59:31 +01:00
if ( empty ( $user -> rights -> holiday -> readall )) {
2020-04-10 10:59:32 +02:00
$userchilds = $user -> getAllChildIds ( 1 );
2021-03-22 12:00:41 +01:00
$filters .= ' AND u.rowid IN (' . $db -> sanitize ( join ( ', ' , $userchilds )) . ')' ;
2017-10-02 18:17:16 +02:00
}
2018-03-09 11:37:23 +01:00
if ( ! empty ( $search_name )) {
2020-04-10 10:59:32 +02:00
$filters .= natural_search ( array ( 'u.firstname' , 'u.lastname' ), $search_name );
2018-03-09 11:37:23 +01:00
}
2021-02-26 17:59:31 +01:00
if ( $search_supervisor > 0 ) {
$filters .= natural_search ( array ( 'u.fk_user' ), $search_supervisor , 2 );
}
2020-04-10 10:59:32 +02: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 );
2021-02-26 17:59:31 +01:00
if ( is_numeric ( $listUsers ) && $listUsers < 0 ) {
2020-10-31 14:32:18 +01: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
2021-02-26 17:59:31 +01:00
if ( count ( $typeleaves ) == 0 ) {
2020-10-31 14:32:18 +01:00
//print '<div class="info">';
print $langs -> trans ( " NoLeaveWithCounterDefined " ) . " <br> \n " ;
print $langs -> trans ( " GoIntoDictionaryHolidayTypes " );
//print '</div>';
2020-05-21 15:05:19 +02:00
} else {
2020-10-31 14:32:18 +01:00
$canedit = 0 ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $user -> rights -> holiday -> define_holiday )) {
$canedit = 1 ;
}
2020-10-31 14:32:18 +01:00
$moreforfilter = '' ;
print '<div class="div-table-responsive">' ;
print '<table class="tagtable liste' . ( $moreforfilter ? " listwithfilterbefore " : " " ) . '" id="tablelines3">' . " \n " ;
print '<tr class="liste_titre_filter">' ;
// User
print '<td class="liste_titre"><input type="text" name="search_name" value="' . dol_escape_htmltag ( $search_name ) . '"></td>' ;
// 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
2021-02-26 17:59:31 +01:00
if ( count ( $typeleaves )) {
foreach ( $typeleaves as $key => $val ) {
2020-10-31 14:32:18 +01:00
print '<td class="liste_titre" style="text-align:center"></td>' ;
}
} else {
print '<td class="liste_titre"></td>' ;
}
print '<td class="liste_titre"></td>' ;
// Action column
print '<td class="liste_titre maxwidthsearch center">' ;
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
print '<tr class="liste_titre">' ;
print_liste_field_titre ( 'Employee' , $_SERVER [ " PHP_SELF " ]);
print_liste_field_titre ( 'Supervisor' , $_SERVER [ " PHP_SELF " ]);
2021-02-26 17:59:31 +01:00
if ( count ( $typeleaves )) {
foreach ( $typeleaves as $key => $val ) {
2020-10-31 14:32:18 +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 " ], '' , '' , '' , '' , '' , '' , 'center ' );
}
} else {
print_liste_field_titre ( 'NoLeaveWithCounterDefined' , $_SERVER [ " PHP_SELF " ], '' , '' , '' , '' );
}
print_liste_field_titre (( empty ( $user -> rights -> holiday -> define_holiday ) ? '' : 'Note' ), $_SERVER [ " PHP_SELF " ]);
print_liste_field_titre ( '' );
print '</tr>' ;
$usersupervisor = new User ( $db );
2021-02-26 17:59:31 +01:00
foreach ( $listUsers as $users ) {
2020-10-31 14:32:18 +01:00
// If user has not permission to edit/read all, we must see only subordinates
2021-02-26 17:59:31 +01:00
if ( empty ( $user -> rights -> holiday -> readall )) {
if (( $users [ 'rowid' ] != $user -> id ) && ( ! in_array ( $users [ 'rowid' ], $userchilds ))) {
continue ; // This user is not into hierarchy of current user, we hide it.
}
2020-10-31 14:32:18 +01:00
}
$userstatic -> id = $users [ 'rowid' ];
$userstatic -> lastname = $users [ 'lastname' ];
$userstatic -> firstname = $users [ 'firstname' ];
$userstatic -> gender = $users [ 'gender' ];
$userstatic -> photo = $users [ 'photo' ];
$userstatic -> statut = $users [ 'status' ];
$userstatic -> employee = $users [ 'employee' ];
$userstatic -> fk_user = $users [ 'fk_user' ];
2021-02-26 17:59:31 +01:00
if ( $userstatic -> fk_user > 0 ) {
$usersupervisor -> fetch ( $userstatic -> fk_user );
}
2020-10-31 14:32:18 +01:00
print '<tr class="oddeven">' ;
// User
print '<td>' ;
print $userstatic -> getNomUrl ( - 1 );
print '</td>' ;
// Supervisor
print '<td>' ;
2021-02-26 17:59:31 +01:00
if ( $userstatic -> fk_user > 0 ) {
print $usersupervisor -> getNomUrl ( - 1 );
}
2020-10-31 14:32:18 +01:00
print '</td>' ;
// Amount for each type
2021-02-26 17:59:31 +01:00
if ( count ( $typeleaves )) {
foreach ( $typeleaves as $key => $val ) {
2020-10-31 14:32:18 +01:00
$nbtoshow = '' ;
2021-02-26 17:59:31 +01:00
if ( $holiday -> getCPforUser ( $users [ 'rowid' ], $val [ 'rowid' ]) != '' ) {
$nbtoshow = price2num ( $holiday -> getCPforUser ( $users [ 'rowid' ], $val [ 'rowid' ]), 5 );
}
2020-10-31 14:32:18 +01:00
//var_dump($users['rowid'].' - '.$val['rowid']);
print '<td style="text-align:center">' ;
2021-02-26 17:59:31 +01:00
if ( $canedit ) {
2021-09-30 01:50:11 +02:00
print '<input type="text"' . ( $canedit ? '' : ' disabled="disabled"' ) . ' value="' . $nbtoshow . '" name="nb_holiday_' . $val [ 'rowid' ] . '[' . $users [ 'rowid' ] . ']" class="width75 center" />' ;
2021-02-26 17:59:31 +01:00
} else {
print $nbtoshow ;
}
2020-10-31 14:32:18 +01:00
//print ' '.$langs->trans('days');
print '</td>' . " \n " ;
}
} else {
print '<td></td>' ;
}
// Note
print '<td>' ;
2021-02-26 17:59:31 +01:00
if ( $canedit ) {
print '<input type="text"' . ( $canedit ? '' : ' disabled="disabled"' ) . ' class="maxwidthonsmartphone" value="" name="note_holiday[' . $users [ 'rowid' ] . ']" size="30"/>' ;
}
2020-10-31 14:32:18 +01:00
print '</td>' ;
// Button modify
print '<td>' ;
2021-02-26 17:59:31 +01:00
if ( ! empty ( $user -> rights -> holiday -> define_holiday )) { // Allowed to set the balance of any user
2020-12-08 19:32:43 +01:00
print '<input type="submit" name="update_cp[' . $users [ 'rowid' ] . ']" value="' . dol_escape_htmltag ( $langs -> trans ( " Save " )) . '" class="button smallpaddingimp"/>' ;
2020-10-31 14:32:18 +01:00
}
print '</td>' . " \n " ;
print '</tr>' ;
$i ++ ;
}
print '</table>' ;
print '</div>' ;
2012-09-05 03:26:57 +02:00
}
2017-06-13 15:34:18 +02:00
print '</form>' ;
2018-08-13 10:20:21 +02:00
// End of page
2012-09-05 12:59:33 +02:00
llxFooter ();
2012-09-05 03:26:57 +02:00
$db -> close ();