Skip to content

Commit

Permalink
Showing 2 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -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
19 changes: 2 additions & 17 deletions server/controllers/finance/reports/monthlyBalance/index.js
Original file line number Diff line number Diff line change
@@ -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,40 +129,28 @@ 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;
}

// 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) {

0 comments on commit 9455a3d

Please sign in to comment.