From b9cec59a022db1d76fb6e3da1e0a5af0bae65417 Mon Sep 17 00:00:00 2001 From: mbayopanda Date: Fri, 14 Jun 2019 10:34:03 +0100 Subject: [PATCH] balance report by email and use of async await --- .../controllers/finance/reports/balance/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/server/controllers/finance/reports/balance/index.js b/server/controllers/finance/reports/balance/index.js index 567642bfb5..7517cace0a 100644 --- a/server/controllers/finance/reports/balance/index.js +++ b/server/controllers/finance/reports/balance/index.js @@ -51,22 +51,24 @@ async function reporting(options, session) { context.shouldHideTitleAccounts = Number.parseInt(params.shouldHideTitleAccounts, 10); context.includeClosingBalances = Number.parseInt(params.includeClosingBalances, 10); + const report = new ReportManager(TEMPLATE, session, params); const currencyId = session.enterprise.currency_id; const period = await getPeriodFromParams(params.fiscal_id, params.period_id, context.includeClosingBalances); _.merge(context, { period }); - const { accounts, totals } = await getBalanceForFiscalYear(period, currencyId); - _.merge(context, { accounts, totals }); + const balance = await getBalanceForFiscalYear(period, currencyId); + context.accounts = balance.accounts; + context.totals = balance.totals; - const tree = await computeBalanceTree(accounts, totals, context, context.shouldPruneEmptyRows); - _.merge(context, { accounts : tree.accounts, totals : tree.totals }); + const tree = await computeBalanceTree(balance.accounts, balance.totals, context, context.shouldPruneEmptyRows); + context.accounts = tree.accounts; + context.totals = tree.totals; if (context.shouldHideTitleAccounts) { - context.accounts = accounts.filter(account => account.isTitleAccount === 0); + context.accounts = context.accounts.filter(account => account.isTitleAccount === 0); } - const report = new ReportManager(TEMPLATE, session, params); return report.render(context); } catch (error) { throw error;