From: Steve Sutton Date: Thu, 29 Mar 2018 15:02:41 +0000 (-0400) Subject: Add shortcode for front end renewal form. X-Git-Tag: v1.0.0^2~95 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=1459ec35bc30bc1c86cb884f7d6a23d880ef9c76;p=WP-Plugins%2Fglm-member-db-billing.git Add shortcode for front end renewal form. Add the renewal form to the front end. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index a8942a6..62f0005 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -787,50 +787,52 @@ class GlmBillingSupport // This may need to have filters setup in the contact plugin as well. $employees = apply_filters( 'glm_contact_has_employees', '', $member_id ); // echo '
$employees: ' . print_r( $employees, true ) . '
'; - foreach ( $employees as $ref_dest ) { - $invoice = false; - $billing_account = $this->getAccountByRefDest( $ref_dest ); - // If we don't have an account for this member then one - // Needs to be created. - if ( !$billing_account ) { - // Get the Member Name - $member_name = $this->wpdb->get_var( - $this->wpdb->prepare( - "SELECT name - FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members - WHERE id = %d", - $ref_dest - ) - ); - if ( $member_name ) { - $this->wpdb->insert( - GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', - array( - 'ref_dest' => $ref_dest, - 'ref_name' => $member_name, - ), - array( - '%d', - '%s' + if ( isset( $employees ) && is_array( $employees ) ) { + foreach ( $employees as $ref_dest ) { + $invoice = false; + $billing_account = $this->getAccountByRefDest( $ref_dest ); + // If we don't have an account for this member then one + // Needs to be created. + if ( !$billing_account ) { + // Get the Member Name + $member_name = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT name + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members + WHERE id = %d", + $ref_dest ) ); - $employee_account_id = $this->wpdb->insert_id; - $billing_account = $this->getAccountByRefDest( $ref_dest ); + if ( $member_name ) { + $this->wpdb->insert( + GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'accounts', + array( + 'ref_dest' => $ref_dest, + 'ref_name' => $member_name, + ), + array( + '%d', + '%s' + ) + ); + $employee_account_id = $this->wpdb->insert_id; + $billing_account = $this->getAccountByRefDest( $ref_dest ); + } } - } - if ( $billing_account ) { - // 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->getInvoiceTypeById( $invoice_type_id ); + if ( $billing_account ) { + // 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->getInvoiceTypeById( $invoice_type_id ); + } + $accounts[$billing_account['id']] = array( + 'id' => $billing_account['id'], + 'ref_dest' => $billing_account['ref_dest'], + 'ref_name' => $billing_account['ref_name'], + 'invoice' => $invoice, + 'email' => $billing_account['email'] + ); } - $accounts[$billing_account['id']] = 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/models/admin/billing/index.php b/models/admin/billing/index.php index 3261927..599c829 100644 --- a/models/admin/billing/index.php +++ b/models/admin/billing/index.php @@ -122,6 +122,7 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts $start = 1; $limit = 20; // Set to the number of listings per page $accounts = false; + $allAccounts = false; $haveInvoices = false; $filterAccounts = ''; $totalInvoices = false; @@ -311,6 +312,7 @@ class GlmMembersAdmin_billing_index extends GlmDataAccounts 'toDate' => $toDate, 'haveInvoices' => $haveInvoices, 'accounts' => $accounts, + 'allAccounts' => $accounts, 'filterAccounts' => $filterAccounts, 'totalInvoices' => $totalInvoices, 'filterPending' => $filterPending, diff --git a/models/front/billing/renew.php b/models/front/billing/renew.php new file mode 100644 index 0000000..b286c02 --- /dev/null +++ b/models/front/billing/renew.php @@ -0,0 +1,334 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @release index.php,v 1.0 2014/10/31 19:31:47 cscott Exp $ + * @link http://dev.gaslightmedia.com/ + */ +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'; + +// Load Billing data abstract +// require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataBilling.php'; + +class GlmMembersFront_billing_renew // extends GlmDataBilling +{ + + /** + * WordPress Database Object + * + * @var $wpdb + * @access public + */ + public $wpdb; + /** + * Plugin Configuration Data + * + * @var $config + * @access public + */ + public $config; + /** + * Billing ID + * + * @var $memberID + * @access public + */ + public $memberID = false; + + /** + * Constructor + * + * This contructor performs the work for this model. This model returns + * an array containing the following. + * + * 'status' + * + * True if successfull and false if there was a fatal failure. + * + * 'view' + * + * A suggested view name that the contoller should use instead of the + * default view for this model or false to indicate that the default view + * should be used. + * + * 'data' + * + * Data that the model is returning for use in merging with the view to + * produce output. + * + * @wpdb object WordPress database object + * + * @return array Array containing status, suggested view, and any data + */ + public function __construct ($wpdb, $config) + { + + // Save WordPress Database object + $this->wpdb = $wpdb; + + // Save plugin configuration object + $this->config = $config; + + /* + * Run constructor for the Billing data class + * + * Note, the third parameter is a flag that indicates to the Contacts + * data class that it should flag a group of fields as 'view_only'. + */ + // parent::__construct(false, false, true); + + } + + public function modelAction($actionData = false) + { + // Initialize Variables Here + $fromMemberMenu = false; + $this->memberID = false; + $memberData = false; + $memberName = false; + $haveMember = false; + $haveAccount = false; + $option = 'renew'; + $view = 'renew'; + $account = false; + $accountID = 0; + $account_data = false; + $balance_due = false; + $invoiceHtml = false; + $management = false; + $messages = array(); + $paymentSuccess = false; + $paymentError = false; + $hasBillingAccount = false; + $employees = false; + $member_invoice = false; + $payable_types = false; + $account_status = false; + + // For lockedToMember. + $lockedToMember = false; + $lockedWhereT = 'true'; + $lockedWhere = 'true'; + + // Call in the support class + $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config ); + // echo '
$this->config: ' . print_r( $this->config, true ) . '
'; + if ( isset( $this->config['loggedInUser'] ) + && isset( $this->config['loggedInUser']['contactUser'] ) + && isset( $this->config['loggedInUser']['contactUser']['ref_dest'] ) + ) { + $this->memberID = $this->config['loggedInUser']['contactUser']['ref_dest']; + } else { + // throw an error + wp_die('Not finding any account for you!'); + } + + // 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); + // echo '
$lockedToMember: ' . print_r( $lockedToMember, true ) . '
'; + if ($lockedToMember) { + $memberID = $lockedToMember; + $this->memberID = $memberID; + $lockedToMember = $memberID; + $lockedWhereT = 'T.ref_type = '.$this->config['ref_type_numb']['Member'].' AND T.ref_dest = '.$memberID; + $lockedWhere = 'ref_type = '.$this->config['ref_type_numb']['Member'].' AND ref_dest = '.$memberID; + } + + require_once GLM_MEMBERS_PLUGIN_CLASS_PATH . '/data/dataMembers.php'; + $this->Members = new GlmDataMembers( $this->wpdb, $this->config ); + + if ( $this->memberID ) { + $memberData = $this->Members->getEntry( $this->memberID ); + } + + if ( isset( $memberData ) && is_array( $memberData ) && $memberData['id'] > 0 ) { + $haveMember = true; + $memberName = $memberData['name']; + } + + if ( isset( $_REQUEST['option'] ) ) { + $option = $_REQUEST['option']; + } + + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; + $Accounts = new GlmDataAccounts( $this->wpdb, $this->config ); + $accountID = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts + WHERE ref_dest = %d", + $this->memberID + ) + ); + $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountID ); + + switch ( $option ) { + case 'renew': + // TODO: only the renew form if the member is not active + if ( $account_status == 'Active' ) { + $view = 'nonrenew'; + } else { + $view = 'renew'; + // echo '
$this->memberID: ' . print_r( $this->memberID, true ) . '
'; + + + // Get list of payable invoice_types + $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); + // echo '
$payable_types: ' . print_r( $payable_types, true ) . '
'; + + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + } + // echo '
$member_invoice: ' . print_r( $member_invoice, true ) . '
'; + + // Get a list of this accounts employees. If they have any. + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + // echo '
$employees: ' . print_r( $employees, true ) . '
'; + + // Load DataClass for Management. + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php'; + $Management = new GlmDataBillingManagement( $this->wpdb, $this->config ); + $management = $Management->getEntry( 1 ); + + // Need to see if there's an account for this member. + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataAccounts.php'; + $account = $Accounts->editEntry( $accountID ); + } + + break; + + case 'renewMembership': + $error = false; + $view = 'renewMembership'; + // $messages[] = '
$_REQUEST: ' . print_r( $_REQUEST, true ) . '
'; + + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + } else { + $error = true; + } + + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + + $invoice_data = array( + 'account_id' => $accountID, + 'renew_type_id' => filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT ), + 'amount' => $_REQUEST['total_renew_amount'], + 'due_date' => date( 'Y-m-d' ), + 'member_invoice' => $member_invoice, + 'employee_data' => $employees, + 'employees' => $_REQUEST['employees'] + ); + if ( !$invoice_data ) { + $error = true; + } + + // Create the invoice for this member. + $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data ); + if ( !$invoice_id ) { + $error = true; + } + + // Now that the invoice is created. Do payment Processing. + + // If there's any errors then re-show the form. + if ( $error ) { + // TODO: Here we'll need to remove the invoice created if any. + $view = 'renew'; + + // Get list of payable invoice_types + $payable_types = $BillingSupport->getAllPayableInvoiceTypes(); + + $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID ); + if ( $member_invoice_id ) { + $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id ); + } + + // Get a list of this accounts employees. If they have any. + $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID ); + + // Load DataClass for Management. + require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH . '/data/dataManagement.php'; + $Management = new GlmDataBillingManagement( $this->wpdb, $this->config ); + $management = $Management->getEntry( 1 ); + + // Need to see if there's an account for this member. + $account = $Accounts->editEntry( $accountID ); + } else { + // Do the Payment Processing. + $errors = $BillingSupport->processMemberRenewal( $accountID, $invoice_id, $invoice_data['amount'], $invoice_data['employees'] ); + // echo '
$errors: ' . print_r( $errors, true ) . '
'; + } + + + break; + + + } + + // 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( + 'accountID' => $accountID, + 'option' => $option, + 'fromMemberMenu' => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ), + 'lockedToMember' => $lockedToMember, + 'numberPending' => $numberPending, + 'memberID' => $this->memberID, + 'haveMember' => $haveMember, + 'haveAccount' => $haveAccount, + 'memberData' => $memberData, + 'memberName' => $memberName, + 'account' => $account, + 'transactions' => $transactions, + 'account_data' => $account_data, + 'balance_due' => $balance_due, + 'transaction_types' => $this->config['transaction_type'], + 'invoiceHtml' => $invoiceHtml, + 'billing_settings' => $this->config['billing_settings'], + 'management' => $management, + 'messages' => $messages, + 'invoices' => $invoices, + 'paymentSuccess' => $paymentSuccess, + 'paymentError' => $paymentError, + 'hasBillingAccount' => $hasBillingAccount, + 'employees' => $employees, + 'member_invoice' => $member_invoice, + 'payable_types' => $payable_types, + 'account_status' => $account_status, + ); + + // Return status, any suggested view, and any data to controller. + return array( + 'status' => true, + 'modelRedirect' => false, + 'view' => 'front/billing/'.$view.'.html', + 'data' => $templateData + ); + + } + + +} diff --git a/setup/shortcodes.php b/setup/shortcodes.php index eb3e3ed..5aa6d09 100644 --- a/setup/shortcodes.php +++ b/setup/shortcodes.php @@ -87,7 +87,26 @@ */ $glmMembersBillingShortcodes = array( + 'glm-members-billing-renew-form' => array( + 'plugin' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + 'menu' => 'billing', + 'action' => 'renew', + 'table' => false, + 'attributes' => array( + 'member_id' => false, + 'template' => false, + ), + ) ); -$glmMembersBillingShortcodesDescription = ''; +$glmMembersBillingShortcodesDescription = ' +ShortcodeAttributeDescription + + [glm-members-billing-renew-form] +   + + Displays a Membership Renewal Form. + + +'; diff --git a/setup/validActions.php b/setup/validActions.php index b6d3d68..52a36df 100644 --- a/setup/validActions.php +++ b/setup/validActions.php @@ -89,6 +89,9 @@ $glmMembersBillingAddOnValidActions = array( ), ), 'frontActions' => array( + 'billing' => array( + 'renew' => GLM_MEMBERS_BILLING_PLUGIN_SLUG, + ), ) ); diff --git a/views/admin/billing/accountSearchForm.html b/views/admin/billing/accountSearchForm.html index 870654e..e2b7875 100644 --- a/views/admin/billing/accountSearchForm.html +++ b/views/admin/billing/accountSearchForm.html @@ -1,3 +1,67 @@ + +
diff --git a/views/admin/billing/accounts.html b/views/admin/billing/accounts.html index 2a5521e..beb6215 100644 --- a/views/admin/billing/accounts.html +++ b/views/admin/billing/accounts.html @@ -57,68 +57,5 @@ {include file='admin/billing/exportBillingModal.html'} - {include file='admin/footer.html'} diff --git a/views/admin/billing/index.html b/views/admin/billing/index.html index 4bc63db..6db40d8 100644 --- a/views/admin/billing/index.html +++ b/views/admin/billing/index.html @@ -51,68 +51,5 @@ {include file='admin/billing/exportBillingModal.html'} - {include file='admin/footer.html'} diff --git a/views/front/billing/nonrenew.html b/views/front/billing/nonrenew.html new file mode 100644 index 0000000..0bcf1d3 --- /dev/null +++ b/views/front/billing/nonrenew.html @@ -0,0 +1,2 @@ +

No renewal needed!

+

Your an active member.

diff --git a/views/front/billing/renew.html b/views/front/billing/renew.html new file mode 100644 index 0000000..3d15717 --- /dev/null +++ b/views/front/billing/renew.html @@ -0,0 +1,241 @@ + +

Membership Renewal

+
+ + {if $paymentSuccess}Payment Completed{/if} + {if $paymentError}Error With Payment{/if} + + {if $messages} + {foreach $messages as $message} +
{$message}
+ {/foreach} + {/if} + + + + + + + + + {if $member_invoice} +
+
+ Membership Class +
+
+ +
+
+ {/if} + + {if $employees} +
+
+ Employees to Renew +
+
+ {foreach $employees as $employee} + + {/foreach} +
+
+ {/if} + +
+
+ Total Due +
+
+
+
+
+
+ +
+
+ First Name +
+
+ +
+
+
+
+ Last Name +
+
+ +
+
+
+
+ Address +
+
+ +
+
+
+
+ City +
+
+ +
+
+
+
+ State / Province +
+
+ +
+
+
+
+ Zip +
+
+ +
+
+ +
+
+ Name on Card +
+
+ +
+
+
+
+ Card Type +
+
+ +
+
+
+
+ Card Number +
+
+ +
+
+
+
+ Card Expiration +
+
+ +
+
+
+
+ C V V +
+
+ +
+
+ + + + +
+ + + + diff --git a/views/front/billing/renewMembership.html b/views/front/billing/renewMembership.html new file mode 100644 index 0000000..251f6da --- /dev/null +++ b/views/front/billing/renewMembership.html @@ -0,0 +1,5 @@ + +{foreach $messages as $message} +{$message}
+{/foreach} +