Files
hr/app/Services/Vacation/VacationBalanceService.php
2026-07-30 17:24:40 +05:00

34 lines
792 B
PHP

<?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);
}
}