Skip to content

Commit

Permalink
perf(vouchers): improve FindReference usability
Browse files Browse the repository at this point in the history
This commit improves the performance and usability of the FindReference
modal on the complex vouchers page.  The dates now render in the format
DD/MM/YYYY, and the grid is cleared every time the user refreshes the
selection.  Additionally, the options for fastWatching and
flatEntityAccess have been put in place.
  • Loading branch information
jniles committed Dec 17, 2017
1 parent 2e03636 commit 0bb06ac
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 43 deletions.
69 changes: 40 additions & 29 deletions client/src/modules/templates/modals/findReference.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,60 @@ angular.module('bhima.controllers')

FindReferenceModalController.$inject = [
'$uibModalInstance', 'VoucherService', 'CashService', 'GridFilteringService',
'entity', 'PatientInvoiceService', 'uiGridConstants', 'NotifyService'
'entity', 'PatientInvoiceService', 'uiGridConstants', 'NotifyService',
'bhConstants',
];

/**
* Find Reference Modal Controller
*
* This controller provides bindings for the find references modal.
* @todo Implement the Cash Payment Data list for the references
* TODO Implement the Cash Payment Data list for the references
*/
function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity, Invoices, uiGridConstants, Notify) {
function FindReferenceModalController(
Instance, Voucher, Cash, GridFilter, entity, Invoices, uiGridConstants,
Notify, bhConstants
) {
var vm = this;

vm.result = {};

vm.loading = false;

vm.documentType = {
'patient_invoice' : {
patient_invoice : {
label : 'VOUCHERS.COMPLEX.PATIENT_INVOICE',
action : referencePatientInvoice
action : referencePatientInvoice,
},
'cash_payment' : {
cash_payment : {
label : 'VOUCHERS.COMPLEX.CASH_PAYMENT',
action : referenceCashPayment
action : referenceCashPayment,
},
'voucher' : {
voucher : {
label : 'VOUCHERS.COMPLEX.VOUCHER',
action : referenceVoucher
}
action : referenceVoucher,
},
};

vm.selectDocType = selectDocType;
vm.submit = submit;
vm.cancel = cancel;
vm.submit = submit;
vm.cancel = cancel;
vm.refresh = refresh;

/* ======================= Grid configurations ============================ */
vm.filterEnabled = false;

// TODO - make this a default options extensible by many different
vm.gridOptions = {};

var filtering = new Filtering(vm.gridOptions);
var filtering = new GridFilter(vm.gridOptions);

vm.gridOptions.multiSelect = false;
vm.gridOptions.multiSelect = false;
vm.gridOptions.enableFiltering = vm.filterEnabled;
vm.gridOptions.onRegisterApi = onRegisterApi;
vm.gridOptions.onRegisterApi = onRegisterApi;
vm.gridOptions.fastWatch = true;
vm.gridOptions.flatEntityAccess = true;
vm.gridOptions.enableColumnMenus = false;
vm.toggleFilter = toggleFilter;

function onRegisterApi(gridApi) {
Expand Down Expand Up @@ -87,16 +96,16 @@ function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity
{ field : 'reference', displayName : 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate' },
{
field : 'date',
cellFilter:'date',
cellFilter : 'date:"'.concat(bhConstants.dates.format, '"'),
filter : { condition : filtering.filterByDate },
displayName : 'TABLE.COLUMNS.BILLING_DATE',
headerCellFilter : 'translate',
sort : { priority : 0, direction : 'desc'}
sort : { priority : 0, direction : 'desc' },
},
{ field : 'patientNames', displayName : 'TABLE.COLUMNS.PATIENT', headerCellFilter : 'translate' },
{ field : 'patientName', displayName : 'TABLE.COLUMNS.PATIENT', headerCellFilter : 'translate' },
{ field : 'cost', displayName : 'TABLE.COLUMNS.COST', headerCellFilter : 'translate', cellTemplate: costTemplate },
{ field : 'serviceName', displayName : 'TABLE.COLUMNS.SERVICE', headerCellFilter : 'translate' },
{ field : 'display_name', displayName : 'TABLE.COLUMNS.BY', headerCellFilter : 'translate' }
{ field : 'serviceName', displayName : 'TABLE.COLUMNS.SERVICE', headerCellFilter : 'translate' },
{ field : 'display_name', displayName : 'TABLE.COLUMNS.BY', headerCellFilter : 'translate' },
];

vm.gridOptions.data = list;
Expand All @@ -119,11 +128,12 @@ function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity
{ field : 'reference', displayName : 'TABLE.COLUMNS.REFERENCE', headerCellFilter: 'translate' },
{
field : 'date',
cellFilter:'date',
cellFilter : 'date:"'.concat(bhConstants.dates.format, '"'),
type : 'date',
filter : { condition : filtering.filterByDate },
displayName : 'TABLE.COLUMNS.BILLING_DATE',
headerCellFilter : 'translate',
sort : { priority : 0, direction : 'desc'}
sort : { priority : 0, direction : 'desc' }
},
{ field : 'description', displayName : 'TABLE.COLUMNS.DESCRIPTION', headerCellFilter : 'translate' },
{ field : 'amount', displayName : 'TABLE.COLUMNS.COST', headerCellFilter : 'translate', cellTemplate: costTemplate }
Expand All @@ -145,16 +155,16 @@ function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity
'{{ row.entity.amount | currency: grid.appScope.enterprise.currency_id }}' +
'</div>';

vm.gridOptions.columnDefs = [
{ field : 'reference', displayName : 'Reference'},
vm.gridOptions.columnDefs = [
{ field : 'reference', displayName : 'Reference' },
{
field : 'date',
displayName : 'Date',
cellFilter : 'date:"mediumDate"',
cellFilter : 'date:"'.concat(bhConstants.dates.format, '"'),
filter : { condition : filtering.filterByDate },
sort : { priority : 0, direction : 'desc'}
sort : { priority : 0, direction : 'desc' }
},
{ field : 'description', displayName : 'Description'},
{ field : 'description', displayName : 'Description' },
{ field : 'amount', displayName : 'Amount', cellTemplate: amountTemplate }
];

Expand All @@ -165,7 +175,7 @@ function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity
reference : item.reference,
date : item.date,
description : item.description,
amount : item.amount
amount : item.amount,
};
});
vm.gridOptions.data = data;
Expand All @@ -182,6 +192,7 @@ function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity

function refresh() {
vm.documentTypeSelected = false;
vm.gridOptions.data = [];
}

function submit() {
Expand All @@ -193,7 +204,7 @@ function FindReferenceModalController(Instance, Voucher, Cash, Filtering, Entity
}

function startup() {
vm.selectedEntity = Entity || {};
vm.selectedEntity = entity || {};
}

function toggleLoadingIndicator() {
Expand Down
23 changes: 12 additions & 11 deletions client/src/modules/vouchers/complex-voucher.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ angular.module('bhima.controllers')
ComplexJournalVoucherController.$inject = [
'VoucherService', 'CurrencyService', 'SessionService',
'FindEntityService', 'FindReferenceService', 'NotifyService',
'VoucherToolkitService', 'ReceiptModal', 'bhConstants', 'GridAggregatorService',
'uiGridConstants', 'VoucherForm', '$timeout',
'VoucherToolkitService', 'ReceiptModal', 'bhConstants', 'uiGridConstants',
'VoucherForm', '$timeout',
];

/**
* Complex Journal Vouchers
* @overview ComplexJournalVoucherController
*
* @description
* This module implements complex journal vouchers. It allows users to quickly create transactions by
* specifying two or more lines of transactions and all relative document references
*
* @constructor
*
* @todo - Implement caching mechanism for incomplete forms (via AppCache)
* @todo/@fixme - this error notification system needs serious refactor.
* TODO - Implement caching mechanism for incomplete forms (via AppCache)
* TODO/FIXME - this error notification system needs serious refactor.
*/
function ComplexJournalVoucherController(
Vouchers, Currencies, Session, FindEntity, FindReference, Notify, Toolkit, Receipts, bhConstants,
GridAggregators, uiGridConstants, VoucherForm, $timeout
Vouchers, $translate, Currencies, Session, FindEntity, FindReference, Notify,
Toolkit, Receipts, bhConstants, uiGridConstants, VoucherForm, $timeout
) {
var vm = this;

Expand Down Expand Up @@ -111,7 +112,7 @@ function ComplexJournalVoucherController(
* @param {object} result
*/
function updateView(result) {
$timeout(function () {
$timeout(function update() {
// transaction type
vm.Voucher.details.type_id = result.type_id || vm.Voucher.details.type_id;

Expand All @@ -132,7 +133,7 @@ function ComplexJournalVoucherController(
*/
function removeNullRows() {
var gridData = JSON.parse(JSON.stringify(vm.gridOptions.data));
gridData.forEach(function (item) {
gridData.forEach(function removeItems(item) {
if (!item.account_id) {
vm.Voucher.store.remove(item.uuid);
}
Expand Down Expand Up @@ -168,8 +169,8 @@ function ComplexJournalVoucherController(
/** Reference modal */
function openReferenceModal(row) {
FindReference.openModal(row.entity)
.then(function (document) {
row.configure({ document: document });
.then(function (doc) {
row.configure({ document: doc });
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="ui-grid-cell-contents"
ng-class="{'bg-info': row.entity.document.uuid}">
<div class="ui-grid-cell-contents" ng-class="{ 'bg-info': row.entity.document.uuid }">
<a class="text-action"
ng-click="grid.appScope.openReferenceModal(row.entity)"
data-reference-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ ConventionPaymentKitController.$inject = [
// Import transaction rows for a convention payment
function ConventionPaymentKitController(
Instance, DebtorGroup, Notify, Cashboxes,
Session, bhConstants, $translate, ToolKits) {
Session, bhConstants, $translate, ToolKits
) {
var vm = this;

var MAX_DECIMAL_PRECISION = bhConstants.precision.MAX_DECIMAL_PRECISION;
Expand Down

0 comments on commit 0bb06ac

Please sign in to comment.