From c7df4194b089663f4293479ae2abb1597ba4d021 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 20 Sep 2018 10:00:28 -0400 Subject: [PATCH] Fix for when adding billing account. Set the invoice type of account based on member type. Set accountID when adding so the form comes up and is not blank. Don't show the current account in search lookup for employees. --- models/admin/member/billing.php | 41 +++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 3bc14a0..e245548 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -436,6 +436,8 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $accountInsertError = true; } else { $accountAdded = true; + // If account is added then get the id + $accountID = $account['fieldData']['id']; } } else { $account = $Accounts->updateEntry( $_REQUEST['id'] ); @@ -446,6 +448,40 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling } } + // Update the Billing Account invoice_type (needs to be related to member_type) + if ( isset( $_REQUEST['member'] ) ) { + $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ); + if ( $member_id ) { + $current_member_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT member_type + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $member_id + ) + ); + if ( $current_member_type ) { + $invoice_type = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE member_type = %d", + $current_member_type + ) + ); + if ( $invoice_type && $accountID ) { + $this->wpdb->update( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + array( 'invoice_type' => $invoice_type ), + array( 'id' => $accountID ), + array( '%d' ), + array( '%d' ) + ); + } + } + } + } + if ( isset( $employees ) && !empty( $employees ) ) { // Check if an employee was removed (deleted) foreach ( $employees as $employee_id => $employee ) { @@ -494,16 +530,17 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling } + $sql_for_employee_list = "T.boss <> true AND T.invoice_type != 0"; // Grab the employee data if ( $accountID ) { // Get a list of this accounts employees. If they have any. $Employees = new GlmDataEmployees( $this->wpdb, $this->config ); $employees = $Employees->getList( "T.account = $accountID" ); + $sql_for_employee_list .= " AND T.id != $accountID "; } - // $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); // 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' ); + $accounts = $Accounts->getSimpleAccountList( $sql_for_employee_list, 'ref_name' ); if ( !$account ) { if ( $accountID ) { -- 2.17.1