From 6143197a1d48da5b19889b794129cbce42c75fea Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 13 Sep 2019 10:28:45 -0400 Subject: [PATCH] Billing Updates for new invoices and new accounts. 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 | 32 +++++++++----- views/admin/billing/accountReveals.html | 54 +++++++++++++++++++++++- views/admin/billing/accounts.html | 1 + views/admin/billing/editAccountAjax.html | 1 - views/admin/billing/editInvoice.html | 20 ++++++--- views/admin/billing/index.html | 1 + 6 files changed, 90 insertions(+), 19 deletions(-) diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 75eaf4b..b7deda2 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -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'; diff --git a/views/admin/billing/accountReveals.html b/views/admin/billing/accountReveals.html index 8640ad8..2da8291 100644 --- a/views/admin/billing/accountReveals.html +++ b/views/admin/billing/accountReveals.html @@ -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(); }); @@ -80,6 +79,59 @@ }); 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(); diff --git a/views/admin/billing/accounts.html b/views/admin/billing/accounts.html index f018a31..322f97e 100644 --- a/views/admin/billing/accounts.html +++ b/views/admin/billing/accounts.html @@ -13,6 +13,7 @@

Accounts

+
Add New Account
Accounts Export
{* Search Form *} diff --git a/views/admin/billing/editAccountAjax.html b/views/admin/billing/editAccountAjax.html index 3dd27c6..3d42d61 100644 --- a/views/admin/billing/editAccountAjax.html +++ b/views/admin/billing/editAccountAjax.html @@ -54,7 +54,6 @@ ]} {include file='ui/f6/text.html'} - {if !$lockedToMember} {if $settings.account_number_enabled} diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index b60e9ad..43f8618 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -111,8 +111,8 @@ {include file='ui/f6/checkbox.html'}
- Add Line Item
- Create New Line Item + Add Line Item +
+ Create New Line Item +
@@ -152,10 +152,14 @@
-
- - -
+ {if $settings.account_number_enabled} +
+ + +
+ {else} + + {/if} {if !$settings.member_types_enabled}
@@ -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 ); diff --git a/views/admin/billing/index.html b/views/admin/billing/index.html index 07527fa..0edc15d 100644 --- a/views/admin/billing/index.html +++ b/views/admin/billing/index.html @@ -20,6 +20,7 @@
Accounts Export +
Add New Account
Create Invoice Make Payment
-- 2.17.1