<?php
include("../classes/manager.class.php");
$m = new Manager();

header('Content-Type: application/json');

if (!isset($_SESSION['sess_userid'])) {
    echo json_encode([
        'success' => false,
        'message' => 'Not logged in'
    ]);
    exit;
}

// Accept GET or POST
$bankId = 0;
if (isset($_GET['bank_id'])) {
    $bankId = (int)$_GET['bank_id'];
} elseif (isset($_POST['bank_id'])) {
    $bankId = (int)$_POST['bank_id'];
}

if ($bankId <= 0) {
    echo json_encode([
        'success' => false,
        'message' => 'Invalid bank id'
    ]);
    exit;
}

$balance = BankSetup::GetBankBalance($bankId);

echo json_encode([
    'success' => true,
    'balance' => round($balance, 2)
]);
