diff --git a/server/controllers/finance/reports/generalLedger/index.js b/server/controllers/finance/reports/generalLedger/index.js
index 294c3686ca..1462983284 100644
--- a/server/controllers/finance/reports/generalLedger/index.js
+++ b/server/controllers/finance/reports/generalLedger/index.js
@@ -9,6 +9,7 @@
const _ = require('lodash');
const ReportManager = require('../../../../lib/ReportManager');
const GeneralLedger = require('../../generalLedger');
+const Tree = require('../../../../lib/Tree');
const REPORT_TEMPLATE = './server/controllers/finance/reports/generalLedger/report.handlebars';
@@ -41,12 +42,29 @@ function renderReport(req, res, next) {
const TITLE_ACCOUNT_ID = 6;
return GeneralLedger.getAccountTotalsMatrix(fiscalYearId)
- .then((rows) => {
- rows.forEach(row => {
- row.isTitleAccount = row.type_id === TITLE_ACCOUNT_ID;
- row.padLeft = row.depth * 15;
+ .then(rows => {
+ const tree = new Tree(rows);
+
+ tree.walk((node, parentNode) => {
+ Tree.common.computeNodeDepth(node, parentNode);
+
+ node.isTitleAccount = node.type_id === TITLE_ACCOUNT_ID;
+ node.padLeft = node.depth * 15;
});
- data = { rows };
+
+ const keys = _.keys(rows[0])
+ .filter(name => name.includes('balance'));
+
+ const root = tree.getRootNode();
+ const balances = root.children.reduce((aggregates, node) => {
+ keys.forEach(key => {
+ aggregates[key] = (aggregates[key] || 0) + node[key];
+ });
+
+ return aggregates;
+ }, {});
+
+ data = { rows : tree.toArray(), footer : balances };
data.fiscal_year_label = options.fiscal_year_label;
return report.render(data);
})
diff --git a/server/controllers/finance/reports/generalLedger/report.handlebars b/server/controllers/finance/reports/generalLedger/report.handlebars
index a43fa25b82..77b4528721 100644
--- a/server/controllers/finance/reports/generalLedger/report.handlebars
+++ b/server/controllers/finance/reports/generalLedger/report.handlebars
@@ -40,77 +40,96 @@
{{number}} |
{{label}} |
- {{currency balance ../metadata.enterprise.currency_id}} |
+ {{debcred balance ../metadata.enterprise.currency_id}} |
{{#if balance0}}
- {{currency balance0 ../metadata.enterprise.currency_id}}
+ {{debcred balance0 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance1}}
- {{currency balance1 ../metadata.enterprise.currency_id}}
+ {{debcred balance1 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance2}}
- {{currency balance2 ../metadata.enterprise.currency_id}}
+ {{debcred balance2 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance3}}
- {{currency balance3 ../metadata.enterprise.currency_id}}
+ {{debcred balance3 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance4}}
- {{currency balance4 ../metadata.enterprise.currency_id}}
+ {{debcred balance4 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance5}}
- {{currency balance5 ../metadata.enterprise.currency_id}}
+ {{debcred balance5 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance6}}
- {{currency balance6 ../metadata.enterprise.currency_id}}
+ {{debcred balance6 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance7}}
- {{currency balance7 ../metadata.enterprise.currency_id}}
+ {{debcred balance7 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance8}}
- {{currency balance8 ../metadata.enterprise.currency_id}}
+ {{debcred balance8 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance9}}
- {{currency balance9 ../metadata.enterprise.currency_id}}
+ {{debcred balance9 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance10}}
- {{currency balance10 ../metadata.enterprise.currency_id}}
+ {{debcred balance10 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance11}}
- {{currency balance11 ../metadata.enterprise.currency_id}}
+ {{debcred balance11 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{#if balance12}}
- {{currency balance12 ../metadata.enterprise.currency_id}}
+ {{debcred balance12 ../metadata.enterprise.currency_id}}
{{/if}}
|
{{else}}
- {{> emptyTable columns=4}}
+ {{> emptyTable columns=16}}
{{/each}}
+