Billing Updates for new invoices and new accounts.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 13 Sep 2019 14:28:45 +0000 (10:28 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 13 Sep 2019 14:28:45 +0000 (10:28 -0400)
Adding ability to add new billing account from the billing side.
Using same form as the edit billing info from billing side.
Auto complete for the new member name.
New invoice page updates:
Don't show the account number field if it's not active in the settings.
Change the add line items to buttons not links.

models/admin/member/billing.php
views/admin/billing/accountReveals.html
views/admin/billing/accounts.html
views/admin/billing/editAccountAjax.html
views/admin/billing/editInvoice.html
views/admin/billing/index.html

index 75eaf4b..b7deda2 100644 (file)
@@ -648,14 +648,16 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $invoiceTypes    = $InvoiceTypesObj->getList();
 
             // Need to see if there's an account for this member.
-            $accountID = $this->wpdb->get_var(
-                $this->wpdb->prepare(
-                    "SELECT id
-                       FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
-                      WHERE ref_dest = %d",
-                    $this->memberID
-                )
-            );
+            if ( $this->memberID ) {
+                $accountID = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT id
+                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                          WHERE ref_dest = %d",
+                        $this->memberID
+                    )
+                );
+            }
 
             // Grab the employee data
             if ( $accountID ) {
@@ -665,6 +667,8 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             }
 
             // Check to see if we're adding an account or editing one.
+            // This only happens if there's a member.
+            // If this is a new Account Form from Billing then there isn't a member assigned yet.
             if ( isset( $_REQUEST['ref_name'] ) ) {
                 $_REQUEST['anniversary_date'] = date('Y-m-d', strtotime($_REQUEST['anniversary_date']));
                 // if there's no id then add account.
@@ -676,6 +680,12 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                         $accountAdded = true;
                         // If account is added then get the id
                         $accountID = $account['fieldData']['id'];
+                        if ( $this->ajaxSide ) {
+                            // trigger_error( 'Account Ajax Hit', E_USER_NOTICE );
+                            header( 'Content-type:application/json;charset=utf-8', true );
+                            echo json_encode( $account, true );
+                            exit;
+                        }
                     }
                 } else {
                     $account = $Accounts->updateEntry( $_REQUEST['id'] );
@@ -773,7 +783,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 }
             }
 
-
             $sql_for_employee_list = "T.boss <> true";
             // Grab the employee data
             if ( $accountID ) {
@@ -794,7 +803,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                     $accountID = 0;
                     $account   = $Accounts->newEntry();
                     // Set the ref_name from memberData
-                    $account['fieldData']['ref_name'] = $memberData['name'];
+                    if ( isset( $memberData ) && isset( $memberData['name'] ) ) {
+                        $account['fieldData']['ref_name'] = $memberData['name'];
+                    }
                     $haveAccount = false;
                 }
             } else {
@@ -802,6 +813,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 $haveAccount = true;
             }
 
+            // Set the view file.
             $view = 'editAccount';
             if ( $this->ajaxSide ) {
                 $view = 'editAccountAjax';
index 8640ad8..2da8291 100644 (file)
@@ -65,7 +65,6 @@
             var member = $(this).data('member');
             var $modal = $('#glmBillingInfo');
             $modal.on('closed.zf.reveal', function(){
-                console.log('Info reveal closed');
                 $('glmBillingInfoFormWrap').remove();
             });
 
             });
             return false;
         });
+        $('#AddAccountButton').on('click', function(e) {
+            e.preventDefault();
+            var availableNonAccountMembers = [];
+            var member = $(this).data('member');
+            var $modal = $('#glmBillingInfo');
+            $modal.on('closed.zf.reveal', function(){
+                $('glmBillingInfoFormWrap').remove();
+            });
+
+            $.ajax({
+                url: '{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=ajaxBillingInfo&option=account',
+                cache: false,
+                beforeSend: startAjax,
+                complete: completeAjax,
+            })
+            .done(function(resp){
+                $modal.html(resp).foundation('open').trigger('resizeme.zp.reveal');
+                updateNonAccountMemberList();
+            });
+            return false;
+        });
+
+        /**
+         * Ajax call to get the list of members without accounts.
+         */
+        function updateNonAccountMemberList() {
+            $.ajax({
+                url: '{$ajaxUrl}',
+                cache: false,
+                type: 'GET',
+                data: 'action=glm_members_admin_ajax&glm_action=billingAccount&option=listNonAccounts',
+                encode: true,
+                dataType: 'json'
+            }).done(function(msg){
+                availableNonAccountMembers = [];
+                for ( index in msg ) {
+                    var obj = msg[index];
+                    availableNonAccountMembers.push( { label: obj.name, value: obj.name, id: obj.id } );
+                }
+                // also need to update the source for the autocomplete
+                $('#ref_name').autocomplete({
+                    source: availableNonAccountMembers,
+                    appendTo: '#glmBillingInfoFormWrap',
+                    select: function( event, ui ) {
+                        $('input[name=ref_dest]').val( ui.item.id );
+                        $('input[name=member]').val( ui.item.id );
+                    },
+                    change: function( event, ui ) {
+                        $(this).val(( ui.item ? ui.item.label : ""));
+                    }
+                });
+            });
+        }
 
         $('.account-member-statements').on('click', function(e){
             e.preventDefault();
index f018a31..322f97e 100644 (file)
@@ -13,6 +13,7 @@
 
 <h3 class="subheader">Accounts</h3>
 
+<div id="AddAccountButton" class="button primary">Add New Account</div>
 <div id="exportAccountsButton" class="button secondary">Accounts Export</div>
 
 {* Search Form *}
index 3dd27c6..3d42d61 100644 (file)
@@ -54,7 +54,6 @@
             ]}
             {include file='ui/f6/text.html'}
 
-
             {if !$lockedToMember}
                 {if $settings.account_number_enabled}
 
index b60e9ad..43f8618 100644 (file)
             {include file='ui/f6/checkbox.html'}
 
             <div class="cell small-12 medium-4">
-                <a id="newLineItemButton" class="glm-billing-add-line-item">Add Line Item</a><br>
-                <a id="newCustomLineItemButton" class="glm-billing-add-line-item">Create New Line Item</a>
+                <a id="newLineItemButton" class="glm-billing-add-line-item button secondary">Add Line Item + </a><br>
+                <a id="newCustomLineItemButton" class="glm-billing-add-line-item button secondary">Create New Line Item + </a>
             </div>
             <div id="invoice-line-items" class="cell small-12 medium-8"> </div>
             <div class="cell small-12 large-8">
                     <label class="glm-required">Member Name (lookup)</label>
                     <input id="glm_member_name" type="text" name="ref_name" value="">
                 </div>
-                <div class="cell small-12">
-                    <label class="glm-required">Account Number</label>
-                    <input type="text" name="account_number" value="">
-                </div>
+                {if $settings.account_number_enabled}
+                    <div class="cell small-12">
+                        <label class="glm-required">Account Number</label>
+                        <input type="text" name="account_number" value="">
+                    </div>
+                {else}
+                    <input type="hidden" name="account_number" value="">
+                {/if}
                 {if !$settings.member_types_enabled}
                     <div class="cell small-12">
                         <label class="glm-required">Payment Types</label>
@@ -600,7 +604,9 @@ jQuery(document).ready(function($){
 
         valid = valid && checkRequired( ref_name, accountTips, 'Name is required!' );
         valid = valid && checkRequired( invoice_type, accountTips, 'Payment Type is required!' );
-        valid = valid && checkRequired( account_number, accountTips, 'Account Number is required!' );
+        {if $settings.account_number_enabled}
+            valid = valid && checkRequired( account_number, accountTips, 'Account Number is required!' );
+        {/if}
         valid = valid && checkRequired( anniversary_date, accountTips, 'Anniversary Date is required!' );
         valid = valid && checkRequired( email, accountTips, 'Email is required!' );
         valid = valid && checkRegexp( email, emailRegex, 'Use valid email!', accountTips );
index 07527fa..0edc15d 100644 (file)
@@ -20,6 +20,7 @@
 
 <div>
     <a class="button secondary" href="#" id="exportAccountsButton">Accounts Export</a>
+    <div id="AddAccountButton" class="button primary">Add New Account</div>
     <a class="button primary" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=invoices&option=add">Create Invoice</a>
     <a class="button success" href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=payments&option=add">Make Payment</a>
 </div>