From 0dc68cc59200bc67ceaa5e69f1476ac03308dffe Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 23 Mar 2018 16:46:28 -0400 Subject: [PATCH] WIP: Renew member process Working on the process for renew member and their employees. --- classes/billingSupport.php | 78 ++++++++++++++++++++++++ models/admin/member/billing.php | 32 +++++++++- views/admin/billing/renew.html | 4 +- views/admin/billing/renewMembership.html | 8 +++ 4 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 views/admin/billing/renewMembership.html diff --git a/classes/billingSupport.php b/classes/billingSupport.php index 7f82b1d..0658212 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -793,5 +793,83 @@ class GlmBillingSupport return $accounts; } + public function createMemberInvoiceWithEmployees( $invoice_data ) + { + // Make sure the required parts of $invoice_data exists. + if ( !isset( $invoice_data['account_id'] ) + || !isset( $invoice_data['amount'] ) + || !isset( $invoice_data['due_date'] ) + || !isset( $invoice_data['member_invoice'] ) + || !isset( $invoice_data['employee_data'] ) + || !isset( $invoice_data['employees'] ) + ) { + return false; + } + // Create invoice. + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoices', + array( + 'transaction_time' => date( 'Y-m-d H:i:s' ), + 'account' => $account_id, + 'amount_total' => $amount, + 'balance' => $amount, + 'due_date' => $due_date, + 'paid' => 0, + 'notes' => '', + 'recurring' => true, + 'recurrence' => 20 + ), + array( + '%s', // transaction_time + '%d', // account + '%s', // amount + '%s', // balance + '%s', // due_date + '%s', // paid + '%s', // notes + '%s', // recurring + '%s', // recurrence + ) + ); + $invoice_id = $this->wpdb->insert_id; + if ( $invoice_id ) { + // Add line items for each employee. + foreach ( $employees as $ref_dest ) { + // Get the account from the ref_dest. + $line_account_id = $this->getAccountByRefDest( $ref_dest ); + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'line_items', + array( + 'invoice' => $invoice_id, + 'line_item_type' => $line_item, + 'name' => $_REQUEST['line_item_name'][$line_item], + 'amount' => $_REQUEST['line_item_amount'][$line_item], + 'quantity' => $_REQUEST['line_item_qty'][$line_item], + 'total' => (float)$_REQUEST['line_item_qty'][$line_item] * (float)$_REQUEST['line_item_amount'][$line_item], + 'created' => date('Y-m-d'), + 'first_due_date' => $_REQUEST['due_date'], + 'next_due_date' => $_REQUEST['due_date'], + 'recurring' => $invoiceType['recurring']['value'], + 'recurrence' => $invoiceType['recurrence'] + ), + array( + '%d', // invoice + '%d', // line_item_type (invoiceType id) + '%s', // name + '%s', // amount + '%d', // quantity + '%d', // total + '%s', // created + '%s', // first_due_date + '%s', // next_due_date + '%d', // recurring + '%d', // recurrence + ) + ); + + } + } + } + } diff --git a/models/admin/member/billing.php b/models/admin/member/billing.php index 4de6596..6ebf47f 100644 --- a/models/admin/member/billing.php +++ b/models/admin/member/billing.php @@ -183,7 +183,6 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $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 ); @@ -192,6 +191,34 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling // Get a list of this accounts employees. If they have any. break; + + case 'renewMembership': + $view = 'renewMembership'; + $messages[] = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoicTypeById( $member_invoice_id ); + } + $messages[] = '
$member_invoice: ' . print_r( $member_invoice, true ) . '
'; + + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + $messages[] = '
$employees: ' . print_r( $employees, true ) . '
'; + + $invoice_data = array( + 'account_id' => filter_var( $_REQUEST['account_id'], FILTER_VALIDATE_INT ), + 'amount' => filter_var( $_REQUEST['total_renew_amount'], FILTER_VALIDATE_STRING ), + 'due_date' => date( 'Y-m-d' ), + 'member_invoice' => $member_invoice, + 'employee_data' => $employees, + 'employees' => $_REQUEST['employees'] + ); + + // Create the invoice for this member. + + + break; + case 'account': require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); @@ -244,6 +271,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $view = 'editAccount'; break; + case 'view': $invoiceHtml = $BillingSupport->viewInvoice( $_REQUEST['id'] ); @@ -252,6 +280,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling $view = 'viewInvoice'; break; + case 'createPayment': $view = 'paymentProcess'; @@ -441,6 +470,7 @@ class GlmMembersAdmin_member_billing // extends GlmDataBilling } break; + case 'makepayment': // Load DataClass for accounts. diff --git a/views/admin/billing/renew.html b/views/admin/billing/renew.html index bd9b804..ab4f35c 100644 --- a/views/admin/billing/renew.html +++ b/views/admin/billing/renew.html @@ -16,9 +16,9 @@
- + - +

Employees:

diff --git a/views/admin/billing/renewMembership.html b/views/admin/billing/renewMembership.html new file mode 100644 index 0000000..62b146c --- /dev/null +++ b/views/admin/billing/renewMembership.html @@ -0,0 +1,8 @@ +{include file='admin/member/header.html'} +{include file='admin/billing/memberBillingSubHeader.html'} + +{foreach $messages as $message} +{$message}
+{/foreach} + +{include file='admin/footer.html'} -- 2.17.1