feat: Add Filament widgets to visualize verification performance and issue distribution by location.

This commit is contained in:
Yoga Pangestu 2026-01-29 10:24:56 +07:00
parent 56535076ad
commit 7d970587fa
2 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?php
namespace App\Filament\Widgets;
use App\Models\IssueManagement;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\Facades\DB;
class IssueLocationChart extends ChartWidget
{
protected ?string $heading = 'Sebaran Isu Berdasarkan Wilayah';
protected static ?int $sort = 15;
protected int|string|array $columnSpan = 'full';
protected function getData(): array
{
$issueTable = (new IssueManagement)->getTable();
$locationTable = (new \App\Models\Location)->getTable();
$data = IssueManagement::query()
->join($locationTable, "{$issueTable}.location_id", '=', "{$locationTable}.id")
->select("{$locationTable}.name", DB::raw('count(*) as total'))
->groupBy("{$locationTable}.id", "{$locationTable}.name")
->orderByDesc('total')
->limit(10)
->get();
return [
'datasets' => [
[
'label' => 'Jumlah Isu',
'data' => $data->pluck('total')->toArray(),
'backgroundColor' => [
'#6366F1',
'#8B5CF6',
'#EC4899',
'#F43F5E',
'#F59E0B',
'#10B981',
'#06B6D4',
'#3B82F6',
'#6366F1',
'#8B5CF6',
],
],
],
'labels' => $data->pluck('name')->toArray(),
];
}
protected function getType(): string
{
return 'bar';
}
}

View File

@ -0,0 +1,63 @@
<?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';
}
}