Adding account list page and update search filters invoices.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Mar 2018 18:01:47 +0000 (13:01 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Mar 2018 18:01:47 +0000 (13:01 -0500)
Update search filters for invoices page.
Add account list and search for anniversary and renewal dates.

models/admin/ajax/account.php
models/admin/billing/accounts.php [new file with mode: 0644]
models/admin/billing/invoices.php
setup/validActions.php
views/admin/billing/accounts.html [new file with mode: 0644]
views/admin/billing/editInvoice.html
views/admin/billing/header.html
views/admin/billing/invoices.html

index 856d9d5..2d953af 100644 (file)
@@ -90,7 +90,8 @@ class GlmMembersAdmin_ajax_account extends GlmDataAccounts
             } else {
                 $accountAdded = true;
                 $return = array(
-                    'status' => true
+                    'status'  => true,
+                    'account' => $account
                 );
             }
             break;
diff --git a/models/admin/billing/accounts.php b/models/admin/billing/accounts.php
new file mode 100644 (file)
index 0000000..96c1cc3
--- /dev/null
@@ -0,0 +1,445 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Transactions List
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+// Load Contacts data class
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php';
+
+class GlmMembersAdmin_billing_accounts extends GlmDataAccounts
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Transactions ID
+     *
+     * @var $account_id
+     * @access public
+     */
+    public $account_id = false;
+
+    /**
+     * Constructor
+     *
+     * This constructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successful and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the controller should use instead of the
+     * default view for this model or false to indicate that the default view
+     * should be used.
+     *
+     * 'data'
+     *
+     * Data that the model is returning for use in merging with the view to
+     * produce output.
+     *
+     * @wpdb object WordPress database object
+     *
+     * @return array Array containing status, suggested view, and any data
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        /*
+         * Run constructor for the Contacts data class
+         *
+         * 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);
+
+    }
+
+    public function modelAction($actionData = false)
+    {
+
+        $option              = 'list';
+        $this->account_id    = false;
+        $haveAccounts        = false;
+        $invoiceUpdated      = false;
+        $invoiceUpdateError  = false;
+        $invoiceAdded        = false;
+        $invoiceAddError     = false;
+        $view                = 'accounts';
+        $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
+        $invTypes            = array();
+        $invoiceTypes        = false;
+        $invoiceTypeJSON     = '';
+        $accounts            = false;
+        $nonAccountMembers   = false;
+        $invoiceHtml         = '';
+        $fromDate            = '';
+        $toDate              = '';
+
+        // Get any provided option
+        if (isset($_REQUEST['option'])) {
+            $option = $_REQUEST['option'];
+        }
+
+        // Do selected option
+        switch ($option) {
+
+        case 'add':
+            $accounts        = $this->newEntry();
+            // Set the view file to editInvoice
+            $view            = 'editInvoice';
+            $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
+            $invoiceTypes    = $InvoiceTypesObj->getList();
+            // Sort the types by parent child
+            $invoiceTypes    = $InvoiceTypesObj->sortParentChild($invoiceTypes);
+            // Need to get the accounts
+            $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+            $accounts = $Accounts->getList( '', 'ref_name' );
+            // echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+
+            // Need a list of members that don't have an account.
+            $nonAccountMembers = $this->wpdb->get_results(
+                "SELECT id,name
+                   FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                  WHERE id NOT IN (
+                        SELECT distinct ref_dest
+                          FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX .  "accounts   )
+                ORDER BY name",
+                ARRAY_A
+            );
+            // echo '<pre>$nonAccountMembers: ' . print_r( $nonAccountMembers, true ) . '</pre>';
+
+            if ( isset( $invoiceTypes ) ) {
+                foreach ( $invoiceTypes as $invoiceType ) {
+                    $invTypes[$invoiceType['id']] = array(
+                        'id'     => $invoiceType['id'],
+                        'name'   => $invoiceType['name'],
+                        'amount' => $invoiceType['amount'],
+                    );
+                }
+                $invoiceTypeJSON = json_encode( $invTypes, JSON_NUMERIC_CHECK );
+            }
+            break;
+
+        case 'insert':
+            // Set transaction_time to current time.
+            $_REQUEST['transaction_time'] = date('Y-m-d H:i:s');
+            $_REQUEST['due_date'] = date('Y-m-d', strtotime($_REQUEST['due_date']));
+            // echo '<pre>' . print_r( $_REQUEST, true ) . '</pre>';
+            $accounts = $this->insertEntry();
+            $this->account_id = $accounts['fieldData']['id'];
+            // After the Invoice is created need to add each line item
+            if ( isset( $_REQUEST['line_items'] ) ) {
+                $line_items =  $_REQUEST['line_items'];
+                if ( is_array( $line_items ) && !empty( $line_items ) ) {
+                    foreach ( $line_items as $key => $line_item ) {
+                        // Add individual line item record
+                        $this->wpdb->insert(
+                            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items',
+                            array(
+                                'invoice'        => $this->account_id,
+                                'line_item_type' => $line_item,
+                                'name'           => $_REQUEST['line_item_name'][$line_item],
+                                'amount'         => $_REQUEST['line_item_amount'][$line_item],
+                                'quantity'       => $_REQUEST['line_item_qty'][$line_item],
+                                'total'          => (float)$_REQUEST['line_item_qty'][$line_item] * (float)$_REQUEST['line_item_amount'][$line_item],
+                            ),
+                            array(
+                                '%d',
+                                '%d',
+                                '%s',
+                                '%s',
+                                '%d',
+                                '%d'
+                            )
+                        );
+                    }
+                }
+            }
+            // Here we're going to generate the invoice total.
+            $totals = $this->generateInvoiceTotal( $this->account_id );
+            // Now we have a total for the invoice we can record the transaction
+            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+            // Calling the support class to save the invoice to transaction table.
+            $BillingSupport->recordInvoice( $this->account_id, $_REQUEST['account'], $totals['amount_total'] );
+
+            // Set the view file to editInvoice
+            $view = 'editInvoice';
+            $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config );
+            $invoiceTypes    = $InvoiceTypesObj->getList();
+            $invoiceTypes    = $InvoiceTypesObj->sortParentChild($invoiceTypes);
+            if ( isset( $invoiceTypes ) ) {
+                foreach ( $invoiceTypes as $invoiceType ) {
+                    $invTypes[$invoiceType['id']] = array(
+                        'id'     => $invoiceType['id'],
+                        'name'   => $invoiceType['name'],
+                        'amount' => $invoiceType['amount'],
+                    );
+                }
+                $invoiceTypeJSON = json_encode( $invTypes, true );
+            }
+            break;
+
+        case 'edit':
+            $accounts = $this->editEntry($this->account_id);
+
+            // If we have a good accounts
+            if ($accounts['status']) {
+                $haveTransactions = true;
+            }
+
+            // If we're locked to a member as a contact user and the accounts member doesn't equal the contact member
+            if ($lockedToMember && $accounts['fieldData']['ref_dest_id'] != $lockedToMember) {
+                $haveTransactions = false;
+                $accounts = false;
+            }
+
+            // Set the view file to editInvoice
+            $view = 'editInvoice';
+            break;
+
+        case 'update':
+
+            // Try to update this accounts
+            $accounts = $this->updateEntry($this->account_id);
+
+            // Check if that was successful
+            if ($accounts['status']) {
+                $invoiceUpdated = true;
+
+                $accounts = $this->editEntry($this->account_id);
+            } else {
+                $invoiceUpdateError = true;
+            }
+
+            // Set the view file to editInvoice
+            $view = 'editInvoice';
+
+            break;
+        case 'view':
+            // Call in the support class
+            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+            $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] );
+
+            // Set the file name for the view file.
+            $view = 'viewInvoice';
+
+            break;
+
+        case 'delete':
+            // Need to remove any line items for the invoice also
+            // $accounts = $this->deleteTransactions($this->account_id);
+
+            if ($accounts) {
+                $invoiceDeleted = true;
+            } else {
+                $invoiceDeleteError = true;
+            }
+
+        case 'list':
+        default:
+
+            $where_params = array( 'true' );
+
+            // Check for paging
+            if ( isset( $_REQUEST['pageSelect'] ) ) {
+                $_SESSION['search']['pageSelect'] = $_REQUEST['pageSelect'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['pageSelect'] ) ) {
+                unset( $_SESSION['search']['pageSelect'] );
+            }
+            if ( isset( $_REQUEST['nextStart'] ) ) {
+                $_SESSION['search']['nextStart'] = $_REQUEST['nextStart'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['nextStart'] ) ) {
+                unset( $_SESSION['search']['nextStart'] );
+            }
+            if ( isset( $_REQUEST['prevStart'] ) ) {
+                $_SESSION['search']['prevStart'] = $_REQUEST['prevStart'];
+            } else if ( isset( $_REQUEST['searched'] ) && !isset( $_REQUEST['prevStart'] ) ) {
+                unset( $_SESSION['search']['prevStart'] );
+            }
+
+            // Check if we're doing paging
+            if (isset($_REQUEST['pageSelect'])) {
+                // If request is for Next
+                if ($_REQUEST['pageSelect'][0] == 'N') {
+                    $newStart = $_REQUEST['nextStart'] - 0;
+
+                // Otherwise it must be Previous
+                } else {
+                    $newStart = $_REQUEST['prevStart'] - 0;
+                }
+
+                if ($newStart > 0) {
+                    $start = $newStart;
+                }
+            }
+
+            if( isset($_SESSION['search']['pageSelect']) ){
+                 // If request is for Next
+                if ($_SESSION['search']['pageSelect'][0] == 'N') {
+                    $newStart = $_SESSION['search']['nextStart'] - 0;
+
+                // Otherwise it must be Previous
+                } else {
+                    $newStart = $_SESSION['search']['prevStart'] - 0;
+                }
+                if ($newStart > 0) {
+                    $start = $newStart;
+                }
+            }
+            // Get any search parameters.
+            $reg_options = array(
+                'options' => array(
+                    'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
+                )
+            );
+            // When searching
+            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['annFromDate'] ) && $_REQUEST['annFromDate']
+                && $annFromDate = filter_var( $_REQUEST['annFromDate'], FILTER_VALIDATE_REGEXP, $reg_options )
+            ) {
+                $annFrom_date = date( 'Y-m-d', strtotime( $annFromDate ) );
+                $where_params[] = "T.anniversary_date >= '$annFrom_date'";
+            }
+            if ( isset( $_REQUEST['annToDate'] ) && $_REQUEST['annToDate']
+                && $annToDate = filter_var( $_REQUEST['annToDate'], FILTER_VALIDATE_REGEXP, $reg_options )
+            ) {
+                $annTo_date = date( 'Y-m-d', strtotime( $annToDate ) );
+                $where_params[] = "T.anniversary_date <= '$annTo_date'";
+            }
+
+            // Build the $where string from the $where_parts array.
+            // By implode with AND.
+            $where = implode( ' AND ', $where_params );
+
+            // Get the list of accounts and determine number of accounts in list
+            $orderBy = 'ref_name';
+            $accountsResult = $this->getList($where, $orderBy, true, 'id', $start, $limit);
+
+            // Get paging results
+            $numbDisplayed = $accountsResult['returned'];
+            $lastDisplayed = $accountsResult['last'];
+            if ($start == 1) {
+                $prevStart = false;
+            } else {
+                $prevStart = $start - $limit;
+                if ($start < 1) {
+                    $start = 1;
+                }
+            }
+            if ($accountsResult['returned'] == $limit) {
+                $nextStart = $start + $limit;
+            }
+
+            // since we're doing paging, we have to break out just the accounts data
+            $accounts = $accountsResult['list'];
+            if (count($accounts)>0) {
+                $haveAccounts = true;
+            }
+            unset($accountsResult);
+
+            // echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+
+            break;
+
+        }
+
+
+        $templateData = array(
+            'option'              => $option,
+            'account_id'          => $this->account_id,
+            'accounts'            => $accounts,
+            'nonAccountMembers'   => $nonAccountMembers,
+            'haveAccounts'        => $haveAccounts,
+            'invoiceUpdated'      => $invoiceUpdated,
+            'invoiceUpdateError'  => $invoiceUpdateError,
+            'invoiceAdded'        => $invoiceAdded,
+            'invoiceAddError'     => $invoiceAddError,
+            'invoiceInsertError'  => $invoiceInsertError,
+            'invoiceDeleted'      => $invoiceDeleted,
+            'invoiceDeleteError'  => $invoiceDeleteError,
+            'invoiceInvoiceError' => $invoiceDeleteError,
+            'numbDisplayed'       => $numbDisplayed,
+            'lastDisplayed'       => $lastDisplayed,
+            'paging'              => $paging,
+            'prevStart'           => $prevStart,
+            'nextStart'           => $nextStart,
+            'start'               => $start = 1,
+            'limit'               => $limit,
+            'invoiceTypeJSON'     => $invoiceTypeJSON,
+            'invoiceTypes'        => $invoiceTypes,
+            'accounts'            => $accounts,
+            'invoiceHtml'         => $invoiceHtml,
+            'fromDate'            => $fromDate,
+            'toDate'              => $toDate,
+            'annFromDate'         => $annFromDate,
+            'annToDate'           => $annToDate,
+        );
+
+        // Return status, any suggested view, and any data to controller
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => "admin/billing/$view.html",
+            'data'          => $templateData
+        );
+
+    }
+
+}
index bc83e53..5eb9656 100644 (file)
@@ -287,7 +287,11 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
         case 'list':
         default:
 
-            $where = 'true';
+            // Need to get the accounts
+            $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+            $accounts = $Accounts->getList();
+
+            $where_params = array( 'true' );
 
             // Check for paging
             if ( isset( $_REQUEST['pageSelect'] ) ) {
@@ -336,6 +340,37 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
                 }
             }
 
+            // Get any search parameters.
+            $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.due_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.due_date <= '$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 from $where_params array.
+            // By imploding them with AND between each array element.
+            $where = implode( ' AND ', $where_params );
+
             // 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);
index ce0161e..0f97213 100644 (file)
@@ -77,6 +77,7 @@ $glmMembersBillingAddOnValidActions = array(
             'list'     => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'invoices' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'payments' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+            'accounts' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'logs'     => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
         ),
         'member' => array(
diff --git a/views/admin/billing/accounts.html b/views/admin/billing/accounts.html
new file mode 100644 (file)
index 0000000..a39dc8a
--- /dev/null
@@ -0,0 +1,88 @@
+{include file='admin/billing/header.html'}
+
+<h2>Accounts</h2>
+
+<form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
+    <input type="hidden" name="glm_action" value="accounts">
+    <input type="hidden" name="option" value="list">
+
+    <input type="hidden" name="searched" value="1">
+    <input type="hidden" name="prevStart" value="{$prevStart}">
+    <input type="hidden" name="nextStart" value="{$nextStart}">
+    <input type="hidden" name="limit" value="{$limit}">
+
+        <div class="">
+            <h3>Search Renewal date</h3>
+            <span class="glm-nowrap">
+                <b>From Date: </b><input type="text" name="fromDate" value="{$fromDate}" class="glm-form-text-input-short glm-date-input">
+                <b>To Date: </b><input type="text" name="toDate" value="{$toDate}" class="glm-form-text-input-short glm-date-input">
+            </span>
+            <br>
+            <h3>Search Anniversary date</h3>
+            <span class="glm-nowrap">
+                <b>From Date: </b><input type="text" name="annFromDate" value="{$annFromDate}" class="glm-form-text-input-short glm-date-input">
+                <b>To Date: </b><input type="text" name="annToDate" value="{$annToDate}" class="glm-form-text-input-short glm-date-input">
+            </span>
+            <br>
+            <span class="glm-nowrap">
+                <!-- <b>Text Search: </b><input  id="glmEventsSearch" name="textSearch" type="text" id="autoTest"> -->
+                <input type="submit" value="Submit">
+            </span>
+        </div>
+        <br clear="all">
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Events" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Events" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+        <br clear="all">
+
+<table class="wp-list-table widefat fixed posts glm-admin-table">
+    <thead>
+        <tr>
+            <th>ID</th>
+            <th>Member Name</th>
+            <th>Billing Email</th>
+            <th>Anniversary Date</th>
+            <th>Renewal Date</th>
+        </tr>
+    </thead>
+    <tbody>
+        {if $haveAccounts}
+            {assign var="i" value="0"}
+            {foreach $accounts as $t}
+                {if $i++ is odd by 1}
+                    <tr>
+                {else}
+                    <tr class="alternate">
+                {/if}
+                    <td> {$t.id} </td>
+                    <td> {$t.ref_name} </td>
+                    <td> {$t.email} </td>
+                    <td> {$t.anniversary_date.date} </td>
+                    <td> {$t.renewal_date.date} </td>
+                </tr>
+            {/foreach}
+        {else}
+            <tr class="alternate"><td colspan="2">(no Invoice Types listed)</td></tr>
+        {/if}
+    </tbody>
+</table>
+
+    {if $paging}
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Events" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Events" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+    {/if}
+
+    </form>
+
+<script type="text/javascript">
+    jQuery(document).ready(function($) {
+
+            // Date Input
+            $('.glm-date-input').datepicker();
+
+    });
+</script>
+
+{include file='admin/footer.html'}
index 1d471cf..34607d5 100644 (file)
@@ -26,7 +26,9 @@
                         <select id="member-account" name="account" required>
                             <option value="">Select an Account</option>
                             {foreach $accounts as $account}
+                                {if $account.id}
                                 <option value="{$account.id}">{$account.ref_name}</option>
+                                {/if}
                             {/foreach}
                         </select>
                         <a id="newAccountButton" href="#">New Account</a>
     </form>
 </div>
 <div id="newAccountDialog" class="glm-dialog-box" title="New Account">
-    <p class="validateAccountTips">* required.</p>
+    <p class="validateAccountTips" style="color:red">* required</p>
     <form id="addAccountForm">
+        <input id="non-member-account" type="hidden" name="ref_dest" value="">
         <table>
             <tr>
-                <th class="glm-required">Member</th>
-                <td>
-                    <select id="non-member-account" name="ref_dest" style="width: 300px;">
-                        <option value="">Select Member</option>
-                        {foreach $nonAccountMembers as $m}
-                        <option value="{$m.id}">{$m.name}</option>
-                        {/foreach}
-                    </select>
-                </td>
-            </tr>
-            <tr>
-                <th class="glm-required">Name</th>
+                <th class="glm-required">Member Name</th>
                 <td>
                     <input id="glm_member_name" type="text" name="ref_name" value="">
                 </td>
 
 <script>
 jQuery(document).ready(function($){
+    var availableAccounts = [
+    {foreach $accounts as $m}
+        { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
+    {/foreach}
+    ];
+    var availableNonAccountMembers = [
+    {foreach $nonAccountMembers as $m}
+        { label: "{$m.name|unescape:'html'|replace:'"':''}", value: "{$m.name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
+    {/foreach}
+    ];
+    $('#member_account_name').autocomplete({
+        source: availableAccounts
+    });
+    $('#glm_member_name').autocomplete({
+        source: availableNonAccountMembers,
+        appendTo: '#newAccountDialog',
+        select: function( event, ui ){
+            $('#non-member-account').val( ui.item.id );
+        },
+    });
     // Initialize variables for this page.
     var dialog,                                                // Dialog for the add line_item form
         newAccountDialog,                                      // Dialog for the add new account
@@ -192,7 +204,6 @@ jQuery(document).ready(function($){
         line_item_type   = $( 'select[name="line_item_type"]' ), // Line item type in the add line_item form
         line_items       = [],                                   // Array holding line_items json objects
         allFields        = $( [] ).add( line_item_type ),        // Array holding the form fields - add line_item form
-        ref_dest         = $( 'select[name="ref_dest"' ),
         ref_name         = $( 'input[name="ref_name"' ),
         anniversary_date = $( 'input[name="anniversary_date"' ),
         renewal_date     = $( 'input[name="renewal_date"' ),
@@ -205,7 +216,7 @@ jQuery(document).ready(function($){
         billing_phone    = $( 'input[name="billing_phone"' ),
         lineTips         = $('.validateTips'),
         accountTips      = $('.validateAccountTips'),
-        allAccountFields = $( [] ).add( ref_dest ) .add( ref_name ) .add( anniversary_date ) .add( renewal_date )
+        allAccountFields = $( [] ).add( ref_name ) .add( anniversary_date ) .add( renewal_date )
             .add( email ) .add( billing_addr1 ) .add( billing_addr2 ) .add( billing_city )
             .add( billing_state ) .add( billing_zip )
             .add( billing_phone ) ,        // Array holding the form fields - add line_item form
@@ -302,7 +313,6 @@ jQuery(document).ready(function($){
         var valid = true;
         allAccountFields.removeClass( 'ui-state-error' );
 
-        valid = valid && checkRequired( ref_dest, accountTips, 'Member is required!' );
         valid = valid && checkRequired( ref_name, accountTips, 'Name is required!' );
         valid = valid && checkRequired( anniversary_date, accountTips, 'Anniversary Date is required!' );
         valid = valid && checkRequired( email, accountTips, 'Email is required!' );
@@ -320,12 +330,12 @@ jQuery(document).ready(function($){
             }).done(function( msg ){
                 if ( msg.status === true ) {
                     // Reload the account select
-                    updateBillingAccountSelect();
-                    updateNonAccountMemberSelect();
+                    updateBillingAccountSelect( msg.account.fieldData.id );
+                    updateNonAccountMemberList();
                     // Close the dialog
                     newAccountDialog.dialog( 'close' );
                 } else {
-                    console.log( 'return', msg );
+                    // console.log( 'return', msg );
                 }
             });
         }
@@ -381,7 +391,7 @@ jQuery(document).ready(function($){
      * Ajax call to get the list of billing accounts and update the select
      * for the Billing account drop down.
      */
-    function updateBillingAccountSelect() {
+    function updateBillingAccountSelect(selected_id = null) {
         $.ajax({
             url: '{$ajaxUrl}',
             cache: false,
@@ -398,13 +408,14 @@ jQuery(document).ready(function($){
                 var obj = msg[index];
                 memberAccount.options[memberAccount.options.length] = new Option( obj.ref_name, obj.id );
             }
+            memberAccount.value = selected_id;
         });
     }
 
     /**
      * Ajax call to get the list of members without accounts.
      */
-    function updateNonAccountMemberSelect() {
+    function updateNonAccountMemberList() {
         $.ajax({
             url: '{$ajaxUrl}',
             cache: false,
@@ -413,14 +424,16 @@ jQuery(document).ready(function($){
             encode: true,
             dataType: 'json'
         }).done(function(msg){
-            // console.log( msg.length );
-            var nonMemberAccount = document.getElementById('non-member-account');
-            nonMemberAccount.options.length = 0;
-            nonMemberAccount.options[nonMemberAccount.options.length] = new Option( 'Select Member', '' );
+            availableNonAccountMembers = [];
             for ( index in msg ) {
                 var obj = msg[index];
-                nonMemberAccount.options[nonMemberAccount.options.length] = new Option( obj.name, obj.id );
+                availableNonAccountMembers.push( { label: obj.name, value: obj.name, id: obj.id } );
             }
+            // also need to update the source for the autocomplete
+            $('#glm_member_name').autocomplete(
+                'option',
+                { source: availableNonAccountMembers }
+            );
         });
     }
 
@@ -495,7 +508,7 @@ jQuery(document).ready(function($){
      */
     newAccountForm = newAccountDialog.find( '#addAccountForm' ).on( 'submit', function(){
         event.preventDefault();
-        console.log('Adding new Account');
+        // console.log('Adding new Account');
     });
 
     /**
index 9cdc580..ff6dc65 100644 (file)
@@ -2,12 +2,10 @@
     <h2>Billing</h2>
     <h2 class="nav-tab-wrapper">
         <a href="{$thisUrl}?page=glm-members-admin-menu-billing" class="nav-tab{if $thisAction==index} nav-tab-active{/if}">Dashboard</a>
-        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices"
-            class="nav-tab{if $thisAction==invoices} nav-tab-active{/if}">Invoices</a>
-        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments"
-            class="nav-tab{if $thisAction==payments} nav-tab-active{/if}">Payments</a>
-        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=logs"
-            class="nav-tab{if $thisAction==logs} nav-tab-active{/if}">Logs</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices" class="nav-tab{if $thisAction==invoices} nav-tab-active{/if}">Invoices</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments" class="nav-tab{if $thisAction==payments} nav-tab-active{/if}">Payments</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=accounts" class="nav-tab{if $thisAction==accounts} nav-tab-active{/if}">Accounts</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=logs" class="nav-tab{if $thisAction==logs} nav-tab-active{/if}">Logs</a>
     </h2>
     <div id="glm-admin-content-container">
 
index 50574e8..ba3f755 100644 (file)
                 <span class="glm-nowrap">
                     <b>Member Account:&nbsp;</b>
                     <select id="filterAccounts" name="filterAccounts">
+                        <option value="">Select Account</option>
                         {foreach from=$accounts item=account}
                             <option value="{$account.id}"{if $account.selected} selected{/if}>
-                                {$account.name}
+                                {$account.ref_dest.name}
                             </option>
                         {/foreach}
                     </select>
                 </span>
-                <span class="glm-nowrap">
-                    <b>Text Search: </b><input  id="glmEventsSearch" name="textSearch" type="text" id="autoTest">
-                    <input type="submit" value="Submit">
-                </span>
             <p>
         </div>
         <br clear="all">