Skip to content

Commit

Permalink
feat(General Ledger): add totals on PDF printout
Browse files Browse the repository at this point in the history
This commit adds totals to the PDF print out, as well as ensuring that
the depth is correctly computed.  Due to API changes with the tree
library, the depth was removed - this restores the calculation.
  • Loading branch information
jniles committed Mar 2, 2018
1 parent 88adc5e commit c72386b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 21 deletions.
28 changes: 23 additions & 5 deletions server/controllers/finance/reports/generalLedger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
})
Expand Down
49 changes: 34 additions & 15 deletions server/controllers/finance/reports/generalLedger/report.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -40,77 +40,96 @@
<tr {{#if isTitleAccount}}style="font-weight:bold;"{{/if}}>
<td>{{number}}</td>
<td style="padding-left: {{padLeft}}px;">{{label}}</td>
<td class="text-right">{{currency balance ../metadata.enterprise.currency_id}}</td>
<td class="text-right">{{debcred balance ../metadata.enterprise.currency_id}}</td>
<td class="text-right">
{{#if balance0}}
{{currency balance0 ../metadata.enterprise.currency_id}}
{{debcred balance0 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance1}}
{{currency balance1 ../metadata.enterprise.currency_id}}
{{debcred balance1 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance2}}
{{currency balance2 ../metadata.enterprise.currency_id}}
{{debcred balance2 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance3}}
{{currency balance3 ../metadata.enterprise.currency_id}}
{{debcred balance3 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance4}}
{{currency balance4 ../metadata.enterprise.currency_id}}
{{debcred balance4 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance5}}
{{currency balance5 ../metadata.enterprise.currency_id}}
{{debcred balance5 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance6}}
{{currency balance6 ../metadata.enterprise.currency_id}}
{{debcred balance6 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance7}}
{{currency balance7 ../metadata.enterprise.currency_id}}
{{debcred balance7 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance8}}
{{currency balance8 ../metadata.enterprise.currency_id}}
{{debcred balance8 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance9}}
{{currency balance9 ../metadata.enterprise.currency_id}}
{{debcred balance9 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance10}}
{{currency balance10 ../metadata.enterprise.currency_id}}
{{debcred balance10 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance11}}
{{currency balance11 ../metadata.enterprise.currency_id}}
{{debcred balance11 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
<td class="text-right">
{{#if balance12}}
{{currency balance12 ../metadata.enterprise.currency_id}}
{{debcred balance12 ../metadata.enterprise.currency_id}}
{{/if}}
</td>
</tr>
{{else}}
{{> emptyTable columns=4}}
{{> emptyTable columns=16}}
{{/each}}
</tbody>
<tfoot>
<tr>
<th colspan="2">{{translate "FORM.LABELS.TOTAL"}}</th>
<th>{{debcred footer.balance metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance0 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance1 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance2 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance3 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance4 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance5 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance6 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance7 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance8 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance9 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance10 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance11 metadata.enterprise.currency_id}}</th>
<th>{{debcred footer.balance12 metadata.enterprise.currency_id}}</th>
</tr>
</tfoot>
</table>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion server/lib/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Tree {
this.buildNodeIndex();

// build a node index

debug(`#constructor() built tree with ${data.length} nodes.`);
}

Expand Down Expand Up @@ -79,6 +78,10 @@ class Tree {
return array;
}

getRootNode() {
return this._rootNode;
}

/**
* @method isRootNode
*
Expand Down

0 comments on commit c72386b

Please sign in to comment.