Adding renew page.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 23 Mar 2018 19:19:58 +0000 (15:19 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 23 Mar 2018 19:19:58 +0000 (15:19 -0400)
Working on the renew page for members.
Showing their employees.
Select unselecting them will update the total amount for the page.

classes/billingSupport.php
css/admin.css
models/admin/member/billing.php
views/admin/billing/memberBillingSubHeader.html
views/admin/billing/renew.html [new file with mode: 0644]

index 80a55c2..7f82b1d 100644 (file)
@@ -741,5 +741,57 @@ class GlmBillingSupport
 
     }
 
+    public function getInvoicTypeById( $id )
+    {
+        return $this->wpdb->get_row(
+            $this->wpdb->prepare(
+                "SELECT *
+                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+                  WHERE id = %d",
+                $id
+            ),
+            ARRAY_A
+        );
+    }
+
+    public function getMembersInvoiceTypeByRefDest( $ref_dest )
+    {
+        return $this->wpdb->get_var(
+            $this->wpdb->prepare(
+                "SELECT id
+                   FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX  . "invoice_types
+                  WHERE member_type IN (
+                        SELECT member_type
+                          FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                         WHERE id = %d )",
+                $ref_dest
+            )
+        );
+    }
+
+    public function getListOfAccountEmployees( $member_id )
+    {
+        $accounts = array();
+        // This may need to have filters setup in the contact plugin as well.
+        $employees = apply_filters( 'glm_contact_has_employees', '', $member_id );
+        foreach ( $employees as $ref_dest ) {
+            $invoice         = false;
+            $billing_account = $this->getAccountByRefDest( $ref_dest );
+            // Need also to get the members type to look up which invoice_type to use
+            $invoice_type_id =  $this->getMembersInvoiceTypeByRefDest( $member_id );
+            if ( $invoice_type_id ) {
+                $invoice = $this->getInvoicTypeById( $invoice_type_id );
+            }
+            $accounts[] = array(
+                'id'       => $billing_account['id'],
+                'ref_dest' => $billing_account['ref_dest'],
+                'ref_name' => $billing_account['ref_name'],
+                'invoice'  => $invoice,
+                'email'    => $billing_account['email']
+            );
+        }
+        return $accounts;
+    }
+
 }
 
index 491b063..a39ce51 100644 (file)
@@ -8,3 +8,18 @@
 .glm-admin-table th {
     white-space: nowrap;
 }
+
+.glm-grid-container {
+    display: grid;
+    grid-template-columns: 600px 200px;
+    grid-gap: 30px;
+    /* background-color: #fff; */
+    /* color: #444; */
+}
+
+.glm-grid-item {
+    /* background-color: #444; */
+    /* color: #fff; */
+    border-radius: 5px;
+    padding: 20px;
+}
index acc47ec..4de6596 100644 (file)
@@ -119,12 +119,18 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         $invoices           = false;
         $paymentSuccess     = false;
         $paymentError       = false;
+        $hasBillingAccount  = false;
+        $employees          = false;
+        $member_invoice     = false;
 
         // For lockedToMember.
         $lockedToMember = false;
         $lockedWhereT   = 'true';
         $lockedWhere    = 'true';
 
+        // Call in the support class
+        $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
         // Check if there's a logged in user who is locked to their own entity.
         $lockedToMember = apply_filters('glm_members_locked_to_member_id', false);
         if ($lockedToMember) {
@@ -171,6 +177,21 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         }
 
         switch ( $option ) {
+        case 'renew':
+            $view = 'renew';
+
+            $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+            if ( $member_invoice_id ) {
+                $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id );
+                // echo '<pre>$member_invoice: ' . print_r( $member_invoice, true ) . '</pre>';
+            }
+
+            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+            // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
+
+            // Get a list of this accounts employees. If they have any.
+
+            break;
         case 'account':
             require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
             $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
@@ -224,8 +245,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             $view = 'editAccount';
             break;
         case 'view':
-            // Call in the support class
-            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
 
             $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] );
 
@@ -371,9 +390,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) {
                     // Need to record the payment
 
-                    // Support class
-                    $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
-
                     // Set transaction_time to current time.
                     $_REQUEST['transaction_time'] = date('Y-m-d H:i:s');
                     // Create new payment.
@@ -408,9 +424,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
                 );
                 $account = $Accounts->editEntry( $accountID );
 
-                // Support class
-                $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
-
                 // Get unpaid invoices
                 $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
                 if ( !empty( $invoices ) ) {
@@ -450,9 +463,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             );
             $account = $Accounts->editEntry( $accountID );
 
-            // Support class
-            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
-
             // Get unpaid invoices
             $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] );
             // echo '<pre>$invoices: ' . print_r( $invoices, true ) . '</pre>';
@@ -469,19 +479,20 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             break;
         case 'list':
-            $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
             $view = 'statements';
-            // Get the list of invoices for this member.
-            $statements = $BillingSupport->getStatementsByRefDest( $this->memberID );
-            // echo '<pre>$statements: ' . print_r( $statements, true ) . '</pre>';
-            if ( $statements ) {
-                $transactions = $statements['transactions'];
-                $account_data = $statements['account_data'];
-                $balance_due  = $statements['balance_due'];
-            }
             break;
         }
-        // echo '<pre>$this->config: ' . print_r( $this->config, true ) . '</pre>';
+
+        // Get the list of invoices for this member.
+        $statements = $BillingSupport->getStatementsByRefDest( $this->memberID );
+        // echo '<pre>$statements: ' . print_r( $statements, true ) . '</pre>';
+        if ( $statements ) {
+            $transactions      = $statements['transactions'];
+            $account_data      = $statements['account_data'];
+            $balance_due       = $statements['balance_due'];
+            $hasBillingAccount = true;
+        }
+        // echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
 
         // Compile template data
         $templateData = array(
@@ -511,6 +522,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             'invoices'           => $invoices,
             'paymentSuccess'     => $paymentSuccess,
             'paymentError'       => $paymentError,
+            'hasBillingAccount'  => $hasBillingAccount,
+            'employees'          => $employees,
+            'member_invoice'     => $member_invoice,
         );
 
         // Return status, any suggested view, and any data to controller.
index c54db63..feaf062 100644 (file)
@@ -1,5 +1,34 @@
-<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
-    <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}" class="nav-tab{if $option == 'list'} nav-tab-active{/if}">Statements</a>
-    <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=account" class="nav-tab{if $option == 'account'} nav-tab-active{/if}">Account Info</a>
-    <a href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=makepayment" class="nav-tab{if $option == 'makepayment'} nav-tab-active{/if}">Make a Payment</a>
-</h2>
+<div class="glm-grid-container">
+    <div class="glm-grid-item">
+        <div><strong>Member Name:</strong> {$memberData.name}</div>
+        <div>{$memberData.member_type_short}</div>
+        {if $account_data}
+        <div><strong>Renewal date:</strong> {$account_data.renewal_date|strtotime|date_format}</div>
+        {/if}
+    </div>
+
+    <div class="glm-grid-item">
+        <ul>
+            <li>
+                <a
+                    href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=account"
+                    class="">Billing Info</a>
+            </li>
+            <li>
+                <a
+                    href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}"
+                    class="">All Statements</a>
+            </li>
+            <li>
+                <a
+                    href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=renew"
+                    class="">Renew</a>
+            </li>
+            <li>
+                <a
+                    href="{$thisUrl}?page=glm-members-admin-menu-member&glm_action=billing&member={$memberID}&option=makepayment"
+                    class="">Pay Invoices</a>
+            </li>
+        </ul>
+    </div>
+</div>
diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html
new file mode 100644 (file)
index 0000000..bd9b804
--- /dev/null
@@ -0,0 +1,99 @@
+{include file='admin/member/header.html'}
+{include file='admin/billing/memberBillingSubHeader.html'}
+
+<div id="billing-payment-form" style="max-width:750px;">
+
+    {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}
+
+    {if $messages}
+        {foreach $messages as $message}
+            <div class="">{$message}</div>
+        {/foreach}
+    {/if}
+<h3>Renew membership</h3>
+
+    <form action="{$thisUrl}?page={$thisPage}&glm_action=billing&option=makePayment" method="post">
+        <input type="hidden" name="page" value="{$thisPage}" />
+        <input type="hidden" name="glm_action" value="billing" />
+        <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" id="total_renew_amount" name="total_renew_amount" value="" />
+
+        <h4>Employees:</h4>
+
+        {if $member_invoice}
+        <div>
+            <label>
+                <input type="checkbox" name="member_renewing" data-amount="{$member_invoice.amount}" value="{$account_data.id}" checked disabled>{$account_data.ref_name}
+                {$member_invoice.name}
+                {$member_invoice.amount}
+            </label>
+        </div>
+        {/if}
+
+        {foreach $employees as $employee}
+            <div>
+                <label>
+                    <input
+                    type="checkbox"
+                    name="employees[]"
+                    data-amount="{$employee.invoice.amount}"
+                    value="{$employee.id}"
+                    checked='checked'>{$employee.ref_name}
+                    {$employee.invoice.name}
+                    {$employee.invoice.amount}
+                </label>
+            </div>
+        {/foreach}
+
+        <div id="renew_total">
+        </div>
+
+        <input class="button button-primary" type="submit" value="Renew Memberships">
+
+    </form>
+</div>
+
+<script>
+jQuery(document).ready(function($){
+
+    $('#billing-invoice-select').change(function(){
+        // Get the data-amount and set the amount being paid.
+        $('#billing-amount').val( $(this).find('option:selected').data( 'amount') );
+    });
+
+    function getPageTotal(){
+
+        // Calculate the total for this page.
+        // Get the member_renewing amount.
+        var member_renewing_amount = parseFloat( $('input[name=member_renewing]').data('amount') );
+
+        // Get each employee and add their amounts.
+        $('input[name^=employees]').each(function(){
+            var isChecked = $(this).prop('checked');
+            if ( isChecked ) {
+                member_renewing_amount += parseFloat( $(this).data('amount') );
+            }
+        });
+        $('#renew_total').html( '$' + member_renewing_amount );
+        $('#total_renew_amount').val( member_renewing_amount );
+
+    }
+
+    getPageTotal();
+
+    // trigger total if changing employees
+    $('input[name^=employees]').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);
+
+});
+</script>
+
+
+{include file='admin/footer.html'}