feat: auto-nonaktifkan siswa lulus/tidak aktif saat sync
Setelah sinkronasi, siswa yang tidak muncul di data sumber (Database Kesiswaan) akan otomatis dinonaktifkan (is_active=false) — mencakup siswa lulus & pindah. Ini memastikan data siswa selalu sinkron dengan tahun ajaran baru tanpa perlu manual cleanup.
This commit is contained in:
@@ -34,7 +34,9 @@ class StudentSyncService
|
||||
$payload = $response->json();
|
||||
$items = Arr::get($payload, 'data', []);
|
||||
|
||||
DB::transaction(function () use ($items, &$results) {
|
||||
\$syncedIds = [];
|
||||
|
||||
DB::transaction(function () use ($items, &$results, &$syncedIds) {
|
||||
foreach ($items as $item) {
|
||||
// Only sync active students
|
||||
$status = $item['status'] ?? 'active';
|
||||
@@ -107,9 +109,17 @@ class StudentSyncService
|
||||
|
||||
if ($student->wasRecentlyCreated) $results['students_created']++;
|
||||
else $results['students_updated']++;
|
||||
|
||||
$syncedIds[] = $student->id;
|
||||
}
|
||||
});
|
||||
|
||||
// Deactivate students not in this sync (graduated/dropped out)
|
||||
\$deactivated = Student::where('is_active', true)
|
||||
->whereNotIn('id', $syncedIds)
|
||||
->update(['is_active' => false]);
|
||||
$results['students_deactivated'] = $deactivated;
|
||||
|
||||
return $results;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Student sync failed: ' . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user