From: Steve Sutton Date: Wed, 28 Mar 2018 20:50:40 +0000 (-0400) Subject: Update for when employees have no account setup. X-Git-Tag: v1.0.0^2~100 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=43ea6cfe5a75ee231907ca8ada09a57bc7657950;p=WP-Plugins%2Fglm-member-db-billing.git Update for when employees have no account setup. Create an account for the employee member. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index dcb9f18..2eec0c2 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -785,21 +785,52 @@ class GlmBillingSupport $accounts = array(); // This may need to have filters setup in the contact plugin as well. $employees = apply_filters( 'glm_contact_has_employees', '', $member_id ); + // echo '
$employees: ' . print_r( $employees, true ) . '
'; 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 ); + // If we don't have an account for this member then one + // Needs to be created. + if ( !$billing_account ) { + // Get the Member Name + $member_name = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $ref_dest + ) + ); + if ( $member_name ) { + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + array( + 'ref_dest' => $ref_dest, + 'ref_name' => $member_name, + ), + array( + '%d', + '%s' + ) + ); + $employee_account_id = $this->wpdb->insert_id; + $billing_account = $this->getAccountByRefDest( $ref_dest ); + } + } + if ( $billing_account ) { + // 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[$billing_account['id']] = array( + 'id' => $billing_account['id'], + 'ref_dest' => $billing_account['ref_dest'], + 'ref_name' => $billing_account['ref_name'], + 'invoice' => $invoice, + 'email' => $billing_account['email'] + ); } - $accounts[$billing_account['id']] = 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; } @@ -1077,7 +1108,7 @@ class GlmBillingSupport array( '%s' ), array( '%d' ) ); - // TODO: Need to update any employees renewal dates + // Need to update any employees renewal dates if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) { foreach ( $employees as $employee ) { $this->wpdb->update( diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 020880d..f29e71d 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -206,6 +206,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Get a list of this accounts employees. If they have any. $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + // echo '
$employees: ' . print_r( $employees, true ) . '
'; // Load DataClass for Management. require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php';