diff --git a/accounts.php b/accounts.php index 983eba3f..94a5f667 100644 --- a/accounts.php +++ b/accounts.php @@ -26,20 +26,23 @@ $account_name = $row['account_name']; $opening_balance = $row['opening_balance']; + $sql_accounts = mysqli_query($mysqli,"SELECT * FROM accounts WHERE account_id = $account_id"); + $row = mysqli_fetch_array($sql_accounts); + $opening_balance = $row['opening_balance']; + + $sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id"); + $row = mysqli_fetch_array($sql_payments); + $total_payments = $row['total_payments']; + + $sql_expenses = mysqli_query($mysqli,"SELECT SUM(expense_amount) AS total_expenses FROM expenses WHERE account_id = $account_id"); + $row = mysqli_fetch_array($sql_expenses); + $total_expenses = $row['total_expenses']; + + $balance = $opening_balance + $total_payments - $total_expenses; ?> + - - $