= DATE_SUB(CURDATE(), INTERVAL 4 DAY) ORDER BY created_at DESC LIMIT 200"; $stmt = $con->prepare($sql); $stmt->execute(); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); // أرقام الركاب المسجَّلين فعلاً، بصيغتها الأصلية $registered = []; foreach ($con->query("SELECT phone FROM passengers WHERE phone IS NOT NULL")->fetchAll(PDO::FETCH_COLUMN) as $enc) { $plain = $encryptionHelper->decryptData($enc); if ($plain) $registered[normalizePhone($plain)] = true; } // الملاحظات المسجَّلة سابقاً عن كل رقم $notes = []; try { $noteRows = $con->query("SELECT phone, note, editor, createdAt FROM notesForPassengerService")->fetchAll(PDO::FETCH_ASSOC); foreach ($noteRows as $n) { $plain = $encryptionHelper->decryptData($n['phone']) ?: $n['phone']; if ($plain) $notes[normalizePhone($plain)] = $n; } } catch (PDOException $e) { error_log('[getPassengersNotCompleteRegistration] notes unavailable: ' . $e->getMessage()); } $result = []; foreach ($rows as $row) { $phone = $encryptionHelper->decryptData($row['phone_enc'] ?? null); // السجلات التي سبقت إضافة phone_enc لا يمكن استرجاع رقمها من المفتاح if (!$phone) continue; $key = normalizePhone($phone); if (isset($registered[$key])) continue; // أكمل تسجيله فعلاً $note = $notes[$key] ?? null; $result[] = [ 'id' => $row['id'], 'phone_number' => $phone, 'created_at' => $row['created_at'], 'note' => $note['note'] ?? null, 'editor' => $note['editor'] ?? null, 'note_created_at' => $note['createdAt'] ?? null, ]; if (count($result) >= 25) break; } if ($result) { jsonSuccess($result); } else { jsonError("No records found"); }