From 0013facf5f875c885ebb0ac2e4fe756bef24e10a Mon Sep 17 00:00:00 2001 From: Novy San87 Date: Thu, 6 Aug 2026 22:43:27 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20filter=20Jenis=20Pelanggaran=20di=20Lap?= =?UTF-8?q?oran=20Rekap=20=E2=80=94=20dropdown=20kategori+jenis=20(poin),?= =?UTF-8?q?=20berlaku=20untuk=20tampilan=20&=20cetak=20PDF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/ViolationReportController.php | 15 +++++++++++-- .../reports/violation-report-pdf.blade.php | 2 +- resources/views/reports/violations.blade.php | 21 +++++++++++++++++-- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Admin/ViolationReportController.php b/app/Http/Controllers/Admin/ViolationReportController.php index 2649320..fcb23d1 100644 --- a/app/Http/Controllers/Admin/ViolationReportController.php +++ b/app/Http/Controllers/Admin/ViolationReportController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Classes; use App\Models\Setting; +use App\Models\ViolationType; use App\Models\Violation; use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Database\Eloquent\Builder; @@ -19,6 +20,10 @@ class ViolationReportController extends Controller public function index(Request $request): View { $classes = Classes::orderBy('name')->get(); + $violationTypes = ViolationType::with('category') + ->orderBy('category_id') + ->orderBy('name') + ->get(); $filters = $this->filters($request); $query = $this->baseQuery($filters); @@ -30,7 +35,7 @@ class ViolationReportController extends Controller ->limit(20) ->get(); - return view('reports.violations', compact('classes', 'filters', 'stats', 'recent')); + return view('reports.violations', compact('classes', 'violationTypes', 'filters', 'stats', 'recent')); } public function pdf(Request $request) @@ -85,9 +90,12 @@ class ViolationReportController extends Controller $periode = ($filters['date_from'] ?? 'Awal').' s/d '.($filters['date_to'] ?? 'Sekarang'); $filterKelas = $filters['class_id'] ? (Classes::find($filters['class_id'])?->name ?? '-') : 'Semua Kelas'; + $filterJenis = $filters['violation_type_id'] + ? (ViolationType::find($filters['violation_type_id'])?->name ?? '-') + : 'Semua Jenis Pelanggaran'; $pdf = Pdf::loadView('reports.violation-report-pdf', compact( - 'violations', 'summary', 'perJenis', 'perKelas', 'school', 'periode', 'filterKelas' + 'violations', 'summary', 'perJenis', 'perKelas', 'school', 'periode', 'filterKelas', 'filterJenis' ))->setPaper('a4', 'landscape'); return $pdf->download('rekap-pelanggaran-'.now()->format('Ymd-His').'.pdf'); @@ -104,6 +112,7 @@ class ViolationReportController extends Controller 'date_from' => ['nullable', 'date'], 'date_to' => ['nullable', 'date', 'after_or_equal:date_from'], 'class_id' => ['nullable', 'integer', 'exists:classes,id'], + 'violation_type_id' => ['nullable', 'integer', 'exists:violation_types,id'], ]; $data = $validate ? $request->validate($rules) : $request->validate($rules); @@ -112,6 +121,7 @@ class ViolationReportController extends Controller 'date_from' => $data['date_from'] ?? null, 'date_to' => $data['date_to'] ?? null, 'class_id' => isset($data['class_id']) ? (int) $data['class_id'] : null, + 'violation_type_id' => isset($data['violation_type_id']) ? (int) $data['violation_type_id'] : null, ]; } @@ -124,6 +134,7 @@ class ViolationReportController extends Controller ->when($filters['date_from'], fn ($q) => $q->whereDate('violation_date', '>=', $filters['date_from'])) ->when($filters['date_to'], fn ($q) => $q->whereDate('violation_date', '<=', $filters['date_to'])) ->when($filters['class_id'], fn ($q) => $q->whereHas('student', fn ($qq) => $qq->where('class_id', $filters['class_id']))) + ->when($filters['violation_type_id'], fn ($q) => $q->where('violation_type_id', $filters['violation_type_id'])) ->when(auth()->user()->isScopedWaliKelas(), fn ($q) => $q->whereHas('student', fn ($qq) => $qq->whereIn('class_id', auth()->user()->homeroomClassIds()))); } diff --git a/resources/views/reports/violation-report-pdf.blade.php b/resources/views/reports/violation-report-pdf.blade.php index 4a099b3..b11be29 100644 --- a/resources/views/reports/violation-report-pdf.blade.php +++ b/resources/views/reports/violation-report-pdf.blade.php @@ -68,7 +68,7 @@ {{-- Judul --}}

Rekap Laporan Pelanggaran Siswa

-

Periode: {{ $periode }}  •  Kelas: {{ $filterKelas }}

+

Periode: {{ $periode }}  •  Kelas: {{ $filterKelas }}  •  Jenis: {{ $filterJenis }}

{{-- Ringkasan --}} diff --git a/resources/views/reports/violations.blade.php b/resources/views/reports/violations.blade.php index 98e7eb5..92fadd5 100644 --- a/resources/views/reports/violations.blade.php +++ b/resources/views/reports/violations.blade.php @@ -46,7 +46,7 @@ {{-- ===== Filter Bar ===== --}}
-
+
@@ -75,6 +75,21 @@ @endforeach +
+
+ +
+ + +
@@ -251,7 +266,7 @@ Rincian Pelanggaran Terbaru - Lihat Semua @@ -311,6 +326,7 @@ dateFrom: {{ json_encode($filters['date_from'] ?? '') }}, dateTo: {{ json_encode($filters['date_to'] ?? '') }}, classId: {{ json_encode($filters['class_id'] ?? '') }}, + jenisId: {{ json_encode($filters['violation_type_id'] ?? '') }}, applyPreset(from, to) { this.dateFrom = from; this.dateTo = to; @@ -320,6 +336,7 @@ this.dateFrom = ''; this.dateTo = ''; this.classId = ''; + this.jenisId = ''; this.$nextTick(() => document.getElementById('filter-form').submit()); }, };