Ejemplo n.º 1
0
//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) {
            echo "The employee has no seniority bonus." . PHP_EOL;
            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;
            }
        } else {
            echo "The employee already has seniority bonus." . PHP_EOL;
        }
    } else {
        echo "recent employee #" . $employee->id . PHP_EOL;
    }
}