35 lines
1.1 KiB
PHP
35 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Employee;
|
|
|
|
use App\DTOs\EmployeeSummaryDto;
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Models\Employee;
|
|
use App\Services\Vacation\VacationBalanceService;
|
|
|
|
class EmployeeStatisticsService
|
|
{
|
|
public function __construct(
|
|
private readonly VacationBalanceService $vacationBalanceService,
|
|
) {}
|
|
|
|
public function summary(Employee $employee): EmployeeSummaryDto
|
|
{
|
|
return new EmployeeSummaryDto(
|
|
vacationTaken: $this->vacationBalanceService->takenAnnualDays($employee),
|
|
vacationRemaining: $this->vacationBalanceService->remainingAnnualDays($employee),
|
|
sickLeaveCount: $employee->sickLeaves()->count(),
|
|
reportsCount: $employee->disciplinaryReports()->count(),
|
|
bonusesTotal: (float) $employee->bonuses()->sum('amount'),
|
|
giftsCount: $employee->gifts()->count(),
|
|
upcomingLeave: $employee->vacations()
|
|
->where('status', ApprovalStatus::Approved)
|
|
->where('start_date', '>=', now()->toDateString())
|
|
->orderBy('start_date')
|
|
->get(),
|
|
);
|
|
}
|
|
}
|