diff --git a/app/Http/Controllers/Dashboard/StatisticController.php b/app/Http/Controllers/Dashboard/StatisticController.php index d3bfcf6..8c4d0d2 100644 --- a/app/Http/Controllers/Dashboard/StatisticController.php +++ b/app/Http/Controllers/Dashboard/StatisticController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\IssueManagement; use App\Models\MediaMonitoring; +use App\Models\Report; use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; @@ -31,8 +32,8 @@ public function index(Request $request){ ], [ 'name' => 'Laporan Bukti Tayang', - 'category' => 'reports', - 'is_available' => false + 'category' => 'airing-proof-reports', + 'is_available' => true ], [ 'name' => 'Media', @@ -91,7 +92,6 @@ public function show(Request $request, $category){ 'login-activities', 'journalists', 'media-cooperations', - 'reports', 'media', 'cooperation-completions', 'users', @@ -104,20 +104,31 @@ public function show(Request $request, $category){ return redirect()->back()->with('waiting-status', 'Dalam pegembangan'); } - $year = $request->input('year') ? $request->input('year') : Carbon::now()->year; + $year = $request->input('year', Carbon::now()->year); + $from_month = $request->input('from_month', null); + $to_month = $request->input('to_month', null); switch($category){ case 'media-monitorings-issue-management': $data['title'] = 'Statistik Monitoring Media & Manajemen Isu'; + // Statistik Isu $issues = IssueManagement::with(['mediaMonitoring']); $mediaMonitorings = MediaMonitoring::with(['issue']); - if($year !== 'all'){ + if($year && $year !== 'all'){ $issues->whereYear('created_at', $year); $mediaMonitorings->whereYear('created_at', $year); } + if($from_month && $to_month){ + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + $issues->whereBetween('created_at', [$start, $end]); + $mediaMonitorings->whereBetween('created_at', [$start, $end]); + } + $issues = $issues->get(); $mediaMonitorings = $mediaMonitorings->get(); @@ -162,15 +173,27 @@ public function show(Request $request, $category){ }); $mediaMonitoringWithoutIssue = MediaMonitoring::doesntHave('issue') - ->when($year !== 'all', function ($query) use ($year) { + ->when($year && $year !== 'all', function ($query) use ($year) { $query->whereYear('created_at', $year); }) + ->when($from_month && $to_month, function ($query) use ($from_month, $to_month) { + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + $query->whereBetween('created_at', [$start, $end]); + }) ->get(); $mediaMonitoringWithIssue = MediaMonitoring::has('issue') - ->when($year !== 'all', function ($query) use ($year) { + ->when($year && $year !== 'all', function ($query) use ($year) { $query->whereYear('created_at', $year); }) + ->when($from_month && $to_month, function ($query) use ($from_month, $to_month) { + $start = Carbon::parse($from_month)->startOfMonth(); + $end = Carbon::parse($to_month)->endOfMonth(); + + $query->whereBetween('created_at', [$start, $end]); + }) ->get(); $data['mediaMonitoringWithoutIssueCount'] = $mediaMonitoringWithoutIssue->count(); @@ -180,9 +203,59 @@ public function show(Request $request, $category){ $data['issueManagementMonthly'] = $issueManagementMonthly; return view('dashboard.statistics.show.media-monitoring-issue-management', $data); - case 'issue-managements': - $data['title'] = 'Statistik Manajemen Isu'; - break; + case 'airing-proof-reports': + $data['title'] = 'Statistik Laporan Bukti Tayang'; + + $airingProofReport = Report::with(['order', 'media'])->get(); + $airingProofThemeCount = $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['proofAiringThemeWaiting'] = $airingProofThemeCount->get('0', 0); + $data['proofAiringThemeAccepted'] = $airingProofThemeCount->get('1', 0); + $data['proofAiringThemeRejected'] = $airingProofThemeCount->get('2', 0); + + return view('dashboard.statistics.show.airing-proof-report', $data); + default: + abort(404); } } } diff --git a/public/assets/dashboard/css/custom.css b/public/assets/dashboard/css/custom.css index 35bddf0..a2e081f 100644 --- a/public/assets/dashboard/css/custom.css +++ b/public/assets/dashboard/css/custom.css @@ -175,3 +175,9 @@ .link-show{ .not-available-text{ color: rgb(195, 195, 195) !important; } + +.apexcharts-xaxis text { + fill: #000 !important; + font-size: 12px !important; + display: block !important; +} diff --git a/resources/views/dashboard/statistics/chart/airing-proof-report.blade.php b/resources/views/dashboard/statistics/chart/airing-proof-report.blade.php new file mode 100644 index 0000000..699f0a6 --- /dev/null +++ b/resources/views/dashboard/statistics/chart/airing-proof-report.blade.php @@ -0,0 +1,259 @@ + + + diff --git a/resources/views/dashboard/statistics/show/airing-proof-report.blade.php b/resources/views/dashboard/statistics/show/airing-proof-report.blade.php new file mode 100644 index 0000000..f83bbd9 --- /dev/null +++ b/resources/views/dashboard/statistics/show/airing-proof-report.blade.php @@ -0,0 +1,171 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'statistics']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+

{{$title}}

+ {{--
+

Data: Tahun {{$data_year}}

+
--}} +
+ {{-- {{dd($cooperationRequests)}} --}} +
+
+ +
+
    +
  • +
    + Kembali +
    +
  • +
  • + @if (filled($year) || filled($from_month) || filled($to_month)) + + + + + + @endif +
    + Filter +
    +
  • +
+
+
+
+
+
+
+
+ @if (is_role(['1'])) +
+
+
+
+
+
+
Status Laporan Bukti Tayang
+
+
+
+ +
+
    +
  • +
    + + Menunggu {{ '('.$proofAiringThemeWaiting.')' }} +
    +
  • +
  • +
    + + Diterima {{ '('.$proofAiringThemeAccepted.')' }} +
    +
  • +
  • +
    + + Ditolak {{ '('.$proofAiringThemeRejected.')' }} +
    +
  • +
+
+
+
+
+ @endif +
+
+
+
+
+
+
Status Laporan Bukti Tayang
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Publikasi Laporan Bukti Tayang
+
+
+
+
+
+
+
+ + {{--
+
+
+
+ +
+
+
+
--}} +
+
+
+
+
+
+ +@include('partials.dashboard.footer', ['statistic_chart' => 'airing-proof-report']) diff --git a/resources/views/dashboard/statistics/show/media-monitoring-issue-management.blade.php b/resources/views/dashboard/statistics/show/media-monitoring-issue-management.blade.php index 7891042..6d43191 100644 --- a/resources/views/dashboard/statistics/show/media-monitoring-issue-management.blade.php +++ b/resources/views/dashboard/statistics/show/media-monitoring-issue-management.blade.php @@ -10,6 +10,9 @@

{{$title}}

+ {{--
+

Data: Tahun {{$data_year}}

+
--}}
{{-- {{dd($cooperationRequests)}} --}}
@@ -23,7 +26,7 @@
  • - @if (isset($year) && filled($year)) + @if (filled($year) || filled($from_month) || filled($to_month)) @@ -31,7 +34,10 @@ @endif
    - Filter + Filter +
    +
    + Export
  • @@ -193,46 +199,87 @@