From fe6d5c78027c8aa7ec819fd7cafb4c78070f4704 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 2 Apr 2018 05:32:21 -0400 Subject: [PATCH] Working on the members pay invoice page. Need to separate the payment processing part. --- classes/billingSupport.php | 54 ++++++------ models/admin/member/billing.php | 5 ++ views/admin/billing/makePayment.html | 118 +++++++++++++-------------- views/admin/billing/renew.html | 3 +- 4 files changed, 92 insertions(+), 88 deletions(-) diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 37bcd92..ed2fe0a 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -91,40 +91,46 @@ class GlmBillingSupport * * @param int $payment_id Payment id * @param int $account Total amount of the Payment - * @param float $payment Payment amount - * @param int $invoice_id Id of the Invoice record + * @param float $payment Payment amount + * @param mixed $invoices Id or Array of the Invoice record * * @access public * @return void */ - public function recordPayment( $payment_id, $account, $payment, $invoice_id = null ) + public function recordPayment( $payment_id, $account, $payment, $invoices = null ) { // record into the transaction table $this->recordTransaction( $this->config['transaction_numb']['Payment'], $payment_id, $account, null, $payment ); // If there's an invoice_id // If the payment amount is over then go through the other invoices. - if ( $invoice_id ) { - // Get the invoice - $invoice = $this->getInvoiceById( $invoice_id ); - $balance = (float)$invoice['balance']; - if ( $payment == $invoice['balance'] ) { - $payment -= $invoice['balance']; - // Mark this as paid then - $this->updateInvoiceBalance( $invoice['id'], (float)0.00 ); - // Record the payment to the invoice_payments table - $this->recordInvoicePayment( $invoice['id'], $payment_id, $balance ); - } else if ( $payment > $invoice['balance'] ) { - $this->updateInvoiceBalance( $invoice['id'], (float)0.00 ); - $payment -= $invoice['balance']; - // Record the payment to the invoice_payments table - $this->recordInvoicePayment( $invoice['id'], $payment_id, $balance ); - } else if ( $invoice['balance'] > $payment ) { - // Update the balance of the invoice - $balance = (float)$balance - (float)$payment; - $this->updateInvoiceBalance( $invoice['id'], (float)$balance ); - // Record the payment to the invoice_payments table - $this->recordInvoicePayment( $invoice['id'], $payment_id, (float)$payment ); + // TODO: Need to deal with an array of invoice_id's + if ( isset( $invoices ) ) { + if ( !is_array( $invoices ) ) { + $invoices = array( $invoices ); + } + foreach ( $invoices as $invoice_id ) { + // Get the invoice + $invoice = $this->getInvoiceById( $invoice_id ); + $balance = (float)$invoice['balance']; + if ( $payment == $invoice['balance'] ) { + $payment -= $invoice['balance']; + // Mark this as paid then + $this->updateInvoiceBalance( $invoice['id'], (float)0.00 ); + // Record the payment to the invoice_payments table + $this->recordInvoicePayment( $invoice['id'], $payment_id, $balance ); + } else if ( $payment > $invoice['balance'] ) { + $this->updateInvoiceBalance( $invoice['id'], (float)0.00 ); + $payment -= $invoice['balance']; + // Record the payment to the invoice_payments table + $this->recordInvoicePayment( $invoice['id'], $payment_id, $balance ); + } else if ( $invoice['balance'] > $payment ) { + // Update the balance of the invoice + $balance = (float)$balance - (float)$payment; + $this->updateInvoiceBalance( $invoice['id'], (float)$balance ); + // Record the payment to the invoice_payments table + $this->recordInvoicePayment( $invoice['id'], $payment_id, (float)$payment ); + } } } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 697fc9a..2c8c44c 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -387,6 +387,11 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // if error + $messages = '
'.print_r( $_REQUEST, true ).'
'; + $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ); + $BillingSupport->processMemberRenewal( $account_id, $invoice_id, $amount ); + + break; diff --git a/views/admin/billing/makePayment.html b/views/admin/billing/makePayment.html index 0977c5c..dd67c4e 100644 --- a/views/admin/billing/makePayment.html +++ b/views/admin/billing/makePayment.html @@ -1,7 +1,7 @@ {include file='admin/member/header.html'} {include file='admin/billing/memberBillingSubHeader.html'} -
+
{if $paymentSuccess}Payment Completed{/if} {if $paymentError}Error With Payment{/if} @@ -19,58 +19,39 @@ + -
{if $invoices} -
-
-
-

Payment Information

-
-
- -
-
Select Invoice
-
- ${$invoice.balance} Due {$invoice.due_date} - - {/foreach} - {/if} - + + {/foreach} + {/if}
-
-
Amount
-
- +
+
Amount
+
+
-
-
Name on Card
-
+
+
Name on Card
+
-
-
Card Type
-
+
+
Card Type
+
-
-
Card Expiration
-
+
+
Card Expiration
+
-
-
C V V
-
+
+
C V V
+
-
-
- -
-
+ -
{else} You don't have any unpaid invoices! {/if} -
@@ -157,6 +129,28 @@ jQuery(document).ready(function($){ $('#billing-amount').val( $(this).find('option:selected').data( 'amount') ); }); + function getPageTotal(){ + + // Calculate the total for this page. + // Get the member_renewing amount. + if ( $('input[name^=invoices]:checked').length ) { + var invoice_amount = parseFloat( $('input[name^=invoices]:checked').data('amount') ); + } else { + var invoice_amount = 0.00; + } + + $('#total_amount_display').html( '$' + invoice_amount ); + $('#total_amount').val( invoice_amount ); + + } + + getPageTotal(); + + // trigger total if changing Membership + $('input[name^=invoices]').change(function(){ + getPageTotal(); + }); + // Flash certain elements for a short time after display $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500); diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html index 7a43577..b16a465 100644 --- a/views/admin/billing/renew.html +++ b/views/admin/billing/renew.html @@ -66,8 +66,7 @@ Total Due
-
-
+
-- 2.17.1