mirror of
https://github.com/itflow-org/itflow
synced 2026-03-20 12:44:50 +00:00
Fix Report for Client Balance Query
This commit is contained in:
@@ -17,21 +17,26 @@ validateAccountantRole();
|
|||||||
<?php
|
<?php
|
||||||
$sql_clients = mysqli_query($mysqli, "
|
$sql_clients = mysqli_query($mysqli, "
|
||||||
SELECT
|
SELECT
|
||||||
c.client_id,
|
clients.client_id,
|
||||||
c.client_name,
|
clients.client_name,
|
||||||
IFNULL(SUM(i.invoice_amount), 0) AS invoice_amounts,
|
SUM(invoices.invoice_amount) - COALESCE(SUM(payments.payment_amount), 0) AS balance
|
||||||
IFNULL(SUM(p.payment_amount), 0) AS amount_paid,
|
|
||||||
IFNULL(SUM(i.invoice_amount), 0) - IFNULL(SUM(p.payment_amount), 0) AS balance
|
|
||||||
FROM
|
FROM
|
||||||
clients c
|
clients
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
invoices i ON c.client_id = i.invoice_client_id AND i.invoice_status NOT IN ('Draft', 'Cancelled')
|
invoices
|
||||||
|
ON
|
||||||
|
clients.client_id = invoices.invoice_client_id
|
||||||
|
AND invoices.invoice_status NOT LIKE 'Draft'
|
||||||
|
AND invoices.invoice_status NOT LIKE 'Cancelled'
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
payments p ON i.invoice_id = p.payment_invoice_id
|
payments
|
||||||
|
ON
|
||||||
|
invoices.invoice_id = payments.payment_invoice_id
|
||||||
GROUP BY
|
GROUP BY
|
||||||
c.client_id
|
clients.client_id,
|
||||||
|
clients.client_name
|
||||||
HAVING
|
HAVING
|
||||||
balance != 0
|
balance > 0
|
||||||
ORDER BY
|
ORDER BY
|
||||||
balance DESC
|
balance DESC
|
||||||
");
|
");
|
||||||
|
|||||||
Reference in New Issue
Block a user