diff --git a/app/Filament/Widgets/CooperationStatusChart.php b/app/Filament/Widgets/CooperationStatusChart.php new file mode 100644 index 0000000..b2678f3 --- /dev/null +++ b/app/Filament/Widgets/CooperationStatusChart.php @@ -0,0 +1,56 @@ +selectRaw('status, count(*) as total') + ->groupBy('status') + ->get(); + + $labels = []; + $counts = []; + $colors = []; + + foreach (CooperationStatus::cases() as $case) { + $labels[] = $case->getLabel(); + $counts[] = $data->where('status', $case)->first()?->total ?? 0; + $colors[] = match ($case) { + CooperationStatus::PENDING => '#F59E0B', + CooperationStatus::ASSIGNMENT => '#3B82F6', + CooperationStatus::VERIFICATION => '#6366F1', + CooperationStatus::PAYMENT => '#8B5CF6', + CooperationStatus::COMPLETED => '#10B981', + }; + } + + return [ + 'datasets' => [ + [ + 'label' => 'Jumlah Kerjasama', + 'data' => $counts, + 'backgroundColor' => $colors, + ], + ], + 'labels' => $labels, + ]; + } + + protected function getType(): string + { + return 'pie'; + } +} diff --git a/app/Filament/Widgets/MediaCooperationRankingChart.php b/app/Filament/Widgets/MediaCooperationRankingChart.php new file mode 100644 index 0000000..3b69e47 --- /dev/null +++ b/app/Filament/Widgets/MediaCooperationRankingChart.php @@ -0,0 +1,45 @@ +join('cooperation_media', 'partner_media.id', '=', 'cooperation_media.partner_media_id') + ->where('cooperation_media.status', ApprovalStatus::ACCEPTED) + ->select('partner_media.name', DB::raw('count(*) as total')) + ->groupBy('partner_media.id', 'partner_media.name') + ->orderByDesc('total') + ->limit(10) + ->get(); + + return [ + 'datasets' => [ + [ + 'label' => 'Total Kerjasama', + 'data' => $data->pluck('total')->toArray(), + 'backgroundColor' => '#6366F1', + ], + ], + 'labels' => $data->pluck('name')->toArray(), + ]; + } + + protected function getType(): string + { + return 'bar'; + } +} diff --git a/app/Filament/Widgets/TaskRealizationChart.php b/app/Filament/Widgets/TaskRealizationChart.php new file mode 100644 index 0000000..4f09f02 --- /dev/null +++ b/app/Filament/Widgets/TaskRealizationChart.php @@ -0,0 +1,69 @@ +select( + DB::raw('COUNT(*) as count'), + DB::raw('status'), + DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month") + ) + ->where('created_at', '>=', now()->subMonths(6)) + ->groupBy('month', 'status') + ->orderBy('month') + ->get(); + + $months = $data->pluck('month')->unique()->sort()->values(); + + $acceptedData = []; + $pendingData = []; + $rejectedData = []; + + foreach ($months as $month) { + $acceptedData[] = $data->where('month', $month)->where('status', ApprovalStatus::ACCEPTED)->first()?->count ?? 0; + $pendingData[] = $data->where('month', $month)->where('status', ApprovalStatus::PENDING)->first()?->count ?? 0; + $rejectedData[] = $data->where('month', $month)->where('status', ApprovalStatus::REJECTED)->first()?->count ?? 0; + } + + return [ + 'datasets' => [ + [ + 'label' => 'Disetujui', + 'data' => $acceptedData, + 'backgroundColor' => '#10B981', + ], + [ + 'label' => 'Menunggu', + 'data' => $pendingData, + 'backgroundColor' => '#F59E0B', + ], + [ + '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'; + } +}