Updates for billing Report Generator
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 28 Jan 2019 22:02:13 +0000 (17:02 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 28 Jan 2019 22:02:13 +0000 (17:02 -0500)
Get totals for payments and invoices.
Fix some php notices.

classes/data/dataTransactions.php
models/admin/billing/payments.php
models/admin/billing/reports.php
views/admin/billing/reports.html

index 3a535d1..865282c 100644 (file)
@@ -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;
+    }
+
 }
index e825942..f85d884 100644 (file)
@@ -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);
index 0ae8d46..661d43b 100644 (file)
@@ -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 '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
-            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 '<pre>$transactions: ' . print_r( $transactions, true ) . '</pre>';
                 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
index 02dd49a..7aeb51c 100644 (file)
         <input type="submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
     {/if}
 </form>
+<div class="report-totals">
+    <div class="total-invoices">Total Invoices: <span>{$totalInvoices}</span></div>
+    <div class="total-payments">Total Payments: <span>{$totalPayments}</span></div>
+</div>
 <script>
 jQuery(document).ready(function($) {
     // Date Input