Updating the settings for billing
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 29 Nov 2017 18:27:47 +0000 (13:27 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 29 Nov 2017 18:27:47 +0000 (13:27 -0500)
Add the invoice types and line items into setting  for billing.
Also updated the form for the invoice settings.

models/admin/settings/billing.php
models/admin/settings/invoiceTypes.php
setup/adminTabs.php
setup/validActions.php
views/admin/settings/billing.html
views/admin/settings/invoiceTypes.html
views/admin/settings/subHeader.html [new file with mode: 0644]

index faf3ad8..d73feef 100644 (file)
@@ -173,6 +173,7 @@ class GlmMembersAdmin_settings_billing extends GlmDataBillingSettings
 
         // Compile template data
         $template_data = array(
+            'action'              => $_REQUEST['glm_action'],
             'enable_members'      => $enable_members,
             'option'              => $option,
             'settingsUpdated'     => $settings_updated,
index 1eec3ea..bee1344 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
  * Gaslight Media Members Database
- * Admin PaymentTypes List
+ * Admin InvoiceTypes List
  *
  * PHP version 5.5
  *
  */
 
 // Load Member Types data abstract
-require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataPaymentTypes.php';
+require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoiceTypes.php';
 
 /*
  * This class performs the work for the default action of the "Members" menu
  * option, which is to display the members dashboard.
  *
  */
-class GlmMembersAdmin_settings_paymentTypes extends GlmDataPaymentTypes
+class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
 {
 
     /**
@@ -100,8 +100,8 @@ class GlmMembersAdmin_settings_paymentTypes extends GlmDataPaymentTypes
     {
 
         $success          = true;
-        $havePaymentTypes = false;
-        $paymentTypes     = false;
+        $haveInvoiceTypes = false;
+        $invoiceTypes     = false;
         $error            = false;
         $enable_members   = $this->config['settings']['enable_members'];
 
@@ -137,20 +137,20 @@ class GlmMembersAdmin_settings_paymentTypes extends GlmDataPaymentTypes
         }
 
         // Get a current list of members
-        $paymentTypes = $this->getList('', 'name');
+        $invoiceTypes = $this->getList('', 'name');
 
-        // echo '<pre>$paymentTypes: ' . print_r( $paymentTypes, true ) . '</pre>';
+        // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
 
         // If we have list entries - even if it's an empty list
         $success          = true;
-        $havePaymentTypes = false;
-        if ($paymentTypes !== false) {
+        $haveInvoiceTypes = false;
+        if ($invoiceTypes !== false) {
 
             $success = true;
 
             // If we have any entries
-            if (count($paymentTypes) > 0) {
-                $havePaymentTypes = true;
+            if (count($invoiceTypes) > 0) {
+                $haveInvoiceTypes = true;
             }
         }
 
@@ -167,9 +167,10 @@ class GlmMembersAdmin_settings_paymentTypes extends GlmDataPaymentTypes
 
         // Compile template data
         $templateData = array(
+            'action'           => $_REQUEST['glm_action'],
             'enable_members'   => $enable_members,
-            'havePaymentTypes' => $havePaymentTypes,
-            'paymentTypes'     => $paymentTypes
+            'haveInvoiceTypes' => $haveInvoiceTypes,
+            'invoiceTypes'     => $invoiceTypes
         );
 
         // Return status, suggested view, and data to controller
@@ -177,7 +178,7 @@ class GlmMembersAdmin_settings_paymentTypes extends GlmDataPaymentTypes
             'status'           => $success,
             'menuItemRedirect' => false,
             'modelRedirect'    => false,
-            'view'             => 'admin/settings/paymentTypes.html',
+            'view'             => 'admin/settings/invoiceTypes.html',
             'data'             => $templateData
         );
 
index 6ae2f5d..99827b5 100644 (file)
@@ -46,19 +46,19 @@ if ( current_user_can( 'glm_members_members' ) ) {
             return $addOnTabs;
         }
     );
-    add_filter( 'glm-member-db-add-tab-for-settings',
-        function( $addOnTabs ) {
-            $newTabs = array(
-                array(
-                    'text'   => 'Payment Types',
-                    'menu'   => 'settings',
-                    'action' => 'paymentTypes',
-                )
-            );
-            $addOnTabs = array_merge( $addOnTabs, $newTabs );
-            return $addOnTabs;
-        }
-    );
+    // add_filter( 'glm-member-db-add-tab-for-settings',
+    //     function( $addOnTabs ) {
+    //         $newTabs = array(
+    //             array(
+    //                 'text'   => 'Payment Types',
+    //                 'menu'   => 'settings',
+    //                 'action' => 'paymentTypes',
+    //             )
+    //         );
+    //         $addOnTabs = array_merge( $addOnTabs, $newTabs );
+    //         return $addOnTabs;
+    //     }
+    // );
     add_filter( 'glm-member-db-add-tab-for-billing',
         function( $addOnTabs ){
             $newTabs = array(
index 8b27d65..d4f1d77 100644 (file)
@@ -61,7 +61,8 @@ $glmMembersBillingAddOnValidActions = array(
     'adminActions' => array(
         'settings' => array(
             'billing'      => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
-            'paymentTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+            'invoiceTypes' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
+            'lineItems'    => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
         ),
         'billing' => array(
             'index' => GLM_MEMBERS_BILLING_PLUGIN_SLUG,
index 67124b4..64378fd 100644 (file)
@@ -1,17 +1,15 @@
 {include file='admin/settings/header.html'}
 
-    <h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
-        <a id="glm-settings" data-show-table="glm-table-settings" class="glm-settings-tab nav-tab{if $option=='settings'} nav-tab-active{/if}">Settings</a>
-    </h2>
+{include file='admin/settings/subHeader.html'}
 
-    <!-- Management Settings -->
+    <!-- Billing Settings -->
 
     <table id="glm-table-settings" class="glm-admin-table glm-settings-table{if $option!='settings'} glm-hidden{/if}">
         <tr>
             <td colspan="2">
                 {if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
                 {if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
-                <h2>Management Settings</h2>
+                <h2>Billing Invoice Settings</h2>
             </td>
         </tr>
         <tr>
                     <input type="hidden" name="option2" value="submit">
                     <table class="glm-admin-table">
 
-                        <tr> <th colspan="2"> Defaults </th> </tr>
-
-                        <tr>
-                            <th {if $billingSettings.fieldRequired.billing_period} class="glm-required"}{/if}>Default Billing Period</th>
-                            <td {if $billingSettings.fieldFail.billing_period}class="glm-form-bad-input" data-tabid="glm-billing-period"{/if}>
-                                <input type="text" name="billing_period" value="{$billingSettings.fieldData.billing_period}" class="glm-form-text-input-short">
-                            {if $billingSettings.fieldFail.billing_period}<p>{$billingSettings.fieldFail.billing_period}</p>{/if}<br>
-                            </td>
-                        </tr>
-
-                        <tr>
-                            <th {if $billingSettings.fieldRequired.invoice_date} class="glm-required"}{/if}>Default Invoice Date</th>
-                            <td {if $billingSettings.fieldFail.invoice_date}class="glm-form-bad-input" data-tabid="glm-invoice-date"{/if}>
-                                <input type="text" name="invoice_date" value="{$billingSettings.fieldData.invoice_date}" class="glm-form-text-input-short">
-                            {if $billingSettings.fieldFail.invoice_date}<p>{$billingSettings.fieldFail.invoice_date}</p>{/if}<br>
-                            </td>
-                        </tr>
-
-                        <tr> <th colspan="2"> Invoice Settings </th> </tr>
-
-                        <tr>
-                            <th {if $billingSettings.fieldRequired.notification_from} class="glm-required"}{/if}>Notification From</th>
-                            <td {if $billingSettings.fieldFail.notification_from}class="glm-form-bad-input" data-tabid="glm-notification-from"{/if}>
-                                <input type="text" name="notification_from" value="{$billingSettings.fieldData.notification_from}" class="glm-form-text-input-short">
-                            {if $billingSettings.fieldFail.notification_from}<p>{$billingSettings.fieldFail.notification_from}</p>{/if}<br>
-                            </td>
-                        </tr>
-
-                        <tr>
-                            <th {if $billingSettings.fieldRequired.notification_message} class="glm-required"}{/if}>Notification Message</th>
-                            <td {if $billingSettings.fieldFail.notification_message}class="glm-form-bad-input" data-tabid="glm-notification-message"{/if}>
-                            <textarea name="notification_message" class="glm-form-textarea">{$billingSettings.fieldData.notification_message}</textarea>
-                                {if $billingSettings.fieldFail.notification_message}
-                                    <p>{$billingSettings.fieldFail.notification_message}</p>
-                                {/if}<br>
-                            </td>
-                        </tr>
-
-                        <tr> <th colspan="2"> Invoice Settings </th> </tr>
-
                         <tr>
                             <th {if $billingSettings.fieldRequired.company_logo} class="glm-required"}{/if}>Company Logo</th>
                             <td {if $billingSettings.fieldFail.company_logo}class="glm-form-bad-input" data-tabid="glm-company-logo"{/if}>
index 6644db2..2c033f7 100644 (file)
@@ -1,14 +1,16 @@
 {include file='admin/settings/header.html'}
 
-    <!-- Add PaymentTypes Button and Dialog Box -->
-    <div id="newPaymentTypeButton" class="button button-primary glm-right">Add a Payment Type</div>
-    <div id="newPaymentTypeDialog" class="glm-dialog-box" title="Enter a New PaymentType">
+{include file='admin/settings/subHeader.html'}
+
+    <!-- Add InvoiceTypes Button and Dialog Box -->
+    <div id="newInvoiceTypeButton" class="button button-primary glm-right">Add a Invoice Type</div>
+    <div id="newInvoiceTypeDialog" class="glm-dialog-box" title="Enter a New InvoiceType">
         <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
-            <input type="hidden" name="glm_action" value="paymentTypes">
+            <input type="hidden" name="glm_action" value="invoiceTypes">
             <input type="hidden" name="option" value="addNew">
             <table class="glm-admin-table">
                 <tr>
-                    <th class="glm-required">Payment Type Name:</th>
+                    <th class="glm-required">Invoice Type Name:</th>
                     <td>
                         <input type="text" name="name" class="glm-form-text-input" required>
                     </td>
                 </tr>
             </table>
             <p><span class="glm-required">*</span> Required</p>
-            <a id="newPaymentTypeCancel" class="button button-primary glm-right">Cancel</a>
-            <input type="submit" value="Add new Payment Type" class="button button-primary">
+            <a id="newInvoiceTypeCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Add new Invoice Type" class="button button-primary">
         </form>
     </div>
 
-    <!-- Add PaymentTypes Button -->
-    <div id="deletePaymentTypeDialog" class="glm-dialog-box" title="Delete PaymentType">
+    <!-- Add InvoiceTypes Button -->
+    <div id="deleteInvoiceTypeDialog" class="glm-dialog-box" title="Delete InvoiceType">
         <center>
-            <p>Are you sure you want to delete this paymentType?</p>
-            <p><div id="deletePaymentTypeConfirm" class="button button-primary">Yes, delete this paymentType</div></p>
-            <p><div id="deletePaymentTypeCancel" class="button button-primary">Cancel</div></p>
+            <p>Are you sure you want to delete this inoiceType?</p>
+            <p><div id="deleteInvoiceTypeConfirm" class="button button-primary">Yes, delete this inoiceType</div></p>
+            <p><div id="deleteInvoiceTypeCancel" class="button button-primary">Cancel</div></p>
         </center>
     </div>
 
-    <!-- Edit PaymentTypes Dialog Box -->
-    <div id="editPaymentTypeDialog" class="glm-dialog-box" title="Edit this PaymentType">
+    <!-- Edit InvoiceTypes Dialog Box -->
+    <div id="editInvoiceTypeDialog" class="glm-dialog-box" title="Edit this InvoiceType">
         <form action="{$thisUrl}?page={$thisPage}" method="post" enctype="multipart/form-data">
-            <input type="hidden" name="glm_action" value="paymentTypes">
+            <input type="hidden" name="glm_action" value="invoiceTypes">
             <input type="hidden" name="option" value="update">
-            <input id="editPaymentTypeID" type="hidden" name="id" value="">
+            <input id="editInvoiceTypeID" type="hidden" name="id" value="">
             <table class="glm-admin-table">
                 <tr>
-                    <th class="glm-required">Payment Type Name:</th>
+                    <th class="glm-required">Invoice Type Name:</th>
                     <td>
-                        <input id="editPaymentTypeName" type="text" name="name" class="glm-form-text-input" required>
+                        <input id="editInvoiceTypeName" type="text" name="name" class="glm-form-text-input" required>
                     </td>
                 </tr>
                 <tr>
                     <th>Code:</th>
                     <td>
-                        <input id="editPaymentTypeQCode" type="text" name="qcode" class="glm-form-text-input">
+                        <input id="editInvoiceTypeQCode" type="text" name="qcode" class="glm-form-text-input">
                     </td>
                 </tr>
                 <tr>
                     <th class="glm-required">Category:</th>
                     <td>
-                        <input id="editPaymentTypeCategory" type="text" name="category" class="glm-form-text-input" required>
+                        <input id="editInvoiceTypeCategory" type="text" name="category" class="glm-form-text-input" required>
                     </td>
                 </tr>
                 <tr>
                     <th class="glm-required">Amount:</th>
                     <td>
-                        <input id="editPaymentTypeAmount" type="text" name="amount" class="glm-form-text-input" required>
+                        <input id="editInvoiceTypeAmount" type="text" name="amount" class="glm-form-text-input" required>
                     </td>
                 </tr>
                 <tr>
                     <th>Dynamic Amount:</th>
                     <td>
                         <input type="hidden" name="dynamic_amount" class="glm-form-text-input" value="0">
-                        <input id="editPaymentTypeDynamicAmount" type="checkbox" name="dynamic_amount" class="glm-form-text-input" value="1">
+                        <input id="editInvoiceTypeDynamicAmount" type="checkbox" name="dynamic_amount" class="glm-form-text-input" value="1">
                     </td>
                 </tr>
                 <tr>
                     <th>Notes:</th>
                     <td>
-                        <textarea id="editPaymentTypeNotes" name="notes" class="glm-form-textarea"></textarea>
+                        <textarea id="editInvoiceTypeNotes" name="notes" class="glm-form-textarea"></textarea>
                     </td>
                 </tr>
             </table>
             <p><span class="glm-required">*</span> Required</p>
-            <a id="editPaymentTypeCancel" class="button button-primary glm-right">Cancel</a>
-            <input type="submit" value="Update this Payment Type">
+            <a id="editInvoiceTypeCancel" class="button button-primary glm-right">Cancel</a>
+            <input type="submit" value="Update this Invoice Type">
         </form>
     </div>
 
-    <h2>PaymentTypes</h2>
+    <h2>InvoiceTypes</h2>
 
     <table class="wp-list-table widefat fixed posts glm-admin-table">
         <thead>
             <tr>
                 <th>ID</th>
-                <th>PaymentType</th>
+                <th>InvoiceType</th>
                 <th>Amount</th>
                 <th>&nbsp;</th>
             </tr>
         </thead>
         <tbody>
-            {if $havePaymentTypes}
+            {if $haveInvoiceTypes}
                 {assign var="i" value="0"}
-                {foreach $paymentTypes as $t}
+                {foreach $invoiceTypes as $t}
                     {if $i++ is odd by 1}
                         <tr>
                     {else}
                     {/if}
                         <td>{$t.id}</td>
                         <td>
-                            <a class="editPaymentType"
-                                data-paymentTypeID="{$t.id}"
-                                data-paymentTypeName="{$t.name}"
-                                data-paymentTypeQCode="{$t.qcode}"
-                                data-paymentTypeCategory="{$t.category}"
-                                data-paymentTypeAmount="{$t.amount}"
-                                data-paymentTypeDynamicAmount="{$t.dynamic_amount}"
-                                data-paymentTypeNotes="{$t.notes}">{$t.name}</a>
+                            <a class="editInvoiceType"
+                                data-inoiceTypeID="{$t.id}"
+                                data-inoiceTypeName="{$t.name}"
+                                data-inoiceTypeQCode="{$t.qcode}"
+                                data-inoiceTypeCategory="{$t.category}"
+                                data-inoiceTypeAmount="{$t.amount}"
+                                data-inoiceTypeDynamicAmount="{$t.dynamic_amount}"
+                                data-inoiceTypeNotes="{$t.notes}">{$t.name}</a>
                         </td>
                         <td>
                             {$t.amount}
                         </td>
                         <td>
-                            <div class="deletePaymentTypeButton button button-secondary glm-button-small glm-right" data-paymentTypeID="{$t.id}">Delete</div>
+                            <div class="deleteInvoiceTypeButton button button-secondary glm-button-small glm-right" data-inoiceTypeID="{$t.id}">Delete</div>
                         </td>
                     </tr>
                 {/foreach}
             {else}
-                <tr class="alternate"><td colspan="2">(no paymentTypes listed)</td></tr>
+                <tr class="alternate"><td colspan="2">(no Invoice Types listed)</td></tr>
             {/if}
         </tbody>
     </table>
     <script type="text/javascript">
         jQuery(document).ready(function($) {
 
-            $("#newPaymentTypeDialog").dialog({
+            $("#newInvoiceTypeDialog").dialog({
                 autoOpen: false,
                 minWidth: 400,
                 dialogClass: "glm-dialog-no-close"
             });
-            $("#editPaymentTypeDialog").dialog({
+            $("#editInvoiceTypeDialog").dialog({
                 autoOpen: false,
                 minWidth: 400,
                 dialogClass: "glm-dialog-no-close"
             });
-            $("#deletePaymentTypeDialog").dialog({
+            $("#deleteInvoiceTypeDialog").dialog({
                 autoOpen: false,
                 minWidth: 400,
                 dialogClass: "glm-dialog-no-close"
             });
 
-            $('#newPaymentTypeButton').click( function() {
-                $("#newPaymentTypeDialog").dialog("open");
+            $('#newInvoiceTypeButton').click( function() {
+                $("#newInvoiceTypeDialog").dialog("open");
             });
-            $('.editPaymentType').click( function() {
-                $('#editPaymentTypeDynamicAmount').prop( 'checked', false );
+            $('.editInvoiceType').click( function() {
+                $('#editInvoiceTypeDynamicAmount').prop( 'checked', false );
 
-                var paymentTypeID = $(this).data('paymenttypeid');
-                var paymentTypeName = $(this).data('paymenttypename');
-                var paymentTypeQCode = $(this).data('paymenttypeqcode');
-                var paymentTypeCategory = $(this).data('paymenttypecategory');
-                var paymentTypeAmount = $(this).data('paymenttypeamount');
-                var paymentTypeDynamicAmount = $(this).data('paymenttypedynamicamount');
-                var paymentTypeNotes = $(this).data('paymenttypenotes');
+                var inoiceTypeID = $(this).data('inoicetypeid');
+                var inoiceTypeName = $(this).data('inoicetypename');
+                var inoiceTypeQCode = $(this).data('inoicetypeqcode');
+                var inoiceTypeCategory = $(this).data('inoicetypecategory');
+                var inoiceTypeAmount = $(this).data('inoicetypeamount');
+                var inoiceTypeDynamicAmount = $(this).data('inoicetypedynamicamount');
+                var inoiceTypeNotes = $(this).data('inoicetypenotes');
 
-                // Set the values of the edit form for the selected paymentType
-                $('#editPaymentTypeID').val( paymentTypeID );
-                $('#editPaymentTypeName').val( paymentTypeName );
-                $('#editPaymentTypeQCode').val( paymentTypeQCode );
-                $('#editPaymentTypeCategory').val( paymentTypeCategory );
-                $('#editPaymentTypeAmount').val( paymentTypeAmount );
-                if ( paymentTypeDynamicAmount === 1 ) {
-                    $('#editPaymentTypeDynamicAmount').prop( 'checked', true );
+                // Set the values of the edit form for the selected inoiceType
+                $('#editInvoiceTypeID').val( inoiceTypeID );
+                $('#editInvoiceTypeName').val( inoiceTypeName );
+                $('#editInvoiceTypeQCode').val( inoiceTypeQCode );
+                $('#editInvoiceTypeCategory').val( inoiceTypeCategory );
+                $('#editInvoiceTypeAmount').val( inoiceTypeAmount );
+                if ( inoiceTypeDynamicAmount === 1 ) {
+                    $('#editInvoiceTypeDynamicAmount').prop( 'checked', true );
                 }
-                $('#editPaymentTypeNotes').val( paymentTypeNotes );
+                $('#editInvoiceTypeNotes').val( inoiceTypeNotes );
 
-                $("#editPaymentTypeDialog").dialog("open");
+                $("#editInvoiceTypeDialog").dialog("open");
             });
-            $('#editPaymentTypeCancel').click( function() {
-                $("#editPaymentTypeDialog").dialog("close");
+            $('#editInvoiceTypeCancel').click( function() {
+                $("#editInvoiceTypeDialog").dialog("close");
             });
-            $('#newPaymentTypeCancel').click( function() {
-                $("#newPaymentTypeDialog").dialog("close");
+            $('#newInvoiceTypeCancel').click( function() {
+                $("#newInvoiceTypeDialog").dialog("close");
             });
 
             var id = false;
-            $('.deletePaymentTypeButton').click( function() {
-                id = $(this).attr('data-paymentTypeID');
-                $("#deletePaymentTypeDialog").dialog("open");
+            $('.deleteInvoiceTypeButton').click( function() {
+                id = $(this).attr('data-inoiceTypeID');
+                $("#deleteInvoiceTypeDialog").dialog("open");
             });
-            $('#deletePaymentTypeConfirm').click( function() {
-                $("#deletePaymentTypeDialog").dialog("close");
-                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=paymentTypes&option=delete&id=" + id;
+            $('#deleteInvoiceTypeConfirm').click( function() {
+                $("#deleteInvoiceTypeDialog").dialog("close");
+                window.location.href = "{$thisUrl}?page={$thisPage}&glm_action=invoiceTypes&option=delete&id=" + id;
             });
-            $('#deletePaymentTypeCancel').click( function() {
-                $("#deletePaymentTypeDialog").dialog("close");
+            $('#deleteInvoiceTypeCancel').click( function() {
+                $("#deleteInvoiceTypeDialog").dialog("close");
             });
 
         });
diff --git a/views/admin/settings/subHeader.html b/views/admin/settings/subHeader.html
new file mode 100644 (file)
index 0000000..ae57844
--- /dev/null
@@ -0,0 +1,8 @@
+<h2 class="nav-tab-wrapper" style="margin-bottom: 1em;">
+    <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=billing"
+       class="glm-settings-tab nav-tab{if $action == 'billing'} nav-tab-active{/if}">Invoice Settings</a>
+    <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=invoiceTypes"
+       class="glm-settings-tab nav-tab{if $action == 'invoiceTypes'} nav-tab-active{/if}">Invoice Types</a>
+    <a href="{$thisUrl}?page=glm-members-admin-menu-settings&glm_action=lineItems"
+       class="glm-settings-tab nav-tab{if $action == 'lineItems'} nav-tab-active{/if}">Line Items</a>
+</h2>