<?php
require_once '../../connections/meekro/db.class.php';

$currentMonth = $_GET['month'] ?? date('n');
$currentYear  = $_GET['year'] ?? date('Y');
$currentMonth = 5;
try {
    $results = DB::query("
        SELECT 
            DAY(transaction_date) AS day,
            DATE_FORMAT(transaction_date, '%e %b') AS label,
            SUM(revenue_collected) AS total_collected
        FROM fast_track
        WHERE MONTH(transaction_date) = '$currentMonth' AND YEAR(transaction_date) = '$currentYear'
        GROUP BY DAY(transaction_date)
        ORDER BY DAY(transaction_date)
    ");

    header('Content-Type: application/json');
    echo json_encode([
        "month" => date("F", mktime(0, 0, 0, $currentMonth, 1)),
        "year" => $currentYear,
        "daily" => $results
    ]);
} catch (Exception $e) {
    echo json_encode(["error" => "Database error: " . $e->getMessage()]);
}
?>
