*/
// Load Contacts data class
-// require_once GLM_MEMBERS_TRANSACTIONS_PLUGIN_CLASS_PATH.'/data/dataTransactions.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php';
-class GlmMembersAdmin_billing_list // extends GlmDataTransactions
+class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
{
/**
* Note, the third parameter is a flag that indicates to the Contacts
* data class that it should flag a group of fields as 'view_only'.
*/
- // parent::__construct(false, false, true);
+ parent::__construct(false, false, true);
}
public function modelAction($actionData = false)
{
- $currentTab = 'glm-table-descr';
- $lockedToMember = false;
- $isModerated = false;
- $numbTransactions = 0;
- $option = 'list';
- $transactions = false;
- $haveTransactions = false;
- $transactions = false;
- $haveTransactions = false;
- $this->transactionID = false;
- $transactionsUpdated = false;
- $transactionsUpdateError = false;
- $transactionsAdded = false;
- $transactionsAddError = false;
- $view = 'list';
- $fromDate = false;
- $toDate = false;
- $filterArchived = false;
- $filterPending = false;
- $filterFeatured = false;
- $transactionsDeleted = false;
- $transactionsDeleteError = false;
- $memberID = false;
- $haveMember = false;
- $memberName = false;
- $memberData = false;
- $numbDisplayed = false;
- $lastDisplayed = false;
- $paging = true;
- $prevStart = false;
- $nextStart = false;
- $start = 1;
- $limit = 20; // Set to the number of listings per page
- $namesList = false;
-
- // Check if there's a logged in user who is locked to their own entity
- $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
- if ($lockedToMember) {
- $isModerated = apply_filters('glm_user_is_moderated', $lockedToMember);
- $memberID = $lockedToMember;
- $this->fields['admin_name']['required'] = true;
- $this->fields['admin_email']['required'] = true;
- $this->fields['admin_phone']['required'] = true;
-
- // Check for Member Menu Use
- } elseif (defined('GLM_TRANSACTIONS_MEMBER_MENU')) {
-
- // Try to get member ID
- $memberID = (isset($_REQUEST['member']) ? $_REQUEST['member'] : 0);
-
- // If there's no valid member ID, we can't continue
- if ($memberID == 0) {
- return array(
- 'status' => false,
- 'menuItemRedirect' => 'error',
- 'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => array(
- 'reason' => 'No member ID was provided.'
- )
- );
- }
- }
-
- // If not a valid member ID
- if ($memberID > 0) {
-
- // Get base member information
- require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMembers.php';
- $Member = new GlmDataMembers($this->wpdb, $this->config);
- $memberData = $Member->getEntry($memberID);
-
- if (!$memberData) {
- return array(
- 'status' => false,
- 'menuItemRedirect' => 'error',
- 'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => array(
- 'reason' => 'No member data found for provided member ID.'
- )
- );
- } else{
- $haveMember = true;
- $memberName = $memberData['name'];
- }
-
- }
+ $option = 'list';
+ $this->transactionID = false;
+ $haveInvoices = false;
+ $invoiceUpdated = false;
+ $invoiceUpdateError = false;
+ $invoiceAdded = false;
+ $invoiceAddError = false;
+ $view = 'invoices';
+ $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
// Get any provided option
if (isset($_REQUEST['option'])) {
$option = $_REQUEST['option'];
}
- // See if there's a currentTab in $_REQUEST array
- if ( isset( $_REQUEST['currentTab'] ) && $_REQUEST['currentTab'] ) {
- $currentTab = filter_var( $_REQUEST['currentTab'], FILTER_SANITIZE_STRING );
- }
-
- // Get transactions ID if supplied
- if (isset($_REQUEST['transactions'])) {
-
- // Make sure it's numeric
- $this->transactionID = ($_REQUEST['transactions'] - 0);
-
- if ($this->transactionID <= 0) {
- $this->transactionID = false;
- }
-
- }
-
// Do selected option
switch ($option) {
case 'add':
- $transactions = $this->newEntry();
- $view = 'edit';
+ $invoices = $this->newEntry();
+ $view = 'editInvoice';
break;
case 'insert':
- $transactions = $this->insertEntry();
- $this->transactionID = $transactions['fieldData']['id'];
- $view = 'edit';
+ $invoices = $this->insertEntry();
+ $this->transactionID = $invoices['fieldData']['id'];
+ $view = 'editInvoice';
break;
case 'edit':
- $transactions = $this->editEntry($this->transactionID);
+ $invoices = $this->editEntry($this->transactionID);
- // If we have a good transactions
- if ($transactions['status']) {
+ // If we have a good invoices
+ if ($invoices['status']) {
$haveTransactions = true;
}
- // If we're locked to a member as a contact user and the transactions member doesn't equal the contact member
- if ($lockedToMember && $transactions['fieldData']['ref_dest_id'] != $lockedToMember) {
+ // If we're locked to a member as a contact user and the invoices member doesn't equal the contact member
+ if ($lockedToMember && $invoices['fieldData']['ref_dest_id'] != $lockedToMember) {
$haveTransactions = false;
- $transactions = false;
+ $invoices = false;
}
- $view = 'edit';
+ $view = 'editInvoice';
break;
case 'update':
- // Try to update this transactions
- $transactions = $this->updateEntry($this->transactionID);
+ // Try to update this invoices
+ $invoices = $this->updateEntry($this->transactionID);
// Check if that was successful
- if ($transactions['status']) {
- $transactionsUpdated = true;
+ if ($invoices['status']) {
+ $invoiceUpdated = true;
- $transactions = $this->editEntry($this->transactionID);
+ $invoices = $this->editEntry($this->transactionID);
} else {
- $transactionsUpdateError = true;
+ $invoiceUpdateError = true;
}
- $view = 'edit';
+ $view = 'editInvoice';
break;
case 'delete':
- $transactions = $this->deleteTransactions($this->transactionID);
+ $invoices = $this->deleteTransactions($this->transactionID);
- if ($transactions) {
- $transactionsDeleted = true;
+ if ($invoices) {
+ $invoiceDeleted = true;
} else {
- $transactionsDeleteError = true;
+ $invoiceDeleteError = true;
}
- case 'list':
+ case 'list':
default:
$where = 'true';
- // If we have a back request then go through the PHP_SESSION
- // and extract them into the REQUEST array.
- if ( isset( $_REQUEST['back'] ) && filter_var( $_REQUEST['back'], FILTER_VALIDATE_BOOLEAN ) ) {
- if ( isset( $_SESSION['search'] ) && is_array( $_SESSION['search'] ) ) {
- foreach ( $_SESSION['search'] as $varName => $sessValue ) {
- $_REQUEST[$varName] = $sessValue;
- }
- }
- }
-
// Check for paging
if ( isset( $_REQUEST['pageSelect'] ) ) {
$_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
unset( $_SESSION['search']['prevStart'] );
}
- // Check for Archived filter
- if (isset($_REQUEST['filterArchived']) && $_REQUEST['filterArchived'] == 'on') {
- $filterArchived = true;
- $_SESSION['search']['archived'] = true;
- $where .= " AND status = " . $this->config['status_numb']['Archived'];
- } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterArchived'] ) ) {
- unset( $_SESSION['search']['archived'] );
- }
-
- // Check for Pending filter
- if (isset($_REQUEST['filterPending']) && $_REQUEST['filterPending'] == 'on') {
- $filterPending = true;
- $_SESSION['search']['pending'] = true;
- $where .= " AND status = " . $this->config['status_numb']['Pending'];
- } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['filterPending'] ) ) {
- unset( $_SESSION['search']['pending'] );
- }
-
- // Check if we have a Text Search string
- if (isset($_REQUEST['textSearch']) && trim($_REQUEST['textSearch']) != '') {
- $textSearch = trim($_REQUEST['textSearch']);
- $where .= " AND name LIKE '%$textSearch%'";
- $_SESSION['search']['textSearch'] = $textSearch;
- } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['textSearch']) == '' ) {
- unset( $_SESSION['search']['textSearch'] );
- }
-
-
- // If we have a From date
- $dateWhere = '';
- if (isset($_REQUEST['fromDate']) && trim($_REQUEST['fromDate']) != '') {
- $fromDate = date('m/d/Y', strtotime($_REQUEST['fromDate']));
- $fromMYSQL = date('Y-m-d', strtotime($fromDate));
- $dateWhere = " end_time >= '$fromMYSQL' ";
- $_SESSION['search']['fromDate'] = $fromDate;
- } else if ( !isset( $_REQUEST['searched'] ) ) {
- $fromDate = date('m/d/Y');
- $fromMYSQL = date('Y-m-d', strtotime($fromDate));
- $dateWhere = " end_time >= '$fromMYSQL' ";
- } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['fromDate']) == '' ) {
- unset( $_SESSION['search']['fromDate'] );
- }
-
- // If we have a to Date
- if (isset($_REQUEST['toDate']) && trim($_REQUEST['toDate']) != '') {
-
- $toDate = date('m/d/Y', strtotime($_REQUEST['toDate']));
- $toMYSQL = date('Y-m-d', strtotime($toDate." +1 day"));
-
- // If we have a from date then we need Parens and AND
- if ($dateWhere != '') {
- $dateWhere = "( ".$dateWhere." AND start_time <= '$toMYSQL' )";
-
- // Otherwise we don't
- } else {
- $dateWhere = " start_time <= '$toMYSQL' ";
- }
- $_SESSION['search']['toDate'] = $toDate;
- } else if ( isset( $_REQUEST['searched'] ) && trim($_REQUEST['toDate']) == '' ) {
- unset( $_SESSION['search']['toDate'] );
- }
-
- // If we have from and to dates, do search for those inclusive
- if ($dateWhere != '') {
- $where .= "
- AND id in (
- SELECT DISTINCT(transactions)
- FROM ".GLM_MEMBERS_TRANSACTIONS_PLUGIN_DB_PREFIX."times
- WHERE $dateWhere
- AND active
- )
- ";
- }
-
- // Check if the list is for a specific member
- if (defined('GLM_TRANSACTIONS_MEMBER_MENU') || $memberID) {
- $where .= " AND ref_dest = $memberID";
- $_SESSION['search']['memberID'] = $memberID;
- }
-
- // Get the total number of transactions listed
- $numbTransactions = $this->getStats($where);
-
- // If the number of transactions is less than a page, don't do paging
- if ($numbTransactions <= $limit) {
- $paging = false;
- }
-
- // Get full list of names matching this where clause for search box
- $namesList = $this->getIdName($where);
-
// Check if we're doing paging
if (isset($_REQUEST['pageSelect'])) {
// If request is for Next
}
}
- // Get the list of transactions and determine number of transactions in list
- $orderBy = 'name';
- // $orderBy = "(select min(start_time) FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "times WHERE T.id = transactions),name";
- $transactionsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
+ // 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 = $transactionsResult['returned'];
- $lastDisplayed = $transactionsResult['last'];
+ $numbDisplayed = $invoicesResult['returned'];
+ $lastDisplayed = $invoicesResult['last'];
if ($start == 1) {
$prevStart = false;
} else {
$start = 1;
}
}
- if ($transactionsResult['returned'] == $limit) {
+ if ($invoicesResult['returned'] == $limit) {
$nextStart = $start + $limit;
}
- // since we're doing paging, we have to break out just the transactions data
- $transactions = $transactionsResult['list'];
- if (count($transactions)>0) {
- $haveTransactions = true;
+ // since we're doing paging, we have to break out just the invoices data
+ $invoices = $invoicesResult['list'];
+ if (count($invoices)>0) {
+ $haveInvoices = true;
}
- unset($transactionsResult);
+ unset($invoicesResult);
break;
}
$templateData = array(
- 'enable_members' => $enable_members,
- 'lockedToMember' => $lockedToMember,
- 'isModerated' => $isModerated,
- 'option' => $option,
- 'transactions' => $transactions,
- 'haveTransactions' => $haveTransactions,
- 'transactions' => $transactions,
- 'haveTransactions' => $haveTransactions,
- 'transactionID' => $this->transactionID,
- 'transactionsUpdated' => $transactionsUpdated,
- 'transactionsUpdateError' => $transactionsUpdateError,
- 'transactionsAdded' => $transactionsAdded,
- 'transactionsAddError' => $transactionsAddError,
- 'numbTransactions' => $numbTransactions,
- 'categories' => $categories,
- 'amenities' => $amenities,
- 'fromDate' => $fromDate,
- 'toDate' => $toDate,
- 'filterArchived' => $filterArchived,
- 'filterPending' => $filterPending,
- 'filterFeatured' => $filterFeatured,
- 'transactionsDeleted' => $transactionsDeleted,
- 'transactionsDeleteError' => $transactionsDeleteError,
- 'memberID' => $memberID,
- 'haveMember' => $haveMember,
- 'memberName' => $memberName,
- 'memberData' => $memberData,
- 'numbDisplayed' => $numbDisplayed,
- 'lastDisplayed' => $lastDisplayed,
- 'paging' => $paging,
- 'prevStart' => $prevStart,
- 'nextStart' => $nextStart,
- 'start' => $start = 1,
- 'limit' => $limit,
- 'namesList' => $namesList,
- 'currentTab' => $currentTab
+ 'option' => $option,
+ 'invoices' => $invoices,
+ 'haveInvoices' => $haveInvoices,
+ 'invoiceUpdated' => $invoiceUpdated,
+ 'invoiceUpdateError' => $invoiceUpdateError,
+ 'invoiceAdded' => $invoiceAdded,
+ 'invoiceAddError' => $invoiceAddError,
+ // 'numbTransactions' => $numbTransactions,
+ 'invoiceDeleted' => $invoiceDeleted,
+ 'invoiceDeleteError' => $invoiceDeleteError,
+ 'invoiceInvoiceError' => $invoiceDeleteError,
+ 'numbDisplayed' => $numbDisplayed,
+ 'lastDisplayed' => $lastDisplayed,
+ 'paging' => $paging,
+ 'prevStart' => $prevStart,
+ 'nextStart' => $nextStart,
+ 'start' => $start = 1,
+ 'limit' => $limit,
);
// Return status, any suggested view, and any data to controller