Updating front end renewal form
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 9 Apr 2018 20:56:33 +0000 (16:56 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 9 Apr 2018 20:56:33 +0000 (16:56 -0400)
Update for how price total is setup

models/admin/member/billing.php
models/front/billing/renew.php
views/admin/billing/renew.html
views/front/billing/renew.html

index 2fbdd8f..0e63552 100644 (file)
@@ -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 '<pre>$processErrors: ' . print_r( $processErrors, true ) . '</pre>';
                     if ( $processErrors ) {
-                        // $messages[] = '<pre>$processErrors: ' . print_r( $processErrors, true ) . '</pre>';
                         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'] ) ) {
index 1312969..fb59ec3 100644 (file)
@@ -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 '<pre>$processErrors: ' . print_r( $processErrors, true ) . '</pre>';
                     if ( $processErrors ) {
-                        // $messages[] = '<pre>$processErrors: ' . print_r( $processErrors, true ) . '</pre>';
                         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' )
+                            );
+                        }
+                    }
                 }
             }
 
index d5aa304..75ab684 100644 (file)
@@ -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',
index b243419..3809422 100644 (file)
@@ -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 );
 
     }