diff --git a/accounts.php b/accounts.php
index 94a5f667..c91c5987 100644
--- a/accounts.php
+++ b/accounts.php
@@ -26,10 +26,6 @@
$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'];
diff --git a/add_expense_modal.php b/add_expense_modal.php
index c24187ca..de2bf313 100644
--- a/add_expense_modal.php
+++ b/add_expense_modal.php
@@ -41,10 +41,7 @@
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'];
+ $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);
diff --git a/add_payment_modal.php b/add_payment_modal.php
index ecad5eb8..35572fc6 100644
--- a/add_payment_modal.php
+++ b/add_payment_modal.php
@@ -46,11 +46,8 @@
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'];
diff --git a/add_transfer_modal.php b/add_transfer_modal.php
index 0228e8a3..92818a3f 100644
--- a/add_transfer_modal.php
+++ b/add_transfer_modal.php
@@ -44,11 +44,8 @@
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'];
@@ -82,11 +79,8 @@
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'];
diff --git a/cron.php b/cron.php
index 518ff6f3..a490aa83 100644
--- a/cron.php
+++ b/cron.php
@@ -109,6 +109,7 @@ $sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
WHERE invoices.client_id = clients.client_id
AND invoices.invoice_number > 0
AND invoices.invoice_status NOT LIKE 'Draft'
+ AND invoices.invoice_status NOT LIKE 'Paid'
AND invoices.invoice_due = CURDATE() + INTERVAL 30 DAY
ORDER BY invoices.invoice_number DESC"
);
@@ -131,6 +132,7 @@ $sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients
WHERE invoices.client_id = clients.client_id
AND invoices.invoice_number > 0
AND invoices.invoice_status NOT LIKE 'Draft'
+ AND invoices.invoice_status NOT LIKE 'Paid'
AND invoices.invoice_due = CURDATE() + INTERVAL 90 DAY
ORDER BY invoices.invoice_number DESC"
);
@@ -156,10 +158,6 @@ while($row = mysqli_fetch_array($sql)){
$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'];
diff --git a/edit_expense_modal.php b/edit_expense_modal.php
index 0f971e43..6d5e8d0f 100644
--- a/edit_expense_modal.php
+++ b/edit_expense_modal.php
@@ -42,8 +42,19 @@
while($row = mysqli_fetch_array($sql2)){
$account_id2 = $row['account_id'];
$account_name = $row['account_name'];
+ $opening_balance = $row['opening_balance'];
+
+ $sql_payments = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS total_payments FROM payments WHERE account_id = $account_id2");
+ $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_id2");
+ $row = mysqli_fetch_array($sql_expenses);
+ $total_expenses = $row['total_expenses'];
+
+ $balance = $opening_balance + $total_payments - $total_expenses;
?>
-
+
-
+
-
+