$accountInsertError = true;
} else {
$accountAdded = true;
+ // If account is added then get the id
+ $accountID = $account['fieldData']['id'];
}
} else {
$account = $Accounts->updateEntry( $_REQUEST['id'] );
}
}
+ // 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 ) {
}
+ $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 ) {