From 1d8bcf2dba60fd1bd899d45ffb9b789723d83919 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 9 Apr 2018 16:56:33 -0400 Subject: [PATCH] Updating front end renewal form Update for how price total is setup --- models/admin/member/billing.php | 37 ++++++++++++++++++++++++++++----- models/front/billing/renew.php | 34 ++++++++++++++++++++++++++++-- views/admin/billing/renew.html | 1 + views/front/billing/renew.html | 9 +++++++- 4 files changed, 73 insertions(+), 8 deletions(-) diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 2fbdd8f..0e63552 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -288,9 +288,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling case 'pay_by_credit_card': // Do the Payment Processing. $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] ); - // echo '
$processErrors: ' . print_r( $processErrors, true ) . '
'; if ( $processErrors ) { - // $messages[] = '
$processErrors: ' . print_r( $processErrors, true ) . '
'; if ( count( $processErrors ) > 0 ) { $error = true; $BillingSupport->removeInvoiceById( $invoice_id ); @@ -331,12 +329,41 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Get the invoice. $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id ); + + // If the member_type is changing then update member + // Get current member type + $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ); + if ( $member_id ) { + $current_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $member_id + ) + ); + $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); + $new_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE id = %d", + $new_type + ) + ); + if ( $current_member_type != $new_member_type ) { + $this->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', + array( 'member_type' => $new_member_type ), + array( 'id' => $member_id ), + array( '%d' ), + array( '%d' ) + ); + } + } } } - - break; - case 'account': // Check to see if we're adding an account or editing one. if ( isset( $_REQUEST['ref_name'] ) ) { diff --git a/models/front/billing/renew.php b/models/front/billing/renew.php index 1312969..fb59ec3 100644 --- a/models/front/billing/renew.php +++ b/models/front/billing/renew.php @@ -279,9 +279,7 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling case 'pay_by_credit_card': // Do the Payment Processing. $processErrors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] ); - // echo '
$processErrors: ' . print_r( $processErrors, true ) . '
'; if ( $processErrors ) { - // $messages[] = '
$processErrors: ' . print_r( $processErrors, true ) . '
'; if ( count( $processErrors ) > 0 ) { $error = true; $BillingSupport->removeInvoiceById( $invoice_id ); @@ -322,6 +320,38 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling // Get the invoice. $invoiceHtml = $BillingSupport->viewInvoice( $invoice_id ); + + // If the member_type is changing then update member + // Get current member type + $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ); + if ( $member_id ) { + $current_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $member_id + ) + ); + $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ); + $new_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE id = %d", + $new_type + ) + ); + if ( $current_member_type != $new_member_type ) { + $this->update( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members', + array( 'member_type' => $new_member_type ), + array( 'id' => $member_id ), + array( '%d' ), + array( '%d' ) + ); + } + } } } diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html index d5aa304..75ab684 100644 --- a/views/admin/billing/renew.html +++ b/views/admin/billing/renew.html @@ -123,6 +123,7 @@ jQuery(document).ready(function($){ $('#billing-amount').val( $(this).find('option:selected').data( 'amount') ); }); + // Create a USD formatter var formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', diff --git a/views/front/billing/renew.html b/views/front/billing/renew.html index b243419..3809422 100644 --- a/views/front/billing/renew.html +++ b/views/front/billing/renew.html @@ -83,6 +83,12 @@ jQuery(document).ready(function($){ $('#billing-amount').val( $(this).find('option:selected').data( 'amount') ); }); + // Create a USD formatter + var formatter = new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + minimunFractionDigits: 2 + }); function getPageTotal(){ // Calculate the total for this page. @@ -100,7 +106,8 @@ jQuery(document).ready(function($){ member_renewing_amount += parseFloat( $(this).data('amount') ); } }); - $('#renew_total').html( '$' + member_renewing_amount ); + + $('#renew_total').html( formatter.format( member_renewing_amount ) ); $('#total_renew_amount').val( member_renewing_amount ); } -- 2.17.1