From 83216f4e363f03482f33a0c67186821e9edf9257 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Thu, 8 Feb 2018 16:21:15 +0100 Subject: [PATCH] chore(fiscal): polish user interface This commit polishes the user interface and updates the code to the latest ESLint checks in the client. The most significant changes are: 1. Title accounts are highlighted on the opening/closing balance grids. 2. Performance increases on the UI-grids via template optimisations and fastWatch. 3. The "Close Fiscal Year" button is hidden if a Fiscal Year is closed. 4. Removes aggregation labels from footers. Partially addresses #2490. References #715. --- .../templates/grid.labelCell.tmpl.html | 5 +- .../modules/fiscal/fiscal.closingBalance.js | 97 ++++++------ client/src/modules/fiscal/fiscal.manage.html | 6 +- client/src/modules/fiscal/fiscal.manage.js | 102 ++++++------ .../modules/fiscal/fiscal.openingBalance.html | 5 +- .../modules/fiscal/fiscal.openingBalance.js | 132 ++++++++-------- .../templates/exploitation_type.tmpl.html | 11 +- .../templates/modals/fiscal.closing.modal.js | 149 +++++++++--------- 8 files changed, 249 insertions(+), 258 deletions(-) diff --git a/client/src/modules/accounts/templates/grid.labelCell.tmpl.html b/client/src/modules/accounts/templates/grid.labelCell.tmpl.html index b76a3c738e..43724d9d2a 100644 --- a/client/src/modules/accounts/templates/grid.labelCell.tmpl.html +++ b/client/src/modules/accounts/templates/grid.labelCell.tmpl.html @@ -1,5 +1,6 @@ -
- +
+ + {{grid.getCellValue(row, col)}}
diff --git a/client/src/modules/fiscal/fiscal.closingBalance.js b/client/src/modules/fiscal/fiscal.closingBalance.js index 5e7bb36f47..bf3232a60b 100644 --- a/client/src/modules/fiscal/fiscal.closingBalance.js +++ b/client/src/modules/fiscal/fiscal.closingBalance.js @@ -2,17 +2,16 @@ angular.module('bhima.controllers') .controller('FiscalClosingBalanceController', FiscalClosingBalanceController); FiscalClosingBalanceController.$inject = [ - '$state', 'AccountService', 'AccountStoreService', 'FiscalService', - 'NotifyService', 'util', 'moment', 'uiGridConstants', + '$state', 'AccountService', 'FiscalService', 'NotifyService', + 'uiGridConstants', 'bhConstants', ]; /** * This controller is responsible for handling the closing balance of a fiscal year. */ -function FiscalClosingBalanceController($state, Accounts, AccountStore, Fiscal, Notify, util, moment, uiGridConstants) { - var vm = this; - var columns; - var fiscalYearId = $state.params.id; +function FiscalClosingBalanceController($state, Accounts, Fiscal, Notify, uiGridConstants, bhConstants) { + const vm = this; + const fiscalYearId = $state.params.id; // expose to the view vm.showAccountFilter = false; @@ -22,42 +21,44 @@ function FiscalClosingBalanceController($state, Accounts, AccountStore, Fiscal, vm.indentTitleSpace = 20; vm.gridApi = {}; - columns = [ - { field : 'number', displayName : '', cellClass : 'text-right', width : 100 }, - { field : 'label', - displayName : 'FORM.LABELS.ACCOUNT', - cellTemplate : '/modules/accounts/templates/grid.labelCell.tmpl.html', - headerCellFilter : 'translate', - enableFiltering : true, - }, - { field : 'debit', - displayName : 'FORM.LABELS.DEBIT', - headerCellClass : 'text-center', - headerCellFilter : 'translate', - cellTemplate : '/modules/fiscal/templates/balance.debit.tmpl.html', - width : 200, - enableFiltering : false, - }, - { field : 'credit', - displayName : 'FORM.LABELS.CREDIT', - headerCellClass : 'text-center', - headerCellFilter : 'translate', - cellTemplate : '/modules/fiscal/templates/balance.credit.tmpl.html', - width : 200, - enableFiltering : false, - }, - ]; + const columns = [{ + field : 'number', + displayName : '', + cellClass : 'text-right', + width : 100, + }, { + field : 'label', + displayName : 'FORM.LABELS.ACCOUNT', + cellTemplate : '/modules/accounts/templates/grid.labelCell.tmpl.html', + headerCellFilter : 'translate', + enableFiltering : true, + }, { + field : 'debit', + displayName : 'FORM.LABELS.DEBIT', + headerCellClass : 'text-center', + headerCellFilter : 'translate', + cellTemplate : '/modules/fiscal/templates/balance.debit.tmpl.html', + width : 200, + enableFiltering : false, + }, { + field : 'credit', + displayName : 'FORM.LABELS.CREDIT', + headerCellClass : 'text-center', + headerCellFilter : 'translate', + cellTemplate : '/modules/fiscal/templates/balance.credit.tmpl.html', + width : 200, + enableFiltering : false, + }]; vm.gridOptions = { appScopeProvider : vm, fastWatch : true, flatEntityAccess : true, enableSorting : false, - enableFiltering : vm.showAccountFilter, enableColumnMenus : false, - rowTemplate : '/modules/accounts/templates/grid.titleRow.tmpl.html', + enableFiltering : vm.showAccountFilter, columnDefs : columns, - onRegisterApi : onRegisterApi, + onRegisterApi, }; // API register function @@ -67,13 +68,13 @@ function FiscalClosingBalanceController($state, Accounts, AccountStore, Fiscal, // get fiscal year Fiscal.read(fiscalYearId) - .then(function (fy) { - vm.fiscal = fy; - $state.params.label = vm.fiscal.label; - return fy.previous_fiscal_year_id; - }) - .then(loadPeriodicBalance) - .catch(Notify.handleError); + .then((fy) => { + vm.fiscal = fy; + $state.params.label = vm.fiscal.label; + return fy.previous_fiscal_year_id; + }) + .then(loadPeriodicBalance) + .catch(Notify.handleError); /** * loadPeriodicBalance @@ -84,11 +85,15 @@ function FiscalClosingBalanceController($state, Accounts, AccountStore, Fiscal, id : fiscalYearId, period_number : vm.fiscal.number_of_months + 1, }) - .then(function (list) { - vm.accounts = list; - vm.gridOptions.data = Accounts.order(vm.accounts); - }) - .catch(Notify.handleError); + .then((list) => { + list.forEach(account => { + account.isTitleAccount = account.type_id === bhConstants.accounts.TITLE; + }); + + vm.accounts = list; + vm.gridOptions.data = Accounts.order(vm.accounts); + }) + .catch(Notify.handleError); } /** diff --git a/client/src/modules/fiscal/fiscal.manage.html b/client/src/modules/fiscal/fiscal.manage.html index 5800fe7c8b..c043943f0e 100644 --- a/client/src/modules/fiscal/fiscal.manage.html +++ b/client/src/modules/fiscal/fiscal.manage.html @@ -1,7 +1,7 @@
-
+
FISCAL.NEW_FISCAL_YEAR
@@ -41,7 +41,7 @@
@@ -66,7 +66,7 @@

FORM.INFO.OTHER_ACTIONS

- + FORM.INFO.CLOSE_FISCAL_YEAR diff --git a/client/src/modules/fiscal/fiscal.manage.js b/client/src/modules/fiscal/fiscal.manage.js index e529b2f9cb..df3449ed2e 100644 --- a/client/src/modules/fiscal/fiscal.manage.js +++ b/client/src/modules/fiscal/fiscal.manage.js @@ -6,24 +6,22 @@ FiscalManagementController.$inject = [ ]; /** - * This controller is responsible for creating and updating a fiscal year. It provides - * utility functions for submission and error handling. + * This controller is responsible for creating and updating a fiscal year. It + * provides utility functions for submission and error handling. */ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment) { - var vm = this; - var id; - var isUpdate; + const vm = this; - // state variables + // state constiables vm.isUpdateState = $state.current.name === 'fiscal.update'; vm.isListState = $state.current.name === 'fiscal.list'; vm.isCreateState = $state.current.name === 'fiscal.create'; // identifier - id = $state.params.id; - isUpdate = (id && vm.isUpdateState); + const { id } = $state.params; + const isUpdate = (id && vm.isUpdateState); - // global variables + // global constiables vm.fiscal = {}; vm.state = $state; vm.submit = submit; @@ -33,42 +31,42 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment) // expose to the view vm.closingFiscalYear = closingFiscalYear; - /** - * @function init - * @description init data for the module - */ - function init() { + function startup() { if (id && vm.isUpdateState) { // concerned fiscal year Fiscal.read(id) - .then(function (fiscalYear) { - vm.fiscal = fiscalYear; - $state.params.label = vm.fiscal.label; - vm.fiscal.start_date = new Date(vm.fiscal.start_date); - vm.fiscal.end_date = new Date(vm.fiscal.end_date); - }) - .catch(Notify.handleError); + .then(fiscalYear => { + vm.fiscal = fiscalYear; + $state.params.label = vm.fiscal.label; + vm.fiscal.start_date = new Date(vm.fiscal.start_date); + vm.fiscal.end_date = new Date(vm.fiscal.end_date); + }) + .catch(Notify.handleError); } // previous fiscal year - Fiscal.read(null, { detailed: 1 }) - .then(function (previous) { - if (!previous.length) { return; } - - // remove the current fiscal year in the previous one list - if (id && vm.isUpdateState) { - previous = previous.filter((fiscYear) => { - return parseInt(fiscYear.id, 10) !== parseInt(id, 10); + Fiscal.read(null, { detailed : 1 }) + .then((previous) => { + if (!previous.length) { return; } + + let years = previous; + + // remove the current fiscal year in the previous one list + if (id && vm.isUpdateState) { + years = years.filter((fiscYear) => { + return parseInt(fiscYear.id, 10) !== parseInt(id, 10); + }); + } + + const fmt = (date) => moment(date).format('DD MMM YYYY'); + + vm.previous_fiscal_year = years.map(fy => { + fy.hrLabel = fy.label + .concat(`(${fmt(fy.start_date)} - ${fmt(fy.end_date)}`); + return fy; }); - } - vm.previous_fiscal_year = previous.map(function (fy) { - fy.hrLabel = fy.label - .concat(' (', moment(fy.start_date).format('DD MMM YYYY').toString(), ' - ') - .concat(moment(fy.end_date).format('DD MMM YYYY').toString(), ')'); - return fy; - }); - }) - .catch(Notify.handleError); + }) + .catch(Notify.handleError); } /** @@ -79,9 +77,9 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment) if (!vm.isUpdateState) { return; } Modal.openClosingFiscalYear(vm.fiscal) - .then(function (res) { + .then(res => { if (!res) { return; } - $state.go('fiscal.list', null, { reload: true }); + $state.go('fiscal.list', null, { reload : true }); }); } @@ -90,40 +88,38 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment) * @description get the number of months between two dates */ function numberOfMonths() { - if (!vm.fiscal) { return ; } - - var start_date = moment(vm.fiscal.start_date); - var end_date = moment(vm.fiscal.end_date); - vm.fiscal.number_of_months = Math.ceil(end_date.diff(start_date, 'months', true)); + if (!vm.fiscal) { return; } + const startDate = moment(vm.fiscal.start_date); + const endDate = moment(vm.fiscal.end_date); + vm.fiscal.number_of_months = Math.ceil(endDate.diff(startDate, 'months', true)); } /** * @method submit + * * @description submit the form */ function submit(form) { - - // ensure all Angular form validation checks have passed + // ensure all angular form validation checks have passed if (form.$invalid) { Notify.danger('FORM.ERRORS.RECORD_ERROR'); - return; + return 0; } // get the number of months numberOfMonths(); - var promise = isUpdate ? Fiscal.update(id, vm.fiscal) : Fiscal.create(vm.fiscal); + const promise = isUpdate ? Fiscal.update(id, vm.fiscal) : Fiscal.create(vm.fiscal); return promise - .then(function () { + .then(() => { Notify.success(isUpdate ? 'FORM.INFO.UPDATE_SUCCESS' : 'FORM.INFO.CREATE_SUCCESS'); // navigate back to list view - $state.go('fiscal.list', null, { reload: true }); + $state.go('fiscal.list', null, { reload : true }); }) .catch(Notify.handleError); } - // excecute - init(); + startup(); } diff --git a/client/src/modules/fiscal/fiscal.openingBalance.html b/client/src/modules/fiscal/fiscal.openingBalance.html index 181680a2e2..7d0094a1eb 100644 --- a/client/src/modules/fiscal/fiscal.openingBalance.html +++ b/client/src/modules/fiscal/fiscal.openingBalance.html @@ -1,8 +1,6 @@

- -
@@ -20,7 +18,6 @@ FORM.BUTTONS.EDIT
-
@@ -47,7 +44,7 @@
diff --git a/client/src/modules/fiscal/fiscal.openingBalance.js b/client/src/modules/fiscal/fiscal.openingBalance.js index 089cff1ece..044dd7cdc6 100644 --- a/client/src/modules/fiscal/fiscal.openingBalance.js +++ b/client/src/modules/fiscal/fiscal.openingBalance.js @@ -2,18 +2,16 @@ angular.module('bhima.controllers') .controller('FiscalOpeningBalanceController', FiscalOpeningBalanceController); FiscalOpeningBalanceController.$inject = [ - '$state', 'AccountService', 'AccountStoreService', 'FiscalService', - 'NotifyService', 'util', 'moment', 'uiGridConstants', 'SessionService', + '$state', 'AccountService', 'FiscalService', 'NotifyService', + 'uiGridConstants', 'SessionService', 'bhConstants', ]; /** * This controller is responsible for handling the opening balance of the new fiscal year. */ -function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, - Notify, util, moment, uiGridConstants, Session) { - var vm = this; - - var fiscalYearId = $state.params.id; +function FiscalOpeningBalanceController($state, Accounts, Fiscal, Notify, uiGridConstants, Session, bhConstants) { + const vm = this; + const fiscalYearId = $state.params.id; // expose to the view vm.enterprise = Session.enterprise; @@ -27,45 +25,47 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, vm.indentTitleSpace = 20; vm.gridApi = {}; - var columns = [ - { field : 'number', displayName : '', cellClass : 'text-right', width : 100 }, - { field : 'label', - displayName : 'FORM.LABELS.ACCOUNT', - cellTemplate : '/modules/accounts/templates/grid.labelCell.tmpl.html', - headerCellFilter : 'translate', - enableFiltering : true, - }, - { field : 'debit', - displayName : 'FORM.LABELS.DEBIT', - headerCellClass : 'text-center', - headerCellFilter : 'translate', - cellTemplate : '/modules/fiscal/templates/balance.debit.tmpl.html', - width : 200, - enableFiltering : false, - }, - { field : 'credit', - displayName : 'FORM.LABELS.CREDIT', - headerCellClass : 'text-center', - headerCellFilter : 'translate', - cellTemplate : '/modules/fiscal/templates/balance.credit.tmpl.html', - width : 200, - enableFiltering : false, - }, - ]; + const columns = [{ + field : 'number', + displayName : '', + cellClass : 'text-right', + width : 100, + }, { + field : 'label', + displayName : 'FORM.LABELS.ACCOUNT', + cellTemplate : '/modules/accounts/templates/grid.labelCell.tmpl.html', + headerCellFilter : 'translate', + enableFiltering : true, + }, { + field : 'debit', + displayName : 'FORM.LABELS.DEBIT', + headerCellClass : 'text-center', + headerCellFilter : 'translate', + cellTemplate : '/modules/fiscal/templates/balance.debit.tmpl.html', + width : 200, + enableFiltering : false, + }, { + field : 'credit', + displayName : 'FORM.LABELS.CREDIT', + headerCellClass : 'text-center', + headerCellFilter : 'translate', + cellTemplate : '/modules/fiscal/templates/balance.credit.tmpl.html', + width : 200, + enableFiltering : false, + }]; vm.gridOptions = { appScopeProvider : vm, + fastWatch : true, + flatEntityAccess : true, enableSorting : false, - enableFiltering : vm.showAccountFilter, - showTreeExpandNoChildren : false, enableColumnMenus : false, - rowTemplate : '/modules/accounts/templates/grid.titleRow.tmpl.html', + enableFiltering : vm.showAccountFilter, columnDefs : columns, - onRegisterApi : onRegisterApi, + onRegisterApi, }; - // init - init(); + startup(); // API register function function onRegisterApi(gridApi) { @@ -73,16 +73,16 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, } // load fiscal year and periodic balance - function init() { + function startup() { Fiscal.read(fiscalYearId) - .then(function (fy) { - vm.fiscal = fy; - $state.params.label = vm.fiscal.label; - return fy.previous_fiscal_year_id; - }) - .then(hasPrevious) - .then(loadPeriodicBalance) - .catch(Notify.handleError); + .then(fy => { + vm.fiscal = fy; + $state.params.label = vm.fiscal.label; + return fy.previous_fiscal_year_id; + }) + .then(hasPrevious) + .then(loadPeriodicBalance) + .catch(Notify.handleError); } // load periodic balance @@ -91,11 +91,16 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, id : fiscalYearId, period_number : 0, }) - .then(function (list) { - vm.accounts = list; - vm.balanced = hasBalancedAccount(); - vm.gridOptions.data = Accounts.order(vm.accounts); - }); + .then(list => { + vm.accounts = list; + vm.balanced = hasBalancedAccount(); + + vm.accounts.forEach(account => { + account.isTitleAccount = account.type_id === bhConstants.accounts.TITLE; + }); + + vm.gridOptions.data = Accounts.order(vm.accounts); + }); } /** @@ -116,11 +121,11 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, fiscal : vm.fiscal, accounts : vm.accounts, }) - .then(function () { - Notify.success(vm.previousFiscalYearExist ? 'FORM.INFO.IMPORT_SUCCESS' : 'FORM.INFO.SAVE_SUCCESS'); - init(); - }) - .catch(Notify.handleError); + .then(() => { + Notify.success(vm.previousFiscalYearExist ? 'FORM.INFO.IMPORT_SUCCESS' : 'FORM.INFO.SAVE_SUCCESS'); + startup(); + }) + .catch(Notify.handleError); } /** @@ -146,7 +151,7 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, * @description check if accounts are balanced */ function hasBalancedAccount() { - var cleanAccounts = vm.accounts.filter(function (item) { + const cleanAccounts = vm.accounts.filter(item => { return (item.debit !== 0 || item.credit !== 0); }); vm.totalDebit = sumOf(cleanAccounts, 'debit').toFixed(2); @@ -160,11 +165,10 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, */ function hasPrevious(previousFiscalYearId) { if (!previousFiscalYearId) { return false; } - return Fiscal.read(previousFiscalYearId) - .then(function (fy) { - vm.previousFiscalYearExist = !!fy.id; - }); + .then(fiscalYear => { + vm.previousFiscalYearExist = !!fiscalYear.id; + }); } /** @@ -174,8 +178,6 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal, * @param {string} property The property for the summation */ function sumOf(array, property) { - return array.reduce(function (a, b) { - return a + b[property]; - }, 0); + return array.reduce((a, b) => a + b[property], 0); } } diff --git a/client/src/modules/fiscal/templates/exploitation_type.tmpl.html b/client/src/modules/fiscal/templates/exploitation_type.tmpl.html index de55b6ef8a..0bb7e58a81 100644 --- a/client/src/modules/fiscal/templates/exploitation_type.tmpl.html +++ b/client/src/modules/fiscal/templates/exploitation_type.tmpl.html @@ -1,8 +1,3 @@ -
- - - - - - -
\ No newline at end of file +
+ +
diff --git a/client/src/modules/fiscal/templates/modals/fiscal.closing.modal.js b/client/src/modules/fiscal/templates/modals/fiscal.closing.modal.js index 8d39c56edc..995d2c2f7c 100644 --- a/client/src/modules/fiscal/templates/modals/fiscal.closing.modal.js +++ b/client/src/modules/fiscal/templates/modals/fiscal.closing.modal.js @@ -9,12 +9,10 @@ ClosingFiscalYearModalController.$inject = [ ]; // The closing fiscal year controller -function ClosingFiscalYearModalController(Notify, Fiscal, Modal, - Session, Instance, Data, uiGridGroupingConstants) { - var vm = this; - var columns; +function ClosingFiscalYearModalController(Notify, Fiscal, Modal, Session, Instance, Data, uiGridGroupingConstants) { + const vm = this; - // global variables + // global vm.currency_id = Session.enterprise.currency_id; // expose to the view @@ -23,32 +21,33 @@ function ClosingFiscalYearModalController(Notify, Fiscal, Modal, vm.onSelectAccount = onSelectAccount; // exploitation grid - columns = [ - { field : 'type', - displayName : '', - cellTemplate : 'modules/fiscal/templates/exploitation_type.tmpl.html', - width : 25, - }, - { field : 'number', - displayName : 'ACCOUNT.NUMBER', - headerCellFilter : 'translate', - treeAggregationType : uiGridGroupingConstants.aggregation.COUNT, - }, - { field : 'label', - displayName : 'TABLE.COLUMNS.ACCOUNT', - headerCellFilter : 'translate', - }, - { field : 'debit', - displayName : 'TABLE.COLUMNS.DEBIT', - headerCellFilter : 'translate', - treeAggregationType : uiGridGroupingConstants.aggregation.SUM, - }, - { field : 'credit', - displayName : 'TABLE.COLUMNS.CREDIT', - headerCellFilter : 'translate', - treeAggregationType : uiGridGroupingConstants.aggregation.SUM, - }, - ]; + const columns = [{ + field : 'type', + displayName : '', + cellTemplate : 'modules/fiscal/templates/exploitation_type.tmpl.html', + width : 25, + }, { + field : 'number', + displayName : 'ACCOUNT.NUMBER', + headerCellFilter : 'translate', + }, { + field : 'label', + displayName : 'TABLE.COLUMNS.ACCOUNT', + headerCellFilter : 'translate', + }, { + field : 'debit', + displayName : 'TABLE.COLUMNS.DEBIT', + headerCellFilter : 'translate', + treeAggregationType : uiGridGroupingConstants.aggregation.SUM, + aggregationHideLabel : true, + }, { + field : 'credit', + displayName : 'TABLE.COLUMNS.CREDIT', + headerCellFilter : 'translate', + treeAggregationType : uiGridGroupingConstants.aggregation.SUM, + aggregationHideLabel : true, + }]; + vm.gridOptions = { columnDefs : columns, enableColumnMenus : false, @@ -63,35 +62,35 @@ function ClosingFiscalYearModalController(Notify, Fiscal, Modal, } Fiscal.read(Data.id) - .then(function (fiscal) { - vm.fiscal = fiscal; - - // get balance until period N of the year to close - return Fiscal.periodicBalance({ - id : vm.fiscal.id, - period_number : vm.fiscal.number_of_months, // last month - }); - }) - .then(function (balance) { - var profit = balance.filter(getProfitAccount); - var charge = balance.filter(getExpenseAccount); - - vm.gridOptions.data = profit.concat(charge); - vm.profit = creditorSold(profit); - vm.charge = debitorSold(charge); - vm.globalResult = vm.profit - vm.charge; - }) - .catch(Notify.handleError); + .then(fiscal => { + vm.fiscal = fiscal; + + // get balance until period N of the year to close + return Fiscal.periodicBalance({ + id : vm.fiscal.id, + period_number : vm.fiscal.number_of_months, // last month + }); + }) + .then(balance => { + const profit = balance.filter(getProfitAccount); + const charge = balance.filter(getExpenseAccount); + + vm.gridOptions.data = profit.concat(charge); + vm.profit = creditorSold(profit); + vm.charge = debitorSold(charge); + vm.globalResult = vm.profit - vm.charge; + }) + .catch(Notify.handleError); // get profit account function getProfitAccount(account) { - var nullBalance = account.debit === account.credit && account.credit === 0; + const nullBalance = account.debit === account.credit && account.credit === 0; return account.type === 'revenue' && !nullBalance; } // get expense account function getExpenseAccount(account) { - var nullBalance = account.debit === account.credit && account.credit === 0; + const nullBalance = account.debit === account.credit && account.credit === 0; return account.type === 'expense' && !nullBalance; } @@ -108,42 +107,38 @@ function ClosingFiscalYearModalController(Notify, Fiscal, Modal, // confirm closing function confirmClosing() { - var request = { + const request = { pattern : vm.fiscal.label, patternName : 'FORM.PATTERNS.FISCAL_YEAR_NAME', }; return Modal.openConfirmDialog(request) - .then(function (ans) { - if (!ans) { return; } - - return Fiscal.closing({ - id : vm.fiscal.id, - account_id : vm.resultAccount.id, + .then(ans => { + if (!ans) { return 0; } + + return Fiscal.closing({ + id : vm.fiscal.id, + account_id : vm.resultAccount.id, + }); + }) + .then(res => { + if (!res) { return; } + + Instance.close(true); + Notify.success('FISCAL.CLOSING_SUCCESS'); + }) + .catch(err => { + Instance.close(false); + Notify.handleError(err); }); - }) - .then(function (res) { - if (!res) { return; } - - Instance.close(true); - Notify.success('FISCAL.CLOSING_SUCCESS'); - }) - .catch(function (err) { - Instance.close(false); - Notify.handleError(err); - }); } - // utilities + // utility fns function debitorSold(array) { - return array.reduce(function (a, b) { - return (a + b.debit) - b.credit; - }, 0); + return array.reduce((a, b) => (a + b.debit) - b.credit, 0); } function creditorSold(array) { - return array.reduce(function (a, b) { - return (a + b.credit) - b.debit; - }, 0); + return array.reduce((a, b) => (a + b.credit) - b.debit, 0); } }