system-locked violation types (alpha & terlambat) + proporsional poin alpha per jam

- Migration: add is_system column to violation_types, mark alpha & terlambat
- DestroyType guard: system types cannot be deleted
- UpdateType guard: slug tetap walau nama diubah untuk system types
- UI: delete button hidden, badge lock untuk system types
- Seeder: ViolationTypeDefaultsSeeder untuk fresh deploy
- AttendanceController: lookup by slug (alpha/terlambat) instead of fuzzy match
- Alpha auto-violation: poin proporsional per jam (round((points/10)*count), min 1)
- Terlambat auto-violation: poin fix sesuai jenis (2 poin)
- Also handles both A (alpha) and T (terlambat) statuses for auto-violations
This commit is contained in:
Bro
2026-07-22 23:55:27 +07:00
parent 4bc3a84203
commit 31ef9c0b0b
19 changed files with 1674 additions and 51 deletions
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('attendances', function (Blueprint $table) {
$table->id();
$table->foreignId('student_id')->constrained()->cascadeOnDelete();
$table->date('date');
$table->unsignedTinyInteger('lesson_hour')->comment('Jam ke- 1 s.d 10');
$table->string('status', 20)->default('hadir')->comment('hadir|sakit|izin|alpha|terlambat');
$table->text('notes')->nullable();
$table->foreignId('recorded_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamps();
$table->unique(['student_id', 'date', 'lesson_hour'], 'attendance_unique');
$table->index('date');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('attendances');
}
};
@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('violation_types', function (Blueprint $table) {
$table->boolean('is_system')->default(false)->after('is_active');
});
// Mark existing alpha & terlambat types as system
DB::table('violation_types')
->whereIn('id', function ($q) {
$q->select('id')
->from('violation_types')
->where('name', 'like', '%alpha%')
->orWhere('slug', 'terlambat-datang-ke-sekolah-1');
})
->update(['is_system' => true]);
// Set clean slugs for system types
DB::table('violation_types')
->where('name', 'like', '%alpha%')
->update(['slug' => 'alpha']);
DB::table('violation_types')
->where('slug', 'terlambat-datang-ke-sekolah-1')
->update(['slug' => 'terlambat']);
}
public function down(): void
{
// Restore slugs
DB::table('violation_types')
->where('slug', 'alpha')
->update(['slug' => 'tidak-masuk-tanpa-keterangan-alpha']);
DB::table('violation_types')
->where('slug', 'terlambat')
->update(['slug' => 'terlambat-datang-ke-sekolah']);
Schema::table('violation_types', function (Blueprint $table) {
$table->dropColumn('is_system');
});
}
};