fix: Export Excel kini mengikuti semua filter (periode, kelas, jenis pelanggaran) + scope wali kelas

This commit is contained in:
Novy San87
2026-08-06 23:04:19 +07:00
parent f5a24a4cf0
commit 27e1e71fc9
@@ -26,6 +26,16 @@ class ViolationExportController extends Controller
if ($request->filled('date_to')) { if ($request->filled('date_to')) {
$query->whereDate('violation_date', '<=', $request->date_to); $query->whereDate('violation_date', '<=', $request->date_to);
} }
if ($request->filled('class_id')) {
$query->whereHas('student', fn ($q) => $q->where('class_id', $request->class_id));
}
if ($request->filled('violation_type_id')) {
$query->where('violation_type_id', $request->violation_type_id);
}
// Wali kelas hanya melihat data kelasnya sendiri
if (auth()->user() && auth()->user()->isScopedWaliKelas()) {
$query->whereHas('student', fn ($q) => $q->whereIn('class_id', auth()->user()->homeroomClassIds()));
}
$violations = $query->orderBy('violation_date', 'desc')->get(); $violations = $query->orderBy('violation_date', 'desc')->get();