Create new front end form for payments.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Mar 2019 14:22:34 +0000 (10:22 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Mar 2019 14:23:13 +0000 (10:23 -0400)
This will allow members to make payments without having to log in.

13 files changed:
classes/billingSupport.php
models/admin/ajax/billingAccount.php
models/admin/billing/reports.php
models/front/billing/paymentForm.php [new file with mode: 0644]
models/front/billing/renew.php
setup/shortcodes.php
setup/validActions.php
views/admin/billing/exportReportModal.html [new file with mode: 0644]
views/admin/billing/header.html
views/admin/billing/reports.html
views/front/billing/paymentForm.html [new file with mode: 0644]
views/front/billing/paymentFormProcess.html [new file with mode: 0644]
views/front/billing/renew.html

index 5727936..9fc180f 100644 (file)
@@ -1480,6 +1480,33 @@ class GlmBillingSupport
 
     }
 
+    public function processOnlinePayment( $account_id, $invoice_id, $amount ) {
+
+        $result = $this->processPayment( $account_id, $invoice_id, $amount );
+
+        if ( $result['status'] === 1 ) {
+
+            $_REQUEST['transaction_time'] = date( 'Y-m-d H:i:s' );
+
+            // Create new payment.
+            $payment_id = $this->createPayment( $account_id, $amount, 'Credit Card' );
+
+            // Record the payment.
+            $this->recordPayment( $payment_id, $account_id, $amount, $invoice_id );
+
+            // Set the contact_role for the member contact so they can login now.
+            if ( $account_id ) {
+                $this->setMemberAccountActive( $account_id );
+            }
+
+            $errors = array();//$result['errors'];
+        } else {
+            $errors = $result['errors'];
+        }
+
+        return $errors;
+    }
+
     /**
      * Set the member contact for this account as active user now.
      * Set member contact to contact_role = 20
index 2df9bc5..a649f51 100644 (file)
@@ -138,10 +138,10 @@ class GlmMembersAdmin_ajax_billingAccount extends GlmDataAccounts
                 if ( !$invoice ) {
                     $return = array( 'status'  => false, 'message' => 'no invoice' );
                 }
-                trigger_error( print_r( $invoice, true ), E_USER_NOTICE );
+                // trigger_error( print_r( $invoice, true ), E_USER_NOTICE );
 
                 $accountId = $invoice['account']['value'];
-                trigger_error( print_r( $accountId, true ), E_USER_NOTICE );
+                // trigger_error( print_r( $accountId, true ), E_USER_NOTICE );
                 if ( !$accountId ) {
                     $return = array( 'status'  => false, 'message' => 'no accountId' );
                 }
@@ -164,7 +164,7 @@ class GlmMembersAdmin_ajax_billingAccount extends GlmDataAccounts
                         ),
                         ARRAY_A
                     );
-                    trigger_error( print_r( $account, true ), E_USER_NOTICE );
+                    // trigger_error( print_r( $account, true ), E_USER_NOTICE );
                     // Returning the invoice_type of the account
                     // TODO: This maybe should be the actual invoice type_id
                     if ( $account ) {
index d092f01..8621b40 100644 (file)
@@ -268,6 +268,7 @@ class GlmMembersAdmin_billing_reports extends GlmDataTransactions
                 $this->member_data = true;
                 $this->notes       = true;
                 $accountsResult    = $this->getList( $reportWhere, $orderBy, true, 'id', $start, $limit );
+                // echo '<pre>' . print_r( $accountsResult, true ) . '</pre>';
                 $totalAccounts     = $this->getStats( $reportWhere );
                 $totalInvoices     = $this->getInvoiceTotal( $reportWhere );
                 $totalPayments     = $this->getPaymentTotal( $reportWhere );
diff --git a/models/front/billing/paymentForm.php b/models/front/billing/paymentForm.php
new file mode 100644 (file)
index 0000000..b57ffab
--- /dev/null
@@ -0,0 +1,380 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * Admin Billing Dashboard
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @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.'/billingSupport.php';
+
+class GlmMembersFront_billing_paymentForm // 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            = 'payment';
+        $view              = 'paymentForm';
+        $account           = false;
+        $accountId         = 0;
+        $account_data      = false;
+        $balance_due       = false;
+        $invoiceHtml       = false;
+        $management        = false;
+        $messages          = array();
+        $paymentSuccess    = false;
+        $paymentError      = false;
+        $hasBillingAccount = false;
+        $member_invoice    = false;
+        $payable_types     = false;
+        $account_status    = false;
+        $unregistered      = false;
+        $invoiceId         = false;
+
+        // For lockedToMember.
+        $lockedToMember = false;
+        $lockedWhereT   = 'true';
+        $lockedWhere    = 'true';
+
+        // Check for unregistered.
+        if ( isset( $actionData['request']['unregistered'] ) && filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN ) ) {
+            $unregistered = filter_var( $actionData['request']['unregistered'], FILTER_VALIDATE_BOOLEAN );
+        }
+
+        // echo '<pre>$unregistered: ' . print_r( $unregistered, true ) . '</pre>';
+
+        // Call in the support class
+        $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
+
+        if ( isset( $_REQUEST['member'] ) && $memberId = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ) ) {
+            $this->memberId = $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'];
+        }
+
+        $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
+
+        if ( isset( $memberId ) && $memberId ) {
+            require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+            $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 ( isset( $accountId ) && $accountId ) {
+                $account_status = apply_filters( 'glm-billing-get-account-status', '', $accountId );
+            }
+        }
+
+        switch ( $option ) {
+        case 'payment':
+            // TODO: only the renew form if the member is not active
+            if ( $account_status == 'Active' ) {
+                $view = 'nonrenew';
+            } else  {
+                $view = 'paymentForm';
+
+                if ( $unregistered ) {
+                    $lockedToMember = true;
+                }
+
+                // Get list of payable invoice_types
+                $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
+                // echo '<pre>$payable_types: ' . print_r( $payable_types, true ) . '</pre>';
+
+                // 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 );
+
+                require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
+                if ( $accountId ) {
+                    // Need to see if there's an account for this member.
+                    $account = $Accounts->editEntry( $accountId );
+                } else {
+                    $account = $Accounts->newEntry();
+                }
+            }
+
+            break;
+
+        case 'paymentProcess':
+            $error = false;
+            $view  = 'paymentFormProcess';
+
+            if ( isset( $_REQUEST['invoice_number'] ) ) {
+                $invoiceId = filter_var( $_REQUEST['invoice_number'], FILTER_VALIDATE_INT );
+            } else {
+                die( 'Error: no invoiceId' );
+            }
+
+            // Check for account_number
+            // If given then this is from unregistered user.
+            // Have to verify that this number does match with billing_account.
+            if ( isset( $_REQUEST['account_number'] ) && $account_number = filter_var( $_REQUEST['account_number'], FILTER_SANITIZE_STRING ) ) {
+                // Verify account number.
+                $accountId = $this->wpdb->get_var(
+                    $this->wpdb->prepare(
+                        "SELECT id
+                           FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
+                          WHERE account_number = %s",
+                        $account_number
+                    )
+                );
+            }
+
+            // Start database transaction
+            $this->wpdb->show_errors();
+            $this->wpdb->query('START TRANSACTION');
+
+            // Look at the payment option given
+            $payment_option = filter_var( $_REQUEST['payment_option'], FILTER_SANITIZE_STRING );
+
+            switch ( $payment_option ) {
+            case 'pay_by_credit_card':
+                // Do the Payment Processing.
+                $processErrors = $BillingSupport->processOnlinePayment( $accountId, $invoiceId, $_REQUEST['total_renew_amount'] );
+
+                if ( $processErrors ) {
+                    if ( isset( $processErrors ) && is_array( $processErrors ) && count( $processErrors ) > 0 ) {
+                        $error = true;
+                        foreach ( $processErrors as $error ) {
+                            $messages[] = '<span style="color: red;">'.$error.'</span>';
+                        }
+                    } else if ( isset( $processErrors ) && $processErrors ) {
+                        $error = true;
+                        $messages[] = '<span style="color: red;">'.$processErrors.'</span>';
+                    } else {
+                        $paymentSuccess = true;
+                    }
+                    $view = 'paymentForm';
+
+                    // 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 );
+                    }
+
+                    if ( $this->config['settings']['allow_employees'] ) {
+                        // 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 );
+                }
+                break;
+            case 'pay_by_check':
+                break;
+            }
+
+            // If there's no error reported then show the invoice
+            if ( !$error ) {
+                $this->wpdb->query( 'COMMIT' );
+                // Now need to show the invoice.
+                $view = 'viewInvoice';
+
+                // Get the invoice.
+                $invoiceHtml = $BillingSupport->viewInvoice( $invoiceId );
+
+                // If the member_type is changing then update member
+                // Get current member type
+                $member_id = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT );
+                if ( $member_id ) {
+                    $current_member_type = $this->wpdb->get_var(
+                        $this->wpdb->prepare(
+                            "SELECT member_type
+                               FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "members
+                              WHERE id = %d",
+                            $member_id
+                        )
+                    );
+                    $new_type = filter_var( $_REQUEST['member_renewing'], FILTER_VALIDATE_INT );
+                    $new_member_type = $this->wpdb->get_var(
+                        $this->wpdb->prepare(
+                            "SELECT member_type
+                               FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "invoice_types
+                              WHERE id = %d",
+                            $new_type
+                        )
+                    );
+                    if ( $current_member_type != $new_member_type ) {
+                        $this->wpdb->update(
+                            GLM_MEMBERS_PLUGIN_DB_PREFIX . 'members',
+                            array( 'member_type' => $new_member_type ),
+                            array( 'id' => $member_id ),
+                            array( '%d' ),
+                            array( '%d' )
+                        );
+                    }
+                }
+            } else {
+                $this->wpdb->query( 'ROLLBACK' );
+            }
+
+            break;
+
+        }
+
+        // Get the list of invoices for this member.
+        $statements        = $BillingSupport->getStatementsByRefDest( $this->memberId );
+        $transactions      = false;
+        $account_data      = false;
+        $balance_due       = false;
+        $hasBillingAccount = false;
+        // echo '<pre>$statements: ' . print_r( $statements, true ) . '</pre>';
+        if ( $statements ) {
+            $transactions      = $statements['transactions'];
+            $account_data      = $statements['account_data'];
+            $balance_due       = $statements['balance_due'];
+            $hasBillingAccount = true;
+        }
+        // echo '<pre>$account_data: ' . print_r( $account_data, true ) . '</pre>';
+
+        // Compile template data
+        $templateData = array(
+            'accountId'          => $accountId,
+            'option'             => $option,
+            'fromMemberMenu'     => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ),
+            'lockedToMember'     => $lockedToMember,
+            'invoiceId'          => $invoiceId,
+            '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,
+            '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
+        );
+
+    }
+
+
+}
index 012e401..a0989f6 100644 (file)
@@ -36,10 +36,10 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
     /**
      * Billing ID
      *
-     * @var $memberID
+     * @var $memberId
      * @access public
      */
-    public $memberID = false;
+    public $memberId = false;
 
     /**
      * Constructor
@@ -89,7 +89,7 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
     {
         // Initialize Variables Here
         $fromMemberMenu    = false;
-        $this->memberID    = false;
+        $this->memberId    = false;
         $memberData        = false;
         $memberName        = false;
         $haveMember        = false;
@@ -127,34 +127,40 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
         // Call in the support class
         $BillingSupport = new GlmBillingSupport( $this->wpdb, $this->config );
 
-        // Check if the user is logged in.
-        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'];
-        } elseif ( $unregistered ) {
-            $option = 'renew';
-        } else {
-            $option = 'noaccount';
+        if ( isset( $_REQUEST['member'] ) && $memberId = filter_var( $_REQUEST['member'], FILTER_VALIDATE_INT ) ) {
+            $this->memberId = $memberId;
         }
 
-        // 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 ( !$this->memberId ) {
+            // Check if the user is logged in.
+            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'];
+            } elseif ( $unregistered ) {
+                $option = 'renew';
+            } else {
+                $option = 'noaccount';
+            }
 
-        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;
+            // 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) {
+                $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 ( $this->memberId ) {
+            $memberData = $this->Members->getEntry( $this->memberId );
         }
 
         if ( isset( $memberData ) && is_array( $memberData ) && $memberData['id'] > 0 ) {
@@ -168,14 +174,14 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
 
         $Accounts = new GlmDataAccounts( $this->wpdb, $this->config );
 
-        if ( isset( $memberID ) && $memberID ) {
+        if ( isset( $memberId ) && $memberId ) {
             require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH .  '/data/dataAccounts.php';
             $accountID = $this->wpdb->get_var(
                 $this->wpdb->prepare(
                     "SELECT id
                        FROM " . GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . "accounts
                       WHERE ref_dest = %d",
-                    $this->memberID
+                    $this->memberId
                 )
             );
             if ( isset( $accountID ) && $accountID ) {
@@ -205,14 +211,14 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
                 $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
                 // echo '<pre>$payable_types: ' . print_r( $payable_types, true ) . '</pre>';
 
-                $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+                $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
                 if ( $member_invoice_id ) {
                     $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
                 }
 
                 if ( $this->config['settings']['allow_employees'] ) {
                     // Get a list of this accounts employees. If they have any.
-                    $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+                    $employees = $BillingSupport->getListOfAccountEmployees( $this->memberId );
                 }
 
                 // Load DataClass for Management.
@@ -250,15 +256,19 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
                 );
             }
 
-            $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+            $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
+            echo '<pre>$this->memberId: ' . print_r( $this->memberId, true ) . '</pre>';
+            echo '<pre>$member_invoice_id: ' . print_r( $member_invoice_id, true ) . '</pre>';
             if ( $member_invoice_id ) {
                 $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
             } else {
-                $error = true;
+                $error        = true;
+                $paymentError = true;
+                trigger_error( 'member_invoice_id not found', E_USER_NOTICE );
             }
 
             if ( $this->config['settings']['allow_employees'] ) {
-                $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+                $employees = $BillingSupport->getListOfAccountEmployees( $this->memberId );
             }
 
             $invoice_data = array(
@@ -301,13 +311,18 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
             // Create the invoice for this member.
             $invoice_id = $BillingSupport->createMemberInvoiceWithEmployees( $invoice_data );
             if ( !$invoice_id ) {
-                $error = true;
+                $error        = true;
+                $paymentError = true;
+                trigger_error( 'invoice_id not found', E_USER_NOTICE );
             }
 
             // Now that the invoice is created. Do payment Processing.
 
             // If there's any errors then re-show the form.
             if ( $error ) {
+                $paymentError = true;
+                trigger_error( 'error', E_USER_NOTICE );
+
                 // Remove the invoice created.
                 if ( $invoice_id ) {
                     $BillingSupport->removeInvoiceById( $invoice_id );
@@ -318,14 +333,14 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
                 // Get list of payable invoice_types
                 $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
 
-                $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+                $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
                 if ( $member_invoice_id ) {
                     $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
                 }
 
                 if ( $this->config['settings']['allow_employees'] ) {
                     // Get a list of this accounts employees. If they have any.
-                    $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+                    $employees = $BillingSupport->getListOfAccountEmployees( $this->memberId );
                 }
 
                 // Load DataClass for Management.
@@ -362,14 +377,14 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
                         // Get list of payable invoice_types
                         $payable_types = $BillingSupport->getAllPayableInvoiceTypes();
 
-                        $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberID );
+                        $member_invoice_id = $BillingSupport->getMembersInvoiceTypeByRefDest( $this->memberId );
                         if ( $member_invoice_id ) {
                             $member_invoice = $BillingSupport->getInvoiceTypeById( $member_invoice_id );
                         }
 
                         if ( $this->config['settings']['allow_employees'] ) {
                             // Get a list of this accounts employees. If they have any.
-                            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberID );
+                            $employees = $BillingSupport->getListOfAccountEmployees( $this->memberId );
                         }
 
                         // Load DataClass for Management.
@@ -437,7 +452,7 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
         }
 
         // Get the list of invoices for this member.
-        $statements        = $BillingSupport->getStatementsByRefDest( $this->memberID );
+        $statements        = $BillingSupport->getStatementsByRefDest( $this->memberId );
         $transactions      = false;
         $account_data      = false;
         $balance_due       = false;
@@ -458,7 +473,7 @@ class GlmMembersFront_billing_renew // extends GlmDataBilling
             'fromMemberMenu'     => ( defined('GLM_MEMBERS_BILLING_MEMBER_MENU' ) ? true: false ),
             'lockedToMember'     => $lockedToMember,
             // 'numberPending'      => $numberPending,
-            'memberID'           => $this->memberID,
+            'memberId'           => $this->memberId,
             'haveMember'         => $haveMember,
             'haveAccount'        => $haveAccount,
             'memberData'         => $memberData,
index 3ab442d..b58f4ad 100644 (file)
@@ -95,7 +95,16 @@ $glmMembersBillingShortcodes = array(
         'attributes' => array(
             'member_id'    => false,
             'template'     => false,
-            'unregistered' => false,
+        ),
+    ),
+    'glm-members-billing-payment-form' => array(
+        'plugin'     => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+        'menu'       => 'billing',
+        'action'     => 'paymentForm',
+        'table'      => false,
+        'attributes' => array(
+            'member_id'    => false,
+            'template'     => false,
         ),
     ),
     'glm-members-billing-become-member-form' => array(
@@ -119,7 +128,13 @@ $glmMembersBillingShortcodesDescription = '
         Displays a Membership Renewal Form.
     </td>
 </tr>
-<tr><th>Shortcode</th><th>Attribute</th><th>Description</th></tr>
+ <tr>
+    <th>[glm-members-billing-payment-form]</th>
+    <td>&nbsp;</td>
+    <td width="50%">
+        Displays an Online Payment Form.
+    </td>
+</tr>
  <tr>
     <th>[glm-members-billing-become-member-form]</th>
     <td>&nbsp;</td>
index 18c2061..940eb8f 100644 (file)
@@ -105,6 +105,7 @@ $glmMembersBillingAddOnValidActions = array(
     'frontActions' => array(
         'billing' => array(
             'renew'        => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+            'paymentForm'  => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
             'becomeMember' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
         ),
     )
diff --git a/views/admin/billing/exportReportModal.html b/views/admin/billing/exportReportModal.html
new file mode 100644 (file)
index 0000000..7601dbf
--- /dev/null
@@ -0,0 +1,58 @@
+<div id="exportReportDialog" class="glm-dialog-box" title="Export Billing Reports">
+    <form id="exportForm" action="{$ajaxUrl}" method="post" enctype="multipart/form-data">
+        <input type="hidden" name="action" value="glm_members_admin_ajax">
+        <input type="hidden" name="glm_action" value="accountsListExport">
+        <table class="glm-admin-table">
+            <tr><th>Show Active: </th><td><input type="checkbox" name="filterActive" {if $filterActive}checked{/if}></td></tr>
+            <tr><th>Show Pending: </th><td><input type="checkbox" name="filterPending" {if $filterPending}checked{/if}></td></tr>
+            <tr><th>Show Overdue: </th><td><input type="checkbox" name="filterOverdue" {if $filterOverdue}checked{/if}></td></tr>
+            <tr><th>Show Archived: </th><td><input type="checkbox" name="filterArchived" {if $filterArchived}checked{/if}></td></tr>
+            <tr><th>Show Expired: </th><td><input type="checkbox" name="filterExpired" {if $filterExpired}checked{/if}></td></tr>
+            <tr>
+                <th>Date Range Search: </th>
+                <td>
+                    <b>From Date: </b><br />
+                    <input type="text" name="fromDate" value="{$fromDate}" class="glm-form-text-input-short glm-date-input"><br />
+                    <b>To Date: </b><br />
+                    <input type="text" name="toDate" value="{$toDate}" class="glm-form-text-input-short glm-date-input"><br />
+                </td>
+            </tr>
+            <tr>
+                <th>Name Search:</th>
+                <td>
+                    <input id="member-account2" type="hidden" name="filterReports" value="{$filterReports}">
+                    <input id="account_name2" name="searchName" value="{if $searchName}{$searchName}{/if}" />
+                </td>
+            </tr>
+            <tr>
+                <th>Fields to export: </th>
+                <td>
+                    <table padding="3">
+                        <tr>
+                            <td colspan="2"><a id="selectAllExportFields">Check All</a> / <a id="unselectAllExportFields">Uncheck All</a></td>
+                        </tr>
+                        <tr>
+                            <td class="exportFieldsTd">
+                                <input type="checkbox" name="exportId"> ID<br>
+                                <input type="checkbox" name="exportTransactionTime" checked> Transaction Time <br>
+                                <input type="checkbox" name="exportMember" checked> {$terms.term_member_cap} Name<br>
+                                <input type="checkbox" name="exportInvoiceAmount" checked> Invoice Amount <br>
+                                <input type="checkbox" name="exportPaymentAmount" checked> Payment Amount <br>
+
+                            </td>
+                        </tr>
+                    </table>
+                </td>
+            </tr>
+            <tr>
+                <th>Export to: </th>
+                <td>
+                    <input type="radio" name="type" value="csv" checked="checked"> Export to Spreadsheet (CSV)<br>
+                </td>
+            </tr>
+        </table>
+        <a id="exportReportsCancel" class="button button-secondary glm-right">Cancel</a>
+        <input type="submit" value="Export" class="button button-primary">
+    </form>
+</div>
+
index 26b4ef3..7dd924c 100644 (file)
@@ -10,5 +10,6 @@
             <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=reports" class="nav-tab{if $thisAction==reports} nav-tab-active{/if}">Reports</a>
         {/if}
         <a href="{$thisUrl}?page=glm-members-admin-menu-billing&glm_action=logs" class="nav-tab{if $thisAction==logs} nav-tab-active{/if}">Logs</a>
+        <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=billing" class="nav-tab{if $thisAction==logs} nav-tab-active{/if}">Settings</a>
     </h2>
     <div id="glm-admin-content-container">
index 1783ce7..05acae7 100644 (file)
@@ -1,6 +1,9 @@
 {include file='admin/billing/header.html'}
 <h2>Invoicing</h2>
 {include file='admin/billing/reportsSubHeader.html'}
+
+<div id="exportReportsButton" class="button button-secondary glm-admin-export-button">Report Export</div>
+
 <form id="reports-form" action="{$thisUrl}?page={$thisPage}" method="get">
     <input type="hidden" name="page" value="{$thisPage}">
     <input type="hidden" name="glm_action" value="reports">
@@ -67,8 +70,8 @@
     <p>Total found: {$totalAccounts}</p>
     {* Paging *}
     {if $paging}
-        <input type="Submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
-        <input type="Submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Previous {$limit} Reports" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="Submit" name="pageSelect" value="Next {$limit} Reports" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
     {/if}
     <br clear="all">
     {if isset( $accounts ) && !empty( $accounts )}
     {/if}
     {* Paging *}
     {if $paging}
-        <input type="submit" name="pageSelect" value="Previous {$limit} Accounts" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
-        <input type="submit" name="pageSelect" value="Next {$limit} Accounts" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
+        <input type="submit" name="pageSelect" value="Previous {$limit} Reports" class="button button-secondary glm-button"{if !$prevStart} disabled{/if}>
+        <input type="submit" name="pageSelect" value="Next {$limit} Reports" class="button button-secondary glm-button"{if !$nextStart} disabled{/if}>
     {/if}
 </form>
 {if $option == 'reportGenerator'}
         <div class="total-payments">Total Payments: <span>{$totalPayments}</span></div>
     </div>
 {/if}
+
+{include file='admin/billing/exportReportModal.html'}
+
 <script>
 jQuery(document).ready(function($) {
     // Date Input
@@ -176,6 +182,29 @@ jQuery(document).ready(function($) {
             $('#reportsForm').submit();
         }
     } );
+
+    // Setup for the modal box
+    $('#exportReportDialog').dialog( {
+        autoOpen: false,
+        minWidth: 700,
+        dialogClass: 'glm-dialog-no-close'
+    } );
+    $('#exportReportsButton').click( function(){
+        $('#exportReportDialog').dialog( 'open' );
+    } );
+    $('#exportReportsCancel').click( function(){
+        $('#exportReportDialog').dialog( 'close' );
+    } );
+    $('#selectAllExportFields').click(function(){
+        $('.exportFieldsTd input[type="checkbox"]').each(function(){
+            $(this).prop('checked', true);
+        });
+    });
+    $('#unselectAllExportFields').click(function(){
+        $('.exportFieldsTd input[type="checkbox"]').each(function(){
+            $(this).prop('checked', false);
+        });
+    });
 });
 </script>
 {include file='admin/footer.html'}
diff --git a/views/front/billing/paymentForm.html b/views/front/billing/paymentForm.html
new file mode 100644 (file)
index 0000000..9874a4b
--- /dev/null
@@ -0,0 +1,173 @@
+
+<h3>Online Payment Form</h3>
+<div id="billing-payment-form" class="glm-billing-form">
+
+    {if $paymentSuccess}<span class="glm-notice glm-flash-updated">Payment Completed</span>{/if}
+    {if $paymentError}<span class="glm-notice glm-flash-updated">Error With Payment</span>{/if}
+
+    {if $messages}
+        {foreach $messages as $message}
+            <div class="">{$message}</div>
+        {/foreach}
+    {/if}
+
+    <form action="{$thisUrl}" method="post">
+        <input type="hidden" name="option" value="paymentProcess" />
+        <input type="hidden" id="member_id" name="member" value="{$memberId}" />
+        <input type="hidden" id="account_id" name="account_id" value="{$accountId}" />
+        <input type="hidden" id="total_renew_amount" name="total_renew_amount" value="" />
+
+        <span id="membername"></span>
+
+        {if $member_invoice}
+            <div class="glm-billing-field">
+                <div class="glm-billing-label glm-required">
+                    Membership Class
+                </div>
+                <div class="glm-billing-input">
+                    {if $settings.allow_membership_choice}
+                        {foreach $payable_types as $type}
+                            <label>
+                                <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}"
+                                {if $type.id == $member_invoice.id}checked{/if}
+                                />
+                                {$type.name} {$type.amount}
+                            </label>
+                        {/foreach}
+                    {else}
+                        <input type="hidden" name="member_renewing" data-amount="{$member_invoice.amount}" value="{$member_invoice.id}" />
+                        {$member_invoice.name} {$member_invoice.amount}
+                    {/if}
+                </div>
+            </div>
+        {else}
+            <div class="glm-billing-field">
+                <div class="glm-billing-label glm-required">
+                    Invoice #
+                </div>
+                <div class="glm-billing-input">
+                    <input id="invoice_number" name="invoice_number" value="{if isset($invoiceId)}{$invoiceId}{/if}" required />
+                </div>
+            </div>
+            <div class="glm-billing-field">
+                <div class="glm-billing-label glm-required">
+                    Membership Class
+                </div>
+                <div class="glm-billing-input">
+                    {if $settings.allow_membership_choice}
+                        {foreach $payable_types as $type}
+                            <label>
+                                <input type="radio" name="member_renewing" data-amount="{$type.amount}" value="{$type.id}" id="invoice_type_id_{$type.id}" />
+                                {$type.name} {$type.amount}
+                            </label>
+                        {/foreach}
+                    {/if}
+                </div>
+            </div>
+        {/if}
+
+        <div class="glm-billing-field">
+            <div class="glm-billing-label">
+                Total Due
+            </div>
+            <div class="glm-billing-input">
+                <div id="renew_total">
+                </div>
+            </div>
+        </div>
+
+        {* Include the Payment Form template *}
+        {include file='common/billing/paymentForm.html'}
+
+        <input class="button button-primary" type="submit" value="Renew">
+
+    </form>
+</div>
+
+<script>
+jQuery(document).ready(function($){
+
+    $('#billing-invoice-select').change(function(){
+        // Get the data-amount and set the amount being paid.
+        $('#billing-amount').val( $(this).find('option:selected').data( 'amount') );
+    });
+
+    // Create a USD formatter
+    var formatter = new Intl.NumberFormat('en-US', {
+        style: 'currency',
+        currency: 'USD',
+        minimunFractionDigits: 2
+    });
+
+    // verify the account number is correct.
+    $('#invoice_number').on( 'change', function(){
+        $.ajax({
+            cache: false,
+            url: '{$ajaxUrl}',
+            dataType: 'json',
+            type: 'POST',
+            data: {
+                'action': 'glm_members_admin_ajax',
+                'glm_action': 'billingAccount',
+                'option': 'verifyInvoiceNumber',
+                'invoice_number': $(this).val(),
+            }
+        }).done(function(msg){
+            console.log( 'msg', msg );
+            if ( msg.status === false ) {
+                alert( 'Not a valid Account #' );
+                $('#invoice_number').val('');
+                $('#membername').html('');
+            } else {
+                // Set the account and member inputs
+                $('#account_id').val( msg.account_id );
+                $('#member_id').val( msg.member_id );
+                if ( msg.invoice.paid.value == "1" ) {
+                    $('#invoice_number').val('');
+                    $('#membername').html('');
+                    alert( 'This invoice has already been paid!' );
+                    return false;
+                }
+                if ( msg.invoice_type ) {
+                    // $('input[name=member_renewing]').prop('checked', false);
+                    console.log( 'invoice_type', msg.invoice_type );
+                    $('#invoice_type_id_' + msg.invoice_type ).attr('checked', true);
+                    $('#membername').html(msg.invoice.member_name);
+                    getPageTotal();
+                }
+            }
+        });
+    } );
+
+
+    // Generate the total for the renewal.
+    function getPageTotal(){
+
+        // Calculate the total for this page.
+        // Get the member_renewing amount.
+        if ( $('input[name=member_renewing]:checked').length ) {
+            var member_renewing_amount = parseFloat( $('input[name=member_renewing]:checked').data('amount') );
+        } else {
+            var member_renewing_amount = parseFloat( $('input[name=member_renewing]:first').data('amount') );
+            $('input[name=member_renewing]:first').prop( 'checked', true );
+        }
+
+        $('#renew_total').html( formatter.format( member_renewing_amount ) );
+        $('#total_renew_amount').val( member_renewing_amount );
+
+    }
+
+    getPageTotal();
+
+    // trigger total if changing Membership
+    $('input[name=member_renewing]').change(function(){
+        getPageTotal();
+    });
+
+    // Flash certain elements for a short time after display
+    $(".glm-flash-updated").fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500).fadeIn(500).fadeOut(500);
+
+});
+</script>
+
+
diff --git a/views/front/billing/paymentFormProcess.html b/views/front/billing/paymentFormProcess.html
new file mode 100644 (file)
index 0000000..251f6da
--- /dev/null
@@ -0,0 +1,5 @@
+
+{foreach $messages as $message}
+{$message}<br>
+{/foreach}
+
index 56ac6e5..62675da 100644 (file)
@@ -13,7 +13,7 @@
 
     <form action="{$thisUrl}" method="post">
         <input type="hidden" name="option" value="renewMembership" />
-        <input type="hidden" id="member_id" name="member" value="{$memberID}" />
+        <input type="hidden" id="member_id" name="member" value="{$memberId}" />
         <input type="hidden" id="account_id" name="account_id" value="{$account_data.id}" />
         <input type="hidden" id="total_renew_amount" name="total_renew_amount" value="" />