diff --git a/client/src/js/services/grid/GridSorting.js b/client/src/js/services/grid/GridSorting.js index bb8b4a5b3b..3704cdcce2 100644 --- a/client/src/js/services/grid/GridSorting.js +++ b/client/src/js/services/grid/GridSorting.js @@ -53,12 +53,13 @@ function GridSortingService(util) { } else { // reference value is passed in the row - simply use this + // FIXME(@jniles) we rarely pass the numeric reference value... first = Number(rowA.entity.reference); second = Number(rowB.entity.reference); } - // This (standard method) casuses transaction groups to be sorted incorrectly - why has not been demonstrated - // Standard integer compare sort: retrun first - second; + // This (standard method) causes transaction groups to be sorted incorrectly - why has not been demonstrated + // Standard integer compare sort: return first - second; if (first > second) { return 1; } @@ -89,5 +90,32 @@ function GridSortingService(util) { }.bind(this)); } + /** + * @function sortByReferece + * + * @description + * Sorts references as if they were numerical values. + * + * @public + */ + function sortByReference(a, b) { + + // get the last index of the dot in the reference (plus offset) + var aIdx = a.lastIndexOf('.') + 1, + bIdx = b.lastIndexOf('.') + 1; + + // get the numerical value + var aReference = parseInt(a.slice(aIdx)), + bReference = parseInt(b.slice(bIdx)); + + // return the correct numerical value + return aReference - bReference; + } + + // bind all algorithms for public consumption + GridSorting.algorithms = { + sortByReference : sortByReference + }; + return GridSorting; } diff --git a/client/src/partials/cash/payments/registry.js b/client/src/partials/cash/payments/registry.js index 4bd0e8138f..456940fcb5 100644 --- a/client/src/partials/cash/payments/registry.js +++ b/client/src/partials/cash/payments/registry.js @@ -4,7 +4,8 @@ angular.module('bhima.controllers') // dependencies injection CashPaymentRegistryController.$inject = [ 'CashService', 'bhConstants', 'NotifyService', 'SessionService', 'uiGridConstants', - 'uiGridGroupingConstants', 'LanguageService', 'appcache', 'ReceiptModal', 'ModalService' + 'uiGridGroupingConstants', 'LanguageService', 'appcache', 'ReceiptModal', 'ModalService', + 'GridSortingService' ]; /** @@ -13,7 +14,7 @@ CashPaymentRegistryController.$inject = [ * This controller is responsible to display all cash payment made and provides * print and search utilities for the registry.`j */ -function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, uiGridConstants, uiGridGroupingConstants, Languages, AppCache, Receipt, Modal) { +function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, uiGridConstants, uiGridGroupingConstants, Languages, AppCache, Receipt, Modal, Sorting) { var vm = this; var cache = AppCache('CashRegistry'); @@ -51,7 +52,8 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, uiGri vm.gridOptions.columnDefs = [{ field : 'reference', displayName : 'TABLE.COLUMNS.REFERENCE', - headerCellFilter: 'translate', aggregationType: uiGridConstants.aggregationTypes.count, aggregationHideLabel : true + headerCellFilter: 'translate', aggregationType: uiGridConstants.aggregationTypes.count, + aggregationHideLabel : true, sortingAlgorithm : Sorting.algorithms.sortByReference }, { field : 'date', displayName : 'TABLE.COLUMNS.DATE', headerCellFilter: 'translate', cellFilter : 'date:"mediumDate"', }, { diff --git a/client/src/partials/patient_invoice/registry/registry.js b/client/src/partials/patient_invoice/registry/registry.js index 06d3a7d9e1..06bc057f89 100644 --- a/client/src/partials/patient_invoice/registry/registry.js +++ b/client/src/partials/patient_invoice/registry/registry.js @@ -4,7 +4,7 @@ angular.module('bhima.controllers') InvoiceRegistryController.$inject = [ 'PatientInvoiceService', 'bhConstants', 'NotifyService', 'SessionService', 'util', 'ReceiptModal', 'appcache', - 'uiGridConstants', 'ModalService', 'CashService' + 'uiGridConstants', 'ModalService', 'CashService', 'GridSortingService' ]; /** @@ -12,7 +12,7 @@ InvoiceRegistryController.$inject = [ * * This module is responsible for the management of Invoice Registry. */ -function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, Receipt, AppCache, uiGridConstants, ModalService, Cash) { +function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, Receipt, AppCache, uiGridConstants, ModalService, Cash, Sorting) { var vm = this; var cache = AppCache('InvoiceRegistry'); @@ -39,7 +39,8 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util, headerCellFilter: 'translate', aggregationType: uiGridConstants.aggregationTypes.count, aggregationHideLabel : true, - footerCellClass : 'text-center' + footerCellClass : 'text-center', + sortingAlgorithm : Sorting.algorithms.sortByReference }, { field : 'date', cellFilter:'date', displayName : 'TABLE.COLUMNS.BILLING_DATE', headerCellFilter : 'translate', type: 'date' }, { field : 'patientName', displayName : 'TABLE.COLUMNS.PATIENT', headerCellFilter : 'translate' }, diff --git a/client/src/partials/patients/registry/registry.js b/client/src/partials/patients/registry/registry.js index b3c1d09264..3cbc403d15 100644 --- a/client/src/partials/patients/registry/registry.js +++ b/client/src/partials/patients/registry/registry.js @@ -2,7 +2,8 @@ angular.module('bhima.controllers') .controller('PatientRegistryController', PatientRegistryController); PatientRegistryController.$inject = [ - '$state', 'PatientService', 'NotifyService', 'AppCache', 'util', 'ReceiptModal', 'uiGridConstants', '$translate', 'GridColumnService' + '$state', 'PatientService', 'NotifyService', 'AppCache', 'util', 'ReceiptModal', + 'uiGridConstants', '$translate', 'GridColumnService', 'GridSortingService' ]; /** @@ -10,7 +11,7 @@ PatientRegistryController.$inject = [ * * This module is responsible for the management of Patient Registry. */ -function PatientRegistryController($state, Patients, Notify, AppCache, util, Receipts, uiGridConstants, $translate, Columns) { +function PatientRegistryController($state, Patients, Notify, AppCache, util, Receipts, uiGridConstants, $translate, Columns, Sorting) { var vm = this; var cacheKey = 'PatientRegistry'; @@ -52,7 +53,8 @@ function PatientRegistryController($state, Patients, Notify, AppCache, util, Rec displayName : 'TABLE.COLUMNS.REFERENCE', aggregationType: uiGridConstants.aggregationTypes.count, aggregationHideLabel : true, headerCellFilter: 'translate', - footerCellClass : 'text-center' + footerCellClass : 'text-center', + sortingAlgorithm : Sorting.algorithms.sortByReference }, { field : 'display_name', displayName : 'TABLE.COLUMNS.NAME', headerCellFilter: 'translate' }, { field : 'patientAge', displayName : 'TABLE.COLUMNS.AGE', headerCellFilter: 'translate', type: 'number' }, diff --git a/client/src/partials/vouchers/index.js b/client/src/partials/vouchers/index.js index 32414f4d50..89a94fcd46 100644 --- a/client/src/partials/vouchers/index.js +++ b/client/src/partials/vouchers/index.js @@ -5,7 +5,7 @@ angular.module('bhima.controllers') VoucherController.$inject = [ 'VoucherService', '$translate', 'NotifyService', 'GridFilteringService', 'uiGridGroupingConstants', 'uiGridConstants', 'ModalService', 'DateService', - 'bhConstants', 'ReceiptModal' + 'bhConstants', 'ReceiptModal', 'GridSortingService' ]; /** @@ -14,7 +14,7 @@ VoucherController.$inject = [ * @description * This controller is responsible for display all vouchers in the voucher table. */ -function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupingConstants, uiGridConstants, Modal, Dates, bhConstants, Receipts) { +function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupingConstants, uiGridConstants, Modal, Dates, bhConstants, Receipts, Sorting) { var vm = this; /* global variables */ @@ -60,8 +60,9 @@ function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupi // grid default options vm.gridOptions.columnDefs = [ { field : 'reference', displayName : 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate', - groupingShowAggregationMenu: false, - aggregationType: uiGridConstants.aggregationTypes.count + treeAggregationType: uiGridGroupingConstants.aggregation.COUNT, + sortingAlgorithm : Sorting.algorithms.sortByReference, + treeAggregationLabel: '', footerCellClass : 'text-center', }, { field : 'type_id', displayName : 'TABLE.COLUMNS.TYPE', headerCellFilter: 'translate', sort: { priority: 0, direction : 'asc' }, @@ -69,12 +70,14 @@ function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupi cellTemplate: 'partials/templates/grid/voucherType.tmpl.html', treeAggregationType: uiGridGroupingConstants.aggregation.SUM, customTreeAggregationFinalizerFn: typeAggregation, + treeAggregationLabel : '', groupingShowAggregationMenu: false }, { field : 'date', displayName : 'TABLE.COLUMNS.DATE', headerCellFilter: 'translate', - cellFilter : 'date:"mediumDate"', + cellFilter : 'date', filter : { condition : filtering.byDate }, customTreeAggregationFinalizerFn: timeAggregation, + treeAggregationLabel : '', type : 'date', groupingShowAggregationMenu: false }, { field : 'description', displayName : 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter: 'translate', @@ -82,7 +85,8 @@ function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupi }, { field : 'amount', displayName : 'TABLE.COLUMNS.AMOUNT', headerCellFilter: 'translate', treeAggregationType: uiGridGroupingConstants.aggregation.SUM, - groupingShowAggregationMenu: false + treeAggregationLabel : '', footerCellClass : 'text-center', + type: 'number', groupingShowAggregationMenu: false }, { field : 'display_name', displayName : 'TABLE.COLUMNS.RESPONSIBLE', headerCellFilter: 'translate', groupingShowAggregationMenu: false @@ -166,7 +170,7 @@ function VoucherController(Vouchers, $translate, Notify, Filtering, uiGridGroupi Notify.handleError(err); }) .finally(function () { - vm.loading = false; + toggleLoadingIndicator(); }); }