From: Steve Sutton Date: Wed, 21 Mar 2018 20:50:08 +0000 (-0400) Subject: Update the billing dashboard and search. X-Git-Tag: v1.0.0^2~111 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=479cf8855f6b2e1b4132620e0c8a9434fec1277f;p=WP-Plugins%2Fglm-member-db-billing.git Update the billing dashboard and search. Now the dash board shows member accounts pending and overdue. The search for the dashboard and billing are now in it's own template. I added filter search for expired accounts. --- diff --git a/models/admin/billing/accounts.php b/models/admin/billing/accounts.php index 7e9e581..bc3e639 100644 --- a/models/admin/billing/accounts.php +++ b/models/admin/billing/accounts.php @@ -88,43 +88,45 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts public function modelAction($actionData = false) { - $option = 'list'; - $this->account_id = false; - $haveAccounts = false; - $invoiceUpdated = false; - $invoiceUpdateError = false; - $invoiceAdded = false; - $invoiceAddError = false; - $view = 'accounts'; - $fromDate = false; - $toDate = false; - $filterArchived = false; - $filterPending = false; - $filterFeatured = false; - $invoiceDeleted = false; - $invoiceDeleteError = false; - $invoiceInsertError = false; - $numbDisplayed = false; - $lastDisplayed = false; - $paging = true; - $prevStart = false; - $nextStart = false; - $start = 1; - $limit = 20; // Set to the number of listings per page - $invTypes = array(); - $invoiceTypes = false; - $invoiceTypeJSON = ''; - $accounts = false; - $nonAccountMembers = false; - $invoiceHtml = ''; - $fromDate = ''; - $toDate = ''; - $annFromDate = ''; - $annToDate = ''; - $totalAccounts = false; - $allAccounts = false; - $filterAccounts = false; - $searchName = false; + $option = 'list'; + $this->account_id = false; + $haveAccounts = false; + $invoiceUpdated = false; + $invoiceUpdateError = false; + $invoiceAdded = false; + $invoiceAddError = false; + $view = 'accounts'; + $fromDate = false; + $toDate = false; + $filterArchived = false; + $filterFeatured = false; + $invoiceDeleted = false; + $invoiceDeleteError = false; + $invoiceInsertError = false; + $numbDisplayed = false; + $lastDisplayed = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $invTypes = array(); + $invoiceTypes = false; + $invoiceTypeJSON = ''; + $accounts = false; + $nonAccountMembers = false; + $invoiceHtml = ''; + $fromDate = ''; + $toDate = ''; + $annFromDate = ''; + $annToDate = ''; + $totalAccounts = false; + $allAccounts = false; + $filterAccounts = false; + $filterPending = false; + $filterOverdue = false; + $filterExpired = false; + $searchName = false; // Get any provided option if ( isset( $_REQUEST['option'] ) ) { @@ -359,18 +361,6 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts $to_date = date( 'Y-m-d', strtotime( $toDate ) ); $where_params[] = "T.renewal_date <= '$to_date'"; } - if ( isset( $_REQUEST['annFromDate'] ) && $_REQUEST['annFromDate'] - && $annFromDate = filter_var( $_REQUEST['annFromDate'], FILTER_VALIDATE_REGEXP, $reg_options ) - ) { - $annFrom_date = date( 'Y-m-d', strtotime( $annFromDate ) ); - $where_params[] = "T.anniversary_date >= '$annFrom_date'"; - } - if ( isset( $_REQUEST['annToDate'] ) && $_REQUEST['annToDate'] - && $annToDate = filter_var( $_REQUEST['annToDate'], FILTER_VALIDATE_REGEXP, $reg_options ) - ) { - $annTo_date = date( 'Y-m-d', strtotime( $annToDate ) ); - $where_params[] = "T.anniversary_date <= '$annTo_date'"; - } if ( isset( $_REQUEST['filterAccounts'] ) && $filterAccounts = filter_var( $_REQUEST['filterAccounts'], FILTER_VALIDATE_INT ) ) { @@ -382,13 +372,29 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts $where_params[] = "T.ref_name like '%" . esc_sql( $searchName ) . "%'"; } + if ( isset( $_REQUEST['filterPending'] ) ) { + $filterPending = filter_var( $_REQUEST['filterPending'], FILTER_VALIDATE_BOOLEAN ); + $where_params[] = "renewal_date >= now()"; + } + if ( isset( $_REQUEST['filterOverdue'] ) ) { + $filterOverdue = filter_var( $_REQUEST['filterOverdue'], FILTER_VALIDATE_BOOLEAN ); + $expiredDate = date( 'Y-m-d', mktime( 0, 0, 0, date( 'n' ), date( 'j' ) - 30, date( 'Y' )) ); + $where_params[] = "renewal_date < now()"; + $where_params[] = "renewal_date >= '$expiredDate'"; + } + if ( isset( $_REQUEST['filterExpired'] ) ) { + $filterExpired = filter_var( $_REQUEST['filterExpired'], FILTER_VALIDATE_BOOLEAN ); + $expiredDate = date( 'Y-m-d', mktime( 0, 0, 0, date( 'n' ), date( 'j' ) - 30, date( 'Y' )) ); + $where_params[] = "renewal_date < '$expiredDate'"; + } + // Build the $where string from the $where_parts array. // By implode with AND. $where = implode( ' AND ', $where_params ); // Get the list of accounts and determine number of accounts in list - $orderBy = 'ref_name'; + $orderBy = 'renewal_date ASC'; $accountsResult = $this->getList( $where, $orderBy, true, 'id', $start, $limit ); $totalAccounts = $this->getStats( $where ); @@ -453,7 +459,10 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts 'totalAccounts' => $totalAccounts, 'allAccounts' => $allAccounts, 'filterAccounts' => $filterAccounts, + 'filterPending' => $filterPending, + 'filterOverdue' => $filterOverdue, 'searchName' => $searchName, + 'filterExpired' => $filterExpired, ); // Return status, any suggested view, and any data to controller diff --git a/models/admin/billing/index.php b/models/admin/billing/index.php index cf2e0c7..5495e9c 100644 --- a/models/admin/billing/index.php +++ b/models/admin/billing/index.php @@ -17,7 +17,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; -class GlmMembersAdmin_billing_index extends GlmDataInvoices +class GlmMembersAdmin_billing_index extends GlmDataAccounts { /** @@ -127,6 +127,7 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices $totalInvoices = false; $filterPending = false; $filterOverdue = false; + $filterExpired = false; $invoices = false; // For lockedToMember @@ -179,89 +180,99 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices } switch ( $option ) { - case 'account': - require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; - $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); - - // Check to see if we're adding an account or editing one. - if ( isset( $_REQUEST['ref_name'] ) ) { - $_REQUEST['anniversary_date'] = date('Y-m-d', strtotime($_REQUEST['anniversary_date'])); - // echo '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; - // if there's no id then add account - if ( !isset( $_REQUEST['id'] ) ) { - $account = $Accounts->insertEntry(); - if ( !$account['status'] ) { - $accountInsertError = true; - } else { - $accountAdded = true; - } - } else { - $account = $Accounts->updateEntry( $_REQUEST['id'] ); - if ( !$account['status'] ) { - $accountUpdateError = true; - } else { - $accountUpdated = true; - } - } - } - - // Need to see if there's an account for this member. - $accountID = $this->wpdb->get_var( - $this->wpdb->prepare( - "SELECT id - FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts - WHERE ref_dest = %d", - $this->memberID - ) - ); - if ( !$account ) { - if ( $accountID ) { - $account = $Accounts->editEntry( $accountID ); - $haveAccount = true; - } else { - $accountID = 0; - $account = $Accounts->newEntry(); - // Set the ref_name from memberData - $account['fieldData']['ref_name'] = $memberData['name']; - $haveAccount = false; - } - } else { - $haveAccount = true; - // echo '
$account: ' . print_r( $account, true ) . '
'; - } - - // echo '
$account: ' . print_r( $account, true ) . '
'; - $view = 'editAccount'; - break; + // case 'account': + // require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; + // $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + // + // // Check to see if we're adding an account or editing one. + // if ( isset( $_REQUEST['ref_name'] ) ) { + // $_REQUEST['anniversary_date'] = date('Y-m-d', strtotime($_REQUEST['anniversary_date'])); + // // if there's no id then add account + // if ( !isset( $_REQUEST['id'] ) ) { + // $account = $Accounts->insertEntry(); + // if ( !$account['status'] ) { + // $accountInsertError = true; + // } else { + // $accountAdded = true; + // } + // } else { + // $account = $Accounts->updateEntry( $_REQUEST['id'] ); + // if ( !$account['status'] ) { + // $accountUpdateError = true; + // } else { + // $accountUpdated = true; + // } + // } + // } + // + // // Need to see if there's an account for this member. + // $accountID = $this->wpdb->get_var( + // $this->wpdb->prepare( + // "SELECT id + // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + // WHERE ref_dest = %d", + // $this->memberID + // ) + // ); + // if ( !$account ) { + // if ( $accountID ) { + // $account = $Accounts->editEntry( $accountID ); + // $haveAccount = true; + // } else { + // $accountID = 0; + // $account = $Accounts->newEntry(); + // // Set the ref_name from memberData + // $account['fieldData']['ref_name'] = $memberData['name']; + // $haveAccount = false; + // } + // } else { + // $haveAccount = true; + // // echo '
$account: ' . print_r( $account, true ) . '
'; + // } + // + // // echo '
$account: ' . print_r( $account, true ) . '
'; + // $view = 'editAccount'; + // break; case 'list': - $orderBy = 'due_date ASC, transaction_time DESC'; - // // Get list of pending invoices ( not overdue ) - $pendingWhere = 'T.paid <> true AND T.due_date > now()'; + // Dash board list should be getting list of members Accounts. (based on renewal_date) + // Expired + // Pass Due + // Pending + // Active + // Get list of pending invoices ( not overdue ) + $orderBy = 'renewal_date ASC'; + $pendingWhere = "renewal_date >= now()"; $start = 1; - $this->line_items_post = true; $pending = $this->getList( $pendingWhere, $orderBy, true, 'id', $start, $limit ); - $this->line_items_post = false; - // /** - // * $pending = array( start, limit, returned, last, list = array...) - // */ + // echo '
$pending: ' . print_r( $pending, true ) . '
'; $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 ); - // - // // Get the number of over due invoices - $overDueWhere = 'T.paid <> true AND T.due_date < now()'; + + // Get the number of over due invoices + $overDueWhere = "renewal_date < now()"; $start = 1; - $this->line_items_post = true; $overdue = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit ); - $this->line_items_post = false; if ( isset( $overdue['returned'] ) ) { $numberOverdue = $overdue['returned']; } + + // Get list of accounts for autocomplete $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); $accounts = $Accounts->getSimpleAccountList(); - break; - default: + $dashboards = array( + 'Pending Accounts' => array( + 'number' => $numberPending, + 'data' => $pending, + ), + 'Overdue Accounts' => array( + 'number' => $numberOverdue, + 'data' => $overdue, + ) + ); break; + default: + break; } @@ -269,12 +280,9 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices $templateData = array( 'accountID' => $accountID, 'option' => $option, - 'fromMemberMenu' => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ), + 'fromMemberMenu' => ( defined( 'GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ), 'lockedToMember' => $lockedToMember, - 'numberPending' => $numberPending, - 'pending' => $pending, - 'numberOverdue' => $numberOverdue, - 'overdue' => $overdue, + 'dashboards' => $dashboards, 'memberID' => $this->memberID, 'haveMember' => $haveMember, 'haveAccount' => $haveAccount, @@ -299,6 +307,7 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices 'totalInvoices' => $totalInvoices, 'filterPending' => $filterPending, 'filterOverdue' => $filterOverdue, + 'filterExpired' => $filterExpired, ); // echo '
$templateData: ' . print_r( $templateData, true ) . '
'; diff --git a/views/admin/billing/accountSearchForm.html b/views/admin/billing/accountSearchForm.html new file mode 100644 index 0000000..e6ad23f --- /dev/null +++ b/views/admin/billing/accountSearchForm.html @@ -0,0 +1,30 @@ +
+ + + + + + + + +
+ + From Date: + To Date: + + + Member Account:  + + + +
+ + Show Pending Only + Show Overdue Only + Show Expired Only + +
+ + + +
diff --git a/views/admin/billing/accounts.html b/views/admin/billing/accounts.html index 77aa3d5..8cfafc1 100644 --- a/views/admin/billing/accounts.html +++ b/views/admin/billing/accounts.html @@ -2,38 +2,7 @@

Accounts

- - - - - - - - - -
-

Search Renewal date

- - From Date: - To Date: - -
-

Search Anniversary date

- - From Date: - To Date: - -
- - Member Account:  - - - -
- - - -
+ {include file='admin/billing/accountSearchForm.html'}

Total found: {$totalAccounts}

diff --git a/views/admin/billing/index.html b/views/admin/billing/index.html index acaf732..b385855 100644 --- a/views/admin/billing/index.html +++ b/views/admin/billing/index.html @@ -8,132 +8,45 @@ Create Invoice Make Payment - - - - - - - - - -
-

- - From Date: - To Date: - - - Member Account:  - - - -
- - Show Pending Only - Show Overdue Only - -
- - - - -

-

+ {include file='admin/billing/accountSearchForm.html'}
-
- - - - - -
Number of Over Due Invoices Listed: {if !$numberOverdue}0{else}{$numberOverdue}{/if}
- -
- - - - - - - - - - - - - - - {if $numberOverdue > 0} - {assign var="i" value="0"} - {foreach $overdue.list as $t} - {if $i++ is odd by 1} - - {else} - - {/if} - - - - - - - - - - {/foreach} - {/if} - -
IDMember NameInvoice ForTimeDue DateAmount TotalBalanceView
{$t.id} {$t.member_name} - {foreach $t.line_items as $item} - {$item.name} {if $item.recurring && $item.recurrence_string}( {$item.recurrence_string} ){/if} - {/foreach} - {$t.transaction_time.datetime} {$t.due_date.date} {$t.amount_total} {$t.balance} View
-
-
- - -
Number of Pending Invoices Listed: {if !$numberPending}0{else}{$numberPending}{/if}
- - - - - - - - - - - - - - - {if $numberPending > 0} - {assign var="i" value="0"} - {foreach $pending.list as $t} - {if $i++ is odd by 1} - - {else} - - {/if} - - - - - - - - - - {/foreach} - {/if} - -
IDMember NameInvoice ForTimeDue DateAmount TotalBalanceView
{$t.id} {$t.member_name} - {foreach $t.line_items as $item} - {$item.name} {if $item.recurring && $item.recurrence_string}( {$item.recurrence_string} ){/if} - {/foreach} - {$t.transaction_time.datetime} {$t.due_date.date} {$t.amount_total} {$t.balance} View
+{foreach $dashboards as $dashboard_title => $list} +
+ + +
{$dashboard_title}
+ + + + + + + + + + + + {if $list.number > 0} + {assign var="i" value="0"} + {foreach $list.data.list as $t} + {if $i++ is odd by 1} + + {else} + + {/if} + + + + + + + {/foreach} + {/if} + +
IDMember NameBilling EmailAnniversary DateRenewal Date
{$t.id} {$t.ref_name} {$t.email} {$t.anniversary_date.date} {$t.renewal_date.date}
+
+{/foreach}