diff --git a/app/Filament/Widgets/IssueLocationChart.php b/app/Filament/Widgets/IssueLocationChart.php new file mode 100644 index 0000000..0d592b6 --- /dev/null +++ b/app/Filament/Widgets/IssueLocationChart.php @@ -0,0 +1,57 @@ +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'; + } +} diff --git a/app/Filament/Widgets/VerificationPerformanceChart.php b/app/Filament/Widgets/VerificationPerformanceChart.php new file mode 100644 index 0000000..de99e3e --- /dev/null +++ b/app/Filament/Widgets/VerificationPerformanceChart.php @@ -0,0 +1,63 @@ +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'; + } +}