WIP for reports
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Dec 2018 22:01:57 +0000 (17:01 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 13 Dec 2018 22:01:57 +0000 (17:01 -0500)
Working on report generator

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

index ee89fe0..9da515c 100644 (file)
@@ -72,6 +72,7 @@ class GlmDataTransactions extends GlmDataAbstract
      * @access public
      */
     public $fields = false;
+    public $member_data = false;
 
     /**
      * Constructor
@@ -183,6 +184,47 @@ class GlmDataTransactions extends GlmDataAbstract
      */
     public function entryPostProcessing($r, $a)
     {
+        if ( $this->member_data ) {
+            $member_data = $this->wpdb->get_row(
+                $this->wpdb->prepare(
+                    "SELECT A.ref_name,A.ref_dest
+                       FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions I
+                       LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts A ON ( I.account = A.id )
+                      WHERE I.id = %d",
+                    $r['id']
+                ),
+                ARRAY_A
+            );
+            if ( isset( $member_data ) && $member_data['ref_name'] ) {
+                $r['member_name'] = $member_data['ref_name'];
+            }
+            if ( isset( $member_data ) && $member_data['ref_dest'] ) {
+                $r['member_id'] = $member_data['ref_dest'];
+            }
+        }
+        if ( $this->notes ) {
+            if ( $r['type'] == $this->config['transaction_numb']['Invoice'] ) {
+                $r['notes'] = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT I.notes
+                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices I
+                           LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions T ON ( I.id = T.type_id )
+                          WHERE T.id = %d",
+                        $r['id']
+                    )
+                );
+            } else {
+                $r['notes'] = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT P.payment_method
+                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "payments P
+                           LEFT OUTER JOIN " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "transactions T ON ( P.id = T.type_id )
+                          WHERE T.id = %d",
+                        $r['id']
+                    )
+                );
+            }
+        }
         return $r;
     }
 
index 1f2377b..bc27656 100644 (file)
@@ -96,6 +96,7 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
         $paymentTypes  = false;
         $counties      = false;
         $accounts      = false;
+        $invoices      = false;
         $paging        = true;
         $prevStart     = false;
         $nextStart     = false;
@@ -105,6 +106,7 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
         $lastDisplayed = false;
         $totalAccounts = false;
         $option2       = false;
+        $transactions  = false;
 
         // Get any provided option
         if ( isset( $_REQUEST['option'] ) ) {
@@ -138,6 +140,46 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
 
         // Do selected option
         switch ($option) {
+        case 'accountsByAge':
+            $wParts[] = "T.id IN (
+                SELECT account
+                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+                 WHERE balance > 0.00
+                   AND transaction_time + INTERVAL 60 DAY <= CURDATE()
+                )";
+            $view = 'reports';
+            break;
+
+        case 'closedAccounts':
+            $wParts[] = "T.id IN (
+                SELECT account
+                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices
+                 WHERE balance = 0.00
+                )";
+            $view = 'reports';
+            break;
+
+        case 'allAccounts':
+            $view = 'reports';
+            break;
+
+        case 'noAccounts':
+            break;
+
+        case 'reportGenerator':
+            // Check if Counties is enabled and fetch counties
+            if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) {
+                // Grab counties
+                $counties = $this->wpdb->get_results(
+                    "SELECT *
+                       FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties
+                    ORDER BY name",
+                    ARRAY_A
+                );
+            }
+
+            $paymentTypes = $BillingSupport->getAllInvoiceTypes();
+            break;
 
         case 'openAccounts':
         default:
@@ -154,19 +196,6 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
         // $where used in all places.
         $where = implode( ' AND ', $wParts );
 
-        // Check if Counties is enabled and fetch counties
-        if ( isset( $this->config['settings']['enable_counties'] ) && $this->config['settings']['enable_counties'] ) {
-            // Grab counties
-            $counties = $this->wpdb->get_results(
-                "SELECT *
-                   FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "counties
-                ORDER BY name",
-                ARRAY_A
-            );
-        }
-
-        $paymentTypes = $BillingSupport->getAllInvoiceTypes();
-
 
         if (isset($_REQUEST['pageSelect'])) {
             // If request is for Next
@@ -182,42 +211,96 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
                 $start = $newStart;
             }
         }
-        $orderBy                = 'member_name';
-        $Accounts->paymentTypes = true;
-        $Accounts->balanceDue   = true;
-        $accountsResult         = $Accounts->getList( $where, $orderBy, true, 'id', $start, $limit );
-        $totalAccounts          = $Accounts->getStats( $where );
-        $Accounts->paymentTypes = false;
-        $Accounts->balanceDue   = false;
-        // Get paging results
-        $numbDisplayed = $accountsResult['returned'];
-        $lastDisplayed = $accountsResult['last'];
-        if ( $start == 1 ) {
-            $prevStart = false;
+        if ( !in_array( $option, array( 'reportGenerator', 'noAccounts' ) ) ) {
+            // Getting the account listings
+            $orderBy                = 'member_name';
+            $Accounts->paymentTypes = true;
+            $Accounts->balanceDue   = true;
+            $accountsResult         = $Accounts->getList( $where, $orderBy, true, 'id', $start, $limit );
+            $totalAccounts          = $Accounts->getStats( $where );
+            $Accounts->paymentTypes = false;
+            $Accounts->balanceDue   = false;
         } else {
-            $prevStart = $start - $limit;
-            if ( $start < 1 ) {
-                $start = 1;
+            switch ( $option ) {
+            case 'reportGenerator':
+                $orderBy           = 'transaction_time';
+                $this->member_data = true;
+                $this->notes       = true;
+                $accountsResult    = $this->getList( $where, $orderBy, true, 'id', $start, $limit );
+                $totalAccounts     = $this->getStats( $where );
+                $this->member_data = false;
+                $this->notes       = false;
+                break;
+            case 'noAccounts':
+                break;
+            default:
+                break;
             }
         }
-        if ( $accountsResult['returned'] == $limit ) {
-            $nextStart = $start + $limit;
-        }
 
-        // 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 ) {
-            $haveAccounts = true;
-        }
+        if ( !in_array( $option, array( 'reportGenerator', 'noAccounts' ) ) ) {
+            // Get paging results
+            $numbDisplayed = $accountsResult['returned'];
+            $lastDisplayed = $accountsResult['last'];
+            if ( $start == 1 ) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ( $start < 1 ) {
+                    $start = 1;
+                }
+            }
 
+            if ( $accountsResult['returned'] == $limit ) {
+                $nextStart = $start + $limit;
+            }
 
+            // 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 ) {
+                $haveAccounts = true;
+            }
+        } else {
+            switch ( $option ) {
+            case 'reportGenerator':
+                // Get paging results
+                $numbDisplayed = $accountsResult['returned'];
+                $lastDisplayed = $accountsResult['last'];
+                if ( $start == 1 ) {
+                    $prevStart = false;
+                } else {
+                    $prevStart = $start - $limit;
+                    if ( $start < 1 ) {
+                        $start = 1;
+                    }
+                }
+
+                if ( $accountsResult['returned'] == $limit ) {
+                    $nextStart = $start + $limit;
+                }
+
+                // 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;
+                }
+                break;
+            case 'noAccounts':
+                break;
+            default:
+                break;
+            }
+        }
 
         $templateData = array(
+            'tActionTypes'  => $this->config['transaction_numb'],
             'option'        => $option,
             'paymentTypes'  => $paymentTypes,
             'counties'      => $counties,
             'accounts'      => $accounts,
+            'transactions'  => $transactions,
             'paging'        => $paging,
             'prevStart'     => $prevStart,
             'nextStart'     => $nextStart,
index a48a860..d9ce994 100644 (file)
@@ -35,6 +35,9 @@
             </div>
         </div>
     {/if}
+    {if $option == 'accountsByAge'}
+    <h3>over 60 days</h3>
+    {/if}
     <br clear="all">
     <br clear="all">
     <p>Total found: {$totalAccounts}</p>
         <input type="Submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
     {/if}
     <br clear="all">
-    <div id="account-list">
-        <table class="wp-list-table widefat fixed posts glm-admin-table">
-            <thead>
-                <tr>
-                    <th> Member Name </th>
-                    <th> Account Number </th>
-                    <th> Payment Type </th>
-                    <th> Balance Due </th>
-                </tr>
-            </thead>
-            {foreach $accounts as $t}
-                <tr>
-                    <td>
-                        <a href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$t.ref_dest}">
-                            {$t.member_name}
-                        </a>
-                    </td>
-                    <td> {$t.account_number} </td>
-                    <td> {$t.payment_type} </td>
-                    <td> {$t.balance_due|string_format:"%.2f"} </td>
-                </tr>
-            {/foreach}
-        </table>
-    </div>
+    {if isset( $accounts ) && !empty( $accounts )}
+        <div id="account-list">
+            <table class="wp-list-table widefat fixed posts glm-admin-table">
+                <thead>
+                    <tr>
+                        <th> Member Name </th>
+                        <th> Account Number </th>
+                        <th> Payment Type </th>
+                        <th> Balance Due </th>
+                    </tr>
+                </thead>
+                {foreach $accounts as $t}
+                    <tr>
+                        <td>
+                            <a href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$t.ref_dest}">
+                                {$t.member_name}
+                            </a>
+                        </td>
+                        <td> {$t.account_number} </td>
+                        <td> {$t.payment_type} </td>
+                        <td> {$t.balance_due|string_format:"%.2f"} </td>
+                    </tr>
+                {/foreach}
+            </table>
+        </div>
+    {/if}
+    {debug}
+    {if isset( $transactions ) && !empty( $transactions )}
+        <div id="invoice-list">
+            <table class="wp-list-table widefat fixed posts glm-admin-table">
+                <thead>
+                    <tr>
+                        <th> Transaction Time </th>
+                        <th> Type </th>
+                        <th> Member Name </th>
+                        <th> Description </th>
+                        <th> Amount </th>
+                    </tr>
+                </thead>
+                {foreach $transactions as $t}
+                    <tr>
+                        <td> {$t.transaction_time.datetime} </td>
+                        <td>
+                            {if $t.type == $tActionTypes.Invoice}
+                                Invoice
+                            {else}
+                                Payment
+                            {/if}
+                        </td>
+                        <td>
+                            <a href="{$adminUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$t.member_id}">
+                                {$t.member_name}
+                            </a>
+                        </td>
+                        <td> {$t.notes} </td>
+                        <td>
+                            {if $t.type == 10}
+                                {$t.current_invoice_total|string_format:"%.2f"}
+                            {else}
+                                {$t.current_payment_total|string_format:"%.2f"}
+                            {/if}
+                        </td>
+                    </tr>
+                {/foreach}
+            </table>
+        </div>
+    {/if}
     {* Paging *}
     {if $paging}
         <input type="submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
index 2f743b5..3ef9678 100644 (file)
@@ -1,6 +1,6 @@
 <h2 class="nav-tab-wrapper">
     <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports&option=openAccounts" class="nav-tab{if $option==openAccounts} nav-tab-active{/if}">Open Accounts</a>
-    <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports&option=cloasedAccounts" class="nav-tab{if $option==cloasedAccounts} nav-tab-active{/if}">Closed Accounts</a>
+    <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports&option=closedAccounts" class="nav-tab{if $option==closedAccounts} nav-tab-active{/if}">Closed Accounts</a>
     <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports&option=accountsByAge" class="nav-tab{if $option==accountsByAge} nav-tab-active{/if}">Accounts By Age</a>
     <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports&option=reportGenerator" class="nav-tab{if $option==reportGenerator} nav-tab-active{/if}">Report Generator</a>
     <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports&option=noAccounts" class="nav-tab{if $option==noAccounts} nav-tab-active{/if}">No Accounts</a>