From: Steve Sutton Date: Thu, 13 Dec 2018 22:01:57 +0000 (-0500) Subject: WIP for reports X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=79311d80d40c4a8a6210fcb692ea04717e3e80d1;p=WP-Plugins%2Fglm-member-db-billing.git WIP for reports Working on report generator --- diff --git a/classes/data/dataTransactions.php b/classes/data/dataTransactions.php index ee89fe0..9da515c 100644 --- a/classes/data/dataTransactions.php +++ b/classes/data/dataTransactions.php @@ -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; } diff --git a/models/admin/billing/reports.php b/models/admin/billing/reports.php index 1f2377b..bc27656 100644 --- a/models/admin/billing/reports.php +++ b/models/admin/billing/reports.php @@ -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 '
$accounts: ' . print_r( $accounts, true ) . '
'; - 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 '
$accounts: ' . print_r( $accounts, true ) . '
'; + 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 '
$transactions: ' . print_r( $transactions, true ) . '
'; + 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, diff --git a/views/admin/billing/reports.html b/views/admin/billing/reports.html index a48a860..d9ce994 100644 --- a/views/admin/billing/reports.html +++ b/views/admin/billing/reports.html @@ -35,6 +35,9 @@ {/if} + {if $option == 'accountsByAge'} +

over 60 days

+ {/if}

Total found: {$totalAccounts}

@@ -44,30 +47,73 @@ {/if}
-
- - - - - - - - - - {foreach $accounts as $t} - - - - - - - {/foreach} -
Member Name Account Number Payment Type Balance Due
- - {$t.member_name} - - {$t.account_number} {$t.payment_type} {$t.balance_due|string_format:"%.2f"}
-
+ {if isset( $accounts ) && !empty( $accounts )} +
+ + + + + + + + + + {foreach $accounts as $t} + + + + + + + {/foreach} +
Member Name Account Number Payment Type Balance Due
+ + {$t.member_name} + + {$t.account_number} {$t.payment_type} {$t.balance_due|string_format:"%.2f"}
+
+ {/if} + {debug} + {if isset( $transactions ) && !empty( $transactions )} +
+ + + + + + + + + + + {foreach $transactions as $t} + + + + + + + + {/foreach} +
Transaction Time Type Member Name Description Amount
{$t.transaction_time.datetime} + {if $t.type == $tActionTypes.Invoice} + Invoice + {else} + Payment + {/if} + + + {$t.member_name} + + {$t.notes} + {if $t.type == 10} + {$t.current_invoice_total|string_format:"%.2f"} + {else} + {$t.current_payment_total|string_format:"%.2f"} + {/if} +
+
+ {/if} {* Paging *} {if $paging} diff --git a/views/admin/billing/reportsSubHeader.html b/views/admin/billing/reportsSubHeader.html index 2f743b5..3ef9678 100644 --- a/views/admin/billing/reportsSubHeader.html +++ b/views/admin/billing/reportsSubHeader.html @@ -1,6 +1,6 @@