47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Models\Employee;
|
|
use Filament\Widgets\ChartWidget;
|
|
class MonthlyHiringChart extends ChartWidget
|
|
{
|
|
protected ?string $heading = 'Monthly Hiring (Last 12 Months)';
|
|
|
|
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[] = Employee::query()
|
|
->whereNotNull('hire_date')
|
|
->whereYear('hire_date', $month->year)
|
|
->whereMonth('hire_date', $month->month)
|
|
->count();
|
|
}
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'New Hires',
|
|
'data' => $data,
|
|
'backgroundColor' => '#3b82f6',
|
|
],
|
|
],
|
|
'labels' => $labels,
|
|
];
|
|
}
|
|
}
|