From be3bd9cdac9b4d61ef910736480fc725df55014e Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 29 Nov 2017 16:52:32 -0500 Subject: [PATCH] WIP - work on invoice types add edit Working currently on how to order it like the categories by hierarchy. --- classes/data/dataInvoiceTypes.php | 50 +++++++++ models/admin/settings/invoiceTypes.php | 12 ++- views/admin/settings/invoiceTypes.html | 140 ++++++++++++++----------- 3 files changed, 137 insertions(+), 65 deletions(-) diff --git a/classes/data/dataInvoiceTypes.php b/classes/data/dataInvoiceTypes.php index d1527fa..cb74304 100644 --- a/classes/data/dataInvoiceTypes.php +++ b/classes/data/dataInvoiceTypes.php @@ -181,6 +181,56 @@ class GlmDataInvoiceTypes extends GlmDataAbstract return $r; } + /* + * Sort a database result array (from DataAbstract.php) by parent, child relationships + * + * @param array $array Array to be sorted + * @param string $name Name of array element that represents the text to sort on + * @param string $parent Name of the array element that represents the parent ID to sort on + * + * @return array Sorted array + */ + public static function sortParentChild($array, $name = 'name', $parent = 'parent') + { + + if (!is_array($array) || count($array) == 0) { + return false; + } + + // Do a sort by custom function with it included in the call + // This lets me directly use $name and $parent in the sort function + uasort($array, function ($a, $b) use ($name, $parent) { + + // If there's a parent, append the name of this entry to the parent + // The '~~~' simply keeps appended strings from any chance of a match with something else + if ($a[$parent]['value']) { + $aVal = $a[$parent]['name'].'~~~'.$a['name']; + } else { + // Otheriwse just use the name. + $aVal = $a['name'].'~~~'; + } + + // Same for b value + if ($b[$parent]['value']) { + $bVal = $b[$parent]['name'].'~~~'.$b['name']; + } else { + $bVal = $b['name'].'~~~'; + } + + if ($aVal > $bVal) { + return 1; + } + + if ($aVal < $bVal) { + return -1; + } + + return 0; + + }); + + return $array; + } } ?> diff --git a/models/admin/settings/invoiceTypes.php b/models/admin/settings/invoiceTypes.php index bee1344..39ca9da 100644 --- a/models/admin/settings/invoiceTypes.php +++ b/models/admin/settings/invoiceTypes.php @@ -137,9 +137,9 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes } // Get a current list of members - $invoiceTypes = $this->getList('', 'name'); + $invoiceTypes = $this->getList(); - // echo '
$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '
'; + echo '
$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '
'; // If we have list entries - even if it's an empty list $success = true; @@ -154,6 +154,11 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes } } + // Sort results by higherarchy (Parent/Child and Alpha) + $invoiceTypes = $this->sortParentChild($invoiceTypes); + echo '
$invoiceTypes: ' . print_r( $invoiceTypes, true ) . '
'; + + // If we had a fatal error, redirect to the error page if ($error) { return array( @@ -170,7 +175,8 @@ class GlmMembersAdmin_settings_invoiceTypes extends GlmDataInvoiceTypes 'action' => $_REQUEST['glm_action'], 'enable_members' => $enable_members, 'haveInvoiceTypes' => $haveInvoiceTypes, - 'invoiceTypes' => $invoiceTypes + 'invoiceTypes' => $invoiceTypes, + 'recurrenceTypes' => $this->config['recurrence'], ); // Return status, suggested view, and data to controller diff --git a/views/admin/settings/invoiceTypes.html b/views/admin/settings/invoiceTypes.html index 2c033f7..0c9bd7b 100644 --- a/views/admin/settings/invoiceTypes.html +++ b/views/admin/settings/invoiceTypes.html @@ -16,15 +16,16 @@ - Code: + Parent: - - - - - Category: - - + @@ -34,16 +35,21 @@ - Dynamic Amount: + Recurring: - - + + - Notes: + Recurrence: - + @@ -56,8 +62,8 @@
-

Are you sure you want to delete this inoiceType?

-

Yes, delete this inoiceType

+

Are you sure you want to delete this invoice Type?

+

Yes, delete this invoice Type

Cancel

@@ -67,43 +73,51 @@
- + - + - - - - - + - + - +
Invoice Type Name: - +
Code:Parent: - +
Category: - -
Amount:Amount:Numbers only (999.99) - +
Dynamic Amount:Recurring: - - + +
Notes:Recurrence: - +
@@ -121,6 +135,8 @@ ID InvoiceType Amount + Recurring + Recurrence   @@ -135,20 +151,21 @@ {/if} {$t.id} - {$t.name} - - - {$t.amount} + + {$t.name} + + {$t.amount} + {if $t.recurring.value}Yes{else}No{/if} + {if $t.recurrence}{$recurrenceTypes[$t.recurrence]}{/if} -
Delete
+
Delete
{/foreach} @@ -181,26 +198,25 @@ $("#newInvoiceTypeDialog").dialog("open"); }); $('.editInvoiceType').click( function() { - $('#editInvoiceTypeDynamicAmount').prop( 'checked', false ); + $('#editRecurring').prop( 'checked', false ); - 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'); + var invoiceID = $(this).data('invoice-id'); + var invoiceName = $(this).data('invoice-name'); + var invoiceParent = $(this).data('invoice-parent'); + var invoiceAmount = $(this).data('invoice-amount'); + var invoiceRecurring = $(this).data('invoice-recurring'); + var invoiceRecurrence = $(this).data('invoice-recurrence'); - // 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 ); + // Set the values of the edit form for the selected invoiceType + $('#edit-id').val( invoiceID ); + $('#edit-name').val( invoiceName ); + $('#edit-parent').val( invoiceParent ); + $('#edit-amount').val( invoiceAmount ); + if ( invoiceRecurring === 1 ) { + $('#edit-recurring').prop( 'checked', true ); } - $('#editInvoiceTypeNotes').val( inoiceTypeNotes ); + console.log(invoiceRecurring); + $('#edit-recurrence').val( invoiceRecurrence ); $("#editInvoiceTypeDialog").dialog("open"); }); @@ -213,7 +229,7 @@ var id = false; $('.deleteInvoiceTypeButton').click( function() { - id = $(this).attr('data-inoiceTypeID'); + id = $(this).attr('data-invoiceTypeID'); $("#deleteInvoiceTypeDialog").dialog("open"); }); $('#deleteInvoiceTypeConfirm').click( function() { -- 2.17.1