From: Steve Sutton Date: Fri, 13 Apr 2018 18:36:42 +0000 (-0400) Subject: Add export to payment list. X-Git-Tag: v1.0.0^2~53 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=68398fc9ff8d7942dc412623e3e99baa6e6ff8a7;p=WP-Plugins%2Fglm-member-db-billing.git Add export to payment list. Adding the export to payment list page. --- diff --git a/models/admin/ajax/paymentsListExport.php b/models/admin/ajax/paymentsListExport.php new file mode 100644 index 0000000..3adc3ad --- /dev/null +++ b/models/admin/ajax/paymentsListExport.php @@ -0,0 +1,198 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + + +// Load Member Info data abstract +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataPayments.php'; + +/** + * + * This class exports the currently selected accounts list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_paymentsListExport extends GlmDataPayments +{ + + /** + * 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; + $havePayments = false; + $list = false; + $success = 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'), + 'exportTime' => $this->checkFlag('exportTime'), + 'exportAmount' => $this->checkFlag('exportAmount'), + 'exportPaymentMethod' => $this->checkFlag('exportPaymentMethod'), + 'exportPaymentData' => $this->checkFlag('exportPaymentData'), + ); + + // Only return information records that are active + + // 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.transaction_time >= '$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.transaction_time <= '$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 string from the $where_parts array. + // By implode with AND. + $where = implode( ' AND ', $where_params ); + + + // Get a current list of accounts without paging + $orderBy = 'transaction_time ASC'; + $list = $this->getList( $where, $orderBy, true ); + + // echo '
$list: ' . print_r( $list, true ) . '
'; + // die('here'); + + // If we have list entries - even if it's an empty list + $success = true; + $havePayments = false; + if ($list !== false) { + $success = true; + $paymentCount = count($list); + $havePayments = true; + } + + // Compile template data + $templateData = array( + 'select' => $select, + 'havePayments' => $havePayments, + 'payments' => $list, + 'paymentCount' => $paymentCount, + 'haveFilter' => $haveFilter, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList + ); + + $view = 'admin/ajax/paymentsListExport.html'; + if ($_REQUEST['type'] == 'csv') { + $view = 'admin/ajax/paymentsListExportCsv.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/payments.php b/models/admin/billing/payments.php index f0b6747..53eefc2 100644 --- a/models/admin/billing/payments.php +++ b/models/admin/billing/payments.php @@ -116,6 +116,8 @@ class GlmMembersAdmin_billing_payments extends GlmDataPayments $invTypes = array(); $accounts = false; $allAccounts = false; + $filterAccounts = false; + $searchName = false; // Get any provided option if (isset($_REQUEST['option'])) { @@ -219,6 +221,7 @@ class GlmMembersAdmin_billing_payments extends GlmDataPayments $allAccounts = $Accounts->getSimpleAccountList(); $where = 'true'; + $where_params = array( 'true' ); // Check for paging // if ( isset( $_REQUEST['pageSelect'] ) ) { diff --git a/setup/validActions.php b/setup/validActions.php index 7469196..4c0975a 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -67,6 +67,7 @@ $glmMembersBillingAddOnValidActions = array( 'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createNewInvoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'paymentsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, ), 'management' => array( 'billing' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/views/admin/ajax/paymentsListExport.html b/views/admin/ajax/paymentsListExport.html new file mode 100644 index 0000000..098923a --- /dev/null +++ b/views/admin/ajax/paymentsListExport.html @@ -0,0 +1,42 @@ + + + + + + Total found: {$paymentCount}   + List of {$terms.term_member_cap} Profiles +
+ + + + + + {if $select.exportId}{/if} + {if $select.exportMember}{/if} + {if $select.exportTime}{/if} + {if $select.exportAmount}{/if} + {if $select.exportPaymentMethod}{/if} + {if $select.exportPaymentData}{/if} + + + + {if $havePayments} + {foreach $payments as $payment} + + {if $select.exportId}{/if} + {if $select.exportMember}{/if} + {if $select.exportTime}{/if} + {if $select.exportAmount}{/if} + {if $select.exportPaymentMethod}{/if} + {if $select.exportPaymentData}{/if} + + + {/foreach} + {else} + + {/if} + +
ID{$terms.term_member_cap} NameTimeAmountPayment MethodPayment Notes
{$payment.id}{$payment.member_name}{$payment.transaction_time.datetime}{$payment.amount}{$payment.payment_method}{$payment.payment_data}
(no Payments listed)
+ + + diff --git a/views/admin/ajax/paymentsListExportCsv.html b/views/admin/ajax/paymentsListExportCsv.html new file mode 100644 index 0000000..5bfbfca --- /dev/null +++ b/views/admin/ajax/paymentsListExportCsv.html @@ -0,0 +1,18 @@ +{if $havePayments} +{if $select.exportId}"ID",{/if} +{if $select.exportMember}"{$terms.term_member_cap} Name",{/if} +{if $select.exportTime}"Time",{/if} +{if $select.exportAmount}"Amount",{/if} +{if $select.exportPaymentMethod}"Payment Method",{/if} +{if $select.exportPaymentData}"Payment Notes",{/if} + +{foreach $payments as $payment} +{if $select.exportId}"{$payment.id}",{/if} +{if $select.exportMember}"{$payment.member_name}",{/if} +{if $select.exportTime}"{$payment.transaction_time.datetime}",{/if} +{if $select.exportAmount}"{$payment.amount}",{/if} +{if $select.exportPaymentMethod}"{$payment.payment_method}",{/if} +{if $select.exportPaymentData}"{$payment.payment_data}",{/if} + +{/foreach} +{else}No Payments Selected{/if} diff --git a/views/admin/billing/exportPaymentModal.html b/views/admin/billing/exportPaymentModal.html new file mode 100644 index 0000000..0f131fb --- /dev/null +++ b/views/admin/billing/exportPaymentModal.html @@ -0,0 +1,83 @@ +
+
+ + + + + + + + + + + + + + + + + + + +
Date Range Search: + From Date:
+
+ To Date:
+
+
Name Search: + + +
Fields to export: + + + + + + + +
Check All / Uncheck All
+ Payment ID
+ {$terms.term_member_cap} Name
+ Time
+ Amount
+ Payment Method
+ Payment Notes
+ +
+
Export to: + Export to Spreadsheet (CSV)
+ Export for Print +
+ Cancel + +
+
+ + diff --git a/views/admin/billing/payments.html b/views/admin/billing/payments.html index a33c442..f0ab051 100644 --- a/views/admin/billing/payments.html +++ b/views/admin/billing/payments.html @@ -2,6 +2,7 @@ {include file='admin/billing/paymentHeader.html'} +
Payments Export

Payments

@@ -107,4 +108,6 @@ jQuery(document).ready(function($) { }); +{include file='admin/billing/exportPaymentModal.html'} + {include file='admin/footer.html'}