Working on the members pay invoice page.
authorSteve Sutton <ssutton@gmail.com>
Mon, 2 Apr 2018 09:32:21 +0000 (05:32 -0400)
committerSteve Sutton <ssutton@gmail.com>
Mon, 2 Apr 2018 09:32:21 +0000 (05:32 -0400)
Need to separate the payment processing part.

classes/billingSupport.php
models/admin/member/billing.php
views/admin/billing/makePayment.html
views/admin/billing/renew.html

index 37bcd92..ed2fe0a 100644 (file)
@@ -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 );
+                }
             }
 
         }
index 697fc9a..2c8c44c 100644 (file)
@@ -387,6 +387,11 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             // if error
 
+            $messages = '<pre>'.print_r( $_REQUEST, true ).'</pre>';
+            $account_id = filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT );
+            $BillingSupport->processMemberRenewal( $account_id, $invoice_id, $amount );
+
+
 
 
             break;
index 0977c5c..dd67c4e 100644 (file)
@@ -1,7 +1,7 @@
 {include file='admin/member/header.html'}
 {include file='admin/billing/memberBillingSubHeader.html'}
 
-<div id="billing-payment-form" style="max-width:750px;">
+<div id="billing-payment-form" class="glm-billing-form">
 
     {if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
     {if $paymentError}<span class="glm-notice glm-flash-updated">Error With Payment</span>{/if}
         <input type="hidden" name="option" value="createPayment">
         <input type="hidden" name="member" value="{$memberID}">
         <input type="hidden" name="account_id" value="{$account.fieldData.id}">
+        <input type="hidden" name="amount" value="" id="total_amount"/>
 
-        <div class="glm-row">
 
             <!-- Call for billing section -->
 
             {if $invoices}
-            <div class="glm-columns glm-small-12 glm-large-12">
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12">
-                        <h2>Payment Information</h2>
-                    </div>
-                </div>
-
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Select Invoice </div>
-                    <div class="glm-columns glm-small-12 glm-large-8">
-                        <select id="billing-invoice-select" name="invoice_id" required>
-                            <option value=""></option>
-                            {if $invoices}
-                                {foreach $invoices as $invoice}
-                                <option
-                                    value="{$invoice.id}"
-                                    data-amount="{$invoice.balance}"
-                                    {if isset($smarty.request.invoice_id) && $smarty.request.invoice_id == $invoice.id} selected{/if}>
+                <h2>Payment Information</h2>
+
+                <div class="glm-billing-field">
+                    <div class="glm-billing-label glm-required"> Select Invoice </div>
+                    <div class="glm-billing-input">
+                        {if $invoices}
+                            {foreach $invoices as $invoice}
+                                <label>
+                                    <input type="checkbox" name="invoices[]" data-amount="{$invoice.balance}" value="{$invoice.id}" checked required />
                                     ${$invoice.balance} Due {$invoice.due_date}
-                                </option>
-                                {/foreach}
-                            {/if}
-                        </select>
+                                </label>
+                            {/foreach}
+                        {/if}
                     </div>
                 </div>
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Amount </div>
-                    <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input
-                            class="glm-form-text-input-small"
-                            type="number"
-                            id="billing-amount"
-                            name="amount"
-                            step="0.01"
-                            min="0.01"
-                            required
-                            {if isset($smarty.request.amount) && $smarty.request.amount}value="{$smarty.request.amount}"{/if} />
+                <div class="glm-billing-field">
+                    <div class="glm-billing-label glm-required"> Amount </div>
+                    <div class="glm-billing-input">
+                        <div id="total_amount_display"></div>
                     </div>
                 </div>
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Name on Card </div>
-                    <div class="glm-columns glm-small-12 glm-medium-8">
+                <div class="glm-billing-field">
+                    <div class="glm-billing-label glm-required"> Name on Card </div>
+                    <div class="glm-billing-input">
                         <input
-                            class="glm-form-text-input-small"
                             type="text"
                             name="cc_name"
                             required
@@ -78,9 +59,9 @@
                     </div>
                 </div>
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Card Type </div>
-                    <div class="glm-columns glm-small-12 glm-medium-8">
+                <div class="glm-billing-field glm-billing-left-half">
+                    <div class="glm-billing-label glm-required"> Card Type </div>
+                    <div class="glm-billing-input">
                         <select name="cc_type" required>
                             <option value=""></option>
                             {foreach $management.cc_accepts.names as $cardId => $cardName}
                     </div>
                 </div>
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Card Number </div>
-                    <div class="glm-columns glm-small-12 glm-medium-8">
+                <div class="glm-billing-field glm-billing-right-half">
+                    <div class="glm-billing-label glm-required"> Card Number </div>
+                    <div class="glm-billing-input">
                         <input
-                            class="glm-form-text-input-small"
                             type="text"
                             placeholder="Numbers Only"
                             name="cc_numb"
                     </div>
                 </div>
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> Card Expiration </div>
-                    <div class="glm-columns glm-small-12 glm-medium-8">
+                <div class="glm-billing-field glm-billing-left-half">
+                    <div class="glm-billing-label glm-required"> Card Expiration </div>
+                    <div class="glm-billing-input">
                         <input
-                            class="glm-form-text-input-small"
                             type="text"
                             placeholder="MM/YY"
                             name="cc_exp"
                     </div>
                 </div>
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-3 glm-required"> C V V </div>
-                    <div class="glm-columns glm-small-12 glm-medium-8">
+                <div class="glm-billing-field glm-billing-right-half">
+                    <div class="glm-billing-label glm-required"> C V V </div>
+                    <div class="glm-billing-input">
                         <input
-                            class="glm-form-text-input-small"
                             type="text"
                             placeholder="3 or 4 digit security code on back of card"
                             name="cc_cvv"
                 </div>
 
 
-                <div class="glm-row">
-                    <div class="glm-columns glm-small-12 glm-medium-8">
-                        <input class="button button-primary" type="submit" value="Make Payment">
-                    </div>
-                </div>
+                <input class="button button-primary" type="submit" value="Make Payment">
 
-            </div>
             {else}
             You don't have any unpaid invoices!
             {/if}
-        </div>
 
     </form>
 </div>
@@ -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);
 
index 7a43577..b16a465 100644 (file)
@@ -66,8 +66,7 @@
                 Total Due
             </div>
             <div class="glm-billing-input">
-                <div id="renew_total">
-                </div>
+                <div id="renew_total"></div>
             </div>
         </div>