Fix for the account data
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Mar 2019 20:21:37 +0000 (16:21 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 14 Mar 2019 20:21:37 +0000 (16:21 -0400)
Need to format as string not number to check against the account_number
as it is a text field.

models/admin/ajax/billingAccount.php
models/front/billing/renew.php
views/front/billing/renew.html

index d620844..988021a 100644 (file)
@@ -126,6 +126,31 @@ class GlmMembersAdmin_ajax_billingAccount extends GlmDataAccounts
                 );
             }
             break;
+        case 'verifyAccountNumber':
+            if ( isset( $_REQUEST['account_number'] ) && $account_number = filter_var( $_REQUEST['account_number'], FILTER_SANITIZE_STRING ) ) {
+                $account = $this->wpdb->get_row(
+                    $this->wpdb->prepare(
+                        "SELECT id,ref_dest
+                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                          WHERE account_number = %s",
+                        $account_number
+                    ),
+                    ARRAY_A
+                );
+                trigger_error( print_r( $account, E_USER_NOTICE ) );
+                if ( $account ) {
+                    $return = array(
+                        'status'     => true,
+                        'member_id'  => $account['id'],
+                        'account_id' => $account['ref_dest'],
+                    );
+                } else {
+                    $return = array( 'status'  => false );
+                }
+            } else {
+                $return = array( 'status'  => false );
+            }
+            break;
         }
 
         header( 'Content-type:application/json;charset=utf-8', true );
index 49e59ed..4478fc1 100644 (file)
@@ -434,7 +434,11 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
         }
 
         // Get the list of invoices for this member.
-        $statements = $BillingSupport->getStatementsByRefDest( $this->memberID );
+        $statements        = $BillingSupport->getStatementsByRefDest( $this->memberID );
+        $transactions      = false;
+        $account_data      = false;
+        $balance_due       = false;
+        $hasBillingAccount = false;
         // echo '<pre>$statements: ' . print_r( $statements, true ) . '</pre>';
         if ( $statements ) {
             $transactions      = $statements['transactions'];
index 1b80447..3f11428 100644 (file)
@@ -13,8 +13,8 @@
 
     <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="member_id" name="member" value="{$memberID}" />
+        <input type="hidden" id="account_id" name="account_id" value="{$account_data.id}" />
         <input type="hidden" id="total_renew_amount" name="total_renew_amount" value="" />
 
         {if $member_invoice}
@@ -44,7 +44,7 @@
                     Member Billing #
                 </div>
                 <div class="glm-billing-input">
-                    <input name="account_number" value="" />
+                    <input id="account_number" name="account_number" required />
                 </div>
             </div>
             <div class="glm-billing-field">
@@ -113,6 +113,33 @@ jQuery(document).ready(function($){
         minimunFractionDigits: 2
     });
 
+    // verify the account number is correct.
+    $('#account_number').on( 'change', function(){
+        $.ajax({
+            cache: false,
+            url: '{$ajaxUrl}',
+            dataType: 'json',
+            type: 'POST',
+            data: {
+                'action': 'glm_members_admin_ajax',
+                'glm_action': 'billingAccount',
+                'option': 'verifyAccountNumber',
+                'account_number': $(this).val(),
+            }
+        }).done(function(msg){
+            console.log( 'msg', msg );
+            if ( msg.status === false ) {
+                alert( 'Not a valid Account #' );
+                $('#account_number').val('');
+            } else {
+                // Set the account and member inputs
+                $('#account_id').val( msg.account_id );
+                $('#member_id').val( msg.member_id );
+            }
+        });
+    } );
+
+
     // Generate the total for the renewal.
     function getPageTotal(){