diff --git a/.gitignore b/.gitignore index 7be55e2..a0ed834 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ _ide_helper.php Homestead.json Homestead.yaml Thumbs.db +.env.bak* diff --git a/app/Http/Controllers/Admin/MasterDataController.php b/app/Http/Controllers/Admin/MasterDataController.php index 798fe52..6b4ae27 100644 --- a/app/Http/Controllers/Admin/MasterDataController.php +++ b/app/Http/Controllers/Admin/MasterDataController.php @@ -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, diff --git a/app/Http/Controllers/Admin/ResetController.php b/app/Http/Controllers/Admin/ResetController.php index 3e7a8bd..d7661c7 100644 --- a/app/Http/Controllers/Admin/ResetController.php +++ b/app/Http/Controllers/Admin/ResetController.php @@ -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); } diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 3a3b726..53a6e78 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -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') diff --git a/app/Models/SpThreshold.php b/app/Models/SpThreshold.php index a15b3ee..2093d78 100644 --- a/app/Models/SpThreshold.php +++ b/app/Models/SpThreshold.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class SpThreshold extends Model { protected $fillable = [ - 'name', 'slug', 'min_points', 'max_points', + 'name', 'slug', 'min_points', 'color', 'default_description', 'is_active', ]; @@ -15,7 +15,6 @@ class SpThreshold extends Model { return [ 'min_points' => 'integer', - 'max_points' => 'integer', 'is_active' => 'boolean', ]; } diff --git a/database/migrations/2026_08_03_141500_drop_max_points_from_sp_thresholds_table.php b/database/migrations/2026_08_03_141500_drop_max_points_from_sp_thresholds_table.php new file mode 100644 index 0000000..8a04a06 --- /dev/null +++ b/database/migrations/2026_08_03_141500_drop_max_points_from_sp_thresholds_table.php @@ -0,0 +1,26 @@ +dropColumn('max_points'); + }); + } + + public function down(): void + { + Schema::table('sp_thresholds', function (Blueprint $table) { + $table->integer('max_points')->nullable()->after('min_points'); + }); + } +}; diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 420a4ba..784aa48 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -218,12 +218,16 @@
- @foreach($spThresholds as $threshold) + @foreach($spThresholds as $i => $threshold) @php - $studentsAtRisk = \App\Models\Student::where('is_active', true)->get()->filter(function($s) use ($threshold) { + // Batas atas level ini = ambang minimal level berikutnya + $nextMin = $spThresholds[$i + 1]->min_points ?? null; + $studentsAtRisk = \App\Models\Student::where('is_active', true)->get()->filter(function($s) use ($threshold, $nextMin) { $pts = $s->total_points; - $maxOk = $threshold->max_points ?? 9999; - return $pts >= $threshold->min_points && $pts <= $maxOk; + if ($nextMin !== null) { + return $pts >= $threshold->min_points && $pts < $nextMin; + } + return $pts >= $threshold->min_points; }); $count = $studentsAtRisk->count(); @endphp @@ -232,7 +236,7 @@

{{ $threshold->name }}

-

{{ $threshold->min_points }}{{ $threshold->max_points ? '–'.$threshold->max_points : '+' }} poin

+

{{ $threshold->min_points }}{{ $nextMin !== null ? '–'.($nextMin - 1) : '+' }} poin

{{ $count }}

diff --git a/resources/views/settings/thresholds.blade.php b/resources/views/settings/thresholds.blade.php index e47489a..e8f216c 100644 --- a/resources/views/settings/thresholds.blade.php +++ b/resources/views/settings/thresholds.blade.php @@ -53,9 +53,7 @@ style="{{ $t->is_active ? 'background-color: ' . $t->color : '' }}">
-

Min {{ $t->min_points }} poin - @if($t->max_points) – Maks {{ $t->max_points }} poin @else + (tak terbatas) @endif -

+

Mulai dari {{ $t->min_points }} poin

@@ -73,7 +71,7 @@
{{-- Fields --}} -
+
-
- - -
-
-
- - -
-
- - -
+
+ +