From cfd174454ada44ae709b83d6adcd14d6cd63f0de Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 23 Apr 2018 14:58:38 -0400 Subject: [PATCH] Update for database Add invoice_type field to the account table. This is for helping to find list of accounts that will have paid types. --- classes/billingSupport.php | 12 +++++++++--- classes/data/dataEmployees.php | 12 ++++++++++++ index.php | 2 +- models/admin/member/billing.php | 5 ++--- ...0.0.22.sql => create_database_V0.0.23.sql} | 7 +++++-- setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.22.sql | 2 +- .../update_database_V0.0.23.sql | 19 +++++++++++++++++++ views/admin/billing/renew.html | 11 ++++++++++- 9 files changed, 60 insertions(+), 11 deletions(-) rename setup/databaseScripts/{create_database_V0.0.22.sql => create_database_V0.0.23.sql} (98%) create mode 100644 setup/databaseScripts/update_database_V0.0.23.sql diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 5179120..7a6e3ad 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -19,6 +19,7 @@ require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoices.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataInvoiceTypes.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataNotificationTypes.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataEmployees.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/notifications.php'; class GlmBillingSupport @@ -832,6 +833,9 @@ class GlmBillingSupport /** * getMembersInvoiceTypeByRefDest * + * TODO: Need to give something back if no invoice_type is found. + * The member may belong to a member type that is free. + * * @access public * @return mixed */ @@ -891,16 +895,16 @@ class GlmBillingSupport // $employees = apply_filters( 'glm_contact_has_employees', '', $member_id ); $main_billing_account = $this->getAccountByRefDest( $member_id ); // echo '
$main_billing_account: ' . print_r( $main_billing_account, true ) . '
'; - require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataEmployees.php'; $Employees = new GlmDataEmployees( $this->wpdb, $this->config ); $employees = $Employees->getList( "T.account = " . $main_billing_account['id'] ); - // echo '
$employees: ' . print_r( $employees, true ) . '
'; + echo '
$employees: ' . print_r( $employees, true ) . '
'; if ( isset( $employees ) && is_array( $employees ) ) { foreach ( $employees as $emp ) { $invoice = false; $billing_account_id = $emp['employee']; $billing_account = $this->getAccountById( $billing_account_id ); + echo '
$billing_account: ' . print_r( $billing_account, true ) . '
'; // If we don't have an account for this member then one // Needs to be created. $ref_dest = $this->wpdb->get_var( @@ -911,6 +915,7 @@ class GlmBillingSupport $emp['employee_name'] ) ); + echo '
$ref_dest: ' . print_r( $ref_dest, true ) . '
'; if ( !$billing_account ) { // Get the Member Name if ( $member_name ) { @@ -931,9 +936,10 @@ class GlmBillingSupport $billing_account = $this->getAccountByRefDest( $ref_dest ); } } - if ( $billing_account ) { + if ( $billing_account && $ref_dest ) { // Need also to get the members type to look up which invoice_type to use $invoice_type_id = $this->getMembersInvoiceTypeByRefDest( $ref_dest ); + echo '
$invoice_type_id: ' . print_r( $invoice_type_id, true ) . '
'; if ( $invoice_type_id ) { $invoice = $this->getInvoiceTypeById( $invoice_type_id ); $accounts[$billing_account_id] = array( diff --git a/classes/data/dataEmployees.php b/classes/data/dataEmployees.php index e16375c..dc281b9 100644 --- a/classes/data/dataEmployees.php +++ b/classes/data/dataEmployees.php @@ -176,6 +176,18 @@ class GlmDataEmployees extends GlmDataAbstract } + public function getSimpleListOfEmployees( $account ) + { + $employees = array(); + + $where = "T.account = $account"; + // $where .= " AND T."; + + $employees = $this->getList( $where ); + + return $employees; + } + /* * Entry Post Processing Call-Back Method * diff --git a/index.php b/index.php index 9dfc503..e100a30 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '0.0.1'); -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.22'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.23'); // 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/member/billing.php b/models/admin/member/billing.php index 73b1993..499e56c 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -16,6 +16,7 @@ define('GLM_MEMBERS_BILLING_MEMBER_MENU', true); require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoices.php'; // require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataPayments.php'; require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/billingSupport.php'; +require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataEmployees.php'; // Load Billing data abstract // require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataBilling.php'; @@ -209,7 +210,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 ) . '
'; + echo '
$employees: ' . print_r( $employees, true ) . '
'; // Load DataClass for Management. require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php'; @@ -384,7 +385,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Grab the employee data if ( $accountID ) { // Get a list of this accounts employees. If they have any. - require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataEmployees.php'; $Employees = new GlmDataEmployees( $this->wpdb, $this->config ); $employees = $Employees->getList( "T.account = $accountID" ); } @@ -461,7 +461,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Grab the employee data if ( $accountID ) { // Get a list of this accounts employees. If they have any. - require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataEmployees.php'; $Employees = new GlmDataEmployees( $this->wpdb, $this->config ); $employees = $Employees->getList( "T.account = $accountID" ); } diff --git a/setup/databaseScripts/create_database_V0.0.22.sql b/setup/databaseScripts/create_database_V0.0.23.sql similarity index 98% rename from setup/databaseScripts/create_database_V0.0.22.sql rename to setup/databaseScripts/create_database_V0.0.23.sql index 92682e9..170c7af 100644 --- a/setup/databaseScripts/create_database_V0.0.22.sql +++ b/setup/databaseScripts/create_database_V0.0.23.sql @@ -1,6 +1,6 @@ -- Gaslight Media Billing Module -- File Created: 11/08/2017 --- Database Version: 0.0.22 +-- Database Version: 0.0.23 -- Database Creation Script -- -- To permit each query below to be executed separately, @@ -15,6 +15,7 @@ CREATE TABLE {prefix}accounts ( archived BOOLEAN DEFAULT '0', -- Marks account as archived ref_dest INT NOT NULL, -- reference to member id ref_name TINYTEXT NOT NULL, -- Name of reference member + invoice_type INT NOT NULL DEFAULT '0', -- Ref to Invoice Type id billing_fname TINYTEXT NULL, -- Billing First Name billing_lname TINYTEXT NULL, -- Billing Last Name billing_addr1 TINYTEXT NULL, -- Billing Address 1 @@ -34,7 +35,9 @@ CREATE TABLE {prefix}accounts ( PRIMARY KEY (id), INDEX(ref_dest), INDEX(ref_name(20)), - INDEX(email(20)) + INDEX(email(20)), + INDEX(invoice_type), + INDEX(renewal_date) ); ---- diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index f7768d2..0975228 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -36,5 +36,6 @@ $glmMembersBillingDbVersions = array( '0.0.20' => array('version' => '0.0.20', 'tables' => 14), '0.0.21' => array('version' => '0.0.21', 'tables' => 15), '0.0.22' => array('version' => '0.0.22', 'tables' => 15), + '0.0.23' => array('version' => '0.0.23', 'tables' => 15), ); diff --git a/setup/databaseScripts/update_database_V0.0.22.sql b/setup/databaseScripts/update_database_V0.0.22.sql index b0eadd5..8bc18e3 100644 --- a/setup/databaseScripts/update_database_V0.0.22.sql +++ b/setup/databaseScripts/update_database_V0.0.22.sql @@ -6,4 +6,4 @@ -- all queries must be separated by a line with four dashes -- Add boss field to accounts table -UPDATE TABLE {prefix}accounts ADD boss BOOLEAN DEFAULT '0'; -- Boss flag +ALTER TABLE {prefix}accounts ADD boss BOOLEAN DEFAULT '0'; -- Boss flag diff --git a/setup/databaseScripts/update_database_V0.0.23.sql b/setup/databaseScripts/update_database_V0.0.23.sql new file mode 100644 index 0000000..ef7c2ab --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.23.sql @@ -0,0 +1,19 @@ +-- Gaslight Media Billing Database +-- File Created: 04/23/2018 +-- Database Version: 0.0.23 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Add invoice_type field to accounts table +ALTER TABLE {prefix}accounts ADD invoice_type INT NOT NULL DEFAULT '0'; -- Ref to Invoice Type id + +---- + +-- Add index for invoice_type +CREATE INDEX account_invoice_type ON {prefix}accounts (invoice_type); + +---- + +-- Add index for renewal_date +CREATE INDEX account_renewal_date ON {prefix}accounts (renewal_date); diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html index 75ab684..8b978a7 100644 --- a/views/admin/billing/renew.html +++ b/views/admin/billing/renew.html @@ -61,7 +61,16 @@ {/if} - {if $employees} + {if $settings.allow_employees} + +
+
Boss
+
+ + {if $account.fieldFail.boss}

{$account.fieldFail.boss}

{/if}
+
+
+
Associated Members/Employees -- 2.17.1