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;
?>
+
|
-
-
$ |
diff --git a/add_expense_modal.php b/add_expense_modal.php
index c6e10d8b..1d8d42f8 100644
--- a/add_expense_modal.php
+++ b/add_expense_modal.php
@@ -41,8 +41,23 @@
while($row = mysqli_fetch_array($sql)){
$account_id = $row['account_id'];
$account_name = $row['account_name'];
+
+ $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;
+
?>
-
+
-
+
-
+
-
+
|