<?php
include "../../connect.php";
$passenger_id = filterRequest("passenger_id");

$sql = "SELECT 
    COALESCE(dummy.passenger_id, '$passenger_id') AS passenger_id,
    COALESCE(SUM(pw.balance), 0) AS total,  -- Adjust column to represent payments
    COALESCE(p.first_name, '') AS first_name,
    COALESCE(p.last_name, '') AS last_name,
    COALESCE(p.phone, '') AS phone
FROM 
    (SELECT '$passenger_id' AS passenger_id) AS dummy
LEFT JOIN `passengerWallet` pw ON pw.passenger_id = dummy.passenger_id
LEFT JOIN passengers p ON p.id = dummy.passenger_id
GROUP BY 
    dummy.passenger_id, p.first_name, p.last_name, p.phone
LIMIT 0, 25;
";
$stmt = $con->prepare($sql);
$stmt->execute();

if ($stmt->rowCount() > 0) {
    // Fetch the record
    $row = $stmt->fetchAll(PDO::FETCH_ASSOC);

    printSuccess( $row);
    
}
    else{
    // Print a failure message
    printFailure($message = "No wallet record found");
}
?>