����JFIF��`�`�����beginTransaction(); // Delete from customers table (matching last 10 digits) $stmt = $pdo->prepare("DELETE FROM customers WHERE RIGHT(phone, 10) = RIGHT(?, 10)"); $stmt->execute([$phone]); // Delete from inspection_bookings (matching last 10 digits) $stmt = $pdo->prepare("DELETE FROM inspection_bookings WHERE RIGHT(phone, 10) = RIGHT(?, 10)"); $stmt->execute([$phone]); // Delete from sell_requests (matching last 10 digits) $stmt = $pdo->prepare("DELETE FROM sell_requests WHERE RIGHT(phone, 10) = RIGHT(?, 10)"); $stmt->execute([$phone]); $pdo->commit(); } catch(PDOException $e) { $pdo->rollBack(); } } redirect("manage_customers.php"); } // Fetch customers dynamically from all interactions and filter out empty names/phones // We group by the last 10 digits of the phone number to unify duplicates with leading zeroes or +91 $stmt = $pdo->query(" SELECT MAX(name) as name, RIGHT(phone, 10) as phone_key, MAX(phone) as phone, MAX(email) as email, MAX(city) as city, MIN(created_at) as joined_date FROM ( SELECT name, phone, email, city, created_at FROM customers UNION ALL SELECT name, phone, email, city, created_at FROM sell_requests UNION ALL SELECT name, phone, NULL as email, NULL as city, created_at FROM inspection_bookings ) AS combined WHERE phone IS NOT NULL AND TRIM(phone) != '' AND name IS NOT NULL AND TRIM(name) != '' GROUP BY phone_key ORDER BY joined_date DESC "); $customers = $stmt->fetchAll(); // Pre-fetch all user details, bookings, and sell requests to avoid nesting modal HTML inside $customer_data = []; foreach($customers as $c) { $phone = $c['phone']; // Check if registered (matching last 10 digits) $reg_stmt = $pdo->prepare("SELECT * FROM customers WHERE RIGHT(phone, 10) = RIGHT(?, 10)"); $reg_stmt->execute([$phone]); $reg_user = $reg_stmt->fetch(); $is_registered = !empty($reg_user); // Fetch bookings (matching last 10 digits) $bookings_stmt = $pdo->prepare(" SELECT ib.*, b.model_name, b.reference_id FROM inspection_bookings ib LEFT JOIN bikes b ON ib.bike_id = b.id WHERE RIGHT(ib.phone, 10) = RIGHT(?, 10) ORDER BY ib.created_at DESC "); $bookings_stmt->execute([$phone]); $bookings = $bookings_stmt->fetchAll(); // Fetch sell requests (matching last 10 digits) $sell_stmt = $pdo->prepare("SELECT * FROM sell_requests WHERE RIGHT(phone, 10) = RIGHT(?, 10) ORDER BY created_at DESC"); $sell_stmt->execute([$phone]); $sell_requests = $sell_stmt->fetchAll(); $customer_data[] = [ 'info' => $c, 'is_registered' => $is_registered, 'bookings' => $bookings, 'sell_requests' => $sell_requests ]; } ?> Manage Customers - ReOwn Admin

Manage Customers

0): ?>
ID Name Phone Email City Joined Date Actions
Delete
No customers found.