diff --git a/report_collections.php b/report_collections.php new file mode 100644 index 00000000..19973c0f --- /dev/null +++ b/report_collections.php @@ -0,0 +1,118 @@ + 0 THEN + (IFNULL(SUM(invoices.invoice_amount), 0) - IFNULL(SUM(payments.payment_amount), 0) - IFNULL(recurring_totals.recurring_monthly_total, 0)) / recurring_totals.recurring_monthly_total + ELSE + 0 + END AS months_behind + FROM + clients + LEFT JOIN + 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 + (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 + LEFT JOIN + contacts + ON + clients.client_id = contacts.contact_client_id AND contacts.contact_billing = 1 + LEFT JOIN + (SELECT + recurring_client_id, + SUM(recurring_amount) AS recurring_monthly_total + FROM recurring + WHERE recurring_status = 1 AND recurring_frequency = 'month' + GROUP BY recurring_client_id) as recurring_totals + ON + clients.client_id = recurring_totals.recurring_client_id + GROUP BY + clients.client_id, + clients.client_name, + contacts.contact_phone, + recurring_totals.recurring_monthly_total + HAVING + balance > 0 AND months_behind >= 2 + ORDER BY + months_behind DESC;"; + $result_client_balance_report = mysqli_query($mysqli, $sql_client_balance_report); +?> + +
+
+

Collections

+
+ +
+
+
+
+
+ + + + + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> + +
Client NameBalanceBilling Contact PhoneMonthly Recurring AmountPast Due BalanceMonths Past Due
$client_name$formatted_balance$billing_contact_phone$formatted_recurring_monthly_total$formatted_behind_amount$months_behind
+
+
+
+
+ + diff --git a/reports_side_nav.php b/reports_side_nav.php index 626dc3c6..77363e97 100644 --- a/reports_side_nav.php +++ b/reports_side_nav.php @@ -54,7 +54,7 @@ @@ -66,7 +66,7 @@ @@ -76,6 +76,12 @@

Balance Sheet

+