Add member type to the edit invoice
authorSteve Sutton <steve@gaslightmedia.com>
Mon, 19 Mar 2018 16:26:57 +0000 (12:26 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Mon, 19 Mar 2018 16:26:57 +0000 (12:26 -0400)
Adding the member type into setting for invoice types

classes/data/dataInvoiceTypes.php
models/admin/settings/invoiceTypes.php
views/admin/settings/invoiceTypes.html

index a4f3d10..1758fa3 100644 (file)
@@ -134,6 +134,18 @@ class GlmDataInvoiceTypes extends GlmDataAbstract
                 'required'   => false,
                 'use'        => 'a'
             ),
+            // Parent - for adding, deleting and editing, has selection tables
+            'member_type' => array(
+                'field'      => 'member_type',
+                'type'       => 'pointer',
+                'p_table'    => GLM_MEMBERS_PLUGIN_DB_PREFIX . 'member_types',
+                'p_field'    => 'name',
+                'p_orderby'  => 'name',
+                'p_blank'    => true,
+                'force_list' => true,
+                'required'   => false,
+                'use'        => 'a'
+            ),
             // Amount
             'amount' => array(
                 'field' => 'amount',
index d948c4d..f31de07 100644 (file)
@@ -15,6 +15,7 @@
 
 // Load Member Types data abstract
 require_once GLM_MEMBERS_BILLING_PLUGIN_CLASS_PATH.'/data/dataInvoiceTypes.php';
+require_once GLM_MEMBERS_PLUGIN_CLASS_PATH.'/data/dataMemberTypes.php';
 
 /*
  * This class performs the work for the default action of the "Members" menu
@@ -104,6 +105,7 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
         $invoiceTypes     = false;
         $error            = false;
         $enable_members   = $this->config['settings']['enable_members'];
+        $memberTypes      = false;
 
         // Check for region id
         $id = 0;
@@ -160,6 +162,11 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
         $invoiceTypes = $this->sortParentChild($invoiceTypes);
         // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
 
+        // Get list of Member Types
+        $MemberType = new GlmDataMemberTypes( $this->wpdb, $this->config );
+        $memberTypes = $MemberType->getList();
+        // echo '<pre>$memberTypes: ' . print_r( $memberTypes, true ) . '</pre>';
+
 
         // If we had a fatal error, redirect to the error page
         if ($error) {
@@ -179,6 +186,7 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
             'haveInvoiceTypes' => $haveInvoiceTypes,
             'invoiceTypes'     => $invoiceTypes,
             'recurrenceTypes'  => $this->config['recurrence'],
+            'memberTypes'      => $memberTypes,
         );
 
         // Return status, suggested view, and data to controller
index e3e6f38..4bfb0d5 100644 (file)
         <input type="hidden" name="option" value="addNew">
         <table class="glm-admin-table">
             <tr>
-                <th class="glm-required">Invoice 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>
             <tr>
-                <th class="glm-required">Parent:</th>
+                <th class="glm-required">Parent</th>
                 <td>
                     <select name="parent">
                         <option value="0">(none)</option>
                     </select>
                 </td>
             </tr>
+            <tr>
+                <th>Member Type</th>
+                <td>
+                    <select name="member_type">
+                        <option value="0">(none)</option>
+                        {if $memberTypes}
+                            {foreach $memberTypes as $type}
+                                <option value="{$type.id}">{$type.name}</option>
+                            {/foreach}
+                        {/if}
+                    </select>
+                </td>
+            </tr>
             <tr>
                 <th class="glm-required">Amount:Numbers only<br> (999.99)</th>
                 <td>
                     </select>
                 </td>
             </tr>
+            <tr>
+                <th>Member Type</th>
+                <td>
+                    <select id="edit-member_type" name="member_type">
+                        <option value="0">(none)</option>
+                        {if $memberTypes}
+                            {foreach $memberTypes as $type}
+                                <option value="{$type.id}">{$type.name}</option>
+                            {/foreach}
+                        {/if}
+                    </select>
+                </td>
+            </tr>
             <tr>
                 <th style="text-align: right;" class="glm-required">Amount:Numbers only<br> (999.99)</th>
                 <td>
                                 data-invoice-id="{$t.id}"
                                 data-invoice-name="{$t.name}"
                                 data-invoice-parent="{$t.parent.value}"
+                                data-invoice-member_type="{$t.member_type.value}"
                                 data-invoice-amount="{$t.amount}"
                                 data-invoice-recurring="{$t.recurring.value}"
                                 data-invoice-recurrence="{$t.recurrence}">{$t.name}</a>
@@ -183,12 +210,12 @@ jQuery(document).ready(function($) {
 
     $("#newInvoiceTypeDialog").dialog({
         autoOpen: false,
-        minWidth: 400,
+        minWidth: 600,
         dialogClass: "glm-dialog-no-close"
     });
     $("#editInvoiceTypeDialog").dialog({
         autoOpen: false,
-        minWidth: 400,
+        minWidth: 600,
         dialogClass: "glm-dialog-no-close"
     });
     $("#deleteInvoiceTypeDialog").dialog({
@@ -206,6 +233,7 @@ jQuery(document).ready(function($) {
         var invoiceID         = $(this).data('invoice-id');
         var invoiceName       = $(this).data('invoice-name');
         var invoiceParent     = $(this).data('invoice-parent');
+        var invoiceType       = $(this).data('invoice-member_type');
         var invoiceAmount     = $(this).data('invoice-amount');
         var invoiceRecurring  = $(this).data('invoice-recurring');
         var invoiceRecurrence = $(this).data('invoice-recurrence');
@@ -216,6 +244,7 @@ jQuery(document).ready(function($) {
         $('#edit-id').val( invoiceID );
         $('#edit-name').val( invoiceName );
         $('#edit-parent').val( invoiceParent );
+        $('#edit-member_type').val( invoiceType );
         $('#edit-amount').val( invoiceAmount );
         if ( invoiceRecurring === 1 ) {
             $('#edit-recurring').prop( 'checked', true );