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

$sql = "SELECT
    (
    SELECT
        COUNT(*)
    FROM
        `ride`
    WHERE
        `ride`.`status` = 'Finished'
        AND `ride`.`created_at` BETWEEN CURRENT_DATE() + INTERVAL 7 HOUR AND CURRENT_DATE() + INTERVAL 10 HOUR
        AND `ride`.`driver_id` = '$driverID'
    ) AS morning_count,
    (
    SELECT
        COUNT(*)
    FROM
        `ride`
    WHERE
        `ride`.`status` = 'Finished'
        AND `ride`.`created_at` BETWEEN CURRENT_DATE() + INTERVAL 15 HOUR AND CURRENT_DATE() + INTERVAL 18 HOUR
        AND `ride`.`driver_id` = '$driverID'
    ) AS afternoon_count,
    (
    SELECT
        COALESCE(SUM(amount), 0) AS total_amount
    FROM
        payments
    WHERE
        isGiven = 'waiting' AND `driverID` = '$driverID'
    ) AS total_amount,
    (
    SELECT
        COALESCE(SUM(price), 0) AS total_amount
    FROM
        ride
    WHERE
        `driver_id` = '$driverID'
        AND `ride`.`status` = 'Finished'
        AND `ride`.`created_at` > CURRENT_DATE() - INTERVAL 1 WEEK
    ) AS total_amount_last_week
FROM
    dual
LIMIT 1;


     ";
$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");
}
?>