Add export to payment list.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 13 Apr 2018 18:36:42 +0000 (14:36 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 13 Apr 2018 18:36:42 +0000 (14:36 -0400)
Adding the export to payment list page.

models/admin/ajax/paymentsListExport.php [new file with mode: 0644]
models/admin/billing/payments.php
setup/validActions.php
views/admin/ajax/paymentsListExport.html [new file with mode: 0644]
views/admin/ajax/paymentsListExportCsv.html [new file with mode: 0644]
views/admin/billing/exportPaymentModal.html [new file with mode: 0644]
views/admin/billing/payments.html

diff --git a/models/admin/ajax/paymentsListExport.php b/models/admin/ajax/paymentsListExport.php
new file mode 100644 (file)
index 0000000..3adc3ad
--- /dev/null
@@ -0,0 +1,198 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Members List Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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 '<pre>$list: ' . print_r( $list, true ) . '</pre>';
+        // 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
+        );
+
+    }
+
+}
index f0b6747..53eefc2 100644 (file)
@@ -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'] ) ) {
index 7469196..4c0975a 100644 (file)
@@ -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 (file)
index 0000000..098923a
--- /dev/null
@@ -0,0 +1,42 @@
+<html>
+    <head>
+    </head>
+    <body>
+
+        <span style="float: right;"><b>Total found: {$paymentCount}&nbsp;&nbsp;</b></span>
+        <b>List&nbsp;of&nbsp;{$terms.term_member_cap} Profiles</b>
+        <br clear="all">
+
+
+        <table>
+            <thead>
+                <tr>
+                    {if $select.exportId}<th align="left">ID</th>{/if}
+                    {if $select.exportMember}<th align="left">{$terms.term_member_cap} Name</th>{/if}
+                    {if $select.exportTime}<th align="left">Time</th>{/if}
+                    {if $select.exportAmount}<th align="left">Amount</th>{/if}
+                    {if $select.exportPaymentMethod}<th align="left">Payment Method</th>{/if}
+                    {if $select.exportPaymentData}<th align="left">Payment Notes</th>{/if}
+                </tr>
+            </thead>
+            <tbody>
+    {if $havePayments}
+        {foreach $payments as $payment}
+                <tr>
+                    {if $select.exportId}<td>{$payment.id}</td>{/if}
+                    {if $select.exportMember}<td>{$payment.member_name}</td>{/if}
+                    {if $select.exportTime}<td>{$payment.transaction_time.datetime}</td>{/if}
+                    {if $select.exportAmount}<td>{$payment.amount}</td>{/if}
+                    {if $select.exportPaymentMethod}<td>{$payment.payment_method}</td>{/if}
+                    {if $select.exportPaymentData}<td>{$payment.payment_data}</td>{/if}
+
+                </tr>
+        {/foreach}
+    {else}
+                <tr class="alternate"><td colspan="2">(no Payments listed)</td></tr>
+    {/if}
+            </tbody>
+        </table>
+
+    </body>
+</html>
diff --git a/views/admin/ajax/paymentsListExportCsv.html b/views/admin/ajax/paymentsListExportCsv.html
new file mode 100644 (file)
index 0000000..5bfbfca
--- /dev/null
@@ -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 (file)
index 0000000..0f131fb
--- /dev/null
@@ -0,0 +1,83 @@
+<div id="exportPaymentDialog" class="glm-dialog-box" title="Export Billing Payments">
+    <form id="exportForm" action="{$ajaxUrl}" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="action" value="glm_members_admin_ajax">
+        <input type="hidden" name="glm_action" value="paymentsListExport">
+        <table class="glm-admin-table">
+            <tr>
+                <th>Date Range Search: </th>
+                <td>
+                    <b>From Date: </b><br />
+                    <input type="text" name="fromDate" value="{$fromDate}" class="glm-form-text-input-short glm-date-input" /><br />
+                    <b>To Date: </b><br />
+                    <input type="text" name="toDate" value="{$toDate}" class="glm-form-text-input-short glm-date-input" /><br />
+                </td>
+            </tr>
+            <tr>
+                <th>Name Search:</th>
+                <td>
+                    <input id="member-account2" type="hidden" name="filterAccounts" value="{$filterAccounts}">
+                    <input id="account_name2" name="searchName" value="{if $searchName}{$searchName}{/if}" />
+                </td>
+            </tr>
+            <tr>
+                <th>Fields to export: </th>
+                <td>
+                    <table padding="3">
+                        <tr>
+                            <td colspan="2"><a id="selectAllExportFields">Check All</a> / <a id="unselectAllExportFields">Uncheck All</a></td>
+                        </tr>
+                        <tr>
+                            <td class="exportFieldsTd">
+                                <input type="checkbox" name="exportId"> Payment ID<br>
+                                <input type="checkbox" name="exportMember" checked> {$terms.term_member_cap} Name<br>
+                                <input type="checkbox" name="exportTime" checked> Time <br>
+                                <input type="checkbox" name="exportAmount" checked> Amount <br>
+                                <input type="checkbox" name="exportPaymentMethod" checked> Payment Method <br>
+                                <input type="checkbox" name="exportPaymentData" checked> Payment Notes <br>
+
+                            </td>
+                        </tr>
+                    </table>
+                </td>
+            </tr>
+            <tr>
+                <th>Export to: </th>
+                <td>
+                    <input type="radio" name="type" value="csv" checked="checked"> Export to Spreadsheet (CSV)<br>
+                    <input type="radio" name="type" value="print"> Export for Print
+                </td>
+            </tr>
+        </table>
+        <a id="exportPaymentsCancel" class="button button-secondary glm-right">Cancel</a>
+        <input type="submit" value="Export" class="button button-primary" autofocus>
+    </form>
+</div>
+
+<script>
+jQuery(document).ready(function($) {
+
+    // Setup for the modal box
+    $('#exportPaymentDialog').dialog( {
+        autoOpen: false,
+        minWidth: 700,
+        dialogClass: 'glm-dialog-no-close'
+    } );
+    $('#exportPaymentsButton').click( function(){
+        $('#exportPaymentDialog').dialog( 'open' );
+    } );
+    $('#exportPaymentsCancel').click( function(){
+        $('#exportPaymentDialog').dialog( 'close' );
+    } );
+    $('#selectAllExportFields').click(function(){
+        $('.exportFieldsTd input[type="checkbox"]').each(function(){
+            $(this).prop('checked', true);
+        });
+    });
+    $('#unselectAllExportFields').click(function(){
+        $('.exportFieldsTd input[type="checkbox"]').each(function(){
+            $(this).prop('checked', false);
+        });
+    });
+
+});
+</script>
index a33c442..f0ab051 100644 (file)
@@ -2,6 +2,7 @@
 
 {include file='admin/billing/paymentHeader.html'}
 
+<div id="exportPaymentsButton" class="button button-secondary glm-admin-export-button">Payments Export</div>
 
 <h2>Payments</h2>
 
@@ -107,4 +108,6 @@ jQuery(document).ready(function($) {
 });
 </script>
 
+{include file='admin/billing/exportPaymentModal.html'}
+
 {include file='admin/footer.html'}