base commit
This commit is contained in:
33
app/Services/Vacation/VacationBalanceService.php
Normal file
33
app/Services/Vacation/VacationBalanceService.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Services\Vacation;
|
||||
|
||||
use App\Enums\ApprovalStatus;
|
||||
use App\Enums\VacationType;
|
||||
use App\Models\Employee;
|
||||
|
||||
class VacationBalanceService
|
||||
{
|
||||
public function entitlement(): int
|
||||
{
|
||||
return (int) config('hr.annual_leave_days');
|
||||
}
|
||||
|
||||
public function takenAnnualDays(Employee $employee, ?int $year = null): int
|
||||
{
|
||||
$year ??= (int) now()->year;
|
||||
|
||||
return (int) $employee->vacations()
|
||||
->where('type', VacationType::Annual)
|
||||
->where('status', ApprovalStatus::Approved)
|
||||
->whereYear('start_date', $year)
|
||||
->sum('days');
|
||||
}
|
||||
|
||||
public function remainingAnnualDays(Employee $employee): int
|
||||
{
|
||||
return $this->entitlement() - $this->takenAnnualDays($employee);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user