From a67a925868d296008fd12203bf884dfea1c8b47e Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 21 Jun 2023 15:47:19 -0400 Subject: [PATCH] Another SQL Attempt to fix Client Balance calc --- report_clients_with_balance.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/report_clients_with_balance.php b/report_clients_with_balance.php index f13e89a0..42364d31 100644 --- a/report_clients_with_balance.php +++ b/report_clients_with_balance.php @@ -19,7 +19,7 @@ validateAccountantRole(); SELECT clients.client_id, clients.client_name, - SUM(invoices.invoice_amount) - COALESCE(SUM(payments.payment_amount), 0) AS balance + IFNULL(SUM(invoices.invoice_amount), 0) - IFNULL(SUM(payments.payment_amount), 0) AS balance FROM clients LEFT JOIN @@ -29,7 +29,11 @@ validateAccountantRole(); AND invoices.invoice_status NOT LIKE 'Draft' AND invoices.invoice_status NOT LIKE 'Cancelled' LEFT JOIN - payments + (SELECT + payment_invoice_id, + SUM(payment_amount) as payment_amount + FROM payments + GROUP BY payment_invoice_id) as payments ON invoices.invoice_id = payments.payment_invoice_id GROUP BY