From 86c97cb44805c529829650f39953ca2cc819e8a8 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 23 Mar 2018 15:19:58 -0400 Subject: [PATCH] Adding renew page. Working on the renew page for members. Showing their employees. Select unselecting them will update the total amount for the page. --- classes/billingSupport.php | 52 ++++++++++ css/admin.css | 15 +++ models/admin/member/billing.php | 56 +++++++---- .../admin/billing/memberBillingSubHeader.html | 39 +++++++- views/admin/billing/renew.html | 99 +++++++++++++++++++ 5 files changed, 235 insertions(+), 26 deletions(-) create mode 100644 views/admin/billing/renew.html diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 80a55c2..7f82b1d 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -741,5 +741,57 @@ class GlmBillingSupport } + public function getInvoicTypeById( $id ) + { + return $this->wpdb->get_row( + $this->wpdb->prepare( + "SELECT * + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE id = %d", + $id + ), + ARRAY_A + ); + } + + public function getMembersInvoiceTypeByRefDest( $ref_dest ) + { + return $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types + WHERE member_type IN ( + SELECT member_type + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d )", + $ref_dest + ) + ); + } + + public function getListOfAccountEmployees( $member_id ) + { + $accounts = array(); + // This may need to have filters setup in the contact plugin as well. + $employees = apply_filters( 'glm_contact_has_employees', '', $member_id ); + foreach ( $employees as $ref_dest ) { + $invoice = false; + $billing_account = $this->getAccountByRefDest( $ref_dest ); + // Need also to get the members type to look up which invoice_type to use + $invoice_type_id = $this->getMembersInvoiceTypeByRefDest( $member_id ); + if ( $invoice_type_id ) { + $invoice = $this->getInvoicTypeById( $invoice_type_id ); + } + $accounts[] = array( + 'id' => $billing_account['id'], + 'ref_dest' => $billing_account['ref_dest'], + 'ref_name' => $billing_account['ref_name'], + 'invoice' => $invoice, + 'email' => $billing_account['email'] + ); + } + return $accounts; + } + } diff --git a/css/admin.css b/css/admin.css index 491b063..a39ce51 100644 --- a/css/admin.css +++ b/css/admin.css @@ -8,3 +8,18 @@ .glm-admin-table th { white-space: nowrap; } + +.glm-grid-container { + display: grid; + grid-template-columns: 600px 200px; + grid-gap: 30px; + /* background-color: #fff; */ + /* color: #444; */ +} + +.glm-grid-item { + /* background-color: #444; */ + /* color: #fff; */ + border-radius: 5px; + padding: 20px; +} diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index acc47ec..4de6596 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -119,12 +119,18 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $invoices = false; $paymentSuccess = false; $paymentError = false; + $hasBillingAccount = false; + $employees = false; + $member_invoice = false; // For lockedToMember. $lockedToMember = false; $lockedWhereT = 'true'; $lockedWhere = 'true'; + // Call in the support class + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + // Check if there's a logged in user who is locked to their own entity. $lockedToMember = apply_filters('glm_members_locked_to_member_id', false); if ($lockedToMember) { @@ -171,6 +177,21 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling } switch ( $option ) { + case 'renew': + $view = 'renew'; + + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id ); + // echo '
$member_invoice: ' . print_r( $member_invoice, true ) . '
'; + } + + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + // echo '
$employees: ' . print_r( $employees, true ) . '
'; + + // Get a list of this accounts employees. If they have any. + + break; case 'account': require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); @@ -224,8 +245,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $view = 'editAccount'; break; case 'view': - // Call in the support class - $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] ); @@ -371,9 +390,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling if (is_array($ccResult) && isset($ccResult['status']) && $ccResult['status'] == 1) { // Need to record the payment - // Support class - $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); - // Set transaction_time to current time. $_REQUEST['transaction_time'] = date('Y-m-d H:i:s'); // Create new payment. @@ -408,9 +424,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling ); $account = $Accounts->editEntry( $accountID ); - // Support class - $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); - // Get unpaid invoices $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] ); if ( !empty( $invoices ) ) { @@ -450,9 +463,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling ); $account = $Accounts->editEntry( $accountID ); - // Support class - $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); - // Get unpaid invoices $invoices = $BillingSupport->getUnPaidInvoicesByAccount( $account['fieldData']['id'] ); // echo '
$invoices: ' . print_r( $invoices, true ) . '
'; @@ -469,19 +479,20 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling break; case 'list': - $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); $view = 'statements'; - // Get the list of invoices for this member. - $statements = $BillingSupport->getStatementsByRefDest( $this->memberID ); - // echo '
$statements: ' . print_r( $statements, true ) . '
'; - if ( $statements ) { - $transactions = $statements['transactions']; - $account_data = $statements['account_data']; - $balance_due = $statements['balance_due']; - } break; } - // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; + + // Get the list of invoices for this member. + $statements = $BillingSupport->getStatementsByRefDest( $this->memberID ); + // echo '
$statements: ' . print_r( $statements, true ) . '
'; + if ( $statements ) { + $transactions = $statements['transactions']; + $account_data = $statements['account_data']; + $balance_due = $statements['balance_due']; + $hasBillingAccount = true; + } + // echo '
$account_data: ' . print_r( $account_data, true ) . '
'; // Compile template data $templateData = array( @@ -511,6 +522,9 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling 'invoices' => $invoices, 'paymentSuccess' => $paymentSuccess, 'paymentError' => $paymentError, + 'hasBillingAccount' => $hasBillingAccount, + 'employees' => $employees, + 'member_invoice' => $member_invoice, ); // Return status, any suggested view, and any data to controller. diff --git a/views/admin/billing/memberBillingSubHeader.html b/views/admin/billing/memberBillingSubHeader.html index c54db63..feaf062 100644 --- a/views/admin/billing/memberBillingSubHeader.html +++ b/views/admin/billing/memberBillingSubHeader.html @@ -1,5 +1,34 @@ - +
+
+
Member Name: {$memberData.name}
+
{$memberData.member_type_short}
+ {if $account_data} +
Renewal date: {$account_data.renewal_date|strtotime|date_format}
+ {/if} +
+ +
+ +
+
diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html new file mode 100644 index 0000000..bd9b804 --- /dev/null +++ b/views/admin/billing/renew.html @@ -0,0 +1,99 @@ +{include file='admin/member/header.html'} +{include file='admin/billing/memberBillingSubHeader.html'} + +
+ + {if $paymentSuccess}Payment Completed{/if} + {if $paymentError}Error With Payment{/if} + + {if $messages} + {foreach $messages as $message} +
{$message}
+ {/foreach} + {/if} +

Renew membership

+ +
+ + + + + + + +

Employees:

+ + {if $member_invoice} +
+ +
+ {/if} + + {foreach $employees as $employee} +
+ +
+ {/foreach} + +
+
+ + + +
+
+ + + + +{include file='admin/footer.html'} -- 2.17.1