From 4d7cafa3097d8ab2cc8d520b20cc8e86772c256f Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Thu, 25 Apr 2019 14:33:32 -0400 Subject: [PATCH] Hotfix for adding employees when renewing in admin. Bug fix for saving the employees when they're added to the account on the renewal page. --- index.php | 6 +-- models/admin/member/billing.php | 75 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 35ececd..f6b343c 100644 --- a/index.php +++ b/index.php @@ -3,7 +3,7 @@ * Plugin Name: GLM Members Billing * Plugin URI: http://www.gaslightmedia.com/ * Description: This is glmAssociate Billing Module - * Version: 1.0.26 + * Version: 1.0.27 * Author: Gaslight Media * Author URI: http://www.gaslightmedia.com/ * License: GPL2 @@ -19,7 +19,7 @@ * @package glmMembersBillingAddOn * @author Chuck Scott * @license http://www.gaslightmedia.com Gaslightmedia - * @version 1.0.26 + * @version 1.0.27 */ /* @@ -37,7 +37,7 @@ * so that we're sure the other add-ons see an up to date * version from this plugin. */ -define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.26'); +define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.27'); define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.26'); // This is the minimum version of the GLM Members DB plugin require for this plugin. diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 4c71901..9fa5f1c 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -247,6 +247,59 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + if ( isset( $employees ) && !empty( $employees ) ) { + // Check if an employee was removed (deleted) + foreach ( $employees as $employee_id => $employee ) { + if ( !isset( $_REQUEST['employees'][$employee['employee']] ) ) { + $this->wpdb->delete( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'employees', + array( 'id' => $employee_id ), + array( '%d' ) + ); + } + // Remove the employee from the $employees array + unset( $employees[$employee_id] ); + } + } + // If there's employees data then add them to this account + if ( isset($accountID) && $accountID && isset( $_REQUEST['employees'] ) && is_array( $_REQUEST['employees'] ) && !empty( $_REQUEST['employees'] ) ) { + $this->wpdb->update( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + array( 'boss' => 1 ), + array( 'id' => $accountID ), + array( '%s' ), + array( '%d' ) + ); + foreach ( $_REQUEST['employees'] as $employee_id => $hasKey ) { + // Should check to see if there's one added with account and employee first + $emp_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "employees + WHERE account = %d + AND employee = %d", + $accountID, + $employee_id + ) + ); + if ( !$emp_id ) { + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'employees', + array( + 'account' => $accountID, + 'employee' => $employee_id, + ), + array( + '%d', + '%d' + ) + ); + } + } + } + // Reset employees + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + $invoice_data = array( 'account_id' => $accountID, 'renew_type_id' => filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ), @@ -356,6 +409,28 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling break; case 'pay_by_check': break; + + case 'mark_paid': + $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' ); + $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] ); + // Mark this invoice as paid + // Create new payment. + $payment_id = $BillingSupport->createPayment( $accountID, $_REQUEST['total_renew_amount'], 'Marked Paid' ); + + // Record the payment. + $BillingSupport->recordPayment( $payment_id, $accountID, $_REQUEST['total_renew_amount'], $invoices ); + + // Set the contact_role for the member contact so they can login now. + if ( $account_id ) { + $BillingSupport->setMemberAccountActive( $account_id ); + } + // Set the contact_role (employees) for the member contact so they can login now. + if ( isset( $employees ) && is_array( $employees ) && !empty( $employees ) ) { + foreach ( $employees as $emp_account_id ) { + $BillingSupport->setMemberAccountActive( $emp_account_id ); + } + } + break; } // If there's no error reported then show the invoice -- 2.17.1