<?php session_start();?>
<?php include'../includes/db.php';?>
<?php
if (isset($_GET['val'])) {
	$val = $_GET['val'];

	$sel = "SELECT *, SUM(amount_owed) AS amount_owed FROM wallet WHERE walletNo = ?";
	$stmt = $pdo->prepare($sel);
	$stmt->execute([$val]);

	$row = $stmt->fetch(PDO::FETCH_ASSOC);
	$customer_name = $row['customer'];
	$owed_amt       = $row['amount_owed'];
	$trackId = $val;
}

// Get the total amount being paid
$tot = "SELECT SUM(amount_paid) AS TOTAL FROM debt_transaction WHERE walletNo = ?";
$totPdo = $pdo->prepare($tot);
$totPdo->execute([$trackId]);
$totalRow = $totPdo->fetch(PDO::FETCH_ASSOC);
$totalAmount = $totalRow['TOTAL'];

// Amount to balance
$amtbal = $owed_amt - $totalAmount;

?>
₦-<?php echo number_format($amtbal, 2);?>