Sederhanakan ambang SP: hapus kolom max_points

- max_points tidak pernah dipakai logika penerbitan SP (trigger hanya baca
  min_points: level dgn ambang tertinggi <= total poin siswa)
- Migrasi drop kolom; model, MasterDataController, ResetController (seeder)
  dibersihkan; form Ambang SP & form tambah cukup satu angka (Min Poin)
- Dashboard Ambang SP: batas atas level dihitung dari min_points level
  berikutnya (level terakhir = tak terbatas), urutan dijamin orderBy min_points
- Test: 29 passed / 99 assertion
This commit is contained in:
Novy San87
2026-08-03 14:22:44 +07:00
parent e815bd28d5
commit 279ef07ae2
8 changed files with 47 additions and 35 deletions
@@ -300,7 +300,6 @@ class MasterDataController extends Controller
'thresholds' => ['required', 'array'],
'thresholds.*.id' => ['required', 'exists:sp_thresholds,id'],
'thresholds.*.min_points' => ['required', 'integer', 'min:0'],
'thresholds.*.max_points' => ['nullable', 'integer', 'min:0'],
'thresholds.*.name' => ['required', 'string', 'max:255'],
'thresholds.*.default_description' => ['nullable', 'string', 'max:500'],
]);
@@ -311,7 +310,6 @@ class MasterDataController extends Controller
$update = [
'name' => $data['name'],
'min_points' => $data['min_points'],
'max_points' => $data['max_points'],
'default_description' => $data['default_description'],
'is_active' => isset($inputs[$idx]['is_active']),
];
@@ -328,7 +326,6 @@ class MasterDataController extends Controller
$data = $request->validate([
'name' => ['required', 'string', 'max:255'],
'min_points' => ['required', 'integer', 'min:0'],
'max_points' => ['nullable', 'integer', 'min:0'],
'default_description' => ['nullable', 'string', 'max:500'],
'color' => ['nullable', 'string', 'max:20'],
]);
@@ -338,7 +335,6 @@ class MasterDataController extends Controller
'name' => $data['name'],
'slug' => $slug,
'min_points' => $data['min_points'],
'max_points' => $data['max_points'],
'default_description' => $data['default_description'],
'color' => $data['color'] ?? '#6b7280',
'is_active' => true,
@@ -199,9 +199,9 @@ class ResetController extends Controller
private function seedDefaultThresholds(): void
{
$thresholds = [
['name' => 'SP 1', 'slug' => 'sp-1', 'min_points' => 50, 'max_points' => 99, 'color' => '#eab308', 'is_active' => true, 'default_description' => 'Surat Peringatan 1 — poin mencapai 50', 'created_at' => now(), 'updated_at' => now()],
['name' => 'SP 2', 'slug' => 'sp-2', 'min_points' => 100, 'max_points' => 149, 'color' => '#f97316', 'is_active' => true, 'default_description' => 'Surat Peringatan 2 — poin mencapai 100', 'created_at' => now(), 'updated_at' => now()],
['name' => 'SP 3', 'slug' => 'sp-3', 'min_points' => 150, 'max_points' => null, 'color' => '#ef4444', 'is_active' => true, 'default_description' => 'Surat Peringatan 3 — poin mencapai 150', 'created_at' => now(), 'updated_at' => now()],
['name' => 'SP 1', 'slug' => 'sp-1', 'min_points' => 50, 'color' => '#eab308', 'is_active' => true, 'default_description' => 'Surat Peringatan 1 — poin mencapai 50', 'created_at' => now(), 'updated_at' => now()],
['name' => 'SP 2', 'slug' => 'sp-2', 'min_points' => 100, 'color' => '#f97316', 'is_active' => true, 'default_description' => 'Surat Peringatan 2 — poin mencapai 100', 'created_at' => now(), 'updated_at' => now()],
['name' => 'SP 3', 'slug' => 'sp-3', 'min_points' => 150, 'color' => '#ef4444', 'is_active' => true, 'default_description' => 'Surat Peringatan 3 — poin mencapai 150', 'created_at' => now(), 'updated_at' => now()],
];
DB::table('sp_thresholds')->insert($thresholds);
}
+1 -1
View File
@@ -59,7 +59,7 @@ class DashboardController extends Controller
->where('is_read', false)
->count();
$spThresholds = \App\Models\SpThreshold::where('is_active', true)->get();
$spThresholds = \App\Models\SpThreshold::where('is_active', true)->orderBy('min_points')->get();
// Data untuk calendar: pelanggaran per tanggal di bulan ini
$calendarData = Violation::selectRaw('DATE(violation_date) as date, COUNT(*) as count')