From d9561b670059f0647d99dfee8a9f9948bfdb99c2 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 27 Mar 2018 14:05:43 -0400 Subject: [PATCH] Setup the account export Con now export billing accounts from dashbeard and the account list page. --- models/admin/ajax/accountsListExport.php | 239 ++++++++++++++++++++ models/admin/billing/accounts.php | 2 +- setup/validActions.php | 11 +- views/admin/ajax/accountsListExport.html | 50 ++++ views/admin/ajax/accountsListExportCsv.html | 26 +++ views/admin/billing/accounts.html | 44 +++- views/admin/billing/exportBillingModal.html | 63 ++++++ views/admin/billing/index.html | 33 +++ 8 files changed, 457 insertions(+), 11 deletions(-) create mode 100644 models/admin/ajax/accountsListExport.php create mode 100644 views/admin/ajax/accountsListExport.html create mode 100644 views/admin/ajax/accountsListExportCsv.html create mode 100644 views/admin/billing/exportBillingModal.html diff --git a/models/admin/ajax/accountsListExport.php b/models/admin/ajax/accountsListExport.php new file mode 100644 index 0000000..908d044 --- /dev/null +++ b/models/admin/ajax/accountsListExport.php @@ -0,0 +1,239 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + + +// Load Member Info data abstract +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; + +/** + * + * This class exports the currently selected accounts list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_accountsListExport extends GlmDataAccounts +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + + /** + * Constructor + * + * This constructor sets up this model. At this time that only includes + * storing away the WordPress data object. + * + * @return object Class object + * + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + parent::__construct(false, false); + + } + + public function checkFlag($t) {return isset($_REQUEST[$t]) && $_REQUEST[$t] == 'on';} + /** + * Perform Model Action + * + * This modelAction takes an AJAX image upload and stores the image in the + * media/images directory of the plugin. + * + * This model action does not return, it simply does it's work then calls die(); + * + * @param $actionData + * + * Echos JSON string as response and does not return + */ + public function modelAction ($actionData = false) + { + + $categories = false; + $haveAccounts = false; + $list = false; + $success = false; + $filterPending = false; + $filterArchived = false; + $filterOverdue = false; + $filterExpired = false; + $haveFilter = 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; + $where_params = array(); + + // Check selected fields + $select = array( + 'exportId' => $this->checkFlag('exportId'), + 'exportMember' => $this->checkFlag('exportMember'), + 'exportEmail' => $this->checkFlag('exportEmail'), + 'exportAddr1' => $this->checkFlag('exportAddr1'), + 'exportAddr2' => $this->checkFlag('exportAddr2'), + 'exportCity' => $this->checkFlag('exportCity'), + 'exportState' => $this->checkFlag('exportState'), + 'exportZip' => $this->checkFlag('exportZip'), + 'exportPhone' => $this->checkFlag('exportPhone'), + 'exportRenewalDate' => $this->checkFlag('exportRenewalDate'), + ); + + // Only return information records that are active + + // Check if this is a request to show archived accounts + if (isset($_REQUEST['filterArchived'])) { + // $where_params[] = "T.archived"; + $filterArchived = true; + $haveFilter = true; + + // If not, don't show them + } else { + // $where_params[] = "T.archived <> true"; + } + + // When searching + $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.renewal_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.renewal_date <= '$to_date'"; + } + if ( isset( $_REQUEST['filterAccounts'] ) + && $filterAccounts = filter_var( $_REQUEST['filterAccounts'], FILTER_VALIDATE_INT ) + ) { + $accounts[$filterAccounts]['selected'] = true; + $where_params[] = "T.id = $filterAccounts"; + } else if ( isset( $_REQUEST['searchName'] ) + && $searchName = filter_var( $_REQUEST['searchName'], FILTER_SANITIZE_STRING ) + ) { + $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()"; + $filterPending = true; + $haveFilter = true; + } + 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 a current list of accounts without paging + $orderBy = 'renewal_date ASC'; + $list = $this->getList( $where, $orderBy ); + + // If we have list entries - even if it's an empty list + $success = true; + $haveAccounts = false; + if ($list !== false) { + $success = true; + $accountCount = count($list); + $haveAccounts = true; + } + + // Compile template data + $templateData = array( + 'select' => $select, + 'haveAccounts' => $haveAccounts, + 'accounts' => $list, + 'accountCount' => $accountCount, + 'haveFilter' => $haveFilter, + 'filterArchived' => $filterArchived, + 'filterFeatured' => $filterFeatured, + 'filterPending' => $filterPending, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList + ); + + $view = 'admin/ajax/accountsListExport.html'; + if ($_REQUEST['type'] == 'csv') { + $view = 'admin/ajax/accountsListExportCsv.html'; + header("Content-Type: text/csv"); + header("Content-Disposition: attachment; filename=file.csv"); + } else { + header("Content-Type: text/html"); + header("Content-Disposition: attachment; filename=file.html"); + } + + // Disable caching + header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 + header("Pragma: no-cache"); // HTTP 1.0 + header("Expires: 0"); // Proxies + + // Return status, suggested view, and data to controller + return array( + 'status' => $success, + 'menuItemRedirect' => false, + 'modelRedirect' => false, + 'view' => $view, + 'data' => $templateData + ); + + } + +} diff --git a/models/admin/billing/accounts.php b/models/admin/billing/accounts.php index bc3e639..55616d9 100644 --- a/models/admin/billing/accounts.php +++ b/models/admin/billing/accounts.php @@ -462,7 +462,7 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts 'filterPending' => $filterPending, 'filterOverdue' => $filterOverdue, 'searchName' => $searchName, - 'filterExpired' => $filterExpired, + 'filterExpired' => $filterExpired, ); // Return status, any suggested view, and any data to controller diff --git a/setup/validActions.php b/setup/validActions.php index 79eaaa4..b6d3d68 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -60,11 +60,12 @@ $glmMembersBillingAddOnValidActions = array( 'adminActions' => array( 'ajax' => array( - 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, - 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, - 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, - 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, - 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'setupQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'runQueue' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'account' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, ), 'management' => array( 'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/views/admin/ajax/accountsListExport.html b/views/admin/ajax/accountsListExport.html new file mode 100644 index 0000000..4afa05c --- /dev/null +++ b/views/admin/ajax/accountsListExport.html @@ -0,0 +1,50 @@ + + + + + + Total found: {$accountCount}   + List of {$terms.term_member_cap} Profiles +
+ + + + + + {if $select.exportId}{/if} + {if $select.exportMember}{/if} + {if $select.exportEmail}{/if} + {if $select.exportAddr1}{/if} + {if $select.exportAddr2}{/if} + {if $select.exportCity}{/if} + {if $select.exportState}{/if} + {if $select.exportZip}{/if} + {if $select.exportPhone}{/if} + {if $select.exportRenewalDate}{/if} + + + + {if $haveAccounts} + {foreach $accounts as $account} + + {if $select.exportId}{/if} + {if $select.exportMember}{/if} + {if $select.exportEmail}{/if} + {if $select.exportAddr1}{/if} + {if $select.exportAddr2}{/if} + {if $select.exportCity}{/if} + {if $select.exportState}{/if} + {if $select.exportZip}{/if} + {if $select.exportPhone}{/if} + {if $select.exportRenewalDate}{/if} + + + {/foreach} + {else} + + {/if} + +
ID{$terms.term_member_cap} NameBilling E-MailBilling AddressBilling Addr Line #2Billing CityBilling StateBilling ZIPBilling PhoneRenewal Date
{$account.id}{$account.ref_name}{$account.email}{$account.billing_addr1}{$account.billing_addr2}{$account.billing_city}{if $account.billing_state}{$account.billing_state.value}{/if}{$account.billing_zip}{$account.billing_phone}{$account.renewal_date.date}
(no Accounts listed)
+ + + diff --git a/views/admin/ajax/accountsListExportCsv.html b/views/admin/ajax/accountsListExportCsv.html new file mode 100644 index 0000000..b4dd5a0 --- /dev/null +++ b/views/admin/ajax/accountsListExportCsv.html @@ -0,0 +1,26 @@ +{if $haveAccounts} +{if $select.exportId}"ID",{/if} +{if $select.exportMember}"{$terms.term_member_cap} Name",{/if} +{if $select.exportEmail}"Billing E-Mail",{/if} +{if $select.exportAddr1}"Billing Address",{/if} +{if $select.exportAddr2}"Billing Addr Line #2",{/if} +{if $select.exportCity}"Billing City",{/if} +{if $select.exportState}"Billing State",{/if} +{if $select.exportZip}"Billing ZIP/Postal",{/if} +{if $select.exportPhone}"Billing Phone",{/if} +{if $select.exportRenewalDate}"Renewal Date",{/if} + +{foreach $accounts as $account} +{if $select.exportId}"{$account.id}",{/if} +{if $select.exportMember}"{$account.ref_name}",{/if} +{if $select.exportEmail}"{$account.email}",{/if} +{if $select.exportAddr1}"{$account.billing_addr1}",{/if} +{if $select.exportAddr2}"{$account.billing_addr2}",{/if} +{if $select.exportCity}"{$account.billing_city}",{/if} +{if $select.exportState}"{if $account.billing_state}{$account.billing_state.value}{/if}",{/if} +{if $select.exportZip}"{$account.billing_zip}",{/if} +{if $select.exportPhone}"{$account.billing_phone}",{/if} +{if $select.exportRenewalDate}"{$account.renewal_date.date}",{/if} + +{/foreach} +{else}No Accounts Selected{/if} diff --git a/views/admin/billing/accounts.html b/views/admin/billing/accounts.html index 8cfafc1..2a5521e 100644 --- a/views/admin/billing/accounts.html +++ b/views/admin/billing/accounts.html @@ -1,5 +1,7 @@ {include file='admin/billing/header.html'} +
Accounts Export
+

Accounts

{include file='admin/billing/accountSearchForm.html'} @@ -46,12 +48,14 @@ - {if $paging} - - - {/if} +{if $paging} + + +{/if} + + - +{include file='admin/billing/exportBillingModal.html'}