Files
hr/app/Filament/Widgets/MonthlyLeaveChart.php
2026-07-30 17:24:40 +05:00

49 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\Widgets;
use App\Enums\ApprovalStatus;
use App\Models\Vacation;
use Filament\Widgets\ChartWidget;
class MonthlyLeaveChart extends ChartWidget
{
protected ?string $heading = 'Vacation Days by Month';
protected int | string | array $columnSpan = 1;
protected function getType(): string
{
return 'bar';
}
protected function getData(): array
{
$labels = [];
$data = [];
for ($i = 11; $i >= 0; $i--) {
$month = now()->subMonths($i);
$labels[] = $month->format('M Y');
$data[] = (int) Vacation::query()
->where('status', ApprovalStatus::Approved)
->whereYear('start_date', $month->year)
->whereMonth('start_date', $month->month)
->sum('days');
}
return [
'datasets' => [
[
'label' => 'Vacation Days',
'data' => $data,
'backgroundColor' => '#f59e0b',
],
],
'labels' => $labels,
];
}
}