Invoice types - parent ordering of invoice types
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 30 Nov 2017 15:32:20 +0000 (10:32 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 30 Nov 2017 15:32:20 +0000 (10:32 -0500)
Now the invoice types can be order correctly based on parent they belong
to. Only the top level parent show in the drop down for parent
selection.

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

index cb74304..7e3ae96 100644 (file)
@@ -129,13 +129,18 @@ class GlmDataInvoiceTypes extends GlmDataAbstract
                 'use'   => 'a',
             ),
 
-            // Parent
+            // Parent - for adding, deleting and editing, has selection tabels
             'parent' => array(
                 'field' => 'parent',
-                'type'  => 'integer',
-                'use'   => 'a'
+                'type' => 'pointer',
+                    'p_table' => GLM_MEMBERS_BILLING_PLUGIN_DB_PREFIX . 'invoice_types',
+                    'p_field' => 'name',
+                    'p_orderby' => 'name',
+                    'p_blank' => true,
+                'force_list' => true,
+                'required' => false,
+                'use' => 'a'
             ),
-
             // Amount
             'amount' => array(
                 'field' => 'amount',
index 39ca9da..12049c8 100644 (file)
@@ -139,7 +139,7 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
         // Get a current list of members
         $invoiceTypes = $this->getList();
 
-        echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
+        // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
 
         // If we have list entries - even if it's an empty list
         $success          = true;
@@ -156,7 +156,7 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes
 
         // Sort results by higherarchy (Parent/Child and Alpha)
         $invoiceTypes = $this->sortParentChild($invoiceTypes);
-        echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
+        // echo '<pre>$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '</pre>';
 
 
         // If we had a fatal error, redirect to the error page
index 0c9bd7b..92334dd 100644 (file)
                         <select name="parent">
                             <option value="0">(none)</option>
                             {if $haveInvoiceTypes}
-                                {foreach $invoiceTypes as $type}
-                                    <option value="{$type.id}">{$type.name}</option>
+                                {foreach $invoiceTypes as $t}
+                                    {if !$t.parent.value} <!-- don't show child categories -->
+                                        <option value="{$t.id}">{$t.name}</option>
+                                    {/if}
                                 {/foreach}
                             {/if}
                         </select>
@@ -47,7 +49,9 @@
                         <select name="recurrence">
                             <option value="">(none)</option>
                                 {foreach $recurrenceTypes as $typeId => $typeLabel}
-                                    <option value="{$typeId}">{$typeLabel}</option>
+                                    {if !$t.parent.value} <!-- don't show child categories -->
+                                        <option value="{$typeId}">{$typeLabel}</option>
+                                    {/if}
                                 {/foreach}
                         </select>
                     </td>
@@ -87,9 +91,9 @@
                         <select id="edit-parent" name="parent">
                             <option value="0">(none)</option>
                                 {if $haveInvoiceTypes}
-                                    {foreach $invoiceTypes as $type}
-                                        {if !$type.parent.value} <!-- don't show child categories -->
-                                            <option value="{$type.id}">{$type.name}</option>
+                                    {foreach $invoiceTypes as $t}
+                                        {if !$t.parent.value} <!-- don't show child categories -->
+                                            <option value="{$t.id}">{$t.name}</option>
                                         {/if}
                                     {/foreach}
                                 {/if}
                                 <a class="editInvoiceType"
                                     data-invoice-id="{$t.id}"
                                     data-invoice-name="{$t.name}"
-                                    data-invoice-parent="{$t.parent}"
+                                    data-invoice-parent="{$t.parent.value}"
                                     data-invoice-amount="{$t.amount}"
                                     data-invoice-recurring="{$t.recurring.value}"
                                     data-invoice-recurrence="{$t.recurrence}">{$t.name}</a>
                 var invoiceID         = $(this).data('invoice-id');
                 var invoiceName       = $(this).data('invoice-name');
                 var invoiceParent     = $(this).data('invoice-parent');
+                console.log(invoiceParent);
                 var invoiceAmount     = $(this).data('invoice-amount');
                 var invoiceRecurring  = $(this).data('invoice-recurring');
                 var invoiceRecurrence = $(this).data('invoice-recurrence');
                 if ( invoiceRecurring === 1 ) {
                     $('#edit-recurring').prop( 'checked', true );
                 }
-                console.log(invoiceRecurring);
                 $('#edit-recurrence').val( invoiceRecurrence );
 
                 $("#editInvoiceTypeDialog").dialog("open");