feat: audit log poin — catat pencatatan/penghapusan pelanggaran (sebelum/sesudah/delta, metadata snapshot, actor, IP) + halaman Riwayat Poin (filter, permission view-point-audit) + 4 feature test

This commit is contained in:
Sari
2026-08-03 09:12:46 +07:00
parent 6f430f35d7
commit 2dda08bb8d
11 changed files with 576 additions and 0 deletions
+20
View File
@@ -3,6 +3,7 @@
namespace App\Services;
use App\Events\ViolationRecorded;
use App\Models\PointAuditLog;
use App\Models\SpLetter;
use App\Models\SpThreshold;
use App\Models\Student;
@@ -45,6 +46,25 @@ class ViolationService
}
}
// Audit log perubahan poin (pencatatan pelanggaran)
$after = $violation->student->total_points;
PointAuditLog::log(
studentId: $violation->student_id,
action: PointAuditLog::ACTION_CREATED,
pointsBefore: $after - $violation->points,
pointsAfter: $after,
description: $violation->violationType?->name ?? 'Pelanggaran',
metadata: [
'violation_date' => $violation->violation_date?->format('Y-m-d'),
'description' => $violation->description,
'sanction' => $violation->sanction,
'location' => $violation->location,
],
violationId: $violation->id,
actorId: $userId,
ipAddress: request()->ip(),
);
return $violation;
});