64 lines
2.0 KiB
PHP
64 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Widgets;
|
|
|
|
use App\Enums\VerificationStatus;
|
|
use App\Models\VerificationRequest;
|
|
use Filament\Widgets\ChartWidget;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class VerificationPerformanceChart extends ChartWidget
|
|
{
|
|
protected ?string $heading = 'Performa Verifikasi (Approved vs Rejected)';
|
|
|
|
protected static ?int $sort = 14;
|
|
|
|
protected int|string|array $columnSpan = 'full';
|
|
|
|
protected function getData(): array
|
|
{
|
|
$data = VerificationRequest::query()
|
|
->select(
|
|
DB::raw('COUNT(*) as count'),
|
|
DB::raw('status'),
|
|
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
|
|
)
|
|
->whereIn('status', [VerificationStatus::APPROVED, VerificationStatus::REJECTED])
|
|
->where('created_at', '>=', now()->subMonths(6))
|
|
->groupBy('month', 'status')
|
|
->orderBy('month')
|
|
->get();
|
|
|
|
$months = $data->pluck('month')->unique()->sort()->values();
|
|
|
|
$approvedData = [];
|
|
$rejectedData = [];
|
|
|
|
foreach ($months as $month) {
|
|
$approvedData[] = $data->where('month', $month)->where('status', VerificationStatus::APPROVED)->first()?->count ?? 0;
|
|
$rejectedData[] = $data->where('month', $month)->where('status', VerificationStatus::REJECTED)->first()?->count ?? 0;
|
|
}
|
|
|
|
return [
|
|
'datasets' => [
|
|
[
|
|
'label' => 'Disetujui',
|
|
'data' => $approvedData,
|
|
'backgroundColor' => '#10B981',
|
|
],
|
|
[
|
|
'label' => 'Ditolak',
|
|
'data' => $rejectedData,
|
|
'backgroundColor' => '#EF4444',
|
|
],
|
|
],
|
|
'labels' => $months->map(fn ($m) => \Carbon\Carbon::createFromFormat('Y-m', $m)->translatedFormat('M Y'))->toArray(),
|
|
];
|
|
}
|
|
|
|
protected function getType(): string
|
|
{
|
|
return 'bar';
|
|
}
|
|
}
|