Export reports
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Mar 2019 18:45:50 +0000 (14:45 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Mar 2019 18:45:50 +0000 (14:45 -0400)
Can now export reports to csv file.

classes/billingSupport.php
models/admin/ajax/reportsListExport.php [new file with mode: 0644]
models/admin/billing/reports.php
models/front/billing/paymentForm.php
setup/validActions.php
views/admin/ajax/reportsListExportCsv.html [new file with mode: 0644]
views/admin/billing/exportReportModal.html
views/front/billing/paymentForm.html

index 9fc180f..1073969 100644 (file)
@@ -925,7 +925,7 @@ class GlmBillingSupport
               WHERE amount > 0
                 AND recurring
                 AND recurrence = 20
-            ORDER BY name",
+            ORDER BY amount,name",
             ARRAY_A
         );
     }
diff --git a/models/admin/ajax/reportsListExport.php b/models/admin/ajax/reportsListExport.php
new file mode 100644 (file)
index 0000000..2715f39
--- /dev/null
@@ -0,0 +1,235 @@
+<?php
+
+/**
+ * Gaslight Media Members Database
+ * Members List Export by AJAX
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @version  0.1
+ */
+
+
+// Load Member Info data abstract
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataTransactions.php';
+
+/**
+ *
+ * This class exports the currently selected accounts list
+ * to a printable HTML file, to a CSV file, or otherwise.
+ */
+class GlmMembersAdmin_ajax_reportsListExport extends GlmDataTransactions
+{
+
+    /**
+     * WordPress Database Object
+     *
+     * @var $wpdb
+     * @access public
+     */
+    public $wpdb;
+    /**
+     * Plugin Configuration Data
+     *
+     * @var $config
+     * @access public
+     */
+    public $config;
+
+    /**
+     * Constructor
+     *
+     * This constructor sets up this model. At this time that only includes
+     * storing away the WordPress data object.
+     *
+     * @return object Class object
+     *
+     */
+    public function __construct ($wpdb, $config)
+    {
+
+        // Save WordPress Database object
+        $this->wpdb = $wpdb;
+
+        // Save plugin configuration object
+        $this->config = $config;
+
+        parent::__construct(false, false);
+
+    }
+
+    public function checkFlag($t) {return isset($_REQUEST[$t]) && $_REQUEST[$t] == 'on';}
+    /**
+     * Perform Model Action
+     *
+     * This modelAction takes an AJAX image upload and stores the image in the
+     * media/images directory of the plugin.
+     *
+     * This model action does not return, it simply does it's work then calls die();
+     *
+     * @param $actionData
+     *
+     * Echos JSON string as response and does not return
+     */
+    public function modelAction ($actionData = false)
+    {
+
+        $categories      = false;
+        $haveAccounts    = false;
+        $list            = false;
+        $success         = false;
+        $filterPending   = false;
+        $filterArchived  = false;
+        $filterOverdue   = false;
+        $filterExpired   = false;
+        $haveFilter      = false;
+        $numbDisplayed   = false;
+        $lastDisplayed   = false;
+        $paging          = true;
+        $prevStart       = false;
+        $nextStart       = false;
+        $start           = 1;
+        $limit           = 20;        // Set to the number of listings per page
+        $namesList       = false;
+        $where_params    = array();
+        $sub_where_parts = array();
+
+        // Check selected fields
+        $select = array(
+            'exportId'              => $this->checkFlag('exportId'),
+            'exportTransactionTime' => $this->checkFlag('exportTransactionTime'),
+            'exportMember'          => $this->checkFlag('exportMember'),
+            'exportInvoiceAmount'   => $this->checkFlag('exportInvoiceAmount'),
+            'exportPaymentAmount'   => $this->checkFlag('exportPaymentAmount'),
+            'exportNotes'           => $this->checkFlag('exportNotes'),
+        );
+
+        // When searching
+        $reg_options = array(
+            'options' => array(
+                'regexp' => '%[0-9]{2}/[0-9]{2}/[0-9]{4}%'
+            )
+        );
+        if ( isset( $_REQUEST['invoice_types'] ) && $invoiceTypes = filter_var( $_REQUEST['invoice_types'], FILTER_VALIDATE_INT,array( 'flags' => FILTER_FORCE_ARRAY ) ) ) {
+            $where_params[] = " T.account IN (
+                SELECT id
+                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                 WHERE invoice_type IN (" . implode(',', $invoiceTypes) . ")
+            ) ";
+        }
+
+        if ( isset( $_REQUEST['counties'] ) && $countiesSelected = filter_var( $_REQUEST['counties'], FILTER_VALIDATE_INT,array( 'flags' => FILTER_FORCE_ARRAY ) ) ) {
+            $where_params[]    = " T.account IN (
+                SELECT id
+                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                 WHERE billing_county IN (" . implode(',', $countiesSelected) . ")
+            ) ";
+        }
+
+        if ( isset( $_REQUEST['member_name'] ) && $member_name = filter_var( $_REQUEST['member_name'], FILTER_SANITIZE_STRING ) ) {
+            $where_params[] = "T.account IN (
+                SELECT id
+                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                 WHERE ref_name like '%" . esc_sql( $member_name )  . "%'
+            )";
+        }
+        if ( isset( $_REQUEST['account_number'] ) && $account_number = filter_var( $_REQUEST['account_number'], FILTER_SANITIZE_STRING ) ) {
+            $where_params[] = "T.account IN (
+                SELECT id
+                  FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                 WHERE account_number = '" . esc_sql( $account_number )  . "'
+            )";
+        }
+        if ( isset( $_REQUEST['transactionTypes'] ) && $transactionTypes = filter_var( $_REQUEST['transactionTypes'], FILTER_VALIDATE_INT,array( 'flags' => FILTER_FORCE_ARRAY ) ) ) {
+            $where_params[] = "T.type IN (" . implode(',', $transactionTypes) . ")";
+        }
+        if ( isset( $_REQUEST['fromDate'] ) && $_REQUEST['fromDate']
+            && $fromDate = filter_var( $_REQUEST['fromDate'], FILTER_VALIDATE_REGEXP, $reg_options )
+        ) {
+            $from_date = date( 'Y-m-d', strtotime( $fromDate ) );
+            $where_params[] = "T.transaction_time >= '$from_date'";
+        }
+        if ( isset( $_REQUEST['toDate'] ) && $_REQUEST['toDate']
+            && $toDate = filter_var( $_REQUEST['toDate'], FILTER_VALIDATE_REGEXP, $reg_options )
+        ) {
+            $to_date = date( 'Y-m-d', strtotime( $toDate ) );
+            $where_params[] = "T.transaction_time <= '$to_date'";
+        }
+        if ( isset( $_REQUEST['searchName'] )
+            && $searchName = filter_var( $_REQUEST['searchName'], FILTER_SANITIZE_STRING )
+        ) {
+            $where_params[] = "T.ref_name like '%" . esc_sql( $searchName ) . "%'";
+        }
+
+        // Get the setting for days before and after.
+        $days_before_renewal = $this->config['settings']['days_before_renewal'];
+        $days_after_expired  = $this->config['settings']['days_after_expired'];
+        $curDate             = date( 'Y-m-d' );
+
+        if ( !empty( $sub_where_parts ) ) {
+            $where_params[] = "(" . implode( ' OR ', $sub_where_parts ) . ")";
+        }
+
+        // Build the $where string from the $where_parts array.
+        // By implode with AND.
+        $where = implode( ' AND ', $where_params );
+
+        // Get a current list of accounts without paging
+        $orderBy = 'transaction_time ASC';
+        $this->member_data = true;
+        $this->notes       = true;
+        $list    = $this->getList( $where, $orderBy, true );
+
+        // If we have list entries - even if it's an empty list
+        $success      = true;
+        $haveAccounts = false;
+        if ( $list !== false ) {
+            $success      = true;
+            $accountCount = count($list);
+            $haveAccounts = true;
+        }
+
+        // Compile template data
+        $templateData = array(
+            'select'         => $select,
+            'haveAccounts'   => $haveAccounts,
+            'accounts'       => $list,
+            'accountCount'   => $accountCount,
+            'haveFilter'     => $haveFilter,
+            'filterArchived' => $filterArchived,
+            'filterPending'  => $filterPending,
+            'numbDisplayed'  => $numbDisplayed,
+            'lastDisplayed'  => $lastDisplayed,
+            'paging'         => $paging,
+            'prevStart'      => $prevStart,
+            'nextStart'      => $nextStart,
+            'start'          => $start,
+            'limit'          => $limit,
+            'namesList'      => $namesList
+        );
+
+        $view = 'admin/ajax/reportsListExportCsv.html';
+        header("Content-Type: text/csv");
+        header("Content-Disposition: attachment; filename=file.csv");
+
+        // Disable caching
+        header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
+        header("Pragma: no-cache"); // HTTP 1.0
+        header("Expires: 0"); // Proxies
+
+        // Return status, suggested view, and data to controller
+        return array(
+            'status'           => $success,
+            'menuItemRedirect' => false,
+            'modelRedirect'    => false,
+            'view'             => $view,
+            'data'             => $templateData
+        );
+
+    }
+
+}
index 8621b40..d092f01 100644 (file)
@@ -268,7 +268,6 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
                 $this->member_data = true;
                 $this->notes       = true;
                 $accountsResult    = $this->getList( $reportWhere, $orderBy, true, 'id', $start, $limit );
-                // echo '<pre>' . print_r( $accountsResult, true ) . '</pre>';
                 $totalAccounts     = $this->getStats( $reportWhere );
                 $totalInvoices     = $this->getInvoiceTotal( $reportWhere );
                 $totalPayments     = $this->getPaymentTotal( $reportWhere );
index b57ffab..ede1f51 100644 (file)
@@ -88,41 +88,32 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
     public function modelAction( $actionData = false )
     {
         // Initialize Variables Here
-        $fromMemberMenu    = false;
-        $this->memberId    = false;
-        $memberData        = false;
-        $memberName        = false;
-        $haveMember        = false;
-        $haveAccount       = false;
-        $option            = 'payment';
-        $view              = 'paymentForm';
-        $account           = false;
-        $accountId         = 0;
-        $account_data      = false;
-        $balance_due       = false;
-        $invoiceHtml       = false;
-        $management        = false;
-        $messages          = array();
-        $paymentSuccess    = false;
-        $paymentError      = false;
-        $hasBillingAccount = false;
-        $member_invoice    = false;
-        $payable_types     = false;
-        $account_status    = false;
-        $unregistered      = false;
-        $invoiceId         = false;
-
-        // For lockedToMember.
-        $lockedToMember = false;
-        $lockedWhereT   = 'true';
-        $lockedWhere    = 'true';
-
-        // Check for unregistered.
-        if ( isset( $actionData['request']['unregistered'] ) && filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN ) ) {
-            $unregistered = filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN );
-        }
-
-        // echo '<pre>$unregistered: ' . print_r( $unregistered, true ) . '</pre>';
+        $fromMemberMenu      = false;
+        $this->memberId      = false;
+        $memberData          = false;
+        $memberName          = false;
+        $haveMember          = false;
+        $haveAccount         = false;
+        $option              = 'payment';
+        $view                = 'paymentForm';
+        $account             = false;
+        $accountId           = 0;
+        $account_data        = false;
+        $balance_due         = false;
+        $invoiceHtml         = false;
+        $management          = false;
+        $messages            = array();
+        $paymentSuccess      = false;
+        $paymentError        = false;
+        $hasBillingAccount   = false;
+        $member_invoice      = false;
+        $payable_types       = false;
+        $account_status      = false;
+        $invoiceId           = false;
+        $selectedPaymentType = false;
+        $lockedWhereT        = 'true';
+        $lockedWhere         = 'true';
+        $lockedToMember      = true;
 
         // Call in the support class
         $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
@@ -172,10 +163,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
             } else  {
                 $view = 'paymentForm';
 
-                if ( $unregistered ) {
-                    $lockedToMember = true;
-                }
-
                 // Get list of payable invoice_types
                 $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
                 // echo '<pre>$payable_types: ' . print_r( $payable_types, true ) . '</pre>';
@@ -200,11 +187,30 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
             $error = false;
             $view  = 'paymentFormProcess';
 
+            // 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 );
             } else {
                 die( 'Error: no invoiceId' );
             }
+            // 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'] ) {
+                        $invoicePaymentType = $lineItem['line_item_type'];
+                    }
+                }
+            }
+            // 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.
@@ -250,10 +256,10 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
                     // Get list of payable invoice_types
                     $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
 
-                    $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
-                    if ( $member_invoice_id ) {
-                        $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
-                    }
+                    // $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
+                    // if ( $member_invoice_id ) {
+                    //     $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
+                    // }
 
                     if ( $this->config['settings']['allow_employees'] ) {
                         // Get a list of this accounts employees. If they have any.
@@ -341,7 +347,6 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
             'accountId'          => $accountId,
             'option'             => $option,
             'fromMemberMenu'     => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ),
-            'lockedToMember'     => $lockedToMember,
             'invoiceId'          => $invoiceId,
             'memberId'           => $this->memberId,
             'haveMember'         => $haveMember,
@@ -364,6 +369,7 @@ class GlmMembersFront_billing_paymentForm // extends GlmDataBilling
             'member_invoice'     => $member_invoice,
             'payable_types'      => $payable_types,
             'account_status'     => $account_status,
+            'lockedToMember'     => $lockedToMember,
         );
 
         // Return status, any suggested view, and any data to controller.
index 940eb8f..a1be48e 100644 (file)
@@ -72,6 +72,7 @@ $glmMembersBillingAddOnValidActions = array(
             'createPDFLabels'         => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'createCSVLabels'         => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'accountsListExport'      => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+            'reportsListExport'       => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'paymentsListExport'      => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'billingFlagExpiredUsers' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'billingFixActiveUsers'   => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
diff --git a/views/admin/ajax/reportsListExportCsv.html b/views/admin/ajax/reportsListExportCsv.html
new file mode 100644 (file)
index 0000000..c4dff4e
--- /dev/null
@@ -0,0 +1,18 @@
+{if $haveAccounts}
+{if $select.exportId}"ID",{/if}
+{if $select.exportTransactionTime}"Transaction Time",{/if}
+{if $select.exportMember}"{$terms.term_member_cap} Name",{/if}
+{if $select.exportInvoiceAmount}"Invoice Amount",{/if}
+{if $select.exportPaymentAmount}"Payment Amount",{/if}
+{if $select.exportNotes}"Notes"{/if}
+
+{foreach $accounts as $account}
+{if $select.exportId}"{$account.id}",{/if}
+{if $select.exportTransactionTime}"{$account.transaction_time.datetime}",{/if}
+{if $select.exportMember}"{$account.member_name}",{/if}
+{if $select.exportInvoiceAmount}"{$account.current_invoice_total|string_format:"%.2f"}",{/if}
+{if $select.exportPaymentAmount}"{$account.current_payment_total|string_format:"%.2f"}",{/if}
+{if $select.exportNotes}"{$account.notes}"{/if}
+
+{/foreach}
+{else}No Accounts Selected{/if}
index 7601dbf..6c26944 100644 (file)
@@ -1,13 +1,40 @@
 <div id="exportReportDialog" class="glm-dialog-box" title="Export Billing Reports">
     <form id="exportForm" action="{$ajaxUrl}" method="post" enctype="multipart/form-data">
         <input type="hidden" name="action" value="glm_members_admin_ajax">
-        <input type="hidden" name="glm_action" value="accountsListExport">
+        <input type="hidden" name="glm_action" value="reportsListExport">
         <table class="glm-admin-table">
-            <tr><th>Show Active: </th><td><input type="checkbox" name="filterActive" {if $filterActive}checked{/if}></td></tr>
-            <tr><th>Show Pending: </th><td><input type="checkbox" name="filterPending" {if $filterPending}checked{/if}></td></tr>
-            <tr><th>Show Overdue: </th><td><input type="checkbox" name="filterOverdue" {if $filterOverdue}checked{/if}></td></tr>
-            <tr><th>Show Archived: </th><td><input type="checkbox" name="filterArchived" {if $filterArchived}checked{/if}></td></tr>
-            <tr><th>Show Expired: </th><td><input type="checkbox" name="filterExpired" {if $filterExpired}checked{/if}></td></tr>
+            <tr>
+                <th>Payment Types</th>
+                <td>
+                    <select multiple size="5" id="invoice_types" name="invoice_types[]">
+                        {foreach $paymentTypes as $paymentType}
+                            <option value="{$paymentType.id}"{if isset($smarty.request.invoice_types) && in_array( $paymentType.id, $smarty.request.invoice_types )} selected{/if}>{$paymentType.name}</option>
+                        {/foreach}
+                    </select>
+                </td>
+            </tr>
+            {if $counties}
+                <tr>
+                    <th>Counties</th>
+                    <td>
+                        <select multiple size="5" id="counties" name="counties[]">
+                            {foreach $counties as $county}
+                                <option value="{$county.id}"{if isset($smarty.request.counties) && in_array( $county.id, $smarty.request.counties )} selected{/if}>{$county.name}</option>
+                            {/foreach}
+                        </select>
+                    </td>
+                </tr>
+            {/if}
+            <tr>
+                <th>Transaction Types</th>
+                <td>
+                    <select multiple size="4" id="transactionTypes" name="transactionTypes[]">
+                        {foreach $actionTypeSel as $typeId => $typeLabel}
+                            <option value="{$typeId}"{if isset($smarty.request.transactionTypes) && in_array( $typeId, $smarty.request.transactionTypes )} selected{/if}>{$typeLabel}</option>
+                        {/foreach}
+                    </select>
+                </td>
+            </tr>
             <tr>
                 <th>Date Range Search: </th>
                 <td>
                                 <input type="checkbox" name="exportMember" checked> {$terms.term_member_cap} Name<br>
                                 <input type="checkbox" name="exportInvoiceAmount" checked> Invoice Amount <br>
                                 <input type="checkbox" name="exportPaymentAmount" checked> Payment Amount <br>
-
+                                <input type="checkbox" name="exportNotes" checked> Notes<br>
                             </td>
                         </tr>
                     </table>
                 </td>
             </tr>
-            <tr>
-                <th>Export to: </th>
-                <td>
-                    <input type="radio" name="type" value="csv" checked="checked"> Export to Spreadsheet (CSV)<br>
-                </td>
-            </tr>
         </table>
         <a id="exportReportsCancel" class="button button-secondary glm-right">Cancel</a>
-        <input type="submit" value="Export" class="button button-primary">
+        <input type="submit" value="Export to CSV" class="button button-primary">
     </form>
 </div>
 
index 9874a4b..36ac87f 100644 (file)
 
         <span id="membername"></span>
 
-        {if $member_invoice}
-            <div class="glm-billing-field">
-                <div class="glm-billing-label glm-required">
-                    Membership Class
-                </div>
-                <div class="glm-billing-input">
-                    {if $settings.allow_membership_choice}
-                        {foreach $payable_types as $type}
-                            <label>
-                                <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}"
-                                {if $type.id == $member_invoice.id}checked{/if}
-                                />
-                                {$type.name} {$type.amount}
-                            </label>
-                        {/foreach}
-                    {else}
-                        <input type="hidden" name="member_renewing" data-amount="{$member_invoice.amount}" value="{$member_invoice.id}" />
-                        {$member_invoice.name} {$member_invoice.amount}
-                    {/if}
-                </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Invoice #
             </div>
-        {else}
-            <div class="glm-billing-field">
-                <div class="glm-billing-label glm-required">
-                    Invoice #
-                </div>
-                <div class="glm-billing-input">
-                    <input id="invoice_number" name="invoice_number" value="{if isset($invoiceId)}{$invoiceId}{/if}" required />
-                </div>
+            <div class="glm-billing-input">
+                <input id="invoice_number" name="invoice_number" value="{if isset($invoiceId)}{$invoiceId}{/if}" required />
             </div>
-            <div class="glm-billing-field">
-                <div class="glm-billing-label glm-required">
-                    Membership Class
-                </div>
-                <div class="glm-billing-input">
-                    {if $settings.allow_membership_choice}
-                        {foreach $payable_types as $type}
-                            <label>
-                                <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}" id="invoice_type_id_{$type.id}" />
-                                {$type.name} {$type.amount}
-                            </label>
-                        {/foreach}
-                    {/if}
-                </div>
+        </div>
+        <div class="glm-billing-field">
+            <div class="glm-billing-label glm-required">
+                Membership Class
+            </div>
+            <div class="glm-billing-input">
+                {if $settings.allow_membership_choice}
+                    {foreach $payable_types as $type}
+                        <label>
+                            <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}" id="invoice_type_id_{$type.id}" />
+                            {$type.name} {$type.amount}
+                        </label>
+                    {/foreach}
+                {else}
+                    <input type="hidden" id="member_renewing" name="member_renewing" data-amount="" value="" />
+                {/if}
             </div>
-        {/if}
+        </div>
 
         <div class="glm-billing-field">
             <div class="glm-billing-label">
@@ -129,11 +108,16 @@ jQuery(document).ready(function($){
                     return false;
                 }
                 if ( msg.invoice_type ) {
-                    // $('input[name=member_renewing]').prop('checked', false);
                     console.log( 'invoice_type', msg.invoice_type );
-                    $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true);
-                    $('#membername').html(msg.invoice.member_name);
-                    getPageTotal();
+                    {if $settings.allow_membership_choice}
+                        $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true);
+                        $('#membername').html(msg.invoice.member_name);
+                        getPageTotal();
+                    {else}
+                        $('#member_renewing').data( 'amount', msg.invoice.amount_total );
+                        $('#member_renewing').val( msg.invoice_type );
+                        getPageTotal();
+                    {/if}
                 }
             }
         });
@@ -157,7 +141,9 @@ jQuery(document).ready(function($){
 
     }
 
-    getPageTotal();
+    {if $settings.allow_membership_choice}
+        getPageTotal();
+    {/if}
 
     // trigger total if changing Membership
     $('input[name=member_renewing]').change(function(){
@@ -169,5 +155,3 @@ jQuery(document).ready(function($){
 
 });
 </script>
-
-