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