From 4f2c75b570e1b32bf0309e06bfcba6f39c456de5 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 14 Mar 2018 15:44:49 -0400 Subject: [PATCH] Update dashboard to show list of invoices. Setup same as list invoices. --- models/admin/billing/index.php | 170 +++++++++++++++++++++++++++--- models/admin/billing/invoices.php | 3 - 2 files changed, 155 insertions(+), 18 deletions(-) diff --git a/models/admin/billing/index.php b/models/admin/billing/index.php index 7c1ef23..46cc37e 100644 --- a/models/admin/billing/index.php +++ b/models/admin/billing/index.php @@ -15,6 +15,7 @@ // Load Billing data abstract 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 { @@ -110,6 +111,19 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices $overdue = false; $numberOverdue = 0; $pending = false; + $fromDate = false; + $toDate = false; + $filterArchived = false; + $filterPending = false; + $filterFeatured = false; + $paging = true; + $prevStart = false; + $nextStart = false; + $start = 1; + $limit = 20; // Set to the number of listings per page + $accounts = false; + $haveInvoices = false; + $filterAccounts = ''; // For lockedToMember $lockedToMember = false; @@ -216,24 +230,139 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices $view = 'editAccount'; break; case 'list': - // Get list of pending invoices ( not overdue ) - $pendingWhere = 'T.paid <> true AND T.due_date > now()'; - $start = 1; - $pending = $this->getList( $pendingWhere, 'transaction_time', true, 'id', $start, $limit ); - /** - * $pending = array( start, limit, returned, last, list = array...) - */ - $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 ); - - // Get the number of over due invoices - $overDueWhere = 'T.paid <> true AND T.due_date < now()'; - $start = 1; - $overdue = $this->getList( $overDueWhere, 'transaction_time', true, 'id', $start, $limit ); - if ( isset( $overdue['returned'] ) ) { - $numberOverdue = $overdue['returned']; + // // Get list of pending invoices ( not overdue ) + // $pendingWhere = 'T.paid <> true AND T.due_date > now()'; + // $start = 1; + // $pending = $this->getList( $pendingWhere, 'transaction_time', true, 'id', $start, $limit ); + // /** + // * $pending = array( start, limit, returned, last, list = array...) + // */ + // $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 ); + // + // // Get the number of over due invoices + // $overDueWhere = 'T.paid <> true AND T.due_date < now()'; + // $start = 1; + // $overdue = $this->getList( $overDueWhere, 'transaction_time', true, 'id', $start, $limit ); + // if ( isset( $overdue['returned'] ) ) { + // $numberOverdue = $overdue['returned']; + // } + // + // break; + default: + + $view = 'invoices'; + // Need to get the accounts + $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + $accounts = $Accounts->getList(); + + $where_params = array( 'true' ); + + // Check for paging + if ( isset( $_REQUEST['pageSelect'] ) ) { + $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect']; + } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) { + unset( $_SESSION['search']['pageSelect'] ); + } + if ( isset( $_REQUEST['nextStart'] ) ) { + $_SESSION['search']['nextStart'] = $_REQUEST['nextStart']; + } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) { + unset( $_SESSION['search']['nextStart'] ); + } + if ( isset( $_REQUEST['prevStart'] ) ) { + $_SESSION['search']['prevStart'] = $_REQUEST['prevStart']; + } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) { + unset( $_SESSION['search']['prevStart'] ); + } + + // Check if we're doing paging + if (isset($_REQUEST['pageSelect'])) { + // If request is for Next + if ($_REQUEST['pageSelect'][0] == 'N') { + $newStart = $_REQUEST['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_REQUEST['prevStart'] - 0; + } + + if ($newStart > 0) { + $start = $newStart; + } } + if( isset($_SESSION['search']['pageSelect']) ){ + // If request is for Next + if ($_SESSION['search']['pageSelect'][0] == 'N') { + $newStart = $_SESSION['search']['nextStart'] - 0; + + // Otherwise it must be Previous + } else { + $newStart = $_SESSION['search']['prevStart'] - 0; + } + if ($newStart > 0) { + $start = $newStart; + } + } + + // Get any search parameters. + $reg_options = array( + 'options' => array( + 'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%' + ) + ); + if ( isset( $_REQUEST['fromDate'] ) + && $_REQUEST['fromDate'] + && $fromDate = filter_var( $_REQUEST['fromDate'], FILTER_VALIDATE_REGEXP, $reg_options ) + ) { + $from_date = date( 'Y-m-d', strtotime( $fromDate ) ); + $where_params[] = "T.due_date >= '$from_date'"; + } + if ( isset( $_REQUEST['toDate'] ) + && $_REQUEST['toDate'] + && $toDate = filter_var( $_REQUEST['toDate'], FILTER_VALIDATE_REGEXP, $reg_options ) + ) { + $to_date = date( 'Y-m-d', strtotime( $toDate ) ); + $where_params[] = "T.due_date <= '$to_date'"; + } + if ( isset( $_REQUEST['filterAccounts'] ) + && $filterAccounts = filter_var( $_REQUEST['filterAccounts'], FILTER_VALIDATE_INT ) + ) { + $accounts[$filterAccounts]['selected'] = true; + $where_params[] = "T.account = $filterAccounts"; + } + + // Build the $where from $where_params array. + // By imploding them with AND between each array element. + $where = implode( ' AND ', $where_params ); + + // Get the list of invoices and determine number of invoices in list + $orderBy = 'transaction_time desc'; + $invoicesResult = $this->getList($where, $orderBy, true, 'id', $start, $limit); + + // Get paging results + $numbDisplayed = $invoicesResult['returned']; + $lastDisplayed = $invoicesResult['last']; + if ($start == 1) { + $prevStart = false; + } else { + $prevStart = $start - $limit; + if ($start < 1) { + $start = 1; + } + } + if ($invoicesResult['returned'] == $limit) { + $nextStart = $start + $limit; + } + + // since we're doing paging, we have to break out just the invoices data + $invoices = $invoicesResult['list']; + if (count($invoices)>0) { + $haveInvoices = true; + } + unset($invoicesResult); + break; + } // Compile template data @@ -256,6 +385,17 @@ class GlmMembersAdmin_billing_index extends GlmDataInvoices 'accountUpdateError' => $accountUpdateError, 'accountAdded' => $accountAdded, 'accountInsertError' => $accountInsertError, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start = 1, + 'limit' => $limit, + 'invoices' => $invoices, + 'fromDate' => $fromDate, + 'toDate' => $toDate, + 'haveInvoices' => $haveInvoices, + 'accounts' => $accounts, + 'filterAccounts' => $filterAccounts, ); // echo '
$templateData: ' . print_r( $templateData, true ) . '
'; diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index eea8fe4..43c4c1b 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -332,7 +332,6 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices // Need to get the accounts $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); $accounts = $Accounts->getList(); - // echo '
$accounts: ' . print_r( $accounts, true ) . '
'; $where_params = array( 'true' ); @@ -440,8 +439,6 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices } unset($invoicesResult); - // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; - break; } -- 2.17.1