fix: akumulasi alpha dari multiple push
Sebelum: violation update cuma dari alphaCount push saat itu,
push ke-2 overwrite data push ke-1.
Sesudah: hitung total alpha dari DB (Attendance::count),
violation selalu mencerminkan total akumulasi.
This commit is contained in:
@@ -117,7 +117,11 @@ class AttendanceSyncController extends Controller
|
|||||||
|
|
||||||
foreach ($allStudentIdsInPush as $studentId => $_) {
|
foreach ($allStudentIdsInPush as $studentId => $_) {
|
||||||
try {
|
try {
|
||||||
$count = $alphaCounts[$studentId] ?? 0;
|
// Hitung total alpha di DB (akumulasi dari semua push, bukan cuma push ini)
|
||||||
|
$totalAlpha = \App\Models\Attendance::where('student_id', $studentId)
|
||||||
|
->where('date', $alphaDate)
|
||||||
|
->where('status', 'alpha')
|
||||||
|
->count();
|
||||||
|
|
||||||
// Cari existing system-generated violation
|
// Cari existing system-generated violation
|
||||||
$existing = \App\Models\Violation::where('student_id', $studentId)
|
$existing = \App\Models\Violation::where('student_id', $studentId)
|
||||||
@@ -126,10 +130,10 @@ class AttendanceSyncController extends Controller
|
|||||||
->whereNull('recorded_by')
|
->whereNull('recorded_by')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($count > 0) {
|
if ($totalAlpha > 0) {
|
||||||
// Ada alpha → buat/update violation
|
// Ada alpha → buat/update violation
|
||||||
$points = max(1, (int) round(($alphaType->points / 10) * $count));
|
$points = max(1, (int) round(($alphaType->points / 10) * $totalAlpha));
|
||||||
$desc = "Alpha - Tidak hadir tanpa keterangan ({$count} jam pelajaran)";
|
$desc = "Alpha - Tidak hadir tanpa keterangan ({$totalAlpha} jam pelajaran)";
|
||||||
|
|
||||||
if ($existing) {
|
if ($existing) {
|
||||||
$existing->update([
|
$existing->update([
|
||||||
|
|||||||
Reference in New Issue
Block a user