From 5371c309a40c851c481b8ccafef2b138d5e3a17a Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 11 Jun 2019 13:44:50 -0400 Subject: [PATCH] Update for database (new setting) New setting for member types that are free. --- classes/data/dataSettings.php | 9 ++++- index.php | 2 +- models/admin/ajax/billingFlagExpiredUsers.php | 33 ++++++++++--------- models/admin/billing/accounts.php | 6 ++++ models/admin/settings/billing.php | 12 +++++++ ...0.0.39.sql => create_database_V0.0.40.sql} | 3 +- setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.40.sql | 9 +++++ views/admin/billing/accounts.html | 19 ++++++++++- views/admin/settings/billing.html | 12 +++++++ 10 files changed, 87 insertions(+), 19 deletions(-) rename setup/databaseScripts/{create_database_V0.0.39.sql => create_database_V0.0.40.sql} (99%) create mode 100644 setup/databaseScripts/update_database_V0.0.40.sql diff --git a/classes/data/dataSettings.php b/classes/data/dataSettings.php index c4fa253..62b8d0a 100644 --- a/classes/data/dataSettings.php +++ b/classes/data/dataSettings.php @@ -328,13 +328,20 @@ class GlmDataBillingSettings extends GlmDataAbstract 'use' => 'a', ), - // Renewal Month + // Member Types that require billing 'member_types_requiring_billing' => array( 'field' => 'member_types_requiring_billing', 'type' => 'text', 'use' => 'a', ), + // Member Types that are free + 'member_types_free' => array( + 'field' => 'member_types_free', + 'type' => 'text', + 'use' => 'a', + ), + // Show account number in invoice 'invoice_show_account_number' => array( 'field' => 'invoice_show_account_number', diff --git a/index.php b/index.php index bec571e..e6eb456 100644 --- a/index.php +++ b/index.php @@ -40,7 +40,7 @@ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.31'); // Database Version -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.39'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.40'); // This is the minimum version of the GLM Members DB plugin require for this plugin. define('GLM_MEMBERS_BILLING_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.8.0'); diff --git a/models/admin/ajax/billingFlagExpiredUsers.php b/models/admin/ajax/billingFlagExpiredUsers.php index 65701d1..f12ec16 100644 --- a/models/admin/ajax/billingFlagExpiredUsers.php +++ b/models/admin/ajax/billingFlagExpiredUsers.php @@ -70,28 +70,32 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers public function modelAction( $actionData = false ) { - // echo '
$actionData: ' . print_r( $actionData, true ) . '
'; $days_after_expired = $this->config['settings']['days_after_expired']; $current_date = date( 'Y-m-d' ); $restrictedRole = $this->config['contact_role_numb']['LogInContact']; - // echo '
$restrictedRole: ' . print_r( $restrictedRole, true ) . '
'; // Update All expired accounts so they can only be in members only not admin. // Find all member contacts (by ref_dest) with accounts that are expired. // With those set their contact_role to 30 (login only) if ( $days_after_expired = filter_var( $days_after_expired, FILTER_VALIDATE_INT ) ) { - // Fix Free members - // These would be memberships that are free so they don't pay. - // They just get updated renewal dates. - $this->wpdb->query( - "UPDATE " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts - SET invoice_type = 0 - WHERE invoice_type != 0 - AND ref_dest IN ( - SELECT id - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members - WHERE member_type in ( 5, 7, 9, 13))" - ); + $member_types_enabled = $this->config['settings']['member_types_enabled']; + if ( $member_types_enabled ) { + $member_types_free = $this->config['settings']['member_types_free']; + if ( $member_types_free && !empty( $member_types_free = unserialize( $member_types_free ) ) ) { + // Fix Free members + // These would be memberships that are free so they don't pay. + // They just get updated renewal dates. + $this->wpdb->query( + "UPDATE " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + SET invoice_type = 0 + WHERE invoice_type != 0 + AND ref_dest IN ( + SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE member_type in ( " . implode( ',', $member_types_free ) . "))" + ); + } + } // Update any account that has invoice_type set to 0 and have an expired renewal_date $this->wpdb->query( "UPDATE " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts @@ -111,7 +115,6 @@ class GlmMembersAdmin_ajax_billingFlagExpiredUsers ); if ( isset( $members ) && $members ) { foreach ( $members as $member ) { - // echo '
$member: ' . print_r( $member, true ) . '
'; apply_filters( 'glm_contact_update_user_role_by_ref_dest', '', diff --git a/models/admin/billing/accounts.php b/models/admin/billing/accounts.php index 31bd15e..1c78262 100644 --- a/models/admin/billing/accounts.php +++ b/models/admin/billing/accounts.php @@ -134,6 +134,12 @@ class GlmMembersAdmin_billing_accounts extends GlmDataAccounts $option = $_REQUEST['option']; } + // Enqueue GLMA Foundation + // wp_enqueue_style( 'glmaFoundation', GLM_MEMBERS_PLUGIN_URL . '/css/glma-foundation.min.css' ); + // wp_enqueue_style( 'Foundation6', GLM_MEMBERS_BILLING_PLUGIN_URL . '/js/foundation/css/foundation.min.css' ); + // wp_enqueue_script( 'Foundation6', GLM_MEMBERS_BILLING_PLUGIN_URL . '/js/foundation/vendor/foundation.min.js' ); + // wp_enqueue_script( 'FoundationReveal', GLM_MEMBERS_BILLING_PLUGIN_URL . '/js/foundation.reveal.js' ); + // Do selected option switch ($option) { diff --git a/models/admin/settings/billing.php b/models/admin/settings/billing.php index c14fc42..1c3d1b6 100644 --- a/models/admin/settings/billing.php +++ b/models/admin/settings/billing.php @@ -151,6 +151,11 @@ class GlmMembersAdmin_settings_billing extends GlmDataBillingSettings if ( isset( $_REQUEST['member_types_requiring_billing_option'] ) ) { $_REQUEST['member_types_requiring_billing'] = serialize( $_REQUEST['member_types_requiring_billing_option'] ); } + // Combine the member types that are free + $_REQUEST['member_types_free'] = ''; + if ( isset( $_REQUEST['member_types_free_option'] ) ) { + $_REQUEST['member_types_free'] = serialize( $_REQUEST['member_types_free_option'] ); + } // Update the billing settings settings $billing_settings = $this->updateEntry(1); @@ -190,6 +195,12 @@ class GlmMembersAdmin_settings_billing extends GlmDataBillingSettings } else { $member_types_requring_billing_selected = array(); } + $member_types_free_selected = $billing_settings['fieldData']['member_types_free']; + if ( $member_types_free_selected ) { + $member_types_free_selected = unserialize( $member_types_free_selected ); + } else { + $member_types_free_selected = array(); + } // Compile template data $template_data = array( @@ -203,6 +214,7 @@ class GlmMembersAdmin_settings_billing extends GlmDataBillingSettings 'renewal_day_opts' => range( 0, 31, 1 ), 'member_types' => $memberTypes, 'selectedMTRB' => $member_types_requring_billing_selected, + 'selectedMTFREE' => $member_types_free_selected, ); // Return status, suggested view, and data to controller diff --git a/setup/databaseScripts/create_database_V0.0.39.sql b/setup/databaseScripts/create_database_V0.0.40.sql similarity index 99% rename from setup/databaseScripts/create_database_V0.0.39.sql rename to setup/databaseScripts/create_database_V0.0.40.sql index fbbacd9..ff3b52e 100644 --- a/setup/databaseScripts/create_database_V0.0.39.sql +++ b/setup/databaseScripts/create_database_V0.0.40.sql @@ -1,6 +1,6 @@ -- Gaslight Media Billing Module -- File Created: 02/19/2019 --- Database Version: 0.0.39 +-- Database Version: 0.0.40 -- Database Creation Script -- -- To permit each query below to be executed separately, @@ -261,6 +261,7 @@ CREATE TABLE {prefix}settings ( allow_membership_choice BOOLEAN DEFAULT '0', -- If memberships can choose their membership levels when they renew allow_employees BOOLEAN DEFAULT '0', -- If memberships have employees member_types_enabled BOOLEAN DEFAULT '1', -- member types determine invoice types + member_types_free TEXT NULL, -- List of member type id's that are free quickbooks_enabled BOOLEAN DEFAULT '0', -- QuickBooks enabled member_billing_enabled BOOLEAN DEFAULT '1', -- Member have access to billing info tab billing_fields_required BOOLEAN DEFAULT '1', -- Require Billing Fields diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index 90f6965..699743f 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -53,5 +53,6 @@ $glmMembersBillingDbVersions = array( '0.0.37' => array('version' => '0.0.37', 'tables' => 16, 'date' => '04/11/2019'), '0.0.38' => array('version' => '0.0.38', 'tables' => 16, 'date' => '04/16/2019'), '0.0.39' => array('version' => '0.0.39', 'tables' => 16, 'date' => '04/17/2019'), + '0.0.40' => array('version' => '0.0.40', 'tables' => 16, 'date' => '06/11/2019'), ); diff --git a/setup/databaseScripts/update_database_V0.0.40.sql b/setup/databaseScripts/update_database_V0.0.40.sql new file mode 100644 index 0000000..3207d5b --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.40.sql @@ -0,0 +1,9 @@ +-- Gaslight Media Billing Database +-- File Created: 06/11/2019 +-- Database Version: 0.0.40 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Update the accounts table +ALTER TABLE {prefix}settings ADD member_types_free TEXT NULL; -- List of member type id's that are free diff --git a/views/admin/billing/accounts.html b/views/admin/billing/accounts.html index 443f145..262e8cf 100644 --- a/views/admin/billing/accounts.html +++ b/views/admin/billing/accounts.html @@ -51,7 +51,7 @@ View Statements | - + {if $t.boss.value} @@ -97,6 +97,7 @@ {include file='admin/billing/exportBillingModal.html'} + + {include file='admin/footer.html'} diff --git a/views/admin/settings/billing.html b/views/admin/settings/billing.html index bca0c61..374c040 100644 --- a/views/admin/settings/billing.html +++ b/views/admin/settings/billing.html @@ -353,6 +353,18 @@ + + + Member Types that are Free + + + + + -- 2.17.1