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 @@
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);
}
}