Skip to content

Commit

Permalink
fix(cash): payments registry filters work
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jonathan Niles authored and jniles committed Jan 6, 2017
1 parent 5514830 commit e98b494
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 50 deletions.
4 changes: 2 additions & 2 deletions client/src/js/services/ModalService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
angular.module('bhima.services')
.service('ModalService', ModalService);
.service('ModalService', ModalService);

ModalService.$inject = [ '$uibModal' ];

Expand Down Expand Up @@ -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',
Expand Down
7 changes: 7 additions & 0 deletions client/src/partials/cash/cash.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -29,6 +35,7 @@ angular.module('bhima.routes')
onEnter :['$state', '$uibModal', transferModal],
onExit : ['$uibModalStack', closeModal]
});

}]);


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="flex-header static">
<div class="bhima-title">
<ol class="headercrumb">
<li class="static">{{ "TREE.FINANCE" | translate }}</li>
<li class="title">{{ "TREE.CASH_PAYMENT_REGISTRY" | translate }}</li>
<li class="static" translate>TREE.FINANCE</li>
<li class="title" translate>TREE.CASH_PAYMENT_REGISTRY</li>
</ol>

<div class="toolbar">
Expand All @@ -11,7 +11,7 @@
ng-click="CPRCtrl.search()"
data-method="search"
class="btn btn-default">
<span class="fa fa-search"></span> {{ "FORM.BUTTONS.SEARCH" | translate }}
<i class="fa fa-search"></i> <span translate>FORM.BUTTONS.SEARCH</span>
</button>
</div>
<div class="toolbar-item">
Expand All @@ -25,22 +25,19 @@
</div>
</div>

<!-- util bar -->
<div class="flex-util" style="min-height : 35px; padding-top : 7px; max-height: initial">
<bh-filters-applied
style="max-width:90%"
filters="CPRCtrl.formatedFilters"
on-remove-filter="CPRCtrl.onRemoveFilter(filter)">
</bh-filters-applied>

<a
href
<a href
ng-click="CPRCtrl.clearFilters()"
ng-show="CPRCtrl.formatedFilters.length > 0"
class="text-danger"
data-method="clear">
<i class="fa fa-ban text-danger"></i>
{{ "FORM.INFO.CLEAR_FILTERS" | translate }}
<i class="fa fa-ban text-danger"></i> <span translate>FORM.INFO.CLEAR_FILTERS</span>
</a>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = [{
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -130,6 +137,10 @@ function CashPaymentRegistryController(Cash, bhConstants, Notify, Session, Modal
});
}

function toggleLoadingIndicator() {
vm.loading = !vm.loading;
}

// startup
load();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="ui-grid-cell-contents text-action" ng-click="grid.appScope.showReceipt(row.entity.uuid)">
<div class="ui-grid-cell-contents text-action" ng-click="grid.appScope.openReceiptModal(row.entity.uuid)">
<a data-link-receipt="{{ ::row.entity.uuid }}" href>
<i class="fa fa-file-pdf-o"></i> <span translate>TABLE.COLUMNS.RECEIPT</span>
</a>
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion server/models/test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/cash/cash.registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e98b494

Please sign in to comment.