Can now add an employee from the admin billing renewal form.
// 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(
$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 ) {
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(
'required' => true,
),
+ 'invoice_type' => array(
+ 'field' => 'invoice_type',
+ 'type' => 'integer',
+ 'use' => 'a',
+ 'required' => false,
+ ),
+
// Anniversary Date
'anniversary_date' => array(
'field' => 'anniversary_date',
'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;
}
}
$account_status = false;
$accounts = false;
$errors = false;
+ $invoiceTypes = false;
// For lockedToMember.
$lockedToMember = false;
// 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';
// 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;
'payable_types' => $payable_types,
'account_status' => $account_status,
'accounts' => $accounts,
+ 'invoiceTypes' => $invoiceTypes,
);
// Return status, any suggested view, and any data to controller.
</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({
},
});
+ // 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);
}
} 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(){