From c53b2402e530579e052098be4d58558e408bef1b Mon Sep 17 00:00:00 2001 From: johnnyq Date: Fri, 28 Aug 2026 15:13:17 -0400 Subject: [PATCH] Spruced up the Account Statement on Guest View Invoice --- guest/guest_view_invoice.php | 226 ++++++++++++++++++----------------- 1 file changed, 116 insertions(+), 110 deletions(-) diff --git a/guest/guest_view_invoice.php b/guest/guest_view_invoice.php index 3046f8959..4df27f768 100644 --- a/guest/guest_view_invoice.php +++ b/guest/guest_view_invoice.php @@ -363,126 +363,132 @@ if ($balance > 0) { CURDATE() AND(invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial') ORDER BY invoice_number DESC"); +$sql_statement = mysqli_query( + $mysqli, + "SELECT invoice_amount, invoice_currency_code, invoice_date, invoice_due, invoice_id, + invoice_number, invoice_prefix, invoice_scope, invoice_url_key, + IFNULL(amount_paid, 0) AS amount_paid + FROM invoices + LEFT JOIN ( + SELECT payment_invoice_id, SUM(payment_amount) AS amount_paid FROM payments + WHERE payment_archived_at IS NULL + GROUP BY payment_invoice_id + ) AS invoice_payments ON payment_invoice_id = invoice_id + WHERE invoice_client_id = $client_id + AND invoice_status NOT IN ('Draft', 'Cancelled', 'Non-Billable') + AND invoice_amount - IFNULL(invoice_payments.amount_paid, 0) > 0 + ORDER BY invoice_date ASC, invoice_number ASC" +); -$current_invoices_count = mysqli_num_rows($sql_current_invoices); +$statement_count = mysqli_num_rows($sql_statement); -if ($current_invoices_count > 0) { ?> +if ($statement_count > 0) { ?> -
-
- Current Invoices +
+
+ + Account Statement +
-
- - - - - - - - - - - - - > - - - - +
+
+
InvoiceDateDueAmount
(Due in Days)
+ + + + + + + + + - - - - -
InvoiceScopeDateDueAmountPaidBalance
-
-
- - - - 0) { ?> - -
-
- Outstanding Invoices -
-
- - - - - - - - - - - - - > - - - - - - + + - -
InvoiceDateDueAmount
(Over Due by Days)
+ /* + * Distinct variable names on purpose. The two cards this + * replaces reused $invoice_id / $invoice_prefix / $invoice_due + * for their loop rows, which clobbered the page's own invoice - + * that is why the old highlight test had to read $_GET instead + * of comparing against $invoice_id. + */ + while ($row = mysqli_fetch_assoc($sql_statement)) { + $statement_invoice_id = intval($row['invoice_id']); + $statement_invoice_prefix = escapeHtml($row['invoice_prefix']); + $statement_invoice_number = intval($row['invoice_number']); + $statement_invoice_scope = escapeHtml($row['invoice_scope']); + $statement_invoice_date = escapeHtml($row['invoice_date']); + $statement_invoice_due = escapeHtml($row['invoice_due']); + $statement_invoice_url_key = escapeHtml($row['invoice_url_key']); + $statement_invoice_amount = floatval($row['invoice_amount']); + $statement_invoice_currency_code = escapeHtml($row['invoice_currency_code']); + $statement_amount_paid = floatval($row['amount_paid']); + $statement_invoice_balance = $statement_invoice_amount - $statement_amount_paid; + + $invoice_tally_total = $invoice_tally_total + $statement_invoice_balance; + + $statement_days = floor((time() - strtotime($statement_invoice_due)) / (60 * 60 * 24)); + + if ($statement_days > 0) { + $statement_due_class = 'text-danger'; + $statement_due_note = "(overdue by $statement_days days)"; + } else { + $statement_due_class = ''; + $statement_due_note = '(due in ' . abs($statement_days) . ' days)'; + } + + ?> + + > + + + + + + + + + + + + + + + + + + + Total Balance Due + + + + +
-