Working on payment form front and in member section
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Apr 2019 20:50:43 +0000 (16:50 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 25 Apr 2019 20:50:43 +0000 (16:50 -0400)
Working on payment form front end.
Working on payment (pay invoice) admin form.

12 files changed:
models/admin/ajax/billingAccount.php
models/admin/billing/invoices.php
models/admin/member/billing.php
models/front/billing/paymentForm.php
views/admin/billing/invoices.html
views/admin/billing/invoicing.html
views/admin/billing/makePayment.html
views/admin/billing/paymentReceipt.html
views/admin/billing/reports.html
views/admin/settings/billing.html
views/common/billing/paymentForm.html
views/front/billing/paymentForm.html

index 7829f9d..b0820d1 100644 (file)
@@ -170,7 +170,6 @@ class GlmMembersAdmin_ajax_billingAccount extends GlmDataAccounts
                             'status'       => true,
                             'member_id'    => (int)$account['ref_dest'],
                             'account_id'   => (int)$account['id'],
-                            'invoice_type' => (int)$invoiceTypeId,
                             'invoice'      => $invoice,
                         );
                     } else {
@@ -187,6 +186,6 @@ class GlmMembersAdmin_ajax_billingAccount extends GlmDataAccounts
 
         header( 'Content-type:application/json;charset=utf-8', true );
         echo json_encode( $return, true );
-        exit();
+        exit;
     }
 }
index eee71a4..eb09b0e 100644 (file)
@@ -369,9 +369,9 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             $invoiceTypes     = $InvoiceTypesObj->getList();
             $invoiceTypes     = $InvoiceTypesObj->sortParentChild($invoiceTypes);
             // Need to get the accounts
-            $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+            $Accounts       = new GlmDataAccounts( $this->wpdb, $this->config );
             $billingAccount = $Accounts->newEntry();
-            $accounts = $Accounts->getSimpleAccountList( '', 'ref_name' );
+            $accounts       = $Accounts->getSimpleAccountList( '', 'ref_name' );
 
             // Need a list of members that don't have an account.
             $nonAccountMembers = $this->wpdb->get_results(
@@ -386,9 +386,9 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices
             if ( isset( $invoiceTypes ) ) {
                 foreach ( $invoiceTypes as $invoiceType ) {
                     $invTypes[$invoiceType['id']] = array(
-                        'id'       => $invoiceType['id'],
-                        'name'     => $invoiceType['name'],
-                        'amount'   => $invoiceType['amount'],
+                        'id'     => $invoiceType['id'],
+                        'name'   => $invoiceType['name'],
+                        'amount' => $invoiceType['amount'],
                     );
                 }
                 $invoiceTypeJSON = json_encode( $invTypes, true );
index 494b20c..b54a233 100644 (file)
@@ -835,12 +835,20 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                     $account = $Accounts->editEntry( $accountID );
 
                     // Get unpaid invoices
-                    $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
-                    if ( !empty( $invoices ) ) {
-                        foreach ( $invoices as &$invoice ) {
-                            $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) );
-                        }
-                    }
+                    // $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
+                    $Invoices       = new GlmDataInvoices( $this->wpdb, $this->config );
+                    $where_params   = array( 'true' );
+                    $where_params[] = "( paid <> true OR paid IS NULL )";
+                    $where_params[] = "account = $accountID";
+                    $where          = implode( ' AND ', $where_params );
+                    $Invoices->line_items_post = true;
+                    $invoices       = $Invoices->getList( $where );
+                    $Invoices->line_items_post = false;
+                    // if ( !empty( $invoices ) ) {
+                    //     foreach ( $invoices as &$invoice ) {
+                    //         $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) );
+                    //     }
+                    // }
 
                     $cc_accepts = $this->config['billing_settings']['cc_accepts'];
 
@@ -895,12 +903,20 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $account = $Accounts->editEntry( $accountID );
 
             // Get unpaid invoices
-            $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
-            if ( !empty( $invoices ) ) {
-                foreach ( $invoices as &$invoice ) {
-                    $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) );
-                }
-            }
+            // $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
+            // if ( !empty( $invoices ) ) {
+            //     foreach ( $invoices as &$invoice ) {
+            //         $invoice['due_date'] = date( 'n/d/Y', strtotime( $invoice['due_date'] ) );
+            //     }
+            // }
+            $Invoices       = new GlmDataInvoices( $this->wpdb, $this->config );
+            $where_params   = array( 'true' );
+            $where_params[] = "( paid <> true OR paid IS NULL )";
+            $where_params[] = "account = $accountID";
+            $where          = implode( ' AND ', $where_params );
+            $Invoices->line_items_post = true;
+            $invoices       = $Invoices->getList( $where );
+            $Invoices->line_items_post = false;
 
             $cc_accepts = $this->config['billing_settings']['cc_accepts'];
 
@@ -995,6 +1011,8 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             'paymentMethods'     => $this->config['alt_payment_method'],
             'renewalFormSession' => $renewalFormSession,
             'nextInvoiceDate'    => $nextInvoiceDate,
+            'pluginJsUrl'        => GLM_MEMBERS_BILLING_PLUGIN_URL . '/js',
+            'pluginCssUrl'       => GLM_MEMBERS_BILLING_PLUGIN_URL . '/css',
         );
 
         // Return status, any suggested view, and any data to controller.
index ed133f1..8bde08e 100644 (file)
@@ -182,10 +182,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
         case 'paymentProcess':
             $error = false;
             $view  = 'paymentFormProcess';
-            // echo '<pre>$_REQUEST: ' . print_r( $_REQUEST, true ) . '</pre>';
-
-            // Here we need to get the chosen Membership plan and adjust the invoice with a new line_item if needed.
-            $selectedPaymentType = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT );
 
             if ( isset( $_REQUEST['invoice_number'] ) ) {
                 $invoiceId = filter_var( $_REQUEST['invoice_number'], FILTER_VALIDATE_INT );
@@ -194,9 +190,7 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
             }
             // Pull member invoice
             $memberInvoice = $BillingSupport->getInvoiceById( $invoiceId );
-            // echo '<pre>$memberInvoice: ' . print_r( $memberInvoice, true ) . '</pre>';
             $memberInvoiceLineItems = $BillingSupport->getLineItemsForInvoice( $invoiceId );
-            // echo '<pre>$memberInvoiceLineItems: ' . print_r( $memberInvoiceLineItems, true ) . '</pre>';
             if ( isset( $memberInvoiceLineItems ) && is_array( $memberInvoiceLineItems ) && !empty( $memberInvoiceLineItems ) ) {
                 foreach ( $memberInvoiceLineItems as $lineItem ) {
                     if ( $lineItem['recurring'] ) {
@@ -204,10 +198,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
                     }
                 }
             }
-            // If there's new invoice type then we need to update the invoice
-            if ( $invoicePaymentType != $selectedPaymentType ) {
-
-            }
 
             // Check for account_number
             // If given then this is from unregistered user.
@@ -232,7 +222,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
                     case 'pay_by_credit_card':
                         // Do the Payment Processing.
                         $processErrors = $BillingSupport->processOnlinePayment( $accountId, $invoiceId, $_REQUEST['total_renew_amount'] );
-                        // echo '<pre>$processErrors: ' . print_r( $processErrors, true ) . '</pre>';
 
                         if ( $processErrors ) {
                             if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
index dff03eb..8215625 100644 (file)
@@ -58,7 +58,7 @@
         <table class="wp-list-table widefat fixed posts glm-admin-table">
             <thead>
                 <tr>
-                    <th>Invoice #</th>
+                    <th width="50">Invoice #</th>
                     <th>Member Name</th>
                     <th>Invoice For</th>
                     <th style="width: 150px;">Time</th>
index 988f4e0..724a5b9 100644 (file)
@@ -88,7 +88,9 @@
             <thead>
                 <tr>
                     <th> Member Name </th>
-                    <th style="width: 200px;"> Account Number </th>
+                    {if isset( $settings.account_number_enabled ) && $settings.account_number_enabled}
+                        <th style="width: 200px;"> Account Number </th>
+                    {/if}
                     <th style="width: 200px;"> Payment Type </th>
                     <th style="width: 100px;"> Balance Due </th>
                 </tr>
                                 {$t.member_name}
                             </a>
                         </td>
-                        <td> {$t.account_number} </td>
+                        {if isset( $settings.account_number_enabled ) && $settings.account_number_enabled}
+                            <td> {$t.account_number} </td>
+                        {/if}
                         <td> {$t.payment_type} </td>
                         <td> {$t.balance_due|string_format:"%.2f"} </td>
                     </tr>
index 1489ec4..eee6ab1 100644 (file)
                             {foreach $invoices as $invoice}
                                 <label>
                                     <input type="checkbox" name="invoices[]" data-amount="{$invoice.balance}" value="{$invoice.id}" checked />
-                                    ${$invoice.balance} Due {$invoice.due_date}
+                                    {foreach $invoice.line_items as $line_items}
+                                        {$line_items.name}
+                                    {/foreach}
+                                    ${$invoice.balance} Due {$invoice.due_date.date}
                                 </label>
                             {/foreach}
                         {/if}
index 2564c83..cafd504 100644 (file)
     margin: 20px; 50px;
 }
 #container-table .line-items {
-    border-collapse: collapse;
+    border-collapse: collapse !important;
+    margin: 0 !important;
+    padding: 0 !important;
 }
 body {
     width: auto !important;
 }
 </style>
-<table id="container-table" width="600" cellspacing="0" cellpadding="0">
-    <tr>
-        <td>{if $settings.company_logo}<img src="{$glmPluginMediaUrl}/images/medium/{$settings.company_logo}">{/if}</td>
-        <td width="160" align="right">
-            <h1>RECEIPT</h1>
-        </td>
-    </tr>
-    <tr>
-        <td>
-            {* Billing Invoice Settings *}
-            <b>{$settings.company_name}</b></b><br>
-        {if $settings.company_name2}{$settings.company_name2}<br>{/if}
-        {if $settings.company_addr1}{$settings.company_addr1}<br>{/if}
-        {if $settings.company_addr2}{$settings.company_addr2}<br>{/if}
-        {if $settings.company_city}{$settings.company_city} {$settings.company_state}, {$settings.company_zip}<br>{/if}
-        {if $settings.company_phone}{$settings.company_phone}<br>{/if}
-        {if $settings.company_email}{$settings.company_email}<br>{/if}
-        </td>
-        <td width="220" valign="top">
-            <table width="100%">
-                <tr>
-                    <th align="right"> Invoice Date: </th>
-                    <td align="right"> {$invoice.transaction_time|date_format:"%D"} </td>
-                </tr>
-                <tr>
-                    <th align="right"> Due Date: </th>
-                    <td align="right"> {$invoice.due_date|date_format:"%D"} </td>
-                </tr>
-                <tr>
-                    <th align="right"> Account #: </th>
-                    <td align="right"> {$account.id} </td>
-                </tr>
-                <tr>
-                    <th align="right"> Invoice #: </th>
-                    <td align="right"> {$invoice.id} </td>
-                </tr>
-            </table>
-        </td>
-    </tr>
-    <tr><td colspan="2"></td></tr>
-    <tr>
-        <td colspan="2">
-            <h4>Bill To:</h4>
-            {if $account.ref_name}{$account.ref_name}<br>{/if}
-            {if $account.billing_addr1}{$account.billing_addr1}<br>{/if}
-            {if $account.billing_addr2}{$account.billing_addr2}<br>{/if}
-            {if $account.billing_city}{$account.billing_city} {$account.billing_state}, {$account.billing_zip}<br>{/if}
-            {if $account.billing_phone}{$account.billing_phone}<br>{/if}
-
-            {* Billing Settings *}
-        </td>
-    </tr>
-    <tr><td colspan="2">&nbsp;</td></tr>
-    <tr>
-        <td colspan="2">
-            <table class="line-items" width="100%">
-                <thead>
+<div id="PrintArea">
+    <table id="container-table" width="600" cellspacing="0" cellpadding="0">
+        <tr>
+            <td>{if $settings.company_logo}<img src="{$glmPluginMediaUrl}/images/medium/{$settings.company_logo}">{/if}</td>
+            <td width="160" align="right">
+                <h1>RECEIPT</h1>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                {* Billing Invoice Settings *}
+                <b>{$settings.company_name}</b></b><br>
+            {if $settings.company_name2}{$settings.company_name2}<br>{/if}
+            {if $settings.company_addr1}{$settings.company_addr1}<br>{/if}
+            {if $settings.company_addr2}{$settings.company_addr2}<br>{/if}
+            {if $settings.company_city}{$settings.company_city} {$settings.company_state}, {$settings.company_zip}<br>{/if}
+            {if $settings.company_phone}{$settings.company_phone}<br>{/if}
+            {if $settings.company_email}{$settings.company_email}<br>{/if}
+            </td>
+            <td width="220" valign="top">
+                <table width="100%">
                     <tr>
-                        <th align="left">Member Name</th>
-                        <th align="left">Date</th>
-                        <th>&nbsp;</th>
-                        <th align="left">Description</th>
-                        <th align="right">Rate</th>
+                        <th align="right"> Invoice Date: </th>
+                        <td align="right"> {$invoice.transaction_time|date_format:"%D"} </td>
                     </tr>
                     <tr>
-                        <td colspan="5"><hr></td>
+                        <th align="right"> Due Date: </th>
+                        <td align="right"> {$invoice.due_date|date_format:"%D"} </td>
                     </tr>
-                </thead>
-                <tbody>
-                    {foreach $line_items as $item}
                     <tr>
-                        {if isset($item.account) && $item.account == "0"}
-                            <td align="left" width="150">N/A</td>
-                            <td align="left" width="40">N/A</td>
-                        {else}
-                            <td align="left" width="150">{$item.account.ref_name}</td>
-                            <td align="left" width="40">{$item.account.anniversary_date|date_format:"%m/%d/%y"}</td>
-                        {/if}
-                        <td align="right" width="10">&nbsp;</td>
-                        <td align="left" width="300">{$item.name}</td>
-                        <td align="right" width="60">${$item.amount|string_format:"%.2f"}</td>
+                        <th align="right"> Invoice #: </th>
+                        <td align="right"> {$invoice.id} </td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <h4>Bill To:</h4>
+                {if $account.ref_name}{$account.ref_name}<br>{/if}
+                {if $account.billing_addr1}{$account.billing_addr1}<br>{/if}
+                {if $account.billing_addr2}{$account.billing_addr2}<br>{/if}
+                {if $account.billing_city}{$account.billing_city} {$account.billing_state}, {$account.billing_zip}<br>{/if}
+                {if $account.billing_phone}{$account.billing_phone}<br>{/if}
+
+                {* Billing Settings *}
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <table class="line-items" width="100%">
+                    <thead>
+                        <tr>
+                            <th align="left">Description</th>
+                            <th align="right" style="text-align: right;">Rate</th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                        {foreach $line_items as $item}
+                        <tr>
+                            <td align="left" width="300">{$item.name}</td>
+                            <td align="right" width="150" style="text-align: right;">${$item.amount|string_format:"%.2f"}</td>
+                        </tr>
+                        {/foreach}
+                    </tbody>
+                </table>
+                <table class="line-items" width="100%">
+                    <tr>
+                        <td colspan="3"><strong>Payment Receipt:</strong></td>
                     </tr>
-                    {/foreach}
                     {foreach $payments as $payment}
                     <tr>
-                        <td align="left" width="150">&nbsp;</td>
                         <td align="left" width="20">{$payment.transaction_time|date_format:"%m/%d/%y"}</td>
-                        <td align="right" width="10">&nbsp;</td>
                         <td align="left"> {$payment.payment_method} </td>
-                        <td align="right" width="60">{if $payment.amount >= 0}-{/if} ${abs($payment.amount)|string_format:"%.2f"}</td>
+                        <td align="right" width="150" style="text-align: right;">{if $payment.amount >= 0}-{/if} ${abs($payment.amount)|string_format:"%.2f"}</td>
                     </tr>
                     {/foreach}
-                    <tr><td colspan="5"><hr></td></tr>
+                </table>
+                <table class="line-items" width="100%">
                     <tr>
-                        <td colspan="4" align="right">Total Amount Due</td>
+                        <td align="right">Total Amount Due</td>
                         <td width="70" align="right">${$invoice.balance|string_format:"%.2f"}</td>
                     </tr>
-                </tbody>
-            </table>
-        </td>
-    </tr>
-    <tr><td colspan="2">&nbsp;</td></tr>
-    {if $settings.receipt_text}
-    <tr>
-        <td colspan="2">
-            {$settings.receipt_text}
-        </td>
-    </tr>
-    {/if}
-    <tr><td colspan="2">&nbsp;</td></tr>
-    {* Footer of invoice *}
-</table>
+                </table>
+            </td>
+        </tr>
+        {if $settings.receipt_text}
+        <tr>
+            <td colspan="2">
+                {$settings.receipt_text}
+            </td>
+        </tr>
+        {/if}
+        <tr>
+            <td colspan="2">
+            <div class="button button-secondary graph-print glm-right" data-areaToPrint="PrintArea">Print Payment Receipt</div>
+            </td>
+        </tr>
+        {* Footer of invoice *}
+    </table>
+</div>
+
+<script src="{$jsUrl}/PrintArea/jquery.PrintArea.js" type="text/JavaScript" language="javascript"></script>
+<script>
+jQuery(document).ready(function($) {
+    $(".graph-print").click(function(){
+        var areaToPrint = $(this).attr('data-areaToPrint');
+        var position = $(this).offset();
+        $('#' + areaToPrint).printArea({
+            mode:       'popup',   // printable window is either iframe or browser popup
+            popHt:      800,       // popup window height
+            popWd:      800,       // popup window width
+            popX:       500,       // popup window screen X position
+            popY:       500,       // popup window screen Y position
+            popTitle:   'Receipt', // popup window title element
+            popClose:   true,      // popup window close after printing
+            extraCss:   '',        // Comma separated list of extra css to include
+            extraHead:  '',        // Comma separated list of extra elements to be appended to head tag
+            strict:     false      // strict or looseTransitional html 4.01 document standard or undefined to not include at all only for popup option
+        });
+    });
+});
+</script>
index 826343e..13b6ea3 100644 (file)
@@ -84,7 +84,9 @@
                 <thead>
                     <tr>
                         <th> Member Name </th>
-                        <th style="width: 200px;"> Account Number </th>
+                        {if isset( $settings.account_number_enabled ) && $settings.account_number_enabled}
+                            <th style="width: 200px;"> Account Number </th>
+                        {/if}
                         <th style="width: 200px;"> Payment Type </th>
                         <th style="width: 100px;"> Balance Due </th>
                     </tr>
@@ -96,7 +98,9 @@
                                 {$t.member_name}
                             </a>
                         </td>
-                        <td> {$t.account_number} </td>
+                        {if isset( $settings.account_number_enabled ) && $settings.account_number_enabled}
+                            <td> {$t.account_number} </td>
+                        {/if}
                         <td> {$t.payment_type} </td>
                         <td>
                             {if $t.balance_due == 'N/A'}
index 4fe4e52..bca0c61 100644 (file)
                         <tr>
                             <th style="text-align: right;" {if $billingSettings.fieldRequired.receipt_text} class="glm-required"}{/if}>Receipt Text</th>
                             <td {if $billingSettings.fieldFail.receipt_text}class="glm-form-bad-input" data-tabid="glm-payment-terms"{/if}>
-                                <input type="text" name="receipt_text" value="{$billingSettings.fieldData.receipt_text}" class="glm-form-text-input-medium">
+                                {wp_editor(
+                                    $billingSettings.fieldData.receipt_text|escape:quotes,
+                                    'receipt_text',
+                                    json_decode('{
+                                        "media_buttons": false,
+                                        "quicktags": false,
+                                        "textarea_name": "receipt_text",
+                                        "editor_height": 200
+                                    }', true)
+                                )}
                             {if $billingSettings.fieldFail.receipt_text}<p>{$billingSettings.fieldFail.receipt_text}</p>{/if}<br>
                             </td>
                         </tr>
index 4d193cc..bce7184 100644 (file)
 </fieldset>
 
 <fieldset>
-    <legend>Payment Options</legend>
+    <legend>Payment Information</legend>
+    <input type="hidden" name="payment_option" value="pay_by_credit_card">
 
+    {* TODO: Check $billing_settings.payment_methods *}
+    {if !$lockedToMember}
     <div class="glm-billing-field">
         <div class="glm-billing-label">
             Select Payment Option
         </div>
-        {* debug *}
         <div class="glm-billing-input">
-            {* TODO: Check $billing_settings.payment_methods *}
             <label> <input class="payment_option" type="radio" name="payment_option" value="pay_by_credit_card" checked> Pay by Credit Card </label>
             <label> <input class="payment_option" type="radio" name="payment_option" value="pay_by_check"> Pay by Check </label>
-            {if !$lockedToMember}
             <label> <input class="payment_option" type="radio" name="payment_option" value="mark_paid"> Mark Paid </label>
-            {/if}
         </div>
     </div>
+    {/if}
 
     {if isset( $account.fieldData.payment_profile_card ) && $account.fieldData.payment_profile_card}
         <div class="glm-billing-field glm-billing-credit">
@@ -217,8 +217,12 @@ jQuery(document).ready(function($){
                 $('.ccard').prop('disabled', true);
             {/if}
         } else if ( payment_option == 'mark_paid' ) {
-            $('.glm-billing-credit').hide();
-            $('.ccard').prop('disabled', true);
+            {if $billing_settings.proc_methods == 4}
+                $('.sq-payment-form').hide();
+            {else}
+                $('.glm-billing-credit').hide();
+                $('.ccard').prop('disabled', true);
+            {/if}
         } else {
             {if $billing_settings.proc_methods == 4}
                 $('.sq-payment-form').show();
index 5c9f1fb..6c04421 100644 (file)
@@ -105,6 +105,11 @@ jQuery(document).ready(function($){
                 alert( 'Not a valid Account #' );
                 $('#invoice_number').val('');
                 $('#membername').html('');
+                $('#member_renewing').data( 'amount', '' );
+                $('#member_renewing').val( '' );
+                $('#billing-total-due').hide();
+                $('#billing-member-name').hide();
+                getPageTotal();
             } else {
                 // Set the account and member inputs
                 $('#account_id').val( msg.account_id );
@@ -112,19 +117,32 @@ jQuery(document).ready(function($){
                 if ( msg.invoice.paid.value == "1" ) {
                     $('#invoice_number').val('');
                     $('#membername').html('');
+                    $('#member_renewing').data( 'amount', '' );
+                    $('#member_renewing').val( '' );
                     alert( 'This invoice has already been paid!' );
+                    getPageTotal();
+                    $('#billing-total-due').hide();
+                    $('#billing-member-name').hide();
                     return false;
                 }
-                if ( msg.invoice_type ) {
-                    console.log( 'invoice_type', msg.invoice_type );
-                        $('#member_renewing').data( 'amount', msg.invoice.amount_total );
-                        $('#member_renewing').val( msg.invoice_type );
-                        $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true);
-                        $('#billing-msg-center').hide();
-                        $('#membername').html(msg.invoice.member_name);
-                        $('#billing-total-due').show();
-                        $('#billing-member-name').show();
-                        getPageTotal();
+                if ( msg.status ) {
+                    // console.log( 'invoice_type', msg.invoice_type );
+                    $('#member_renewing').data( 'amount', msg.invoice.amount_total );
+                    $('#member_renewing').val( msg.invoice_type );
+                    // $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true);
+                    $('#billing-msg-center').hide();
+                    $('#membername').html(msg.invoice.member_name);
+                    $('#billing-total-due').show();
+                    $('#billing-member-name').show();
+                    getPageTotal();
+                } else {
+                    $('#invoice_number').val('');
+                    $('#membername').html('');
+                    $('#member_renewing').data( 'amount', '' );
+                    $('#member_renewing').val( '' );
+                    $('#billing-total-due').hide();
+                    $('#billing-member-name').hide();
+                    getPageTotal();
                 }
             }
         });