//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) { $contract = $api->getContracts($contract_id); $startdate = $api->getStartDate($contract, $period); $enddate = $api->getEndDate($contract, $period); $api->addEntitledDaysContract($contract->id, $startdate, $enddate, $days, $type, $description); echo 'Added ' . $days . ' day(s) to contract #' . $contract_id . PHP_EOL; } //Get the list of entity ids and add the entitled days foreach ($entity_ids as $entity_id) {
//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) { echo "Test 1 = " . ($credit->startdate == $startdate) . PHP_EOL; echo "Test 2 = " . ($credit->enddate == $enddate) . PHP_EOL; echo "Test 3 = " . ($credit->type == $leave_type) . PHP_EOL; //TODO :Return of API is a string for leave type and not a number ! if ($credit->startdate == $startdate && $credit->enddate == $enddate && $credit->type == $leave_type) { echo "The employee already has seniority bonus." . PHP_EOL; $found = TRUE; } } if (!$found) { $description = "Inserted by Seniority Robot"; $result = $api->addEntitledDaysEmployee($employee->id, $startdate, $enddate, $nb_of_days, $leave_type, $description); echo "RESULT / entitled days = " . $result . PHP_EOL; } } else { echo "recent employee = " . $employee->id . PHP_EOL; } }