From 9455a3d38e6e4c18feccbb20f388f59913ad7b5f Mon Sep 17 00:00:00 2001 From: Chris Lomame Date: Sun, 21 Jul 2019 09:36:14 +0100 Subject: [PATCH] Sanitaze code --- .../monthlyBalanceAnalysis.config.js | 13 +++---------- .../finance/reports/monthlyBalance/index.js | 19 ++----------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/client/src/modules/reports/generate/monthlyBalanceAnalysis/monthlyBalanceAnalysis.config.js b/client/src/modules/reports/generate/monthlyBalanceAnalysis/monthlyBalanceAnalysis.config.js index c8a53db4b1..91d022357c 100644 --- a/client/src/modules/reports/generate/monthlyBalanceAnalysis/monthlyBalanceAnalysis.config.js +++ b/client/src/modules/reports/generate/monthlyBalanceAnalysis/monthlyBalanceAnalysis.config.js @@ -16,9 +16,9 @@ function MonthlyBalanceAnalysisController($sce, Notify, SavedReports, AppCache, Accounts.read() .then(elements => { // bind the accounts to the controller - let accounts = Accounts.order(elements); + const accounts = Accounts.order(elements); vm.accounts = accounts; - }); + }); vm.onSelectFiscalYear = (fiscalYear) => { vm.reportDetails.fiscal_id = fiscalYear.id; @@ -34,13 +34,6 @@ function MonthlyBalanceAnalysisController($sce, Notify, SavedReports, AppCache, vm.previewResult = null; }; - vm.resetAnalysis = () => { - if (!vm.reportDetails.monthlyAnalysis) { - vm.reportDetails = {}; - vm.reportDetails.fiscal_id = null; - } - } - vm.preview = function preview(form) { if (form.$invalid) { Notify.danger('FORM.ERRORS.RECORD_ERROR'); @@ -56,7 +49,7 @@ function MonthlyBalanceAnalysisController($sce, Notify, SavedReports, AppCache, if (vm.reportDetails.allAccount) { vm.reportDetails.accountNumber = null; vm.reportDetails.accountLabel = null; - vm.reportDetails.accountId = null; + vm.reportDetails.accountId = null; } // update cached configuration diff --git a/server/controllers/finance/reports/monthlyBalance/index.js b/server/controllers/finance/reports/monthlyBalance/index.js index d4551c6cee..297eacaa55 100644 --- a/server/controllers/finance/reports/monthlyBalance/index.js +++ b/server/controllers/finance/reports/monthlyBalance/index.js @@ -1,7 +1,6 @@ const q = require('q'); const _ = require('lodash'); -const Exchange = require('../../../finance/exchange'); const db = require('../../../../lib/db'); const util = require('../../../../lib/util'); const Tree = require('../../../../lib/Tree'); @@ -53,14 +52,12 @@ function reporting(opts, session) { return fiscal.getDateRangeFromPeriods(periods).then(dateRange => { range = dateRange; - const sqlParams = [ params.fiscal_id, params.period_id, ]; let filterByAccount; - if (accountNumber) { filterByAccount = selectAccountParent(accountNumber); } else { @@ -132,19 +129,15 @@ function selectAccountParent(account) { if (accountArray.length) { let accountFilter = ``; - - if (accountArray.length > 1) { for (let i = 0; i < accountArray.length; i++) { accountFilter += `${accountArray[i]}`; - let conditionOr = (i < (accountArray.length - 1)) ? `OR` : ``; + const conditionOr = (i < (accountArray.length - 1)) ? `OR` : ``; sqlFilter += `ac.number = '${accountFilter}' ${conditionOr} `; } - sqlFilter = `OR (${sqlFilter})`; } - - sqlFilter = ` AND (ac.number LIKE '${account}%' ${sqlFilter})`; + sqlFilter = ` AND (ac.number LIKE '${account}%' ${sqlFilter})`; } return sqlFilter; @@ -152,20 +145,12 @@ function selectAccountParent(account) { // create the tree structure, filter by property and sum nodes' summableProp function prepareTree(data, amount, debit, credit) { - // if the after result is 0, that means no movements occurred - const isEmptyRow = (row) => ( - row.before === 0 - && row.during === 0 - && row.after === 0 - ); - const tree = new Tree(data); try { tree.walk(Tree.common.sumOnProperty(amount), false); tree.walk(Tree.common.sumOnProperty(debit), false); tree.walk(Tree.common.sumOnProperty(credit), false); - tree.walk(Tree.common.computeNodeDepth); return tree.toArray(); } catch (error) {