<?php
header('Content-Type: application/json');
include '../db.php'; // Include your database connection file

$driver_id = isset($_GET['driver_id']) ? $_GET['driver_id'] : 0;

if ($driver_id == 0) {
    echo json_encode([]);
    exit;
}

$sql = "SELECT trip_id, user_id, pickup_latitude, pickup_longitude, dropoff_latitude, dropoff_longitude, vehicle_type, distance, estimated_time, total_cost, payment_method, timestamp FROM earnings INNER JOIN new_trip_booking ON earnings.trip_id = new_trip_booking.id WHERE earnings.driver_id = $driver_id";
$result = $conn->query($sql);

$earnings = [];
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $earnings[] = $row;
    }
}

echo json_encode($earnings);

$conn->close();
?>
