* - Insert the test dataset into DB : * INSERT INTO oauth_clients (client_id, client_secret, redirect_uri) VALUES ("testclient", "testpass", "http://fake/"); * */ require "JoraniAPI.php"; $nb_of_days = 1; //Number of days to be added to the credit $leave_type = 1; //Id of the leave type for seniority leave (see list of leave types into the web ui) $condition = ' - 1 year'; //Condition for date hired ' - 365 day' //Current yearly period $startdate = date('Y') . '-01-01'; $enddate = date('Y') . '-12-31'; //Connect to the REST API $api = new JoraniAPI('http://localhost/jorani/', 'testclient', 'testpass'); //Get the list of employees $employees = $api->getEmployeesList(); //echo "Employees = " . var_dump($employees) . PHP_EOL; //Iterate on the employees list (datehired > $condition) $last_year = new DateTime(date('Y-m-d', strtotime(date("Y-m-d", time()) . $condition))); //TODO : get the label of Seniority Leave ? foreach ($employees as $employee) { $datehired = new DateTime($employee->datehired); if ($datehired < $last_year) { echo "senior employee = " . $employee->id . PHP_EOL; //Check if we already credited seniority entitled days for the current period $entitled_days = $api->getEntitledDaysEmployeeList($employee->id); echo "entitled days = " . var_dump($entitled_days) . PHP_EOL; $found = FALSE; foreach ($entitled_days as $credit) {
$days = (double) 1; //Type of leave (pick a number in the IDs defined in Jorani, eg http://localhost/jorani/leavetypes) $type = 1; //Description of the credit line $description = 'Credit line added by robot - ' . date("D M d, Y G:i"); //Define entitlment period //CURRENT_PERIOD The entitlement can be taken only during the current yearly period (recommended) //'FROM_MONTH The entitlement can be taken from the current month to the end of yearly period //CURRENT_MONTH The entitlement can be taken only during the current month //CURRENT_YEAR The entitlement can be taken only during the current year $period = JoraniAPI::CURRENT_PERIOD; //--------------------------------------------------------------------------------------------------------------------------------------------------- // End of configuration //--------------------------------------------------------------------------------------------------------------------------------------------------- //Connect to the REST API $api = new JoraniAPI($url, $user, $password); //Get the list of employee ids and add the entitled days foreach ($employee_ids as $employee_id) { $employee = $api->getEmployees($employee_id); $contract = $api->getContracts($employee->contract); $startdate = $api->getStartDate($contract, $period); $enddate = $api->getEndDate($contract, $period); if ($employee->active == 1) { $api->addEntitledDaysEmployee($employee->id, $startdate, $enddate, $days, $type, $description); echo 'Added ' . $days . ' day(s) to employee #' . $employee->id . PHP_EOL; } else { echo 'No credit to inactiveemployee #' . $employee->id . PHP_EOL; } } //Get the list of contract ids and add the entitled days foreach ($contract_ids as $contract_id) {
//You must use a dedicated leave type for seniority bonus for this script to work //Condition tested against date hired field ' - 365 day' $condition = ' - 1 year'; //Description of the credit line $description = 'Seniority bonus added by robot - ' . date("D M d, Y G:i"); //Define entitlment period //CURRENT_YEAR The entitlement can be taken only during the current year (most current case) //CURRENT_PERIOD The entitlement can be taken only during the current yearly period //'FROM_MONTH The entitlement can be taken from the current month to the end of yearly period //CURRENT_MONTH The entitlement can be taken only during the current month $period = JoraniAPI::CURRENT_YEAR; //--------------------------------------------------------------------------------------------------------------------------------------------------- // End of configuration //--------------------------------------------------------------------------------------------------------------------------------------------------- //Connect to the REST API $api = new JoraniAPI($url, $user, $password); //Iterate on the employees list (datehired > $condition). Most of the time, last year. $floorDate = new DateTime(date('Y-m-d', strtotime(date("Y-m-d", time()) . $condition))); //Get the list of employees $employees = $api->getEmployees(); foreach ($employees as $employee) { $datehired = new DateTime($employee->datehired); if ($datehired < $floorDate) { echo "senior employee #" . $employee->id . PHP_EOL; //Check if we already credited seniority entitled days for the current period $entitled_days = $api->getEntitledDaysListForEmployee($employee->id); $contract = $api->getContracts($employee->contract); $startdate = $api->getStartDate($contract, $period); $enddate = $api->getEndDate($contract, $period); $hasSeniority = $api->hasEntitlementInPeriod($employee->id, $type, $startdate, $enddate); if (!$hasSeniority) {