Billing renewal form now deals with adding employees.
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 25 Apr 2018 14:35:36 +0000 (10:35 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 25 Apr 2018 14:35:36 +0000 (10:35 -0400)
Can now add an employee from the admin billing renewal form.

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

index 7a6e3ad..f671429 100644 (file)
@@ -897,14 +897,14 @@ class GlmBillingSupport
         // echo '<pre>$main_billing_account: ' . print_r( $main_billing_account, true ) . '</pre>';
         $Employees = new GlmDataEmployees( $this->wpdb, $this->config );
         $employees = $Employees->getList( "T.account = " . $main_billing_account['id'] );
-        echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
+        // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
 
         if ( isset( $employees ) && is_array( $employees ) ) {
             foreach ( $employees as $emp ) {
                 $invoice            = false;
                 $billing_account_id = $emp['employee'];
                 $billing_account = $this->getAccountById( $billing_account_id );
-                echo '<pre>$billing_account: ' . print_r( $billing_account, true ) . '</pre>';
+                // echo '<pre>$billing_account: ' . print_r( $billing_account, true ) . '</pre>';
                 // If we don't have an account for this member then one
                 // Needs to be created.
                 $ref_dest = $this->wpdb->get_var(
@@ -915,7 +915,7 @@ class GlmBillingSupport
                         $emp['employee_name']
                     )
                 );
-                echo '<pre>$ref_dest: ' . print_r( $ref_dest, true ) . '</pre>';
+                // echo '<pre>$ref_dest: ' . print_r( $ref_dest, true ) . '</pre>';
                 if ( !$billing_account ) {
                     // Get the Member Name
                     if ( $member_name ) {
@@ -939,7 +939,7 @@ class GlmBillingSupport
                 if ( $billing_account && $ref_dest ) {
                     // Need also to get the members type to look up which invoice_type to use
                     $invoice_type_id =  $this->getMembersInvoiceTypeByRefDest( $ref_dest );
-                    echo '<pre>$invoice_type_id: ' . print_r( $invoice_type_id, true ) . '</pre>';
+                    // echo '<pre>$invoice_type_id: ' . print_r( $invoice_type_id, true ) . '</pre>';
                     if ( $invoice_type_id ) {
                         $invoice = $this->getInvoiceTypeById( $invoice_type_id );
                         $accounts[$billing_account_id] = array(
index 100650f..5a4ac4d 100644 (file)
@@ -146,6 +146,13 @@ class GlmDataAccounts extends GlmDataAbstract
                 'required' => true,
             ),
 
+            'invoice_type' => array(
+                'field'    => 'invoice_type',
+                'type'     => 'integer',
+                'use'      => 'a',
+                'required' => false,
+            ),
+
             // Anniversary Date
             'anniversary_date' => array(
                 'field'    => 'anniversary_date',
@@ -328,14 +335,15 @@ class GlmDataAccounts extends GlmDataAbstract
             'id'               => $fSave['id'],
             'name'             => $fSave['ref_name'],
             'anniversary_date' => $fSave['anniversary_date'],
+            'invoice_type'     => $fSave['invoice_type'],
         );
 
-        $memberList = $this->getList($where, $order, $fieldVals, $idField, $start, $limit);
+        $accountList = $this->getList($where, $order, $fieldVals, $idField, $start, $limit);
 
         // Restore the fields list
         $this->fields = $fSave;
 
-        return $memberList;
+        return $accountList;
     }
 
 }
index 726c838..c3de638 100644 (file)
@@ -127,6 +127,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
         $account_status     = false;
         $accounts           = false;
         $errors             = false;
+        $invoiceTypes       = false;
 
         // For lockedToMember.
         $lockedToMember = false;
@@ -211,7 +212,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
 
             // Get a list of this accounts employees. If they have any.
             $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
-            echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
+            // echo '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
 
             // Load DataClass for Management.
             require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php';
@@ -225,6 +226,10 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             // Need to get the accounts
             $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
             $accounts = $Accounts->getSimpleAccountList( "T.boss <> true AND T.boss IS NOT NULL AND T.invoice_type != 0", 'ref_name' );
+            // echo '<pre>$accounts: ' . print_r( $accounts, true ) . '</pre>';
+
+            $invoiceTypes = $BillingSupport->getAllPayableInvoiceTypes();
+            // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
 
             break;
 
@@ -664,6 +669,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling
             'payable_types'      => $payable_types,
             'account_status'     => $account_status,
             'accounts'           => $accounts,
+            'invoiceTypes'       => $invoiceTypes,
         );
 
         // Return status, any suggested view, and any data to controller.
index 5ab1fec..9fd53b8 100644 (file)
                 </div>
             </div>
 
-            <div class="glm-billing-field">
+            <div id="glm-emp-list" class="glm-billing-field">
                 <div class="glm-billing-label">
                     <strong>Associated Members/Employees</strong>
                 </div>
                 <div class="glm-billing-input">
                     <input id="glm-billing-member-list" placeholder="Lookup Member">
-                    <table>
+                    <table id="glm-billing-employees">
                         {foreach $employees as $employee}
                             <tr>
                                 <td>
 <script>
 jQuery(document).ready(function($){
 
-    var accounts = [ {foreach $accounts as $m} { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}' }, {/foreach} ];
+    var accounts = [ {foreach $accounts as $m} { label: "{$m.ref_name|unescape:'html'|replace:'"':''}", value: "{$m.ref_name|unescape:'html'|replace:'"':''}", id: '{$m.id}', invoice_type: {$m.invoice_type} }, {/foreach} ];
+    var isBoss = {if $account.fieldData.boss.value}true{else}false{/if};
+    var invoiceTypes = [ {foreach $invoiceTypes as $it} { id: {$it.id}, name: "{$it.name|unescape:'html'|replace:'"':''}", amount: "{$it.amount}" }, {/foreach} ];
 
     // Setup autocomplete for both inputs
     $('#glm-billing-member-list').autocomplete({
@@ -146,12 +148,56 @@ jQuery(document).ready(function($){
         },
     });
 
+    // If the boss flag in unchecked then hide the employees box and
+    // disable the employees inputs.
+    $('#billing-boss').change(function(){
+        if ( $(this).is(':checked') ) {
+            isBoss = true;
+        } else {
+            isBoss = false;
+        }
+        setupEmployeesPart();
+    });
+    function setupEmployeesPart() {
+        if ( isBoss ) {
+            $('#glm-emp-list').show();
+            $('input[name^="employees"]').each(function(){
+                $(this).removeAttr('disabled');
+            });
+        } else {
+            $('#glm-emp-list').hide();
+            $('input[name^="employees"]').each(function(){
+                $(this).prop('disabled', true);
+            });
+        }
+    }
+    setupEmployeesPart();
+
     function addEmployee( employee ) {
-        var html = '<div class="glm-billing-employee">';
-        html += '<input type="hidden" name="employees[' + employee.id + ']" value="1">';
+
+        // Need to get the invoice name and amount
+        var invoiceName   = '';
+        var invoiceAmount = '';
+        var index, len;
+
+        for ( index = 0, len = invoiceTypes.length; index < len; ++index ) {
+            if ( invoiceTypes[index].id == employee.invoice_type ) {
+                invoiceName   = invoiceTypes[index].name;
+                invoiceAmount = invoiceTypes[index].amount;
+            }
+        }
+
+        var html = '<tr><td>';
+        html += '<input checked id="employee-' + employee.id + '" type="checkbox" name="employees[' + employee.id + ']" value="' + employee.id + '">';
+        html += '</td><td>';
+        html += '<label for="employee-' + employee.id + '">';
         html += employee.label;
-        html += '<span class="glm-billing-employee-del dashicons dashicons-trash glm-right"></span>';
-        html += '</div>';
+        html += '</label>';
+        html += '</td><td>';
+        html += invoiceName;
+        html += '</td><td class="price">';
+        html += invoiceAmount;
+        html += '</td></tr>';
         $('#glm-billing-employees').append(html);
     }
 
@@ -175,8 +221,6 @@ jQuery(document).ready(function($){
         } else {
             var member_renewing_amount = parseFloat( $('input[name=member_renewing]').data('amount') );
         }
-        console.log( member_renewing_amount );
-
 
         // Get each employee and add their amounts.
         $('input[name^=employees]').each(function(){