<?php
header("Content-Type: application/json; charset=UTF-8");
include 'config.php';

// 1️⃣ Total Used Transaction (status = 1)
$q1 = "SELECT COUNT(*) AS used_total FROM ShuvoPays WHERE status='1'";
$r1 = $conn->query($q1)->fetch_assoc();
$used_total = intval($r1['used_total']);

// 2️⃣ Total Unused Transaction (status = 0)
$q2 = "SELECT COUNT(*) AS unused_total FROM ShuvoPays WHERE status='0'";
$r2 = $conn->query($q2)->fetch_assoc();
$unused_total = intval($r2['unused_total']);

// 3️⃣ Today's total deposit (status যাই হোক)
$today = date("Y-m-d");

$stmt = $conn->prepare("
    SELECT COUNT(*) AS daily_total, SUM(amount) AS daily_amount
    FROM ShuvoPays
    WHERE DATE(created_at) = ?
");
$stmt->bind_param("s", $today);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$daily_total  = intval($row['daily_total']); // আজকের ডিপোজিটের সংখ্যা
$daily_amount = floatval($row['daily_amount']); // আজকের মোট টাকা

$stmt->close();
$conn->close();

// Final Response
echo json_encode([
    "success"       => true,
    "used_total"    => $used_total,
    "unused_total"  => $unused_total,
    "daily_total"   => $daily_total,
    "daily_amount"  => $daily_amount
], JSON_PRETTY_PRINT);
?>