diff --git a/app/Http/Controllers/Dashboard/StatisticController.php b/app/Http/Controllers/Dashboard/StatisticController.php index 02284f7..992ec16 100644 --- a/app/Http/Controllers/Dashboard/StatisticController.php +++ b/app/Http/Controllers/Dashboard/StatisticController.php @@ -111,10 +111,18 @@ public function show(Request $request, $category){ switch($category){ case 'login-activities': $data['title'] = 'Statistik Aktivitas Login'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; $monthlyCount = array_fill(0, 12, 0); - $loginActivities = LoginHistory::with(['user'])->get(); + $loginActivities = LoginHistory::with(['user']); + + if($year && $year !== 'all'){ + $loginActivities->whereYear('created_at', '=', $year); + } + + $loginActivities = $loginActivities->get(); + $loginActivities->groupBy(function ($item) { return (int) \Carbon\Carbon::parse($item->created_at)->format('m'); })->each(function ($items, $month) use (&$monthlyCount) { @@ -125,8 +133,161 @@ public function show(Request $request, $category){ $data['loginActivities'] = $monthlyCount; return view('dashboard.statistics.show.login-activity', $data); + case 'media-cooperations': + $data['title'] = 'Statistik Kerja Sama Media'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; + + $mediaCooperation = MediaCooperation::with(['cooperation', 'media']); + + if($year && $year !== 'all'){ + $mediaCooperation->whereYear('created_at', '=', $year); + } + + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + + $mediaCooperation->whereBetween('created_at', [$start, $end]); + } + + $mediaCooperation = $mediaCooperation->get(); + + $mediaCooperationCount = $mediaCooperation->groupBy('status')->map(function ($group) { + return $group->count(); + }); + + // Inisialisasi array 12 bulan untuk masing-masing status + $monthlyStatus = [ + 'waiting' => array_fill(0, 12, 0), + 'accepted' => array_fill(0, 12, 0), + 'rejected' => array_fill(0, 12, 0), + ]; + + // Kelompokkan data berdasarkan status lalu bulan + $mediaCooperation->groupBy('status')->each(function ($groupedByStatus, $status) use (&$monthlyStatus) { + $label = match ((int)$status) { + 0 => 'waiting', + 1 => 'accepted', + 2 => 'rejected', + default => null, + }; + + if ($label) { + $groupedByStatus->groupBy(function ($item) { + return (int)$item->created_at->format('m'); // bulan sebagai angka 1–12 + })->each(function ($items, $month) use (&$monthlyStatus, $label) { + $monthlyStatus[$label][$month - 1] = $items->count(); + }); + } + }); + + $monthlyCount = array_fill(0, 12, 0); + + $mediaCooperation->groupBy(function ($item) { + return (int) \Carbon\Carbon::parse($item->created_at)->format('m'); + })->each(function ($items, $month) use (&$monthlyCount) { + // Simpan jumlah item tiap bulan ke index bulan - 1 (0-based) + $monthlyCount[$month - 1] = $items->count(); + }); + + // Simpan ke variabel `$data` + $data['mediaCooperationStatusMonthly'] = $monthlyStatus; + $data['mediaCooperationMonthly'] = $monthlyCount; + + $data['mediaCooperationWaiting'] = $mediaCooperationCount->get('0', 0); + $data['mediaCooperationAccepted'] = $mediaCooperationCount->get('1', 0); + $data['mediaCooperationRejected'] = $mediaCooperationCount->get('2', 0); + + return view('dashboard.statistics.show.media-cooperation', $data); + case 'airing-proof-reports': + $data['title'] = 'Statistik Laporan Bukti Tayang'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; + + $airingProofReport = Report::with(['order', 'media']); + + if($year && $year !== 'all'){ + $airingProofReport->whereYear('created_at', '=', $year); + } + + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + + $airingProofReport->whereBetween('created_at', [$start, $end]); + } + + $airingProofReport = $airingProofReport->get(); + + $airingProofReportCount = $airingProofReport->groupBy('status')->map(function ($group) { + return $group->count(); + }); + + // Inisialisasi array 12 bulan untuk masing-masing status + $monthlyStatus = [ + 'waiting' => array_fill(0, 12, 0), + 'accepted' => array_fill(0, 12, 0), + 'rejected' => array_fill(0, 12, 0), + ]; + + // Kelompokkan data berdasarkan status lalu bulan + $airingProofReport->groupBy('status')->each(function ($groupedByStatus, $status) use (&$monthlyStatus) { + $label = match ((int)$status) { + 0 => 'waiting', + 1 => 'accepted', + 2 => 'rejected', + default => null, + }; + + if ($label) { + $groupedByStatus->groupBy(function ($item) { + return (int)$item->created_at->format('m'); // bulan sebagai angka 1–12 + })->each(function ($items, $month) use (&$monthlyStatus, $label) { + $monthlyStatus[$label][$month - 1] = $items->count(); + }); + } + }); + + $monthlyCount = array_fill(0, 12, 0); + + $airingProofReport->groupBy(function ($item) { + return (int) \Carbon\Carbon::parse($item->publication_date)->format('m'); + })->each(function ($items, $month) use (&$monthlyCount) { + // Simpan jumlah item tiap bulan ke index bulan - 1 (0-based) + $monthlyCount[$month - 1] = $items->count(); + }); + + // Simpan ke variabel `$data` + $data['airingProofReportStatusMonthly'] = $monthlyStatus; + $data['airingProofReportPublicationMonthly'] = $monthlyCount; + + $data['airingProofReportWaiting'] = $airingProofReportCount->get('0', 0); + $data['airingProofReportAccepted'] = $airingProofReportCount->get('1', 0); + $data['airingProofReportRejected'] = $airingProofReportCount->get('2', 0); + + return view('dashboard.statistics.show.airing-proof-report', $data); case 'media-monitorings-issue-management': $data['title'] = 'Statistik Monitoring Media & Manajemen Isu'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; // Statistik Isu $issues = IssueManagement::with(['mediaMonitoring']); @@ -141,6 +302,16 @@ public function show(Request $request, $category){ $start = Carbon::parse($from_month)->startOfMonth(); $end = Carbon::parse($to_month)->endOfMonth(); + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + $issues->whereBetween('created_at', [$start, $end]); $mediaMonitorings->whereBetween('created_at', [$start, $end]); } @@ -219,91 +390,35 @@ public function show(Request $request, $category){ $data['issueManagementMonthly'] = $issueManagementMonthly; return view('dashboard.statistics.show.media-monitoring-issue-management', $data); - case 'airing-proof-reports': - $data['title'] = 'Statistik Laporan Bukti Tayang'; - - $airingProofReport = Report::with(['order', 'media'])->get(); - $airingProofReportCount = $airingProofReport->groupBy('status')->map(function ($group) { - return $group->count(); - }); - - // Inisialisasi array 12 bulan untuk masing-masing status - $monthlyStatus = [ - 'waiting' => array_fill(0, 12, 0), - 'accepted' => array_fill(0, 12, 0), - 'rejected' => array_fill(0, 12, 0), - ]; - - // Kelompokkan data berdasarkan status lalu bulan - $airingProofReport->groupBy('status')->each(function ($groupedByStatus, $status) use (&$monthlyStatus) { - $label = match ((int)$status) { - 0 => 'waiting', - 1 => 'accepted', - 2 => 'rejected', - default => null, - }; - - if ($label) { - $groupedByStatus->groupBy(function ($item) { - return (int)$item->created_at->format('m'); // bulan sebagai angka 1–12 - })->each(function ($items, $month) use (&$monthlyStatus, $label) { - $monthlyStatus[$label][$month - 1] = $items->count(); - }); - } - }); - - $monthlyCount = array_fill(0, 12, 0); - - $airingProofReport->groupBy(function ($item) { - return (int) \Carbon\Carbon::parse($item->publication_date)->format('m'); - })->each(function ($items, $month) use (&$monthlyCount) { - // Simpan jumlah item tiap bulan ke index bulan - 1 (0-based) - $monthlyCount[$month - 1] = $items->count(); - }); - - // Simpan ke variabel `$data` - $data['airingProofReportStatusMonthly'] = $monthlyStatus; - $data['airingProofReportPublicationMonthly'] = $monthlyCount; - - $data['airingProofReportWaiting'] = $airingProofReportCount->get('0', 0); - $data['airingProofReportAccepted'] = $airingProofReportCount->get('1', 0); - $data['airingProofReportRejected'] = $airingProofReportCount->get('2', 0); - - return view('dashboard.statistics.show.airing-proof-report', $data); - case 'users': - $data['title'] = 'Statistik Pengguna'; - - $monthlyCount = array_fill(0, 12, 0); - - $registerUsers = User::all(); - $registerUsers->groupBy(function ($item) { - return (int) \Carbon\Carbon::parse($item->created_at)->format('m'); - })->each(function ($items, $month) use (&$monthlyCount) { - $monthlyCount[$month - 1] = $items->count(); - }); - - $data['registerUserMonth'] = $monthlyCount; - - return view('dashboard.statistics.show.user', $data); - case 'website-visitors': - $data['title'] = 'Statistik Pengunjung Website'; - - $monthlyCount = array_fill(0, 12, 0); - - $websiteVisitors = Visitor::all(); - $websiteVisitors->groupBy(function ($item) { - return (int) \Carbon\Carbon::parse($item->created_at)->format('m'); - })->each(function ($items, $month) use (&$monthlyCount) { - $monthlyCount[$month - 1] = $items->count(); - }); - - $data['websiteVisitorMonth'] = $monthlyCount; - - return view('dashboard.statistics.show.website-visitor', $data); case 'cooperation-completions': $data['title'] = 'Statistik Laporan Bukti Tayang'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; + + $cooperationCompletion = CooperationCompletion::with(['order', 'media']); + + if($year && $year !== 'all'){ + $cooperationCompletion->whereYear('created_at', '=', $year); + } + + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + + $cooperationCompletion->whereBetween('created_at', [$start, $end]); + } + + $cooperationCompletion = $cooperationCompletion->get(); - $cooperationCompletion = CooperationCompletion::with(['order', 'media'])->get(); $cooperationCompletionCount = $cooperationCompletion->groupBy('status')->map(function ($group) { return $group->count(); }); @@ -351,61 +466,75 @@ public function show(Request $request, $category){ $data['cooperationCompletionRejected'] = $cooperationCompletionCount->get('2', 0); return view('dashboard.statistics.show.cooperation-completion', $data); - case 'media-cooperations': - $data['title'] = 'Statistik Laporan Bukti Tayang'; - - $mediaCooperation = MediaCooperation::with(['cooperation', 'media'])->get(); - $mediaCooperationCount = $mediaCooperation->groupBy('status')->map(function ($group) { - return $group->count(); - }); - - // Inisialisasi array 12 bulan untuk masing-masing status - $monthlyStatus = [ - 'waiting' => array_fill(0, 12, 0), - 'accepted' => array_fill(0, 12, 0), - 'rejected' => array_fill(0, 12, 0), - ]; - - // Kelompokkan data berdasarkan status lalu bulan - $mediaCooperation->groupBy('status')->each(function ($groupedByStatus, $status) use (&$monthlyStatus) { - $label = match ((int)$status) { - 0 => 'waiting', - 1 => 'accepted', - 2 => 'rejected', - default => null, - }; - - if ($label) { - $groupedByStatus->groupBy(function ($item) { - return (int)$item->created_at->format('m'); // bulan sebagai angka 1–12 - })->each(function ($items, $month) use (&$monthlyStatus, $label) { - $monthlyStatus[$label][$month - 1] = $items->count(); - }); - } - }); + case 'users': + $data['title'] = 'Statistik Pengguna'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; $monthlyCount = array_fill(0, 12, 0); - $mediaCooperation->groupBy(function ($item) { + $registerUsers = User::query(); + + if($year && $year !== 'all'){ + $registerUsers->whereYear('created_at', '=', $year); + } + + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + + $registerUsers->whereBetween('created_at', [$start, $end]); + } + + $registerUsers = $registerUsers->get(); + + $registerUsers->groupBy(function ($item) { return (int) \Carbon\Carbon::parse($item->created_at)->format('m'); })->each(function ($items, $month) use (&$monthlyCount) { - // Simpan jumlah item tiap bulan ke index bulan - 1 (0-based) $monthlyCount[$month - 1] = $items->count(); }); - // Simpan ke variabel `$data` - $data['mediaCooperationStatusMonthly'] = $monthlyStatus; - $data['mediaCooperationMonthly'] = $monthlyCount; + $data['registerUserMonth'] = $monthlyCount; - $data['mediaCooperationWaiting'] = $mediaCooperationCount->get('0', 0); - $data['mediaCooperationAccepted'] = $mediaCooperationCount->get('1', 0); - $data['mediaCooperationRejected'] = $mediaCooperationCount->get('2', 0); - - return view('dashboard.statistics.show.media-cooperation', $data); + return view('dashboard.statistics.show.user', $data); case 'content-recaps': $data['title'] = 'Statistik Rekap Konten'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; + + $contenteRecap = ContentRecap::with(['enhancer', 'classification']); + + if($year && $year !== 'all'){ + $contenteRecap->whereYear('created_at', '=', $year); + } + + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + + $contenteRecap->whereBetween('created_at', [$start, $end]); + } + + $contenteRecap = $contenteRecap->get(); - $contenteRecap = ContentRecap::with(['enhancer', 'classification'])->get(); $contentRecapChannelCount = $contenteRecap->groupBy('channel')->map(function ($group) { return $group->count(); }); @@ -438,6 +567,46 @@ public function show(Request $request, $category){ $data['socialMedia3ContentRecap'] = $contentRecapSocialMediaCount->get('Purwakarta Saber Hoaks', 0); return view('dashboard.statistics.show.content-recap', $data); + case 'website-visitors': + $data['title'] = 'Statistik Pengunjung Website'; + $data['data_time'] = $year === 'all' ? 'Semua' : 'Tahun '.$year; + + $monthlyCount = array_fill(0, 12, 0); + + $websiteVisitors = Visitor::query(); + + if($year && $year !== 'all'){ + $websiteVisitors->whereYear('created_at', '=', $year); + } + + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + // Asumsikan from_month dan to_month dalam format 'YYYY-MM' + $fromDate = $from_month ? Carbon::createFromFormat('Y-m', $from_month) : null; + $toDate = $to_month ? Carbon::createFromFormat('Y-m', $to_month) : null; + + // Format ke bentuk "Mei 2025" + $fromFormatted = $fromDate ? $fromDate->translatedFormat('F Y') : '-'; + $toFormatted = $toDate ? $toDate->translatedFormat('F Y') : '-'; + + $data['data_time'] = $fromFormatted . ' - ' . $toFormatted; + + $websiteVisitors->whereBetween('created_at', [$start, $end]); + } + + $websiteVisitors = $websiteVisitors->get(); + + $websiteVisitors->groupBy(function ($item) { + return (int) \Carbon\Carbon::parse($item->created_at)->format('m'); + })->each(function ($items, $month) use (&$monthlyCount) { + $monthlyCount[$month - 1] = $items->count(); + }); + + $data['websiteVisitorMonth'] = $monthlyCount; + + return view('dashboard.statistics.show.website-visitor', $data); default: abort(404); } diff --git a/resources/views/dashboard/statistics/show/airing-proof-report.blade.php b/resources/views/dashboard/statistics/show/airing-proof-report.blade.php index 4eec37f..8ab8155 100644 --- a/resources/views/dashboard/statistics/show/airing-proof-report.blade.php +++ b/resources/views/dashboard/statistics/show/airing-proof-report.blade.php @@ -10,9 +10,9 @@
Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+Data: Tahun {{$data_year}}
-Data: {{$data_time}}
+