diff --git a/client/src/js/services/TrialBalanceService.js b/client/src/js/services/TrialBalanceService.js index bd8a141551..04ed31e93e 100644 --- a/client/src/js/services/TrialBalanceService.js +++ b/client/src/js/services/TrialBalanceService.js @@ -135,13 +135,12 @@ function TrialBalanceService(util, $http, $translate) { * * This function is called only when every test are passed without a fatal error **/ - function postToGeneralLedger (records) { - + function postToGeneralLedger(records) { var transactions = getTransactionList(records); var url = baseUrl.concat('post_transactions/'); /** posting a list of transactions to the server to be stored to the general ledger **/ - return $http.post(url, {transactions : transactions}); + return $http.post(url, { transactions : transactions }); } /** diff --git a/client/src/partials/journal/journal.routes.js b/client/src/partials/journal/journal.routes.js index 9559aeda17..01f78bc26a 100644 --- a/client/src/partials/journal/journal.routes.js +++ b/client/src/partials/journal/journal.routes.js @@ -3,35 +3,32 @@ angular.module('bhima.routes') $stateProvider .state('journal', { - url : '/journal', - controller : 'JournalController as JournalCtrl', + url : '/journal', + controller : 'JournalController as JournalCtrl', templateUrl : 'partials/journal/journal.html' }) .state('journalPrint', { - controller : 'journal.print', + controller : 'journal.print', templateUrl : 'partials/journal/print.html' }) .state('journalVoucher', { - controller: 'JournalVoucherController as JournalVoucherCtrl', - templateUrl: 'partials/journal/voucher/voucher.html' + controller : 'JournalVoucherController as JournalVoucherCtrl', + templateUrl : 'partials/journal/voucher/voucher.html' }) .state('journalModal', { - parent : 'journal', + parent : 'journal', onEnter : ['$state', '$uibModal', function ($state, Modal) { Modal.open({ size : 'lg', templateUrl : 'partials/journal/modals/trialBalanceStructure.html' - }).result.then(function () { - // go to the parent state (with refresh) - $state.go('journal', null, { reload : true }); - }) - .catch(function () { - $state.go('journal', null, { notify: false }); + }).result + .then(function () { + $state.go('journal', null, { reload: true }); }); }], onExit : ['$uibModalStack', function (ModalStack) { ModalStack.dismissAll(); - }] + }], }) .state('trialBalanceMain',{ parent : 'journalModal', diff --git a/client/src/partials/journal/modals/trialBalanceMain.body.js b/client/src/partials/journal/modals/trialBalanceMain.body.js index 3c573e427a..157c9beff9 100644 --- a/client/src/partials/journal/modals/trialBalanceMain.body.js +++ b/client/src/partials/journal/modals/trialBalanceMain.body.js @@ -3,7 +3,7 @@ angular.module('bhima.controllers') TrialBalanceMainBodyController.$inject = [ 'SessionService', 'TrialBalanceService', 'GridGroupingService', 'GridColumnService', - 'NotifyService', '$state', '$timeout', 'uiGridConstants' + 'NotifyService', '$state', '$timeout', 'uiGridConstants', ]; /** @@ -58,11 +58,11 @@ function TrialBalanceMainBodyController(Session, trialBalanceService, Grouping, }; vm.gridOptions = { - enableColumnMenus: false, - treeRowHeaderAlwaysVisible: false, - appScopeProvider: vm, - columnDefs : columns, - onRegisterApi: function(gridApi){ vm.gridApi = gridApi;} + enableColumnMenus : false, + treeRowHeaderAlwaysVisible : false, + appScopeProvider : vm, + columnDefs : columns, + onRegisterApi : function(gridApi) { vm.gridApi = gridApi;} }; vm.grouping = new Grouping(vm.gridOptions, false); @@ -75,7 +75,7 @@ function TrialBalanceMainBodyController(Session, trialBalanceService, Grouping, * This function fetch data by account from the server * through the trial balance service module **/ - function fetchDataByAccount(){ + function fetchDataByAccount() { return trialBalanceService.getDataByAccount(vm.dataByTrans); } @@ -184,19 +184,20 @@ function TrialBalanceMainBodyController(Session, trialBalanceService, Grouping, * The target view is not the main view, because you can not post to the general ledger from this view, * you have to reset the view to the main view first, this view is just giving complementary information to the user. **/ - function viewErrorList () { + function viewErrorList() { var lines = trialBalanceService.parseErrorRecord(errorList); - //FIX ME : what is the good way of keeping records? using appcache? - $state.go('trialBalanceErrors', {lines : lines, feedBack : vm.feedBack, records : records}, {reload : false}); + // FIX ME : what is the good way of keeping records? using appcache? + $state.go('trialBalanceErrors', { lines: lines, feedBack: vm.feedBack, records: records }, { reload: false }); } /** - * @function switchView + * @function switchView * @description - * This method can change the way data are filled in the grid, from transaction grouping to account grouping vice versa - **/ - function switchView (){ + * This method can change the way data are filled in the grid, from + * transaction grouping to account grouping vice versa + */ + function switchView() { var newView = trialBalanceService.switchView(vm.viewDetail.selected); vm.viewDetail[newView](); } @@ -219,12 +220,14 @@ function TrialBalanceMainBodyController(Session, trialBalanceService, Grouping, vm.feedBack = trialBalanceService.getFeedBack(errorList); //getting a feedback object to customize the grid vm.isInvalid = vm.feedBack.hasError || vm.feedBack.hasWarning; cssClass = trialBalanceService.getCSSClass(vm.feedBack); + $state.current.data.checkingData = {errors : errorList, feedBack : vm.feedBack, cssClass : cssClass}; $state.current.data.checked = true; columns.forEach(function (col) { col.headerCellClass = cssClass; }); + vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN); }) .catch(errorHandler) diff --git a/client/src/partials/journal/modals/trialBalanceMain.footer.js b/client/src/partials/journal/modals/trialBalanceMain.footer.js index 3adc1546f2..79ffafddb3 100644 --- a/client/src/partials/journal/modals/trialBalanceMain.footer.js +++ b/client/src/partials/journal/modals/trialBalanceMain.footer.js @@ -1,9 +1,8 @@ - angular.module('bhima.controllers') .controller('TrialBalanceMainFooterController', TrialBalanceMainFooterController); TrialBalanceMainFooterController.$inject = [ - '$state', 'TrialBalanceService', 'NotifyService' + '$state', 'TrialBalanceService', 'NotifyService', ]; /** @@ -14,7 +13,6 @@ TrialBalanceMainFooterController.$inject = [ */ function TrialBalanceMainFooterController($state, trialBalanceService, Notify) { var vm = this; - vm.state = $state; /** @@ -23,7 +21,7 @@ function TrialBalanceMainFooterController($state, trialBalanceService, Notify) { * closes the modal and stop the posting process **/ function cancel() { - $state.transitionTo('journal'); + $state.go('journal'); } /** @@ -33,7 +31,7 @@ function TrialBalanceMainFooterController($state, trialBalanceService, Notify) { function submit() { trialBalanceService.postToGeneralLedger($state.params.records) .then(function () { - $state.go('generalLedger', null, {reload : true}); + $state.go('generalLedger'); }) .catch(Notify.handleError); } diff --git a/server/controllers/finance/trialBalance/index.js b/server/controllers/finance/trialBalance/index.js index 735a019817..8f480ea032 100644 --- a/server/controllers/finance/trialBalance/index.js +++ b/server/controllers/finance/trialBalance/index.js @@ -1,4 +1,3 @@ - /** * The trial balance provides a description of what the general * ledger would look like after posting data from the @@ -6,26 +5,23 @@ * It also submit errors back to the client. */ const q = require('q'); -const uuid = require('node-uuid'); const _ = require('lodash'); const db = require('../../../lib/db'); -const util = require('../../../lib/util'); -const NotFound = require('../../../lib/errors/NotFound'); const BadRequest = require('../../../lib/errors/BadRequest'); // creates an error report for a given code function createErrorReport(code, isFatal, rows) { return { - code : code, - fatal : isFatal, - transactions : rows.map((row) => row.trans_id), - affectedRows : _.sumBy(rows, 'count') + code, + fatal : isFatal, + transactions : rows.map(row => row.trans_id), + affectedRows : _.sumBy(rows, 'count'), }; } // make sure that a entity_uuid exists for each deb_cred_type function checkDescriptionExists(transactions) { - let sql = + const sql = `SELECT COUNT(pj.uuid) AS count, pj.trans_id, pj.description FROM posting_journal AS pj WHERE pj.trans_id IN (?) GROUP BY trans_id HAVING pj.description IS NULL;`; @@ -41,7 +37,7 @@ function checkDescriptionExists(transactions) { // make sure that the record Id exist in each line of the transaction function checkRecordUuidExists(transactions) { - let sql = + const sql = `SELECT COUNT(pj.uuid) AS count, pj.record_uuid, pj.trans_id FROM posting_journal AS pj WHERE pj.trans_id IN (?) GROUP BY pj.trans_id HAVING pj.record_uuid IS NULL;`; @@ -57,7 +53,7 @@ function checkRecordUuidExists(transactions) { // make sure dates are in their correct period function checkDateInPeriod(transactions) { - let sql = + const sql = `SELECT COUNT(pj.uuid) AS count, pj.trans_id, pj.trans_date, p.start_date, p.end_date FROM posting_journal AS pj JOIN period as p ON pj.period_id = p.id WHERE DATE(pj.trans_date) NOT BETWEEN DATE(p.start_date) AND DATE(p.end_date) AND @@ -76,7 +72,7 @@ function checkDateInPeriod(transactions) { // make sure fiscal years and periods exist for all transactions function checkPeriodAndFiscalYearExists(transactions) { - let sql = + const sql = `SELECT COUNT(pj.uuid) AS count, pj.trans_id FROM posting_journal AS pj WHERE pj.trans_id IN (?) AND (pj.period_id IS NULL OR pj.fiscal_year_id IS NULL) @@ -94,7 +90,7 @@ function checkPeriodAndFiscalYearExists(transactions) { // make sure there are no missing accounts in the transactions function checkMissingAccounts(transactions) { - let sql = + const sql = `SELECT COUNT(pj.uuid) AS count, pj.trans_id FROM posting_journal AS pj LEFT JOIN account ON pj.account_id = account.id @@ -113,7 +109,7 @@ function checkMissingAccounts(transactions) { // Ensure no accounts are locked in the transactions function checkAccountsLocked(transactions) { - let sql = + const sql = `SELECT COUNT(pj.uuid) AS count, pj.trans_id FROM posting_journal AS pj LEFT JOIN account ON pj.account_id = account.id @@ -132,7 +128,7 @@ function checkAccountsLocked(transactions) { // make sure the debit_equiv, credit_equiv are balanced function checkTransactionsBalanced(transactions) { - let sql = ` + const sql = ` SELECT COUNT(pj.uuid) AS count, pj.trans_id, SUM(pj.debit_equiv - pj.credit_equiv) AS balance FROM posting_journal AS pj WHERE pj.trans_id IN (?) @@ -149,9 +145,9 @@ function checkTransactionsBalanced(transactions) { }); } -//Check if there is no transaction with one line to avoid single line with ero in debit and credit which is valuable -function checkSingleLineTransaction (transactions){ - let sql = +// Check if there is no transaction with one line to avoid single line with ero in debit and credit which is valuable +function checkSingleLineTransaction(transactions) { + const sql = `SELECT COUNT(pj.uuid) AS count, pj.trans_id FROM posting_journal AS pj WHERE pj.trans_id IN (?) GROUP BY trans_id HAVING count = 1;`; @@ -167,10 +163,10 @@ function checkSingleLineTransaction (transactions){ } exports.getDataPerAccount = function (req, res, next) { - let transactions = req.body.transactions; + const transactions = req.body.transactions; // @FIXME This could use a lot of comments - let requestString = + const requestString = `SELECT pt.debit_equiv, pt.credit_equiv, pt.account_id, pt.balance_before, account.number AS account_number, (pt.balance_before + (pt.debit_equiv - pt.credit_equiv)) as balance_final @@ -222,7 +218,7 @@ exports.getDataPerAccount = function (req, res, next) { * }] **/ exports.checkTransactions = function (req, res, next) { - let transactions = req.body.transactions; + const transactions = req.body.transactions; if (!transactions) { return next(new BadRequest('The transaction list is null or undefined')); @@ -235,10 +231,10 @@ exports.checkTransactions = function (req, res, next) { return q.all([ checkSingleLineTransaction(transactions), checkTransactionsBalanced(transactions), checkAccountsLocked(transactions), checkMissingAccounts(transactions), checkPeriodAndFiscalYearExists(transactions), checkDateInPeriod(transactions), - checkRecordUuidExists(transactions), checkDescriptionExists(transactions) + checkRecordUuidExists(transactions), checkDescriptionExists(transactions), ]) - .then(function (errorReports){ - let errors = errorReports.filter(function (errorReport) { + .then(function (errorReports) { + const errors = errorReports.filter(function (errorReport) { return errorReport; }); res.status(201).json(errors); @@ -253,15 +249,15 @@ exports.checkTransactions = function (req, res, next) { * It posts data to the general ledger. **/ exports.postToGeneralLedger = function (req, res, next) { - let transaction = db.transaction(); - let transactions = req.body.transactions; + const transaction = db.transaction(); + const transactions = req.body.transactions; if (!transactions || !Array.isArray(transactions)) { return next(new BadRequest('The transaction list is null or undefined otherwise The query is bad formatted')); } - //Just a workaround because mysql does not have a type for array - let transactionString = + // Just a workaround because mysql does not have a type for array + const transactionString = transactions.map((trans_id) => `"${trans_id}"`).join(','); transaction.addQuery('CALL postToGeneralLedger(?)', [transactionString]);