$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 '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
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;
}
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(