<?php namespace App\Business;

use App\Models\Employee;

class EmployeeStatistics{

    public static function rateOfDelay($id,$intervalTime,$intervalTimeLate){
        $nbrLog=logInByInterval($id,$intervalTime);
        $nbrLogLate=logInByInterval($id,$intervalTimeLate);
        return ($nbrLogLate/$nbrLog);
    }

    public static function logInByInterval($id,$intervalTime){
       $employee=Employee::Find($id);
        $nbrLogs=$employee->logs()->logIn();
        if($intervalTime->year)
            $nbrLogs=$nbrLogs->filterByYear($intervalTime->year);
        if($intervalTime->month)
            $nbrLogs=$nbrLogs->filterByMonth($intervalTime->month);
        if($intervalTime->hour&&$intervalTime->inf&&$intervalTime->sup)
            $nbrLogs=$nbrLogs->filterByInterval($intervalTime->hour, $intervalTime->inf, $intervalTime->sup);
        $nbrLogs=$nbrLogs->count();
        return $nbrLogs;
    }
    public static function logOutByInterval($id,$intervalTime){
        $employee=Employee::Find($id);
        $nbrLogs=$employee->logs()->logOut();
        if($intervalTime->year)
            $nbrLogs=$nbrLogs->filterByYear($intervalTime->year);
        if($intervalTime->month)
            $nbrLogs=$nbrLogs->filterByMonth($intervalTime->month);
        if($intervalTime->hour&&$intervalTime->inf&&$intervalTime->sup)
            $nbrLogs=$nbrLogs->filterByInterval($intervalTime->hour, $intervalTime->inf, $intervalTime->sup);
        $nbrLogs=$nbrLogs->count();
        return $nbrLogs;
    }


}
