<?php
require_once __DIR__ . '/../../connect.php';
$passenger_id = filterRequest("passenger_id");

$sql = "SELECT
    passengerWallet.`id`,
    passengerWallet.`passenger_id`,
    SUM(passengerWallet.balance) AS total,
    passengers.first_name,
    passengers.last_name,
    passengers.phone,
    passengers.email
FROM
    `passengerWallet`
LEFT JOIN passengers ON passengers.id = passengerWallet.passenger_id
GROUP BY
    passenger_id";
$stmt = $con->prepare($sql);
$stmt->execute();

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

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