<?php
include_once '../config/connect.php';

$query = "SELECT SUM(balance) AS total_saldo FROM tb_user";
$result = mysqli_query($call, $query);
$row = mysqli_fetch_assoc($result);
$total_saldo = $row['total_saldo'] ?? 0;

$data = [
    "Kurang dari 1jt" => mysqli_fetch_assoc(mysqli_query($call, "SELECT SUM(balance) AS saldo FROM tb_user WHERE balance < 1000000"))['saldo'] ?? 0,
    "1jt - 10jt" => mysqli_fetch_assoc(mysqli_query($call, "SELECT SUM(balance) AS saldo FROM tb_user WHERE balance BETWEEN 1000000 AND 10000000"))['saldo'] ?? 0,
    "10jt - 50jt" => mysqli_fetch_assoc(mysqli_query($call, "SELECT SUM(balance) AS saldo FROM tb_user WHERE balance BETWEEN 10000000 AND 50000000"))['saldo'] ?? 0,
    "Lebih dari 50jt" => mysqli_fetch_assoc(mysqli_query($call, "SELECT SUM(balance) AS saldo FROM tb_user WHERE balance > 50000000"))['saldo'] ?? 0,
];

header('Content-Type: application/json');
echo json_encode($data);
?>
