// 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
{
$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;
$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
'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 '<pre>$templateData: ' . print_r( $templateData, true ) . '</pre>';