From: Steve Sutton Date: Thu, 14 Mar 2019 18:35:09 +0000 (-0400) Subject: Need account_number to be required and unique X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=de01f08b79238b8b6132f92f7a103a83f40de42b;p=WP-Plugins%2Fglm-member-db-billing.git Need account_number to be required and unique This will have to be check on: Adding new account (create invoice) Add edit on Member billing Renew forms will use this if not logged in. --- diff --git a/classes/data/dataAccounts.php b/classes/data/dataAccounts.php index ea64078..ea2ae3e 100644 --- a/classes/data/dataAccounts.php +++ b/classes/data/dataAccounts.php @@ -186,7 +186,8 @@ class GlmDataAccounts extends GlmDataAbstract 'field' => 'account_number', 'type' => 'text', 'use' => 'a', - 'required' => false, + 'required' => true, + 'unique' => true, ), // Invoice Delivery Methods diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 350b651..7ce5179 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -835,6 +835,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling break; case 'makepaymentadjustment': + $view = 'makePaymentAdjustment'; // Get unpaid invoices diff --git a/models/front/billing/renew.php b/models/front/billing/renew.php index 18cf554..49e59ed 100644 --- a/models/front/billing/renew.php +++ b/models/front/billing/renew.php @@ -14,12 +14,8 @@ */ 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 { @@ -89,52 +85,63 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling } - public function modelAction($actionData = false) + 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; + $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; + $unregistered = false; // For lockedToMember. $lockedToMember = false; $lockedWhereT = 'true'; $lockedWhere = 'true'; + // Check for unregistered. + if ( isset( $actionData['request']['unregistered'] ) && filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN ) ) { + $unregistered = filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN ); + } + + echo '
$unregistered: ' . print_r( $unregistered, true ) . '
'; + // Call in the support class $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); - // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; + + // Check if the user is logged in. 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']; + } elseif ( $unregistered ) { + $option = 'renew'; } else { $option = 'noaccount'; } // 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 '
$lockedToMember: ' . print_r( $lockedToMember, true ) . '
'; + if ($lockedToMember) { $memberID = $lockedToMember; $this->memberID = $memberID; @@ -159,30 +166,39 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling $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 ); + if ( isset( $memberID ) && $memberID ) { + 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 + ) + ); + if ( isset( $accountID ) && $accountID ) { + $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID ); + } + } switch ( $option ) { case 'noaccount': $view = 'noaccount'; break; + case 'renew': // TODO: only the renew form if the member is not active if ( $account_status == 'Active' ) { $view = 'nonrenew'; + } elseif ( !$account_status && !$unregistered ) { + $view = 'noaccount'; } else { $view = 'renew'; - // echo '
$this->memberID: ' . print_r( $this->memberID, true ) . '
'; + if ( $unregistered ) { + $lockedToMember = true; + } // Get list of payable invoice_types $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); @@ -192,20 +208,22 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling if ( $member_invoice_id ) { $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); } - // echo '
$member_invoice: ' . print_r( $member_invoice, true ) . '
'; - // Get a list of this accounts employees. If they have any. - $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); - // echo '
$employees: ' . print_r( $employees, true ) . '
'; + if ( $this->config['settings']['allow_employees'] ) { + // 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. - require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; - $account = $Accounts->editEntry( $accountID ); + if ( $accountID ) { + // 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; @@ -214,6 +232,21 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling $error = false; $view = 'renewMembership'; + // Check for account_number + // If given then this is from unregistered user. + // Have to verify that this number does match with billing_account. + if ( isset( $_REQUEST['account_number'] ) && $account_number = filter_var( $_REQUEST['account_number'], FILTER_SANITIZE_STRING ) ) { + // Verify account number. + $accountID = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE account_number = %s", + $account_number + ) + ); + } + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); if ( $member_invoice_id ) { $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); @@ -221,7 +254,9 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling $error = true; } - $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + if ( $this->config['settings']['allow_employees'] ) { + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + } $invoice_data = array( 'account_id' => $accountID, @@ -236,6 +271,10 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling $error = true; } + // Start database transaction + $this->wpdb->show_errors(); + $this->wpdb->query('START TRANSACTION'); + // Before we create an invoice for this member see if they already have one. // If we find one then delete it. $old_invoice_ids = $this->wpdb->get_results( @@ -281,8 +320,10 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); } - // Get a list of this accounts employees. If they have any. - $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + if ( $this->config['settings']['allow_employees'] ) { + // 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'; @@ -292,6 +333,7 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling // Need to see if there's an account for this member. $account = $Accounts->editEntry( $accountID ); } else { + // Look at the payment option given $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING ); @@ -322,8 +364,10 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); } - // Get a list of this accounts employees. If they have any. - $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + if ( $this->config['settings']['allow_employees'] ) { + // 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'; @@ -340,6 +384,7 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling // If there's no error reported then show the invoice if ( !$error ) { + $this->wpdb->query( 'COMMIT' ); // Now need to show the invoice. $view = 'viewInvoice'; @@ -377,6 +422,8 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling ); } } + } else { + $this->wpdb->query( 'ROLLBACK' ); } } diff --git a/setup/shortcodes.php b/setup/shortcodes.php index 0cecf1d..3ab442d 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -93,8 +93,9 @@ $glmMembersBillingShortcodes = array( 'action' => 'renew', 'table' => false, 'attributes' => array( - 'member_id' => false, - 'template' => false, + 'member_id' => false, + 'template' => false, + 'unregistered' => false, ), ), 'glm-members-billing-become-member-form' => array( diff --git a/views/admin/billing/editAccount.html b/views/admin/billing/editAccount.html index feb2aa3..108ed62 100644 --- a/views/admin/billing/editAccount.html +++ b/views/admin/billing/editAccount.html @@ -24,6 +24,7 @@ {if $lockedToMember} + {/if} {if $accountID} @@ -41,6 +42,8 @@ + {if !$lockedToMember} +
Account Number
@@ -49,9 +52,6 @@
- {if !$lockedToMember} - - {if !$settings.member_types_enabled}
diff --git a/views/admin/billing/editInvoice.html b/views/admin/billing/editInvoice.html index cc222a7..bdc87b4 100644 --- a/views/admin/billing/editInvoice.html +++ b/views/admin/billing/editInvoice.html @@ -94,6 +94,12 @@ + + Account Number + + + + Anniversary Date @@ -315,6 +321,7 @@ jQuery(document).ready(function($){ line_items = [], // Array holding line_items json objects allFields = $( [] ).add( line_item_type ), // Array holding the form fields - add line_item form ref_name = $( 'input[name="ref_name"' ), + account_number = $( 'input[name="account_number"' ), anniversary_date = $( 'input[name="anniversary_date"' ), renewal_date = $( 'input[name="renewal_date"' ), email = $( 'input[name="email"' ), @@ -337,7 +344,7 @@ jQuery(document).ready(function($){ lineTips = $( '.validateTips' ), accountTips = $( '.validateAccountTips' ), customTips = $( '.validateCustomTips' ), - allAccountFields = $( [] ).add( ref_name ) .add( anniversary_date ) .add( renewal_date ) + allAccountFields = $( [] ).add( ref_name ) .add( account_number ) .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_county) {if $settings.billing_contact_name_enabled}.add( billing_contact_name ){else}.add( billing_fname ).add( billing_lname ){/if} @@ -492,6 +499,7 @@ jQuery(document).ready(function($){ allAccountFields.removeClass( 'ui-state-error' ); valid = valid && checkRequired( ref_name, accountTips, 'Name is required!' ); + valid = valid && checkRequired( account_number, accountTips, 'Account Number is required!' ); 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 ); @@ -519,7 +527,11 @@ jQuery(document).ready(function($){ // Close the dialog newAccountDialog.dialog( 'close' ); } else { - //console.log( 'return', msg ); + // Check for unqique account number + if ( msg.fieldFail.account_number ) { + alert( 'Account Number must be unique!' ); + } + console.log( 'return', msg ); } }); } diff --git a/views/admin/billing/memberBillingSubHeader.html b/views/admin/billing/memberBillingSubHeader.html index 6b1ae01..972392c 100644 --- a/views/admin/billing/memberBillingSubHeader.html +++ b/views/admin/billing/memberBillingSubHeader.html @@ -27,7 +27,7 @@ Membership Renewal {/if} - {if isset( $billing_settings.uptravel_payment_form ) && $billing_settings.uptravel_payment_form && $accountID} + {if isset( $billing_settings.uptravel_payment_form ) && $billing_settings.uptravel_payment_form && $accountID && !$fromMemberMenu} {$hasInvoice = apply_filters('glm-billing-account-has-invoice', false, $accountID )}
  • {if $hasInvoice} diff --git a/views/admin/billing/statements.html b/views/admin/billing/statements.html index a4c3367..f73d491 100644 --- a/views/admin/billing/statements.html +++ b/views/admin/billing/statements.html @@ -128,7 +128,7 @@ ${$transaction.transaction_data.amount_total} ${$transaction.transaction_data.balance} - {if isset( $billing_settings.uptravel_payment_form ) && $billing_settings.uptravel_payment_form} + {if isset( $billing_settings.uptravel_payment_form ) && $billing_settings.uptravel_payment_form && !$fromMemberMenu} {if $transaction.transaction_data.paid} {else}Make A Payment{/if} {else} {if $transaction.transaction_data.paid} {else}Pay Invoice{/if} diff --git a/views/front/billing/renew.html b/views/front/billing/renew.html index 3809422..1b80447 100644 --- a/views/front/billing/renew.html +++ b/views/front/billing/renew.html @@ -17,28 +17,51 @@ - {if $member_invoice} -
    -
    - Membership Class +
    +
    + Membership Class +
    +
    + {if $settings.allow_membership_choice} + {foreach $payable_types as $type} + + {/foreach} + {else} + + {$member_invoice.name} {$member_invoice.amount} + {/if} +
    -
    - {if $settings.allow_membership_choice} - {foreach $payable_types as $type} - - {/foreach} - {else} - - {$member_invoice.name} {$member_invoice.amount} - {/if} + {else} +
    +
    + Member Billing # +
    +
    + +
    +
    +
    +
    + Membership Class +
    +
    + {if $settings.allow_membership_choice} + {foreach $payable_types as $type} + + {/foreach} + {/if} +
    -
    {/if} {if $employees} @@ -67,8 +90,8 @@
    -{* Include the Payment Form template *} -{include file='common/billing/paymentForm.html'} + {* Include the Payment Form template *} + {include file='common/billing/paymentForm.html'} @@ -89,6 +112,8 @@ jQuery(document).ready(function($){ currency: 'USD', minimunFractionDigits: 2 }); + + // Generate the total for the renewal. function getPageTotal(){ // Calculate the total for this page. @@ -96,9 +121,12 @@ jQuery(document).ready(function($){ if ( $('input[name=member_renewing]:checked').length ) { var member_renewing_amount = parseFloat( $('input[name=member_renewing]:checked').data('amount') ); } else { - var member_renewing_amount = parseFloat( $('input[name=member_renewing]').data('amount') ); + var member_renewing_amount = parseFloat( $('input[name=member_renewing]:first').data('amount') ); + $('input[name=member_renewing]:first').prop( 'checked', true ); } + // console.log( 'member_renewing_amount', member_renewing_amount ); + // Get each employee and add their amounts. $('input[name^=employees]').each(function(){ var isChecked = $(this).prop('checked');