Add shortcode for front end renewal form.
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 29 Mar 2018 15:02:41 +0000 (11:02 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 29 Mar 2018 15:02:41 +0000 (11:02 -0400)
Add the renewal form to the front end.

classes/billingSupport.php
models/admin/billing/index.php
models/front/billing/renew.php [new file with mode: 0644]
setup/shortcodes.php
setup/validActions.php
views/admin/billing/accountSearchForm.html
views/admin/billing/accounts.html
views/admin/billing/index.html
views/front/billing/nonrenew.html [new file with mode: 0644]
views/front/billing/renew.html [new file with mode: 0644]
views/front/billing/renewMembership.html [new file with mode: 0644]

index a8942a6..62f0005 100644 (file)
@@ -787,50 +787,52 @@ class GlmBillingSupport
         // This may need to have filters setup in the contact plugin as well.
         $employees = apply_filters( 'glm_contact_has_employees', '', $member_id );
         // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
-        foreach ( $employees as $ref_dest ) {
-            $invoice         = false;
-            $billing_account = $this->getAccountByRefDest( $ref_dest );
-            // If we don't have an account for this member then one
-            // Needs to be created.
-            if ( !$billing_account ) {
-                // Get the Member Name
-                $member_name = $this->wpdb->get_var(
-                    $this->wpdb->prepare(
-                        "SELECT name
-                           FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
-                          WHERE id = %d",
-                        $ref_dest
-                    )
-                );
-                if ( $member_name ) {
-                    $this->wpdb->insert(
-                        GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
-                        array(
-                            'ref_dest' => $ref_dest,
-                            'ref_name' => $member_name,
-                        ),
-                        array(
-                            '%d',
-                            '%s'
+        if ( isset( $employees ) && is_array( $employees ) ) {
+            foreach ( $employees as $ref_dest ) {
+                $invoice         = false;
+                $billing_account = $this->getAccountByRefDest( $ref_dest );
+                // If we don't have an account for this member then one
+                // Needs to be created.
+                if ( !$billing_account ) {
+                    // Get the Member Name
+                    $member_name = $this->wpdb->get_var(
+                        $this->wpdb->prepare(
+                            "SELECT name
+                               FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                              WHERE id = %d",
+                            $ref_dest
                         )
                     );
-                    $employee_account_id = $this->wpdb->insert_id;
-                    $billing_account     = $this->getAccountByRefDest( $ref_dest );
+                    if ( $member_name ) {
+                        $this->wpdb->insert(
+                            GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+                            array(
+                                'ref_dest' => $ref_dest,
+                                'ref_name' => $member_name,
+                            ),
+                            array(
+                                '%d',
+                                '%s'
+                            )
+                        );
+                        $employee_account_id = $this->wpdb->insert_id;
+                        $billing_account     = $this->getAccountByRefDest( $ref_dest );
+                    }
                 }
-            }
-            if ( $billing_account ) {
-                // Need also to get the members type to look up which invoice_type to use
-                $invoice_type_id =  $this->getMembersInvoiceTypeByRefDest( $member_id );
-                if ( $invoice_type_id ) {
-                    $invoice = $this->getInvoiceTypeById( $invoice_type_id );
+                if ( $billing_account ) {
+                    // Need also to get the members type to look up which invoice_type to use
+                    $invoice_type_id =  $this->getMembersInvoiceTypeByRefDest( $member_id );
+                    if ( $invoice_type_id ) {
+                        $invoice = $this->getInvoiceTypeById( $invoice_type_id );
+                    }
+                    $accounts[$billing_account['id']] = array(
+                        'id'       => $billing_account['id'],
+                        'ref_dest' => $billing_account['ref_dest'],
+                        'ref_name' => $billing_account['ref_name'],
+                        'invoice'  => $invoice,
+                        'email'    => $billing_account['email']
+                    );
                 }
-                $accounts[$billing_account['id']] = array(
-                    'id'       => $billing_account['id'],
-                    'ref_dest' => $billing_account['ref_dest'],
-                    'ref_name' => $billing_account['ref_name'],
-                    'invoice'  => $invoice,
-                    'email'    => $billing_account['email']
-                );
             }
         }
         return $accounts;
index 3261927..599c829 100644 (file)
@@ -122,6 +122,7 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts
         $start              = 1;
         $limit              = 20;        // Set to the number of listings per page
         $accounts           = false;
+        $allAccounts        = false;
         $haveInvoices       = false;
         $filterAccounts     = '';
         $totalInvoices      = false;
@@ -311,6 +312,7 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts
             'toDate'             => $toDate,
             'haveInvoices'       => $haveInvoices,
             'accounts'           => $accounts,
+            'allAccounts'           => $accounts,
             'filterAccounts'     => $filterAccounts,
             'totalInvoices'      => $totalInvoices,
             'filterPending'      => $filterPending,
diff --git a/models/front/billing/renew.php b/models/front/billing/renew.php
new file mode 100644 (file)
index 0000000..b286c02
--- /dev/null
@@ -0,0 +1,334 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Billing Dashboard
+ *
+ * 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/
+ */
+define('GLM_MEMBERS_BILLING_MEMBER_MENU', true);
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php';
+// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataPayments.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php';
+
+// Load Billing data abstract
+// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataBilling.php';
+
+class GlmMembersFront_billing_renew // extends GlmDataBilling
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+    /**
+     * Billing ID
+     *
+     * @var $memberID
+     * @access public
+     */
+    public $memberID = false;
+
+    /**
+     * Constructor
+     *
+     * This contructor performs the work for this model. This model returns
+     * an array containing the following.
+     *
+     * 'status'
+     *
+     * True if successfull and false if there was a fatal failure.
+     *
+     * 'view'
+     *
+     * A suggested view name that the contoller 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 Billing 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)
+    {
+        // Initialize Variables Here
+        $fromMemberMenu     = false;
+        $this->memberID     = false;
+        $memberData         = false;
+        $memberName         = false;
+        $haveMember         = false;
+        $haveAccount        = false;
+        $option             = 'renew';
+        $view               = 'renew';
+        $account            = false;
+        $accountID          = 0;
+        $account_data       = false;
+        $balance_due        = false;
+        $invoiceHtml        = false;
+        $management         = false;
+        $messages           = array();
+        $paymentSuccess     = false;
+        $paymentError       = false;
+        $hasBillingAccount  = false;
+        $employees          = false;
+        $member_invoice     = false;
+        $payable_types      = false;
+        $account_status     = false;
+
+        // For lockedToMember.
+        $lockedToMember = false;
+        $lockedWhereT   = 'true';
+        $lockedWhere    = 'true';
+
+        // Call in the support class
+        $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+        // echo '<pre>$this->config: ' . print_r( $this->config, true ) . '</pre>';
+        if ( isset( $this->config['loggedInUser'] )
+            && isset( $this->config['loggedInUser']['contactUser'] )
+            && isset( $this->config['loggedInUser']['contactUser']['ref_dest'] )
+        ) {
+            $this->memberID = $this->config['loggedInUser']['contactUser']['ref_dest'];
+        } else {
+            // throw an error
+            wp_die('Not finding any account for you!');
+        }
+
+        // Check if there's a logged in user who is locked to their own entity.
+        $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
+        // echo '<pre>$lockedToMember: ' . print_r( $lockedToMember, true ) . '</pre>';
+        if ($lockedToMember) {
+            $memberID       = $lockedToMember;
+            $this->memberID = $memberID;
+            $lockedToMember = $memberID;
+            $lockedWhereT   = 'T.ref_type = '.$this->config['ref_type_numb']['Member'].' AND T.ref_dest = '.$memberID;
+            $lockedWhere    = 'ref_type = '.$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$memberID;
+        }
+
+        require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php';
+        $this->Members = new GlmDataMembers( $this->wpdb, $this->config );
+
+        if ( $this->memberID ) {
+            $memberData = $this->Members->getEntry( $this->memberID );
+        }
+
+        if ( isset( $memberData ) && is_array( $memberData ) && $memberData['id'] > 0 ) {
+            $haveMember = true;
+            $memberName = $memberData['name'];
+        }
+
+        if ( isset( $_REQUEST['option'] ) ) {
+            $option = $_REQUEST['option'];
+        }
+
+        require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+        $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+        $accountID = $this->wpdb->get_var(
+            $this->wpdb->prepare(
+                "SELECT id
+                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                  WHERE ref_dest = %d",
+                $this->memberID
+            )
+        );
+        $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID );
+
+        switch ( $option ) {
+        case 'renew':
+            // TODO: only the renew form if the member is not active
+            if ( $account_status == 'Active' ) {
+                $view = 'nonrenew';
+            } else  {
+                $view = 'renew';
+                // echo '<pre>$this->memberID: ' . print_r( $this->memberID, true ) . '</pre>';
+
+
+                // Get list of payable invoice_types
+                $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+                // echo '<pre>$payable_types: ' . print_r( $payable_types, true ) . '</pre>';
+
+                $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+                if ( $member_invoice_id ) {
+                    $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+                }
+                // echo '<pre>$member_invoice: ' . print_r( $member_invoice, true ) . '</pre>';
+
+                // Get a list of this accounts employees. If they have any.
+                $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+                // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
+
+                // Load DataClass for Management.
+                require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataManagement.php';
+                $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
+                $management = $Management->getEntry( 1 );
+
+                // Need to see if there's an account for this member.
+                require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+                $account = $Accounts->editEntry( $accountID );
+            }
+
+            break;
+
+        case 'renewMembership':
+            $error = false;
+            $view  = 'renewMembership';
+            // $messages[] = '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
+
+            $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+            if ( $member_invoice_id ) {
+                $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+            } else {
+                $error = true;
+            }
+
+            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+
+            $invoice_data = array(
+                'account_id'     => $accountID,
+                'renew_type_id'  => filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ),
+                'amount'         => $_REQUEST['total_renew_amount'],
+                'due_date'       => date( 'Y-m-d' ),
+                'member_invoice' => $member_invoice,
+                'employee_data'  => $employees,
+                'employees'      => $_REQUEST['employees']
+            );
+            if ( !$invoice_data ) {
+                $error = true;
+            }
+
+            // Create the invoice for this member.
+            $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
+            if ( !$invoice_id ) {
+                $error = true;
+            }
+
+            // Now that the invoice is created. Do payment Processing.
+
+            // If there's any errors then re-show the form.
+            if ( $error ) {
+                // TODO: Here we'll need to remove the invoice created if any.
+                $view = 'renew';
+
+                // 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 );
+                }
+
+                // Get a list of this accounts employees. If they have any.
+                $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+
+                // Load DataClass for Management.
+                require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataManagement.php';
+                $Management = new GlmDataBillingManagement( $this->wpdb, $this->config );
+                $management = $Management->getEntry( 1 );
+
+                // Need to see if there's an account for this member.
+                $account = $Accounts->editEntry( $accountID );
+            } else {
+                // Do the Payment Processing.
+                $errors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] );
+                // echo '<pre>$errors: ' . print_r( $errors, true ) . '</pre>';
+            }
+
+
+            break;
+
+
+        }
+
+        // Get the list of invoices for this member.
+        $statements = $BillingSupport->getStatementsByRefDest( $this->memberID );
+        // echo '<pre>$statements: ' . print_r( $statements, true ) . '</pre>';
+        if ( $statements ) {
+            $transactions      = $statements['transactions'];
+            $account_data      = $statements['account_data'];
+            $balance_due       = $statements['balance_due'];
+            $hasBillingAccount = true;
+        }
+        // echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
+
+        // Compile template data
+        $templateData = array(
+            'accountID'          => $accountID,
+            'option'             => $option,
+            'fromMemberMenu'     => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ),
+            'lockedToMember'     => $lockedToMember,
+            'numberPending'      => $numberPending,
+            'memberID'           => $this->memberID,
+            'haveMember'         => $haveMember,
+            'haveAccount'        => $haveAccount,
+            'memberData'         => $memberData,
+            'memberName'         => $memberName,
+            'account'            => $account,
+            'transactions'       => $transactions,
+            'account_data'       => $account_data,
+            'balance_due'        => $balance_due,
+            'transaction_types'  => $this->config['transaction_type'],
+            'invoiceHtml'        => $invoiceHtml,
+            'billing_settings'   => $this->config['billing_settings'],
+            'management'         => $management,
+            'messages'           => $messages,
+            'invoices'           => $invoices,
+            'paymentSuccess'     => $paymentSuccess,
+            'paymentError'       => $paymentError,
+            'hasBillingAccount'  => $hasBillingAccount,
+            'employees'          => $employees,
+            'member_invoice'     => $member_invoice,
+            'payable_types'      => $payable_types,
+            'account_status'     => $account_status,
+        );
+
+        // Return status, any suggested view, and any data to controller.
+        return array(
+            'status'        => true,
+            'modelRedirect' => false,
+            'view'          => 'front/billing/'.$view.'.html',
+            'data'          => $templateData
+        );
+
+    }
+
+
+}
index eb3e3ed..5aa6d09 100644 (file)
  */
 
 $glmMembersBillingShortcodes = array(
+    'glm-members-billing-renew-form' => array(
+        'plugin'     => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+        'menu'       => 'billing',
+        'action'     => 'renew',
+        'table'      => false,
+        'attributes' => array(
+            'member_id' => false,
+            'template'  => false,
+        ),
+    )
 );
 
-$glmMembersBillingShortcodesDescription = '';
+$glmMembersBillingShortcodesDescription = '
+<tr><th>Shortcode</th><th>Attribute</th><th>Description</th></tr>
+     <tr>
+        <th>[glm-members-billing-renew-form]</th>
+        <td>&nbsp;</td>
+        <td width="50%">
+            Displays a Membership Renewal Form.
+        </td>
+    </tr>
+';
 
index b6d3d68..52a36df 100644 (file)
@@ -89,6 +89,9 @@ $glmMembersBillingAddOnValidActions = array(
         ),
     ),
     'frontActions' => array(
+        'billing' => array(
+            'renew' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+        ),
     )
 );
 
index 870654e..e2b7875 100644 (file)
@@ -1,3 +1,67 @@
+<script>
+jQuery(document).ready(function($) {
+
+    // Date Input
+    $('.glm-date-input').datepicker({
+        dateFormat: 'mm/dd/yy'
+    });
+
+    // Setup for the modal box
+    $('#exportAccountDialog').dialog( {
+        autoOpen: false,
+        minWidth: 700,
+        dialogClass: 'glm-dialog-no-close'
+    } );
+    $('#exportAccountsButton').click( function(){
+        $('#exportAccountDialog').dialog( 'open' );
+    } );
+    $('#exportAccountsCancel').click( function(){
+        $('#exportAccountDialog').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);
+        });
+    });
+
+    var availableAccounts = [
+    {foreach $allAccounts as $m}
+        { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
+    {/foreach}
+    ]
+
+    // Setup autocomplete for both inputs
+    $('#account_name').autocomplete({
+        source: availableAccounts,
+        select: function( event, ui ){
+            $('#member-account').val( ui.item.id );
+        },
+    });
+    $('#account_name2').autocomplete({
+        source: availableAccounts,
+        select: function( event, ui ){
+            $('#member-account2').val( ui.item.id );
+        },
+    });
+
+    {if $filterAccounts}
+        {$selected = 0}
+        {foreach $accounts as $m}
+            {if $m.id == $filterAccounts}
+                {$selected = $m.ref_name|unescape:'html'|replace:'"':''}
+            {/if}
+        {/foreach}
+        $('#account_name').autocomplete().val('{$selected}');
+    {/if}
+
+});
+</script>
+
 <form action="{$thisUrl}?page={$thisPage}" method="post" id="searchForm">
     <input type="hidden" name="glm_action" value="accounts">
     <input type="hidden" name="option" value="list">
index 2a5521e..beb6215 100644 (file)
 
 {include file='admin/billing/exportBillingModal.html'}
 
-<script type="text/javascript">
-    jQuery(document).ready(function($) {
-
-        // Date Input
-        $('.glm-date-input').datepicker({
-            dateFormat: 'mm/dd/yy'
-        });
-
-        // Setup for the modal box
-        $('#exportAccountDialog').dialog( {
-            autoOpen: false,
-            minWidth: 700,
-            dialogClass: 'glm-dialog-no-close'
-        } );
-        $('#exportAccountsButton').click( function(){
-            $('#exportAccountDialog').dialog( 'open' );
-        } );
-        $('#exportAccountsCancel').click( function(){
-            $('#exportAccountDialog').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);
-            });
-        });
-
-        var availableAccounts = [
-        {foreach $allAccounts as $m}
-            { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
-        {/foreach}
-        ]
-
-        // Setup autocomplete for both inputs
-        $('#account_name').autocomplete({
-            source: availableAccounts,
-            select: function( event, ui ){
-                $('#member-account').val( ui.item.id );
-            },
-        });
-        $('#account_name2').autocomplete({
-            source: availableAccounts,
-            select: function( event, ui ){
-                $('#member-account2').val( ui.item.id );
-            },
-        });
-
-        {if $filterAccounts}
-            {$selected = 0}
-            {foreach $accounts as $m}
-                {if $m.id == $filterAccounts}
-                    {$selected = $m.ref_name|unescape:'html'|replace:'"':''}
-                {/if}
-            {/foreach}
-            $('#account_name').autocomplete().val('{$selected}');
-        {/if}
-
-    });
-</script>
 
 {include file='admin/footer.html'}
index 4bc63db..6db40d8 100644 (file)
 
 {include file='admin/billing/exportBillingModal.html'}
 
-<script>
-    jQuery(document).ready(function($) {
-
-        // Date Input
-        $('.glm-date-input').datepicker({
-            dateFormat: 'mm/dd/yy'
-        });
-
-        // Setup for the modal box
-        $('#exportAccountDialog').dialog( {
-            autoOpen: false,
-            minWidth: 700,
-            dialogClass: 'glm-dialog-no-close'
-        } );
-        $('#exportAccountsButton').click( function(){
-            $('#exportAccountDialog').dialog( 'open' );
-        } );
-        $('#exportAccountsCancel').click( function(){
-            $('#exportAccountDialog').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);
-            });
-        });
-
-        var availableAccounts = [
-        {foreach $accounts as $m}
-            { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
-        {/foreach}
-        ]
-
-        // Setup autocomplete for both inputs
-        $('#account_name').autocomplete({
-            source: availableAccounts,
-            select: function( event, ui ){
-                $('#member-account').val( ui.item.id );
-            },
-        })
-        $('#account_name2').autocomplete({
-            source: availableAccounts,
-            select: function( event, ui ){
-                $('#member-account2').val( ui.item.id );
-            },
-        });
-
-        {if $filterAccounts}
-            {$selected = 0}
-            {foreach $accounts as $m}
-                {if $m.id == $filterAccounts}
-                    {$selected = $m.ref_name|unescape:'html'|replace:'"':''}
-                {/if}
-            {/foreach}
-            $('#account_name').autocomplete().val('{$selected}');
-        {/if}
-
-    });
-</script>
 
 {include file='admin/footer.html'}
diff --git a/views/front/billing/nonrenew.html b/views/front/billing/nonrenew.html
new file mode 100644 (file)
index 0000000..0bcf1d3
--- /dev/null
@@ -0,0 +1,2 @@
+<h2>No renewal needed!</h2>
+<p>Your an active member.</p>
diff --git a/views/front/billing/renew.html b/views/front/billing/renew.html
new file mode 100644 (file)
index 0000000..3d15717
--- /dev/null
@@ -0,0 +1,241 @@
+
+<h3>Membership Renewal</h3>
+<div id="billing-payment-form" class="glm-billing-form">
+
+    {if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
+    {if $paymentError}<span class="glm-notice glm-flash-updated">Error With Payment</span>{/if}
+
+    {if $messages}
+        {foreach $messages as $message}
+            <div class="">{$message}</div>
+        {/foreach}
+    {/if}
+
+    <form action="{$thisUrl}" method="post">
+        <input type="hidden" name="option" value="renewMembership" />
+        <input type="hidden" name="member" value="{$memberID}" />
+        <input type="hidden" name="account_id" value="{$account_data.id}" />
+        <input type="hidden" id="total_renew_amount" name="total_renew_amount" value="" />
+
+
+        {if $member_invoice}
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Membership Class
+            </div>
+            <div class="glm-billing-input">
+                <label>
+                    {foreach $payable_types as $type}
+                        <label>
+                            <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}"
+                            {if $type.id == $member_invoice.id}checked{/if}
+                            />
+                            {$type.name} {$type.amount}
+                        </label>
+                    {/foreach}
+                </label>
+            </div>
+        </div>
+        {/if}
+
+        {if $employees}
+            <div class="glm-billing-field">
+                <div class="glm-billing-label">
+                    Employees to Renew
+                </div>
+                <div class="glm-billing-input">
+                    {foreach $employees as $employee}
+                        <label>
+                            <input type="checkbox" name="employees[]" data-amount="{$employee.invoice.amount}" value="{$employee.id}" checked='checked' />
+                            {$employee.ref_name} {$employee.invoice.name} {$employee.invoice.amount}
+                        </label>
+                    {/foreach}
+                </div>
+            </div>
+        {/if}
+
+        <div class="glm-billing-field">
+            <div class="glm-billing-label">
+                Total Due
+            </div>
+            <div class="glm-billing-input">
+                <div id="renew_total">
+                </div>
+            </div>
+        </div>
+
+        <div class="glm-billing-field glm-billing-left-half">
+            <div class="glm-billing-label glm-required">
+                First Name
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_fname" value="{$account.fieldData.billing_fname}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half">
+            <div class="glm-billing-label glm-required">
+                Last Name
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_lname" value="{$account.fieldData.billing_lname}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Address
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_addr1" value="{$account.fieldData.billing_addr1}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-left-half">
+            <div class="glm-billing-label glm-required">
+                City
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_city" value="{$account.fieldData.billing_city}" required />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half">
+            <div class="glm-billing-label glm-required">
+                State / Province
+            </div>
+            <div class="glm-billing-input">
+                <select name="billing_state" required>
+                    <option value=""></option>
+                    {foreach $account.fieldData.billing_state.list as $s}
+                        <option value="{$s.value}"{if $account.fieldData.billing_state.value == $s.value} selected="selected"{/if}>
+                            {$s.name}
+                        </option>
+                    {/foreach}
+                </select>
+            </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Zip
+            </div>
+            <div class="glm-billing-input">
+                <input type="text" name="billing_zip" value="{$account.fieldData.billing_zip}" required />
+            </div>
+        </div>
+
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Name on Card
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    name="cc_name"
+                    required
+                    {if isset($smarty.request.cc_name) && $smarty.request.cc_name}value="{$smarty.request.cc_name}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-left-half">
+            <div class="glm-billing-label glm-required">
+                Card Type
+            </div>
+            <div class="glm-billing-input">
+                <select name="cc_type" required>
+                    <option value=""></option>
+                    {foreach $management.cc_accepts.names as $cardId => $cardName}
+                        <option value="{$cardId}"
+                        {if isset($smarty.request.cc_type) && $smarty.request.cc_type == $cardId} selected{/if}>{$cardName}</option>
+                    {/foreach}
+                </select>
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half">
+            <div class="glm-billing-label glm-required">
+                Card Number
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    placeholder="Numbers Only"
+                    name="cc_numb"
+                    required
+                    pattern="\d*"
+                    {if isset($smarty.request.cc_numb) && $smarty.request.cc_numb}value="{$smarty.request.cc_numb}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-left-half">
+            <div class="glm-billing-label glm-required">
+                Card Expiration
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    placeholder="MM/YY"
+                    name="cc_exp"
+                    required
+                    pattern="{literal}\d{2}/\d{2}{/literal}"
+                    {if isset($smarty.request.cc_exp) && $smarty.request.cc_exp}value="{$smarty.request.cc_exp}"{/if} />
+            </div>
+        </div>
+        <div class="glm-billing-field glm-billing-right-half">
+            <div class="glm-billing-label glm-required">
+            C V V
+            </div>
+            <div class="glm-billing-input">
+                <input
+                    type="text"
+                    placeholder="3 or 4 digit security code on back of card"
+                    name="cc_cvv"
+                    required
+                    pattern="{literal}\d{3,4}{/literal}"
+                    {if isset($smarty.request.cc_cvv) && $smarty.request.cc_cvv}value="{$smarty.request.cc_cvv}"{/if} />
+            </div>
+        </div>
+
+        <input class="button button-primary" type="submit" value="Renew">
+
+    </form>
+</div>
+
+<script>
+jQuery(document).ready(function($){
+
+    $('#billing-invoice-select').change(function(){
+        // Get the data-amount and set the amount being paid.
+        $('#billing-amount').val( $(this).find('option:selected').data( 'amount') );
+    });
+
+    function getPageTotal(){
+
+        // Calculate the total for this page.
+        // Get the member_renewing amount.
+        var member_renewing_amount = parseFloat( $('input[name=member_renewing]:checked').data('amount') );
+
+        // Get each employee and add their amounts.
+        $('input[name^=employees]').each(function(){
+            var isChecked = $(this).prop('checked');
+            if ( isChecked ) {
+                member_renewing_amount += parseFloat( $(this).data('amount') );
+            }
+        });
+        $('#renew_total').html( '$' + member_renewing_amount );
+        $('#total_renew_amount').val( member_renewing_amount );
+
+    }
+
+    getPageTotal();
+
+    // trigger total if changing Membership
+    $('input[name=member_renewing]').change(function(){
+        getPageTotal();
+    });
+
+    // trigger total if changing employees
+    $('input[name^=employees]').change(function(){
+        getPageTotal();
+    });
+
+    // Flash certain elements for a short time after display
+    $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+});
+</script>
+
+
diff --git a/views/front/billing/renewMembership.html b/views/front/billing/renewMembership.html
new file mode 100644 (file)
index 0000000..251f6da
--- /dev/null
@@ -0,0 +1,5 @@
+
+{foreach $messages as $message}
+{$message}<br>
+{/foreach}
+