66 lines
2.4 KiB
PHP
66 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Enums\EmploymentStatus;
|
|
use App\Models\Employee;
|
|
use App\Models\SickLeave;
|
|
use App\Models\Vacation;
|
|
use Filament\Widgets\StatsOverviewWidget;
|
|
use Filament\Widgets\StatsOverviewWidget\Stat;
|
|
|
|
class HrStatsOverviewWidget extends StatsOverviewWidget
|
|
{
|
|
protected ?string $heading = 'HR Overview';
|
|
|
|
protected function getStats(): array
|
|
{
|
|
$today = now()->toDateString();
|
|
|
|
$onVacationToday = Vacation::query()
|
|
->where('status', ApprovalStatus::Approved)
|
|
->whereDate('start_date', '<=', $today)
|
|
->whereDate('end_date', '>=', $today)
|
|
->count();
|
|
|
|
$onSickLeaveToday = SickLeave::query()
|
|
->whereDate('start_date', '<=', $today)
|
|
->whereDate('end_date', '>=', $today)
|
|
->count();
|
|
|
|
$pendingRequests = Vacation::query()
|
|
->where('status', ApprovalStatus::Pending)
|
|
->count();
|
|
|
|
return [
|
|
Stat::make('Total Employees', Employee::query()->count())
|
|
->description('All employees in the system')
|
|
->descriptionIcon('heroicon-o-users')
|
|
->color('primary'),
|
|
Stat::make('Active', Employee::query()->where('employment_status', EmploymentStatus::Active)->count())
|
|
->description('Currently active employees')
|
|
->descriptionIcon('heroicon-o-check-circle')
|
|
->color('success'),
|
|
Stat::make('Inactive', Employee::query()->where('employment_status', EmploymentStatus::Inactive)->count())
|
|
->description('Inactive employees')
|
|
->descriptionIcon('heroicon-o-pause-circle')
|
|
->color('gray'),
|
|
Stat::make('On Vacation Today', $onVacationToday)
|
|
->description('Approved vacations in progress')
|
|
->descriptionIcon('heroicon-o-sun')
|
|
->color('warning'),
|
|
Stat::make('On Sick Leave Today', $onSickLeaveToday)
|
|
->description('Employees on sick leave')
|
|
->descriptionIcon('heroicon-o-heart')
|
|
->color('danger'),
|
|
Stat::make('Pending Requests', $pendingRequests)
|
|
->description('Vacation requests awaiting approval')
|
|
->descriptionIcon('heroicon-o-clock')
|
|
->color('info'),
|
|
];
|
|
}
|
|
}
|