info("Initializing Fractional Tardiness Matrix Sync..."); // Map users $legacyUsers = DB::connection('legacy')->table('users')->get(['id', 'name']); $newUserIdMap = []; foreach ($legacyUsers as $lu) { $matchingLocal = User::where('name', $lu->name)->first(); if ($matchingLocal) { // Key = legacy user ID, Value = local user ID $newUserIdMap[$lu->id] = $matchingLocal->id; } } // Loop target logs $logs = DB::connection('legacy')->table('attendances') ->whereNotNull('late_hours') ->orWhereNotNull('early_hours') ->get(); $bar = $this->output->createProgressBar(count($logs)); foreach ($logs as $log) { if (!isset($newUserIdMap[$log->user_id])) { $bar->advance(); continue; } $localUserId = $newUserIdMap[$log->user_id]; AttendanceRecord::where('employee_id', $localUserId) ->where('date', $log->date) ->update([ 'late_hours' => collect([$log->late_hours, 0])->max(), 'early_hours' => collect([$log->early_hours, 0])->max(), ]); $bar->advance(); } $bar->finish(); $this->info("\nPrecision Hour Synchronization locked directly into native Engine!"); } }