From b71a69942e1dff99c7dd6b75b9ddb31353a97e65 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 25 Mar 2019 11:07:30 -0400 Subject: [PATCH] Update the renewal form use invoice # for lookup --- models/admin/ajax/billingAccount.php | 77 ++++++++++++++++++++-------- views/front/billing/renew.html | 18 ++++--- 2 files changed, 65 insertions(+), 30 deletions(-) diff --git a/models/admin/ajax/billingAccount.php b/models/admin/ajax/billingAccount.php index adfbfe2..2df9bc5 100644 --- a/models/admin/ajax/billingAccount.php +++ b/models/admin/ajax/billingAccount.php @@ -15,6 +15,7 @@ // Load Members data abstract require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoices.php'; /** * This class performs the work of handling images passed to it via @@ -78,12 +79,12 @@ class GlmMembersAdmin_ajax_billingAccount extends GlmDataAccounts $return = false; $option = filter_var( $_REQUEST['option'], FILTER_SANITIZE_STRING ); - trigger_error( print_r( $_REQUEST, E_USER_NOTICE ) ); + // trigger_error( print_r( $_REQUEST, true ), E_USER_NOTICE ); switch ( $option ) { case 'add': $account = $this->insertEntry(); - trigger_error( print_r( $account['fieldFail'], E_USER_NOTICE ) ); + trigger_error( print_r( $account['fieldFail'], true ), E_USER_NOTICE ); if ( !$account['status'] ) { $accountInsertError = true; $return = $account; @@ -126,30 +127,62 @@ 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,invoice_type - 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' => (int)$account['id'], - 'account_id' => (int)$account['ref_dest'], - 'invoice_type' => (int)$account['invoice_type'], + case 'verifyInvoiceNumber': + if ( isset( $_REQUEST['invoice_number'] ) && $invoiceNumber = filter_var( $_REQUEST['invoice_number'], FILTER_SANITIZE_STRING ) ) { + // Get the invoice + $Invoices = new GlmDataInvoices( $this->wpdb, $this->config ); + $Invoices->line_items_post = true; + $invoice = $Invoices->getEntry( $invoiceNumber ); + $Invoices->line_items_post = false; + // trigger_error( print_r( $invoice, true ), E_USER_NOTICE ); + if ( !$invoice ) { + $return = array( 'status' => false, 'message' => 'no invoice' ); + } + trigger_error( print_r( $invoice, true ), E_USER_NOTICE ); + + $accountId = $invoice['account']['value']; + trigger_error( print_r( $accountId, true ), E_USER_NOTICE ); + if ( !$accountId ) { + $return = array( 'status' => false, 'message' => 'no accountId' ); + } + $invoiceTypeId = false; + // Get the invoice id for the renewal line item + if ( isset( $invoice['line_items'] ) && is_array( $invoice['line_items'] ) ) { + + foreach ( $invoice['line_items'] as $line_item ) { + if ( $line_item['recurring'] ) { + $invoiceTypeId = $line_item['line_item_type']; + } + } + + $account = $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT id,ref_dest,invoice_type + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE id = %d", + $accountId + ), + ARRAY_A ); + trigger_error( print_r( $account, true ), E_USER_NOTICE ); + // Returning the invoice_type of the account + // TODO: This maybe should be the actual invoice type_id + if ( $account ) { + $return = array( + 'status' => true, + 'member_id' => (int)$account['id'], + 'account_id' => (int)$account['ref_dest'], + 'invoice_type' => (int)$invoiceTypeId, + 'invoice' => $invoice, + ); + } else { + $return = array( 'status' => false, 'message' => 'no account' ); + } } else { - $return = array( 'status' => false ); + $return = array( 'status' => false, 'message' => 'no line_items' ); } } else { - $return = array( 'status' => false ); + $return = array( 'status' => false, 'message' => 'no invoiceNumber' ); } break; } diff --git a/views/front/billing/renew.html b/views/front/billing/renew.html index 883f22a..56ac6e5 100644 --- a/views/front/billing/renew.html +++ b/views/front/billing/renew.html @@ -41,10 +41,10 @@ {else}
- Member Billing # + Invoice #
- +
@@ -55,7 +55,7 @@ {if $settings.allow_membership_choice} {foreach $payable_types as $type} {/foreach} @@ -114,7 +114,7 @@ jQuery(document).ready(function($){ }); // verify the account number is correct. - $('#account_number').on( 'change', function(){ + $('#invoice_number').on( 'change', function(){ $.ajax({ cache: false, url: '{$ajaxUrl}', @@ -123,20 +123,22 @@ jQuery(document).ready(function($){ data: { 'action': 'glm_members_admin_ajax', 'glm_action': 'billingAccount', - 'option': 'verifyAccountNumber', - 'account_number': $(this).val(), + 'option': 'verifyInvoiceNumber', + 'invoice_number': $(this).val(), } }).done(function(msg){ console.log( 'msg', msg ); if ( msg.status === false ) { alert( 'Not a valid Account #' ); - $('#account_number').val(''); + $('#invoice_number').val(''); } else { // Set the account and member inputs $('#account_id').val( msg.account_id ); $('#member_id').val( msg.member_id ); if ( msg.invoice_type ) { - $('input[name=member_renewing], input[value=' + msg.invoice_type + ']').prop('checked', true); + // $('input[name=member_renewing]').prop('checked', false); + console.log( 'invoice_type', msg.invoice_type ); + $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true); getPageTotal(); } } -- 2.17.1