<?php
// ajax_get_customer_balance.php
require_once __DIR__ . '/config/db.php';
require_once __DIR__ . '/src/auth.php';
require_login();
header('Content-Type: application/json');
$id = intval($_GET['id'] ?? 0);
if(!$id) { echo json_encode(['success'=>false]); exit; }
$stmt = $pdo->prepare("SELECT COALESCE(balance,0) as bal FROM customers WHERE id=?");
$stmt->execute([$id]);
$bal = $stmt->fetchColumn();
echo json_encode(['success'=>true, 'balance'=>number_format(floatval($bal),2)]);
