base commit
This commit is contained in:
46
app/Filament/Widgets/MonthlyHiringChart.php
Normal file
46
app/Filament/Widgets/MonthlyHiringChart.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user