From e98b494935202c9f00954a365df4406824df73dc Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Sat, 31 Dec 2016 08:37:15 +0100 Subject: [PATCH] fix(cash): payments registry filters work This commit reimplements the payments registry filtering scheme in a way that can be cached and improved upon later. Previously, filters were not able to be removed and frequent errors were thrown in the console. It also refactors the routes so that all the payments routes are together in the `cash` folder. This is more in line with how the invoices work. --- client/src/js/services/ModalService.js | 4 +- client/src/partials/cash/cash.routes.js | 7 +++ .../payments/registry.html} | 13 ++-- .../payments/registry.js} | 63 +++++++++++-------- .../payments}/templates/action.grid.html | 2 +- .../payments}/templates/amount.grid.html | 0 .../templates/cancelCash.action.tmpl.html | 0 .../templates/grid.canceled.tmpl.html | 0 .../payments}/templates/search.modal.html | 0 .../payments}/templates/search.modal.js | 0 .../cash_payment/cash_payment.routes.js | 11 ---- server/models/test/data.sql | 2 +- test/end-to-end/cash/cash.registry.js | 2 +- 13 files changed, 54 insertions(+), 50 deletions(-) rename client/src/partials/{finance/reports/cash_payment/cash_payment.html => cash/payments/registry.html} (80%) rename client/src/partials/{finance/reports/cash_payment/cash_payment.js => cash/payments/registry.js} (74%) rename client/src/partials/{finance/reports/cash_payment => cash/payments}/templates/action.grid.html (83%) rename client/src/partials/{finance/reports/cash_payment => cash/payments}/templates/amount.grid.html (100%) rename client/src/partials/{finance/reports/cash_payment => cash/payments}/templates/cancelCash.action.tmpl.html (100%) rename client/src/partials/{finance/reports/cash_payment => cash/payments}/templates/grid.canceled.tmpl.html (100%) rename client/src/partials/{finance/reports/cash_payment => cash/payments}/templates/search.modal.html (100%) rename client/src/partials/{finance/reports/cash_payment => cash/payments}/templates/search.modal.js (100%) delete mode 100644 client/src/partials/finance/reports/cash_payment/cash_payment.routes.js diff --git a/client/src/js/services/ModalService.js b/client/src/js/services/ModalService.js index 565a1e50cb..aecb525da0 100644 --- a/client/src/js/services/ModalService.js +++ b/client/src/js/services/ModalService.js @@ -1,5 +1,5 @@ angular.module('bhima.services') -.service('ModalService', ModalService); + .service('ModalService', ModalService); ModalService.$inject = [ '$uibModal' ]; @@ -377,7 +377,7 @@ function ModalService(Modal) { /** searchCashPayment */ function openSearchCashPayment(request) { var params = angular.extend(modalParameters, { - templateUrl : 'partials/finance/reports/cash_payment/templates/search.modal.html', + templateUrl : 'partials/cash/payments/templates/search.modal.html', controller : 'SearchCashPaymentModalController', controllerAs : '$ctrl', size : 'md', diff --git a/client/src/partials/cash/cash.routes.js b/client/src/partials/cash/cash.routes.js index 1af8b9b638..1c4b4d5af7 100644 --- a/client/src/partials/cash/cash.routes.js +++ b/client/src/partials/cash/cash.routes.js @@ -2,6 +2,12 @@ angular.module('bhima.routes') .config(['$stateProvider', function ($stateProvider) { $stateProvider + .state('cashRegistry', { + url : '/payments', + controller: 'CashPaymentRegistryController as CPRCtrl', + templateUrl: 'partials/cash/payments/registry.html' + }) + .state('cash', { url : '/cash', abstract: true, @@ -29,6 +35,7 @@ angular.module('bhima.routes') onEnter :['$state', '$uibModal', transferModal], onExit : ['$uibModalStack', closeModal] }); + }]); diff --git a/client/src/partials/finance/reports/cash_payment/cash_payment.html b/client/src/partials/cash/payments/registry.html similarity index 80% rename from client/src/partials/finance/reports/cash_payment/cash_payment.html rename to client/src/partials/cash/payments/registry.html index 0034765e65..305ca32c40 100644 --- a/client/src/partials/finance/reports/cash_payment/cash_payment.html +++ b/client/src/partials/cash/payments/registry.html @@ -1,8 +1,8 @@
    -
  1. {{ "TREE.FINANCE" | translate }}
  2. -
  3. {{ "TREE.CASH_PAYMENT_REGISTRY" | translate }}
  4. +
  5. TREE.FINANCE
  6. +
  7. TREE.CASH_PAYMENT_REGISTRY
@@ -11,7 +11,7 @@ ng-click="CPRCtrl.search()" data-method="search" class="btn btn-default"> - {{ "FORM.BUTTONS.SEARCH" | translate }} + FORM.BUTTONS.SEARCH
@@ -25,7 +25,6 @@
- diff --git a/client/src/partials/finance/reports/cash_payment/cash_payment.js b/client/src/partials/cash/payments/registry.js similarity index 74% rename from client/src/partials/finance/reports/cash_payment/cash_payment.js rename to client/src/partials/cash/payments/registry.js index d3617726b6..8731fe4a51 100644 --- a/client/src/partials/finance/reports/cash_payment/cash_payment.js +++ b/client/src/partials/cash/payments/registry.js @@ -3,37 +3,41 @@ angular.module('bhima.controllers') // dependencies injection CashPaymentRegistryController.$inject = [ - 'CashService', 'bhConstants', 'NotifyService', 'SessionService', 'ModalService', - 'uiGridConstants', 'uiGridGroupingConstants', 'LanguageService', 'ReceiptService' + 'CashService', 'bhConstants', 'NotifyService', 'SessionService', 'uiGridConstants', + 'uiGridGroupingConstants', 'LanguageService', 'appcache', 'ReceiptModal', 'ModalService' ]; /** * Cash Payment Registry Controller + * * This controller is responsible to display all cash payment made and provides - * print and search utilities for the registry + * print and search utilities for the registry.`j */ -function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal, uiGridConstants, uiGridGroupingConstants, Languages, Receipts) { +function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, uiGridConstants, uiGridGroupingConstants, Languages, AppCache, Receipt, Modal) { var vm = this; + var cache = AppCache('CashRegistry'); + + // Background color for make the difference between the valid and cancel paiement + var reversedBackgroundColor = { 'background-color': '#ffb3b3' }; + var regularBackgroundColor = { 'background-color': 'none' }; + // global variables vm.filters = { lang: Languages.key }; vm.formatedFilters = []; vm.gridOptions = {}; - vm.loading = false; vm.enterprise = Session.enterprise; vm.bhConstants = bhConstants; + // bind the cash payments receipt + vm.openReceiptModal = Receipt.cash; + // expose to the view - vm.showReceipt = showReceipt; vm.search = search; vm.onRemoveFilter = onRemoveFilter; vm.clearFilters = clearFilters; vm.cancelCash = cancelCash; - // Background color for make the difference betwen the valid and cancel paiement - var reversedBackgroundColor = {'background-color': '#ffb3b3' }; - var regularBackgroundColor = { 'background-color': 'none' }; - // grid default options vm.gridOptions = { appScopeProvider : vm, @@ -42,7 +46,7 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal flatEntityAccess : true, fastWatch : true, enableFiltering : vm.filterEnabled, - rowTemplate : '/partials/finance/reports/cash_payment/templates/grid.canceled.tmpl.html' + rowTemplate : '/partials/cash/payments/templates/grid.canceled.tmpl.html' }; vm.gridOptions.columnDefs = [{ @@ -56,27 +60,31 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal field : 'description', displayName : 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter: 'translate' }, { field : 'amount', displayName : 'TABLE.COLUMNS.AMOUNT', headerCellFilter: 'translate', - cellTemplate: 'partials/finance/reports/cash_payment/templates/amount.grid.html' + cellTemplate : 'partials/cash/payments/templates/amount.grid.html' }, { field : 'cashbox_label', displayName : 'TABLE.COLUMNS.CASHBOX', headerCellFilter: 'translate' }, { field : 'display_name', displayName : 'TABLE.COLUMNS.USER', headerCellFilter: 'translate' }, { field : 'action', displayName : '', enableFiltering: false, enableSorting: false, - cellTemplate: 'partials/finance/reports/cash_payment/templates/action.grid.html' + cellTemplate: 'partials/cash/payments/templates/action.grid.html' }, { field : 'action', displayName : '', enableFiltering: false, enableSorting: false, - cellTemplate: 'partials/finance/reports/cash_payment/templates/cancelCash.action.tmpl.html' + cellTemplate: 'partials/cash/payments/templates/cancelCash.action.tmpl.html' }]; + function handleError(error) { + vm.hasError = true; + Notify.handleError(error); + } + // search function search() { Modal.openSearchCashPayment() .then(function (filters) { if (!filters) { return; } reload(filters); - }) - .catch(Notify.handleError); + }); } // on remove one filter @@ -88,7 +96,7 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal // remove a filter with from the filter object, save the filters and reload function clearFilters() { - reload({ display : undefined, identifiers : undefined }); + reload({ display : [], identifiers : {} }); } // reload with filter @@ -98,16 +106,12 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal load(filters.identifiers); } - // showReceipt - function showReceipt(uuid) { - var url = '/reports/finance/cash/' + uuid; - var params = { renderer: 'pdf', lang: Languages.key, posReceipt : Receipts.posReceipt }; - - Modal.openReports({ url: url, params: params }); - } - // load cash function load(filters) { + vm.hasError = false; + + toggleLoadingIndicator(); + Cash.search(filters) .then(function (rows) { rows.forEach(function (row) { @@ -117,7 +121,10 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal vm.gridOptions.data = rows; }) - .catch(Notify.handleError); + .catch(handleError) + .finally(function () { + toggleLoadingIndicator(); + }); } // Function for Cancel Cash cancel all Invoice @@ -130,6 +137,10 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal }); } + function toggleLoadingIndicator() { + vm.loading = !vm.loading; + } + // startup load(); } diff --git a/client/src/partials/finance/reports/cash_payment/templates/action.grid.html b/client/src/partials/cash/payments/templates/action.grid.html similarity index 83% rename from client/src/partials/finance/reports/cash_payment/templates/action.grid.html rename to client/src/partials/cash/payments/templates/action.grid.html index 92d3f9b543..4b1cbaeec0 100644 --- a/client/src/partials/finance/reports/cash_payment/templates/action.grid.html +++ b/client/src/partials/cash/payments/templates/action.grid.html @@ -1,4 +1,4 @@ -
+
TABLE.COLUMNS.RECEIPT diff --git a/client/src/partials/finance/reports/cash_payment/templates/amount.grid.html b/client/src/partials/cash/payments/templates/amount.grid.html similarity index 100% rename from client/src/partials/finance/reports/cash_payment/templates/amount.grid.html rename to client/src/partials/cash/payments/templates/amount.grid.html diff --git a/client/src/partials/finance/reports/cash_payment/templates/cancelCash.action.tmpl.html b/client/src/partials/cash/payments/templates/cancelCash.action.tmpl.html similarity index 100% rename from client/src/partials/finance/reports/cash_payment/templates/cancelCash.action.tmpl.html rename to client/src/partials/cash/payments/templates/cancelCash.action.tmpl.html diff --git a/client/src/partials/finance/reports/cash_payment/templates/grid.canceled.tmpl.html b/client/src/partials/cash/payments/templates/grid.canceled.tmpl.html similarity index 100% rename from client/src/partials/finance/reports/cash_payment/templates/grid.canceled.tmpl.html rename to client/src/partials/cash/payments/templates/grid.canceled.tmpl.html diff --git a/client/src/partials/finance/reports/cash_payment/templates/search.modal.html b/client/src/partials/cash/payments/templates/search.modal.html similarity index 100% rename from client/src/partials/finance/reports/cash_payment/templates/search.modal.html rename to client/src/partials/cash/payments/templates/search.modal.html diff --git a/client/src/partials/finance/reports/cash_payment/templates/search.modal.js b/client/src/partials/cash/payments/templates/search.modal.js similarity index 100% rename from client/src/partials/finance/reports/cash_payment/templates/search.modal.js rename to client/src/partials/cash/payments/templates/search.modal.js diff --git a/client/src/partials/finance/reports/cash_payment/cash_payment.routes.js b/client/src/partials/finance/reports/cash_payment/cash_payment.routes.js deleted file mode 100644 index 539fa8fb33..0000000000 --- a/client/src/partials/finance/reports/cash_payment/cash_payment.routes.js +++ /dev/null @@ -1,11 +0,0 @@ -angular.module('bhima.routes') - .config(['$stateProvider', function ($stateProvider) { - - $stateProvider - .state('cashPaymentRegistry', { - url : '/finance/reports/cash_payment', - controller: 'CashPaymentRegistryController as CPRCtrl', - templateUrl: 'partials/finance/reports/cash_payment/cash_payment.html' - }); - - }]); diff --git a/server/models/test/data.sql b/server/models/test/data.sql index 88e7f007b8..158c5297b8 100644 --- a/server/models/test/data.sql +++ b/server/models/test/data.sql @@ -51,7 +51,7 @@ INSERT INTO unit VALUES (145, 'Cashflow', 'TREE.CASHFLOW', 'The Cashflow Report', 144, '/partials/finance/cashflow', '/reports/cashflow'), (148, 'Chart of Accounts', 'REPORT.CHART_OF_ACCOUNTS', 'The COA Report', 144, '/partials/finance/chart_of_accounts', '/reports/accounts_chart'), (146, 'Creditor Groups Management', 'TREE.CREDITOR_GROUP', 'Creditor Groups Management module', 1, '/partials/admin/creditor_groups/', '/admin/creditor_groups'), - (147, 'Cash Payment Registry', 'TREE.CASH_PAYMENT_REGISTRY', 'Cash Payment Registry', 5, '/partials/finance/reports/cash_payment', '/finance/reports/cash_payment'), + (147, 'Cash Payment Registry', 'TREE.CASH_PAYMENT_REGISTRY', 'Cash Payment Registry', 5, '/partials/cash/payments', '/payments'), (149, 'Income Expenses', 'TREE.INCOME_EXPENSE', 'The Report of income and expenses', 144, '/partials/finance/income_expense', '/reports/income_expense'), (150, 'Balance Report', 'TREE.BALANCE', 'Balance report module', 144, 'null', '/reports/balance'), (151, 'Customer Debts', 'TREE.CUSTOMER_DEBTS', 'Customer Debts', 144, '/partials/finance/reports/agedDebtors', '/reports/agedDebtors'), diff --git a/test/end-to-end/cash/cash.registry.js b/test/end-to-end/cash/cash.registry.js index c38ab21e1f..e32ce7d86a 100644 --- a/test/end-to-end/cash/cash.registry.js +++ b/test/end-to-end/cash/cash.registry.js @@ -11,7 +11,7 @@ const moment = require('moment'); function CashPaymentsRegistryTests() { // navigate to the page - before(() => helpers.navigate('#/finance/reports/cash_payment')); + before(() => helpers.navigate('#/payments')); const PAYMENT_INSIDE_REGISTRY = 3; const PAYMENT_PRIMARY_CASHBOX = 0;