<?php
require_once __DIR__ . "/../_core.php";

cors_headers();
start_erp_session();
require_login();

$conn = db_connect();

$cash_account_id = (int)($_GET["cash_account_id"] ?? 0);
if ($cash_account_id <= 0) {
    respond(false, "cash_account_id দিন", null, 400);
}

$q = "
SELECT id, account_name, opening_balance, current_balance
FROM cash_accounts
WHERE id = $cash_account_id
LIMIT 1
";
$res = mysqli_query($conn, $q);

if (!$res) {
    respond(false, "DB Error", ["error" => mysqli_error($conn)], 500);
}

$row = mysqli_fetch_assoc($res);
if (!$row) {
    respond(false, "Account not found", ["id" => $cash_account_id], 404);
}

respond(true, "balance ok", [
    "id" => (int)$row["id"],
    "account_name" => $row["account_name"],
    "opening_balance" => (float)$row["opening_balance"],
    "current_balance" => (float)$row["current_balance"]
]);