public function importEmployees()
{
+ $this->wpdb->query('START TRANSACTION');
+ $this->wpdb->query("DELETE FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "employees");
$sql = "
SELECT *
FROM member_employees";
$employee['member_id']
)
);
- $employee['member_account_id'] = $member_account_id;
- // Find the old_member_id for employee
- $employee_account_id = $this->wpdb->get_var(
- $this->wpdb->prepare(
- "SELECT id
- FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
- WHERE ref_dest IN (SELECT id
- FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
- WHERE old_member_id = %d)",
- $employee['employee']
- )
- );
- $employee['employee_account_id'] = $employee_account_id;
- // If we have both of these then add employee (if not already there)
- $this->addEmployee( $member_account_id, $employee_account_id );
+ echo '<pre>$member_account_id: ' . print_r( $member_account_id, true ) . '</pre>';
+ if ( $member_account_id ) {
+ $employee['member_account_id'] = $member_account_id;
+ // Find the old_member_id for employee
+ $employee_account_id = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+ WHERE ref_dest IN (SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = %d)",
+ $employee['employee']
+ )
+ );
+ if ( !$employee_account_id ) {
+ $ref_dest = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+ WHERE old_member_id = %d",
+ $employee['employee']
+ )
+ );
+ // Need to add the account
+ // Get data for the old employee
+ $employeeSql = "
+ SELECT *
+ FROM member
+ WHERE member_id = " . $employee['employee'];
+ $empStmt = $this->dbh->query( $employeeSql );
+ $member = $empStmt->fetch();
+ // Fiend the invoice type
+ $member_type = $this->member_types[$member['member_class']];
+ $invoice_type = $this->wpdb->get_var(
+ $this->wpdb->prepare(
+ "SELECT id
+ FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+ WHERE member_type = %d",
+ $member_type
+ )
+ );
+ $this->wpdb->insert(
+ GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts',
+ array(
+ 'ref_dest' => $ref_dest,
+ 'ref_name' => $member['primary_contact_lname'] . ', ' . $member['primary_contact_fname'],
+ 'anniversary_date' => date( 'Y-m-d' ),
+ 'boss' => $member['boss'],
+ 'invoice_type' => $invoice_type,
+ 'billing_fname' => $member['primary_contact_fname'],
+ 'billing_lname' => $member['primary_contact_lname'],
+ 'billing_addr1' => $member['mailing_address'],
+ 'billing_city' => $member['mailing_city'],
+ 'billing_state' => $member['state_abb'],
+ 'billing_zip' => $member['mailing_zip'],
+ 'billing_phone' => $member['phone'],
+ 'email' => $member['process_email'],
+ ),
+ array(
+ '%d', // ref_dest
+ '%s', // ref_name
+ '%s', // anniversary_date
+ '%d', // boss
+ '%d', // invoice_type
+ '%s', // billing_fname
+ '%s', // billing_lname
+ '%s', // billing_addr1
+ '%s', // billing_city
+ '%s', // billing_state
+ '%s', // billing_zip
+ '%s', // billing_phone
+ '%s', // email
+ )
+ );
+ $employee_account_id = $this->wpdb->insert_id;
+ }
+ $employee['employee_account_id'] = $employee_account_id;
+ // If we have both of these then add employee (if not already there)
+ $this->addEmployee( $member_account_id, $employee_account_id );
+ }
}
+ $this->wpdb->query('COMMIT');
return '<pre>$employees: ' . print_r( $employees, true ) . '</pre>';
}