From b2cf2c94777c0b7e94dc6d0ee688c05499402b52 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 28 Jan 2019 17:02:13 -0500 Subject: [PATCH] Updates for billing Report Generator Get totals for payments and invoices. Fix some php notices. --- classes/data/dataTransactions.php | 38 +++++++++++++++++++++++++++++++ models/admin/billing/payments.php | 2 +- models/admin/billing/reports.php | 10 ++++++-- views/admin/billing/reports.html | 4 ++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/classes/data/dataTransactions.php b/classes/data/dataTransactions.php index 3a535d1..865282c 100644 --- a/classes/data/dataTransactions.php +++ b/classes/data/dataTransactions.php @@ -237,4 +237,42 @@ class GlmDataTransactions extends GlmDataAbstract } + /** + * getInvoiceTotal + * + * Get total for all invoices given the $where clause + * + * @param string $where Where clause + * + * @return mixed + */ + public function getInvoiceTotal( $where ) + { + $totalInvoices = $this->wpdb->get_var( + "SELECT SUM(current_invoice_total) + FROM " . $this->table . " T + WHERE $where" + ); + return $totalInvoices; + } + + /** + * getPaymentTotal + * + * Get total payments given the $where clause + * + * @param string $where Where clause + * + * @return mixed + */ + public function getPaymentTotal( $where ) + { + $totalInvoices = $this->wpdb->get_var( + "SELECT SUM(current_payment_total) + FROM " . $this->table . " T + WHERE $where" + ); + return $totalInvoices; + } + } diff --git a/models/admin/billing/payments.php b/models/admin/billing/payments.php index e825942..f85d884 100644 --- a/models/admin/billing/payments.php +++ b/models/admin/billing/payments.php @@ -331,7 +331,7 @@ class GlmMembersAdmin_billing_payments extends GlmDataPayments // since we're doing paging, we have to break out just the payments data $payments = $paymentsResult['list']; - if (count($payments)>0) { + if ( isset( $payments ) && is_array( $payments ) && count($payments)>0) { $havePayments = true; } unset($paymentsResult); diff --git a/models/admin/billing/reports.php b/models/admin/billing/reports.php index 0ae8d46..661d43b 100644 --- a/models/admin/billing/reports.php +++ b/models/admin/billing/reports.php @@ -110,6 +110,8 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions $totalAccounts = false; $option2 = false; $transactions = false; + $totalInvoices = 0; + $totalPayments = 0; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -263,6 +265,9 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions $this->notes = true; $accountsResult = $this->getList( $reportWhere, $orderBy, true, 'id', $start, $limit ); $totalAccounts = $this->getStats( $reportWhere ); + $totalInvoices = $this->getInvoiceTotal( $reportWhere ); + $totalPayments = $this->getPaymentTotal( $reportWhere ); + $this->member_data = false; $this->notes = false; break; @@ -309,7 +314,7 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions // since we're doing paging, we have to break out just the accounts data $accounts = $accountsResult['list']; // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; - if ( count( $accounts ) > 0 ) { + if ( isset( $accounts ) && is_array( $accounts ) && count( $accounts ) > 0 ) { $haveAccounts = true; } } else { @@ -333,7 +338,6 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions // since we're doing paging, we have to break out just the transactions data $transactions = $accountsResult['list']; - // echo '
$transactions: ' . print_r( $transactions, true ) . '
'; if ( count( $transactions ) > 0 ) { $haveAccounts = true; } @@ -362,6 +366,8 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions 'numbDisplayed' => $numbDisplayed, 'lastDisplayed' => $lastDisplayed, 'totalAccounts' => $totalAccounts, + 'totalInvoices' => $totalInvoices, + 'totalPayments' => $totalPayments, ); // Return status, any suggested view, and any data to controller diff --git a/views/admin/billing/reports.html b/views/admin/billing/reports.html index 02dd49a..7aeb51c 100644 --- a/views/admin/billing/reports.html +++ b/views/admin/billing/reports.html @@ -147,6 +147,10 @@ {/if} +
+
Total Invoices: {$totalInvoices}
+
Total Payments: {$totalPayments}
+