diff --git a/client/src/modules/vouchers/modals/search.modal.html b/client/src/modules/vouchers/modals/search.modal.html index aba5cf81c2..c1d1354297 100644 --- a/client/src/modules/vouchers/modals/search.modal.html +++ b/client/src/modules/vouchers/modals/search.modal.html @@ -37,6 +37,15 @@ + + + + diff --git a/client/src/modules/vouchers/modals/search.modal.js b/client/src/modules/vouchers/modals/search.modal.js index 5827f86ddf..2fa25fa251 100644 --- a/client/src/modules/vouchers/modals/search.modal.js +++ b/client/src/modules/vouchers/modals/search.modal.js @@ -2,8 +2,8 @@ angular.module('bhima.controllers') .controller('VoucherRegistrySearchModalController', VoucherRegistrySearchModalController); VoucherRegistrySearchModalController.$inject = [ - '$uibModalInstance', 'filters', 'NotifyService', 'moment', 'PeriodService', 'Store', 'util', - 'TransactionTypeService', '$translate', 'VoucherService', + '$uibModalInstance', 'filters', 'NotifyService', 'PeriodService', 'Store', + 'util', 'VoucherService', ]; /** @@ -14,50 +14,40 @@ VoucherRegistrySearchModalController.$inject = [ * returning it as a JSON object to the parent controller. The data can be * preset by passing in a filters object using filtersProvider(). */ -function VoucherRegistrySearchModalController(ModalInstance, filters, Notify, moment, Periods, Store, util, - TransactionTypes, $translate, Vouchers) { +function VoucherRegistrySearchModalController( + ModalInstance, filters, Notify, Periods, Store, util, + Vouchers +) { var vm = this; var changes = new Store({ identifier : 'key' }); var searchQueryOptions = [ - 'reference', 'description', 'user_id', 'type_ids', + 'reference', 'description', 'user_id', 'type_ids', 'account_id', ]; + // displayValues will be an id:displayValue pair + var displayValues = {}; + var lastDisplayValues = Vouchers.filters.getDisplayValueMap(); + vm.filters = filters; // searchQueries is the same id:value pair vm.searchQueries = {}; - vm.defaultQueries = {}; - var lastDisplayValues = Vouchers.filters.getDisplayValueMap(); - - // displayValues will be an id:displayValue pair - var displayValues = {}; - // assign already defined custom filters to searchQueries object vm.searchQueries = util.maskObjectFromKeys(filters, searchQueryOptions); - // load all Transaction types - TransactionTypes.read() - .then(function (types) { - types.forEach(function (item) { - item.typeText = $translate.instant(item.text); - }); - vm.transactionTypes = types; - }) - .catch(Notify.handleError); - if (filters.limit) { vm.defaultQueries.limit = filters.limit; } vm.onTransactionTypesChange = function onTransactionTypesChange(transactionTypes) { - vm.searchQueries.type_ids = transactionTypes; var typeText = '/'; + vm.searchQueries.type_ids = transactionTypes; transactionTypes.forEach(function (typeId) { vm.transactionTypes.forEach(function (type) { if (typeId === type.id) { - typeText += type.typeText + ' / '; + typeText += type.typeText.concat(' / '); } }); }); @@ -81,13 +71,19 @@ function VoucherRegistrySearchModalController(ModalInstance, filters, Notify, mo }; // default filter limit - directly write to changes list - vm.onSelectLimit = function onSelectLimit(value) { + vm.onSelectLimit = function onSelectLimit(_value) { // input is type value, this will only be defined for a valid number - if (angular.isDefined(value)) { - changes.post({ key : 'limit', value : value }); + if (angular.isDefined(_value)) { + changes.post({ key : 'limit', value : _value }); } }; + // custom filter account_id - assign the value to the searchQueries object + vm.onSelectAccount = function onSelectAccount(account) { + vm.searchQueries.account_id = account.id; + displayValues.account_id = String(account.number).concat(' - ', account.label); + }; + // deletes a filter from the custom filter object, this key will no longer be written to changes on exit vm.clear = function clear(key) { delete vm.searchQueries[key]; @@ -97,21 +93,26 @@ function VoucherRegistrySearchModalController(ModalInstance, filters, Notify, mo // submit the filter object to the parent controller. vm.submit = function submit(form) { + var _displayValue; + var loggedChanges; + + if (form.$invalid) { return; } + // delete type_ids if there is no transaction type sent if (vm.searchQueries.type_ids && vm.searchQueries.type_ids.length === 0) { vm.clear('type_ids'); } // push all searchQuery values into the changes array to be applied - angular.forEach(vm.searchQueries, function (value, key) { - if (angular.isDefined(value)) { + angular.forEach(vm.searchQueries, function (_value, _key) { + if (angular.isDefined(_value)) { // default to the original value if no display value is defined - var displayValue = displayValues[key] || lastDisplayValues[key] || value; - changes.post({ key: key, value: value, displayValue: displayValue }); - } + _displayValue = displayValues[_key] || lastDisplayValues[_key] || _value; + changes.post({ key : _key, value : _value, displayValue : _displayValue }); + } }); - var loggedChanges = changes.getAll(); + loggedChanges = changes.getAll(); // return values to the voucher controller return ModalInstance.close(loggedChanges); diff --git a/client/src/modules/vouchers/vouchers.service.js b/client/src/modules/vouchers/vouchers.service.js index ba596a7ce7..00f0815950 100644 --- a/client/src/modules/vouchers/vouchers.service.js +++ b/client/src/modules/vouchers/vouchers.service.js @@ -4,7 +4,7 @@ angular.module('bhima.services') VoucherService.$inject = [ 'PrototypeApiService', 'TransactionTypeStoreService', '$uibModal', 'FilterService', 'PeriodService', 'LanguageService', '$httpParamSerializer', - 'appcache', 'bhConstants', 'TransactionService', '$translate' + 'appcache', 'bhConstants', 'TransactionService', '$translate', ]; /** @@ -41,14 +41,16 @@ function VoucherService( voucherFilters.registerDefaultFilters(bhConstants.defaultFilters); voucherFilters.registerCustomFilters([ - { key: 'user_id', label: 'FORM.LABELS.USER' }, - { key: 'reference', label: 'FORM.LABELS.REFERENCE' }, - { key: 'reversed', label: 'FORM.INFO.ANNULLED' }, - { key: 'description', label: 'FORM.LABELS.DESCRIPTION' }, - { key: 'entity_uuid', label: 'FORM.LABELS.ENTITY' }, - { key: 'cash_uuid', label: 'FORM.INFO.PAYMENT' }, - { key: 'invoice_uuid', label: 'FORM.LABELS.INVOICE' }, - { key: 'type_ids', label: 'FORM.LABELS.TRANSACTION_TYPE' }]); + { key : 'user_id', label : 'FORM.LABELS.USER' }, + { key : 'reference', label : 'FORM.LABELS.REFERENCE' }, + { key : 'reversed', label : 'FORM.INFO.ANNULLED' }, + { key : 'description', label : 'FORM.LABELS.DESCRIPTION' }, + { key : 'entity_uuid', label : 'FORM.LABELS.ENTITY' }, + { key : 'account_id', label : 'FORM.LABELS.ACCOUNT' }, + { key : 'cash_uuid', label : 'FORM.INFO.PAYMENT' }, + { key : 'invoice_uuid', label : 'FORM.LABELS.INVOICE' }, + { key : 'type_ids', label : 'FORM.LABELS.TRANSACTION_TYPE' }, + ]); if (filterCache.filters) { @@ -134,7 +136,7 @@ function VoucherService( return sum + row.debit; }, 0); - return Api.create.call(service, { voucher: v }); + return Api.create.call(service, { voucher : v }); } /** @@ -161,14 +163,13 @@ function VoucherService( item.hrText = $translate.instant(item.text); return item; }); - }) - ; + }); } // downloads a type of report based on the function download(type) { var filterOpts = voucherFilters.formatHTTP(); - var defaultOpts = { renderer: type, lang: Languages.key }; + var defaultOpts = { renderer : type, lang: Languages.key }; // combine options var options = angular.merge(defaultOpts, filterOpts); @@ -184,14 +185,14 @@ function VoucherService( */ function openSearchModal(filters) { return Modal.open({ - templateUrl: 'modules/vouchers/modals/search.modal.html', - size: 'md', - animation: false, - keyboard: false, - backdrop: 'static', - controller: 'VoucherRegistrySearchModalController as $ctrl', - resolve: { - filters: function filtersProvider() { return filters; }, + templateUrl : 'modules/vouchers/modals/search.modal.html', + size : 'md', + animation : false, + keyboard : false, + backdrop : 'static', + controller : 'VoucherRegistrySearchModalController as $ctrl', + resolve : { + filters : function filtersProvider() { return filters; }, }, }).result; }