From ad4897c0dc5df8070d06b7ecd7c845dfecbc6b39 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 May 2026 12:46:06 +0800 Subject: [PATCH] chore: add temporary shift sync script --- public/sync-paul-shift.php | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 public/sync-paul-shift.php diff --git a/public/sync-paul-shift.php b/public/sync-paul-shift.php new file mode 100644 index 000000000..726d65c1a --- /dev/null +++ b/public/sync-paul-shift.php @@ -0,0 +1,64 @@ +make(Illuminate\Contracts\Console\Kernel::class); + $kernel->bootstrap(); + + // 1. Find Paul Rei Paas + $employee = \App\Models\Employee::where('biometric_emp_id', '2068')->first(); + if (!$employee) { + throw new \Exception("Employee Paul Rei Paas (2068) not found."); + } + + $userId = $employee->user_id; + echo "Employee found: User ID $userId\n"; + + // 2. Update default shift to 17 in employees table + $employee->shift_id = 17; + $employee->save(); + echo "Updated employee default shift_id to 17 (OPS 08:00AM-05:00PM) in employees table.\n"; + + // 3. Update shift_id to 17 in all attendance_records from March 1st onwards + $updatedRecords = \App\Models\AttendanceRecord::where('employee_id', $userId) + ->where('date', '>=', '2026-03-01') + ->update(['shift_id' => 17]); + + echo "Updated shift_id to 17 for $updatedRecords attendance records (since 2026-03-01).\n"; + + // 4. Reprocess all these records so the status, total hours, and warnings are recalculated using shift 17 + $records = \App\Models\AttendanceRecord::where('employee_id', $userId) + ->where('date', '>=', '2026-03-01') + ->get(); + + $reprocessedCount = 0; + foreach ($records as $record) { + $oldStatus = $record->status; + $record->processAttendance(); + $newStatus = $record->status; + if ($oldStatus !== $newStatus) { + echo "Date: " . $record->date . " | Updated status from $oldStatus to $newStatus\n"; + } + $reprocessedCount++; + } + + echo "\nCompleted successfully. Reprocessed $reprocessedCount records.\n"; + +} catch (\Exception $e) { + echo "ERROR: " . $e->getMessage() . "\n"; +}