From a3e2034e23fdb8e15d319d078d42c318d282cd34 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 17 Apr 2019 16:09:39 -0400 Subject: [PATCH] Update for database and dashboard Adding options for the main billing dashboard. New dashboard list of accounts that have overdue invoices. Adding invoice number search on invoices tab. Fix issue with payment form to get the card type with test card. --- classes/billingSupport.php | 4 +- classes/data/dataInvoices.php | 24 +++ classes/data/dataManagement.php | 24 +++ index.php | 2 +- models/admin/billing/index.php | 143 +++++++----------- models/admin/billing/invoices.php | 29 +++- models/admin/dashboard/billing.php | 2 +- ...0.0.38.sql => create_database_V0.0.39.sql} | 6 +- setup/databaseScripts/dbVersions.php | 1 + .../update_database_V0.0.38.sql | 2 +- .../update_database_V0.0.39.sql | 19 +++ views/admin/billing/index.html | 13 +- views/admin/billing/invoices.html | 25 ++- views/admin/management/billing.html | 35 +++++ views/common/billing/paymentForm.html | 2 +- 15 files changed, 224 insertions(+), 107 deletions(-) rename setup/databaseScripts/{create_database_V0.0.38.sql => create_database_V0.0.39.sql} (98%) create mode 100644 setup/databaseScripts/update_database_V0.0.39.sql diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 6f14d2d..fd6878b 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1360,7 +1360,7 @@ class GlmBillingSupport // If we need to check for proper credit card data if ($checkCC) { // Check all credit card input - if ( $cardData['cc_type'] && $cardData['cc_type'] > 0 + if ( $cardData['cc_type'] && $cardData['cc_type'] != '' && $cardData['cc_name'] && $cardData['cc_name'] != '' && $cardData['cc_numb'] && $cardData['cc_numb'] > 0 && $cardData['cc_exp'] && $cardData['cc_exp'] != '' @@ -1553,7 +1553,7 @@ class GlmBillingSupport $lastFour = ''; if ( isset( $_REQUEST['cc_type'] ) && $_REQUEST['cc_type'] ) { // need to know number to card type - $cardBrand = $_REQUEST['cc_type']; + $cardBrand = $this->config['credit_card'][$_REQUEST['cc_type']]; } if ( isset( $_REQUEST['cc_numb'] ) && $_REQUEST['cc_numb'] ) { // Get last four numbers diff --git a/classes/data/dataInvoices.php b/classes/data/dataInvoices.php index 39382c7..0eeddca 100644 --- a/classes/data/dataInvoices.php +++ b/classes/data/dataInvoices.php @@ -277,5 +277,29 @@ class GlmDataInvoices extends GlmDataAbstract ); } + public function getSimpleInvoiceList( + $where = '', + $order = '', + $fieldVals = true, + $idField = 'id', + $start = false, + $limit = false + ) { + // Save the current fields array and make a copy + $fSave = $this->fields; + + // Remove what we don't want from the copy and get the list + $this->fields = array( + 'id' => $fSave['id'], + 'name' => $fSave['ref_name'], + ); + + $invoiceList = $this->getList($where, $order, $fieldVals, $idField, $start, $limit); + + // Restore the fields list + $this->fields = $fSave; + + return $invoiceList; + } } diff --git a/classes/data/dataManagement.php b/classes/data/dataManagement.php index be74e04..0fe6be6 100644 --- a/classes/data/dataManagement.php +++ b/classes/data/dataManagement.php @@ -283,6 +283,30 @@ class GlmDataBillingManagement extends GlmDataAbstract 'default' => 0, ), + // Show pending renewals + 'dashboard_pending_renewals' => array ( + 'field' => 'dashboard_pending_renewals', + 'type' => 'checkbox', + 'use' => 'a', + 'default' => 0, + ), + + // Show overdue renewals + 'dashboard_overdue_renewals' => array ( + 'field' => 'dashboard_overdue_renewals', + 'type' => 'checkbox', + 'use' => 'a', + 'default' => 0, + ), + + // Show overdue invoices + 'dashboard_overdue_invoices' => array ( + 'field' => 'dashboard_overdue_invoices', + 'type' => 'checkbox', + 'use' => 'a', + 'default' => 0, + ), + ); } diff --git a/index.php b/index.php index 8a91e54..bca4230 100644 --- a/index.php +++ b/index.php @@ -38,7 +38,7 @@ * version from this plugin. */ define('GLM_MEMBERS_BILLING_PLUGIN_VERSION', '1.0.26'); -define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.38'); +define('GLM_MEMBERS_BILLING_PLUGIN_DB_VERSION', '0.0.39'); // 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/billing/index.php b/models/admin/billing/index.php index 53e5e0c..f20ddc4 100644 --- a/models/admin/billing/index.php +++ b/models/admin/billing/index.php @@ -183,105 +183,75 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts } switch ( $option ) { - // case 'account': - // require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; - // $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); - // - // // Check to see if we're adding an account or editing one. - // if ( isset( $_REQUEST['ref_name'] ) ) { - // $_REQUEST['anniversary_date'] = date('Y-m-d', strtotime($_REQUEST['anniversary_date'])); - // // if there's no id then add account - // if ( !isset( $_REQUEST['id'] ) ) { - // $account = $Accounts->insertEntry(); - // if ( !$account['status'] ) { - // $accountInsertError = true; - // } else { - // $accountAdded = true; - // } - // } else { - // $account = $Accounts->updateEntry( $_REQUEST['id'] ); - // if ( !$account['status'] ) { - // $accountUpdateError = true; - // } else { - // $accountUpdated = true; - // } - // } - // } - // - // // Need to see if there's an account for this member. - // $accountID = $this->wpdb->get_var( - // $this->wpdb->prepare( - // "SELECT id - // FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts - // WHERE ref_dest = %d", - // $this->memberID - // ) - // ); - // if ( !$account ) { - // if ( $accountID ) { - // $account = $Accounts->editEntry( $accountID ); - // $haveAccount = true; - // } else { - // $accountID = 0; - // $account = $Accounts->newEntry(); - // // Set the ref_name from memberData - // $account['fieldData']['ref_name'] = $memberData['name']; - // $haveAccount = false; - // } - // } else { - // $haveAccount = true; - // // echo '
$account: ' . print_r( $account, true ) . '
'; - // } - // - // // echo '
$account: ' . print_r( $account, true ) . '
'; - // $view = 'editAccount'; - // break; case 'list': - // Dash board list should be getting list of members Accounts. (based on renewal_date) - // Expired - // Pass Due - // Pending - // Active - // Get list of pending invoices ( not overdue ) + // Dashboard could show invoices or accounts. + // Overdue invoices + // MiGCSA shows accounts (based on renewal_date) + // Expired + // Pass Due + // Pending + // Active + + // Get list of pending renewals ( not overdue ) $days_before_renewal = $this->config['settings']['days_before_renewal']; $days_after_expired = $this->config['settings']['days_after_expired']; $orderBy = 'renewal_date ASC'; $curDate = date( 'Y-m-d' ); - $pendingWhere = "T.archived <> true AND invoice_type != 0 "; - $pendingWhere .= " AND T.renewal_date + INTERVAL 1 YEAR - INTERVAL $days_before_renewal DAY <= '$curDate'" ; - $pendingWhere .= " AND T.renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY >= '$curDate'"; - $start = 1; - $this->postEmployees = true; - $pending = $this->getList( $pendingWhere, $orderBy, true, 'id', $start, $limit ); - $this->postEmployees = false; - // echo '
$pending: ' . print_r( $pending, true ) . '
'; - $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 ); - - // Get the number of over due invoices - $overDueWhere = "T.archived <> true AND invoice_type != 0"; - $overDueWhere .= " AND T.renewal_date + INTERVAL 1 YEAR < '$curDate'"; - $start = 1; - $this->postEmployees = true; - $overdue = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit ); - $this->postEmployees = false; - if ( isset( $overdue['returned'] ) ) { - $numberOverdue = $overdue['returned']; - } // Get list of accounts for autocomplete $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); $accounts = $Accounts->getSimpleAccountList(); - $dashboards = array( - 'Pending Accounts' => array( + $dashboards = array(); + if ( $this->config['billing_settings']['dashboard_pending_renewals'] ) { + $pendingWhere = "T.archived <> true AND invoice_type != 0 "; + $pendingWhere .= " AND T.renewal_date + INTERVAL 1 YEAR - INTERVAL $days_before_renewal DAY <= '$curDate'" ; + $pendingWhere .= " AND T.renewal_date + INTERVAL 1 YEAR + INTERVAL $days_after_expired DAY >= '$curDate'"; + $start = 1; + $this->postEmployees = true; + $pending = $this->getList( $pendingWhere, $orderBy, true, 'id', $start, $limit ); + $this->postEmployees = false; + $numberPending = ( isset( $pending['returned'] ) ? $pending['returned'] : 0 ); + $dashboards['Accounts with Pending Renewals'] = array( 'number' => $numberPending, 'data' => $pending, - ), - 'Overdue Accounts' => array( + ); + } + if ( $this->config['billing_settings']['dashboard_overdue_renewals'] ) { + // Get the number of over due renewals + $overDueWhere = "T.archived <> true AND invoice_type != 0"; + $overDueWhere .= " AND T.renewal_date + INTERVAL 1 YEAR < '$curDate'"; + $start = 1; + $this->postEmployees = true; + $overdue = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit ); + $this->postEmployees = false; + $numberOverdue = ( isset( $overdue['returned'] ) ? $overdue['returned'] : 0 ); + $dashboards['Accounts with Overdue Renewals'] = array( 'number' => $numberOverdue, 'data' => $overdue, - ) - ); + ); + } + if ( $this->config['billing_settings']['dashboard_overdue_invoices'] ) { + // Get the number of over due renewals + $overDueWhere = "T.archived <> true AND invoice_type != 0"; + // $overDueWhere .= " AND T.renewal_date + INTERVAL 1 YEAR < '$curDate'"; + $overDueWhere .= " AND T.id IN ( + SELECT account + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoices + WHERE due_date < '$curDate' + AND ( paid <> true OR paid IS NULL ) + )"; + $start = 1; + $this->postEmployees = true; + $overdue = $this->getList( $overDueWhere, $orderBy, true, 'id', $start, $limit ); + $this->postEmployees = false; + $numberOverdue = ( isset( $overdue['returned'] ) ? $overdue['returned'] : 0 ); + $dashboards['Accounts with Overdue Invoices'] = array( + 'number' => $numberOverdue, + 'data' => $overdue, + ); + } + break; default: @@ -316,7 +286,7 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts 'toDate' => $toDate, 'haveInvoices' => $haveInvoices, 'accounts' => $accounts, - 'allAccounts' => $accounts, + 'allAccounts' => $accounts, 'filterAccounts' => $filterAccounts, 'totalInvoices' => $totalInvoices, 'filterPending' => $filterPending, @@ -326,7 +296,6 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts 'filterArchived' => $filterArchived, 'searchName' => $searchName, ); - // echo '
$templateData: ' . print_r( $templateData, true ) . '
'; // Return status, any suggested view, and any data to controller return array( diff --git a/models/admin/billing/invoices.php b/models/admin/billing/invoices.php index eebe5eb..55fd69b 100644 --- a/models/admin/billing/invoices.php +++ b/models/admin/billing/invoices.php @@ -120,12 +120,13 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $invoiceTypes = false; $invoiceTypeJSON = ''; $accounts = false; + $invoices = false; $billingAccount = false; $nonAccountMembers = false; $invoiceHtml = ''; $fromDate = ''; $toDate = ''; - $invoices = false; + $invoiceList = false; $fromMemberMenu = false; $filterAccounts = ''; $totalInvoices = false; @@ -186,7 +187,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices if ( isset( $_REQUEST['id'] ) ) { $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $this->invoice_id = filter_var( $_REQUEST['id'], FILTER_VALIDATE_INT ); - $invoices = $this->editEntry( $this->invoice_id ); + $nvoices = $this->editEntry( $this->invoice_id ); // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; $view = 'editInvoice'; $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); @@ -478,14 +479,14 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices // Here we're going to generate the invoice total. $totals = $this->generateInvoiceTotal( $this->invoice_id ); // echo '
' . print_r( $totals, true ) . '
'; - // Now we have a total for the invoice we can record the transaction + // Now we have a total for the invoice we can record the transaction. $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); // Calling the support class to save the invoice to transaction table. - // Reset for the edit form + // Reset for the edit form. $InvoiceTypesObj = new GlmDataInvoiceTypes( $this->wpdb, $this->config ); $invoiceTypes = $InvoiceTypesObj->getList(); $lineItems = $BillingSupport->getLineItemsForInvoice( $this->invoice_id ); - // Sort the types by parent child + // Sort the types by parent child. $invoiceTypes = $InvoiceTypesObj->sortParentChild($invoiceTypes); if ( isset( $invoiceTypes ) ) { foreach ( $invoiceTypes as $invoiceType ) { @@ -585,10 +586,15 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices case 'list': default: + // echo '
'.print_r( $_REQUEST, true ).'
'; // Need to get the accounts $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); $accounts = $Accounts->getSimpleAccountList(); + // Get list of invoices for invoice # search + $Invoices = new GlmDataInvoices( $this->wpdb, $this->config ); + $invoiceList = $Invoices->getSimpleInvoiceList(); + $where_params = array( 'true' ); // Check if we're doing paging @@ -648,6 +654,18 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices $where_params[] = "T.paid <> true"; } } + if ( isset( $_REQUEST['filterInvoice'] ) && $_REQUEST['filterInvoice'] ) { + $filterInvoice = filter_var( $_REQUEST['filterInvoice'], FILTER_VALIDATE_INT ); + if ( $filterInvoice ) { + $where_params[] = "T.id = $filterInvoice"; + } + } + if ( isset( $_REQUEST['searchInvoice'] ) && $_REQUEST['searchInvoice'] ) { + $searchInvoice = filter_var( $_REQUEST['searchInvoice'], FILTER_VALIDATE_INT ); + if ( $searchInvoice ) { + $where_params[] = "T.id = $searchInvoice"; + } + } if ( isset( $_REQUEST['filterPending'] ) ) { $filterPending = filter_var( $_REQUEST['filterPending'], FILTER_VALIDATE_BOOLEAN ); $where_params[] = "T.paid <> true"; @@ -726,6 +744,7 @@ class GlmMembersAdmin_billing_invoices extends GlmDataInvoices 'lineItemJSON' => $lineItemJSON, 'invoiceTypes' => $invoiceTypes, 'accounts' => $accounts, + 'invoiceList' => $invoiceList, 'billingAccount' => $billingAccount, 'invoiceHtml' => $invoiceHtml, 'fromDate' => $fromDate, diff --git a/models/admin/dashboard/billing.php b/models/admin/dashboard/billing.php index b7e8aa9..6870f50 100644 --- a/models/admin/dashboard/billing.php +++ b/models/admin/dashboard/billing.php @@ -21,7 +21,7 @@ * Each Add-On can have one or more dashboards. */ -class GlmMembersAdmin_dashboard_billing //extends GlmDataBilling +class GlmMembersAdmin_dashboard_billing { /** * Word Press Database Object diff --git a/setup/databaseScripts/create_database_V0.0.38.sql b/setup/databaseScripts/create_database_V0.0.39.sql similarity index 98% rename from setup/databaseScripts/create_database_V0.0.38.sql rename to setup/databaseScripts/create_database_V0.0.39.sql index 64e88cf..fbbacd9 100644 --- a/setup/databaseScripts/create_database_V0.0.38.sql +++ b/setup/databaseScripts/create_database_V0.0.39.sql @@ -1,6 +1,6 @@ -- Gaslight Media Billing Module -- File Created: 02/19/2019 --- Database Version: 0.0.37 +-- Database Version: 0.0.39 -- Database Creation Script -- -- To permit each query below to be executed separately, @@ -318,6 +318,10 @@ CREATE TABLE {prefix}management ( -- Uptravel options uptravel_invoice_template BOOLEAN DEFAULT '0', -- Use uptravel template for invoices. uptravel_payment_form BOOLEAN DEFAULT '0', -- Use uptravel payment form style. + -- Dashboard options + dashboard_pending_renewals BOOLEAN DEFAULT '1', -- Show pending renewals + dashboard_overdue_renewals BOOLEAN DEFAULT '1', -- Show overdue renewals + dashboard_overdue_invoices BOOLEAN DEFAULT '1', -- Show overdue invoices PRIMARY KEY (id) ); diff --git a/setup/databaseScripts/dbVersions.php b/setup/databaseScripts/dbVersions.php index e03da49..90f6965 100644 --- a/setup/databaseScripts/dbVersions.php +++ b/setup/databaseScripts/dbVersions.php @@ -52,5 +52,6 @@ $glmMembersBillingDbVersions = array( '0.0.36' => array('version' => '0.0.36', 'tables' => 16, 'date' => '04/02/2019'), '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'), ); diff --git a/setup/databaseScripts/update_database_V0.0.38.sql b/setup/databaseScripts/update_database_V0.0.38.sql index c50131f..5d0252b 100644 --- a/setup/databaseScripts/update_database_V0.0.38.sql +++ b/setup/databaseScripts/update_database_V0.0.38.sql @@ -1,6 +1,6 @@ -- Gaslight Media Billing Database -- File Created: 04/11/2019 --- Database Version: 0.0.37 +-- Database Version: 0.0.38 -- -- To permit each query below to be executed separately, -- all queries must be separated by a line with four dashes diff --git a/setup/databaseScripts/update_database_V0.0.39.sql b/setup/databaseScripts/update_database_V0.0.39.sql new file mode 100644 index 0000000..51c3c08 --- /dev/null +++ b/setup/databaseScripts/update_database_V0.0.39.sql @@ -0,0 +1,19 @@ +-- Gaslight Media Billing Database +-- File Created: 04/17/2019 +-- Database Version: 0.0.39 +-- +-- To permit each query below to be executed separately, +-- all queries must be separated by a line with four dashes + +-- Update the management table +ALTER TABLE {prefix}management ADD dashboard_pending_renewals BOOLEAN DEFAULT '1'; -- Show invoices on the dashboard + +---- + +-- Update the management table +ALTER TABLE {prefix}management ADD dashboard_overdue_renewals BOOLEAN DEFAULT '1'; -- Show invoices on the dashboard + +---- + +-- Update the management table +ALTER TABLE {prefix}management ADD dashboard_overdue_invoices BOOLEAN DEFAULT '1'; -- Show invoices on the dashboard diff --git a/views/admin/billing/index.html b/views/admin/billing/index.html index 9ceaed1..47f19f1 100644 --- a/views/admin/billing/index.html +++ b/views/admin/billing/index.html @@ -5,12 +5,13 @@ {include file='admin/billing/header.html'} {/if} -
Accounts Export
+

Accounts

+
Accounts Export
- Create Invoice - Make Payment +Create Invoice +Make Payment - {include file='admin/billing/accountSearchForm.html'} +{include file='admin/billing/accountSearchForm.html'} {foreach $dashboards as $dashboard_title => $list} @@ -58,9 +59,7 @@ {if $t.boss.value} - +
{foreach $t.employees as $emp} diff --git a/views/admin/billing/invoices.html b/views/admin/billing/invoices.html index d706699..3a84e78 100644 --- a/views/admin/billing/invoices.html +++ b/views/admin/billing/invoices.html @@ -28,6 +28,11 @@
+
+ + + +