From: Steve Sutton Date: Fri, 29 Mar 2019 18:45:50 +0000 (-0400) Subject: Export reports X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=8a856caa5272a065bcd12bc00175dccfeeb72b6b;p=WP-Plugins%2Fglm-member-db-billing.git Export reports Can now export reports to csv file. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 9fc180f..1073969 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -925,7 +925,7 @@ class GlmBillingSupport WHERE amount > 0 AND recurring AND recurrence = 20 - ORDER BY name", + ORDER BY amount,name", ARRAY_A ); } diff --git a/models/admin/ajax/reportsListExport.php b/models/admin/ajax/reportsListExport.php new file mode 100644 index 0000000..2715f39 --- /dev/null +++ b/models/admin/ajax/reportsListExport.php @@ -0,0 +1,235 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @version 0.1 + */ + + +// Load Member Info data abstract +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataTransactions.php'; + +/** + * + * This class exports the currently selected accounts list + * to a printable HTML file, to a CSV file, or otherwise. + */ +class GlmMembersAdmin_ajax_reportsListExport extends GlmDataTransactions +{ + + /** + * 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(); + $sub_where_parts = array(); + + // Check selected fields + $select = array( + 'exportId' => $this->checkFlag('exportId'), + 'exportTransactionTime' => $this->checkFlag('exportTransactionTime'), + 'exportMember' => $this->checkFlag('exportMember'), + 'exportInvoiceAmount' => $this->checkFlag('exportInvoiceAmount'), + 'exportPaymentAmount' => $this->checkFlag('exportPaymentAmount'), + 'exportNotes' => $this->checkFlag('exportNotes'), + ); + + // When searching + $reg_options = array( + 'options' => array( + 'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%' + ) + ); + if ( isset( $_REQUEST['invoice_types'] ) && $invoiceTypes = filter_var( $_REQUEST['invoice_types'], FILTER_VALIDATE_INT,array( 'flags' => FILTER_FORCE_ARRAY ) ) ) { + $where_params[] = " T.account IN ( + SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE invoice_type IN (" . implode(',', $invoiceTypes) . ") + ) "; + } + + if ( isset( $_REQUEST['counties'] ) && $countiesSelected = filter_var( $_REQUEST['counties'], FILTER_VALIDATE_INT,array( 'flags' => FILTER_FORCE_ARRAY ) ) ) { + $where_params[] = " T.account IN ( + SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE billing_county IN (" . implode(',', $countiesSelected) . ") + ) "; + } + + if ( isset( $_REQUEST['member_name'] ) && $member_name = filter_var( $_REQUEST['member_name'], FILTER_SANITIZE_STRING ) ) { + $where_params[] = "T.account IN ( + SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE ref_name like '%" . esc_sql( $member_name ) . "%' + )"; + } + if ( isset( $_REQUEST['account_number'] ) && $account_number = filter_var( $_REQUEST['account_number'], FILTER_SANITIZE_STRING ) ) { + $where_params[] = "T.account IN ( + SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE account_number = '" . esc_sql( $account_number ) . "' + )"; + } + if ( isset( $_REQUEST['transactionTypes'] ) && $transactionTypes = filter_var( $_REQUEST['transactionTypes'], FILTER_VALIDATE_INT,array( 'flags' => FILTER_FORCE_ARRAY ) ) ) { + $where_params[] = "T.type IN (" . implode(',', $transactionTypes) . ")"; + } + 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['searchName'] ) + && $searchName = filter_var( $_REQUEST['searchName'], FILTER_SANITIZE_STRING ) + ) { + $where_params[] = "T.ref_name like '%" . esc_sql( $searchName ) . "%'"; + } + + // Get the setting for days before and after. + $days_before_renewal = $this->config['settings']['days_before_renewal']; + $days_after_expired = $this->config['settings']['days_after_expired']; + $curDate = date( 'Y-m-d' ); + + if ( !empty( $sub_where_parts ) ) { + $where_params[] = "(" . implode( ' OR ', $sub_where_parts ) . ")"; + } + + // 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'; + $this->member_data = true; + $this->notes = true; + $list = $this->getList( $where, $orderBy, true ); + + // 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, + 'filterPending' => $filterPending, + 'numbDisplayed' => $numbDisplayed, + 'lastDisplayed' => $lastDisplayed, + 'paging' => $paging, + 'prevStart' => $prevStart, + 'nextStart' => $nextStart, + 'start' => $start, + 'limit' => $limit, + 'namesList' => $namesList + ); + + $view = 'admin/ajax/reportsListExportCsv.html'; + header("Content-Type: text/csv"); + header("Content-Disposition: attachment; filename=file.csv"); + + // 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/reports.php b/models/admin/billing/reports.php index 8621b40..d092f01 100644 --- a/models/admin/billing/reports.php +++ b/models/admin/billing/reports.php @@ -268,7 +268,6 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions $this->member_data = true; $this->notes = true; $accountsResult = $this->getList( $reportWhere, $orderBy, true, 'id', $start, $limit ); - // echo '
' . print_r( $accountsResult, true ) . '
'; $totalAccounts = $this->getStats( $reportWhere ); $totalInvoices = $this->getInvoiceTotal( $reportWhere ); $totalPayments = $this->getPaymentTotal( $reportWhere ); diff --git a/models/front/billing/paymentForm.php b/models/front/billing/paymentForm.php index b57ffab..ede1f51 100644 --- a/models/front/billing/paymentForm.php +++ b/models/front/billing/paymentForm.php @@ -88,41 +88,32 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling public function modelAction( $actionData = false ) { // Initialize Variables Here - $fromMemberMenu = false; - $this->memberId = false; - $memberData = false; - $memberName = false; - $haveMember = false; - $haveAccount = false; - $option = 'payment'; - $view = 'paymentForm'; - $account = false; - $accountId = 0; - $account_data = false; - $balance_due = false; - $invoiceHtml = false; - $management = false; - $messages = array(); - $paymentSuccess = false; - $paymentError = false; - $hasBillingAccount = false; - $member_invoice = false; - $payable_types = false; - $account_status = false; - $unregistered = false; - $invoiceId = false; - - // For lockedToMember. - $lockedToMember = false; - $lockedWhereT = 'true'; - $lockedWhere = 'true'; - - // Check for unregistered. - if ( isset( $actionData['request']['unregistered'] ) && filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN ) ) { - $unregistered = filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN ); - } - - // echo '
$unregistered: ' . print_r( $unregistered, true ) . '
'; + $fromMemberMenu = false; + $this->memberId = false; + $memberData = false; + $memberName = false; + $haveMember = false; + $haveAccount = false; + $option = 'payment'; + $view = 'paymentForm'; + $account = false; + $accountId = 0; + $account_data = false; + $balance_due = false; + $invoiceHtml = false; + $management = false; + $messages = array(); + $paymentSuccess = false; + $paymentError = false; + $hasBillingAccount = false; + $member_invoice = false; + $payable_types = false; + $account_status = false; + $invoiceId = false; + $selectedPaymentType = false; + $lockedWhereT = 'true'; + $lockedWhere = 'true'; + $lockedToMember = true; // Call in the support class $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); @@ -172,10 +163,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling } else { $view = 'paymentForm'; - if ( $unregistered ) { - $lockedToMember = true; - } - // Get list of payable invoice_types $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); // echo '
$payable_types: ' . print_r( $payable_types, true ) . '
'; @@ -200,11 +187,30 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling $error = false; $view = 'paymentFormProcess'; + // Here we need to get the chosen Membership plan and adjust the invoice with a new line_item if needed. + $selectedPaymentType = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); + if ( isset( $_REQUEST['invoice_number'] ) ) { $invoiceId = filter_var( $_REQUEST['invoice_number'], FILTER_VALIDATE_INT ); } else { die( 'Error: no invoiceId' ); } + // Pull member invoice + $memberInvoice = $BillingSupport->getInvoiceById( $invoiceId ); + echo '
$memberInvoice: ' . print_r( $memberInvoice, true ) . '
'; + $memberInvoiceLineItems = $BillingSupport->getLineItemsForInvoice( $invoiceId ); + echo '
$memberInvoiceLineItems: ' . print_r( $memberInvoiceLineItems, true ) . '
'; + if ( isset( $memberInvoiceLineItems ) && is_array( $memberInvoiceLineItems ) && !empty( $memberInvoiceLineItems ) ) { + foreach ( $memberInvoiceLineItems as $lineItem ) { + if ( $lineItem['recurring'] ) { + $invoicePaymentType = $lineItem['line_item_type']; + } + } + } + // If there's new invoice type then we need to update the invoice + if ( $invoicePaymentType != $selectedPaymentType ) { + + } // Check for account_number // If given then this is from unregistered user. @@ -250,10 +256,10 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling // Get list of payable invoice_types $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); - $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId ); - if ( $member_invoice_id ) { - $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); - } + // $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId ); + // if ( $member_invoice_id ) { + // $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + // } if ( $this->config['settings']['allow_employees'] ) { // Get a list of this accounts employees. If they have any. @@ -341,7 +347,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling 'accountId' => $accountId, 'option' => $option, 'fromMemberMenu' => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ), - 'lockedToMember' => $lockedToMember, 'invoiceId' => $invoiceId, 'memberId' => $this->memberId, 'haveMember' => $haveMember, @@ -364,6 +369,7 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling 'member_invoice' => $member_invoice, 'payable_types' => $payable_types, 'account_status' => $account_status, + 'lockedToMember' => $lockedToMember, ); // Return status, any suggested view, and any data to controller. diff --git a/setup/validActions.php b/setup/validActions.php index 940eb8f..a1be48e 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -72,6 +72,7 @@ $glmMembersBillingAddOnValidActions = array( 'createPDFLabels' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'createCSVLabels' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'accountsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'reportsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'paymentsListExport' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'billingFlagExpiredUsers' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, 'billingFixActiveUsers' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, diff --git a/views/admin/ajax/reportsListExportCsv.html b/views/admin/ajax/reportsListExportCsv.html new file mode 100644 index 0000000..c4dff4e --- /dev/null +++ b/views/admin/ajax/reportsListExportCsv.html @@ -0,0 +1,18 @@ +{if $haveAccounts} +{if $select.exportId}"ID",{/if} +{if $select.exportTransactionTime}"Transaction Time",{/if} +{if $select.exportMember}"{$terms.term_member_cap} Name",{/if} +{if $select.exportInvoiceAmount}"Invoice Amount",{/if} +{if $select.exportPaymentAmount}"Payment Amount",{/if} +{if $select.exportNotes}"Notes"{/if} + +{foreach $accounts as $account} +{if $select.exportId}"{$account.id}",{/if} +{if $select.exportTransactionTime}"{$account.transaction_time.datetime}",{/if} +{if $select.exportMember}"{$account.member_name}",{/if} +{if $select.exportInvoiceAmount}"{$account.current_invoice_total|string_format:"%.2f"}",{/if} +{if $select.exportPaymentAmount}"{$account.current_payment_total|string_format:"%.2f"}",{/if} +{if $select.exportNotes}"{$account.notes}"{/if} + +{/foreach} +{else}No Accounts Selected{/if} diff --git a/views/admin/billing/exportReportModal.html b/views/admin/billing/exportReportModal.html index 7601dbf..6c26944 100644 --- a/views/admin/billing/exportReportModal.html +++ b/views/admin/billing/exportReportModal.html @@ -1,13 +1,40 @@
- + - - - - - + + + + + {if $counties} + + + + + {/if} + + + +
Show Active:
Show Pending:
Show Overdue:
Show Archived:
Show Expired:
Payment Types + +
Counties + +
Transaction Types + +
Date Range Search: @@ -38,21 +65,15 @@ {$terms.term_member_cap} Name
Invoice Amount
Payment Amount
- + Notes
- - Export to: - - Export to Spreadsheet (CSV)
- - Cancel - +
diff --git a/views/front/billing/paymentForm.html b/views/front/billing/paymentForm.html index 9874a4b..36ac87f 100644 --- a/views/front/billing/paymentForm.html +++ b/views/front/billing/paymentForm.html @@ -19,52 +19,31 @@ - {if $member_invoice} -
-
- Membership Class -
-
- {if $settings.allow_membership_choice} - {foreach $payable_types as $type} - - {/foreach} - {else} - - {$member_invoice.name} {$member_invoice.amount} - {/if} -
+
+
+ Invoice #
- {else} -
-
- Invoice # -
-
- -
+
+
-
-
- Membership Class -
-
- {if $settings.allow_membership_choice} - {foreach $payable_types as $type} - - {/foreach} - {/if} -
+
+
+
+ Membership Class +
+
+ {if $settings.allow_membership_choice} + {foreach $payable_types as $type} + + {/foreach} + {else} + + {/if}
- {/if} +
@@ -129,11 +108,16 @@ jQuery(document).ready(function($){ return false; } if ( msg.invoice_type ) { - // $('input[name=member_renewing]').prop('checked', false); console.log( 'invoice_type', msg.invoice_type ); - $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true); - $('#membername').html(msg.invoice.member_name); - getPageTotal(); + {if $settings.allow_membership_choice} + $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true); + $('#membername').html(msg.invoice.member_name); + getPageTotal(); + {else} + $('#member_renewing').data( 'amount', msg.invoice.amount_total ); + $('#member_renewing').val( msg.invoice_type ); + getPageTotal(); + {/if} } } }); @@ -157,7 +141,9 @@ jQuery(document).ready(function($){ } - getPageTotal(); + {if $settings.allow_membership_choice} + getPageTotal(); + {/if} // trigger total if changing Membership $('input[name=member_renewing]').change(function(){ @@ -169,5 +155,3 @@ jQuery(document).ready(function($){ }); - -