Skip to content

Commit

Permalink
fix(report): accounts report gives the document
Browse files Browse the repository at this point in the history
This commit finally fixes the cumulative SUM in the accounts report as
well as putting in a new column with the originating document number.
This will allow administrators to really quickly look up the details of
that transaction.
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 24, 2017
1 parent 0db0bb9 commit 2154748
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
15 changes: 9 additions & 6 deletions server/controllers/finance/reports/reportAccounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ function getAccountTransactions(accountId, source, dateFrom, dateTo) {
const csum = 'SET @csum := 0;';

const sql = `
SELECT a.trans_id, a.debit, a.credit, a.balance, a.trans_date, (@csum := @csum + a.balance) AS cumulBalance,
a.description
SELECT a.trans_id, a.debit, a.credit, a.balance, a.trans_date, a.document_reference,
(@csum := IFNULL(@csum, 0) + a.balance) AS cumulBalance, a.description
FROM (
SELECT trans_id, BUID(entity_uuid) AS entity_uuid, description, trans_date,
document_map.text AS document_reference,
SUM(debit_equiv) as debit, SUM(credit_equiv) as credit, (SUM(debit_equiv) - SUM(credit_equiv)) AS balance
FROM ${tableName}
LEFT JOIN document_map ON record_uuid = document_map.uuid
WHERE account_id = ? ${dateCondition}
GROUP BY trans_id
GROUP BY record_uuid
ORDER BY trans_date ASC
) AS a`;
) AS a
`;


const sqlAggrega = `
Expand All @@ -100,10 +103,10 @@ function getAccountTransactions(accountId, source, dateFrom, dateTo) {
SUM(debit_equiv) as debit, SUM(credit_equiv) as credit
FROM ${tableName}
WHERE account_id = ? ${dateCondition}
GROUP BY trans_id
GROUP BY record_uuid
ORDER BY trans_date ASC
) AS t
`;
`;

const bundle = {};
return db.exec(csum)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,33 @@
<table class="table table-condensed table-striped table-report table-bordered">
<thead>
<tr class="text-capitalize text-center" style="background-color: #ddd;">
<th style="width: 10%;">{{translate "TABLE.COLUMNS.DATE" }}</th>
<th style="width: 10%;">{{translate "TABLE.COLUMNS.TRANSACTION" }}</th>
<th style="width: 40%;">{{translate "TABLE.COLUMNS.DESCRIPTION" }}</th>
<th style="width: 12%;">{{translate "TABLE.COLUMNS.DEBIT" }}</th>
<th style="width: 12%;">{{translate "TABLE.COLUMNS.CREDIT" }}</th>
<th style="width: 16%;">{{translate "TABLE.COLUMNS.BALANCE" }}</th>
<th>{{translate "TABLE.COLUMNS.DATE" }}</th>
<th>{{translate "TABLE.COLUMNS.TRANSACTION" }}</th>
<th>{{translate "TABLE.COLUMNS.DOCUMENT" }}</th>
<th>{{translate "TABLE.COLUMNS.DESCRIPTION" }}</th>
<th style="width:12%">{{translate "TABLE.COLUMNS.DEBIT" }}</th>
<th style="width:12%">{{translate "TABLE.COLUMNS.CREDIT" }}</th>
<th style="width:12%">{{translate "TABLE.COLUMNS.BALANCE" }}</th>
</tr>
</thead>
<tbody>
{{#each transactions}}
<tr>
<td>{{date this.trans_date}}</td>
<td>{{this.trans_id}}</td>
<td>{{this.document_reference}}</td>
<td>{{this.description}}</td>
<td class="text-right">{{currency this.debit ../metadata.enterprise.currency_id}}</td>
<td class="text-right">{{currency this.credit ../metadata.enterprise.currency_id}}</td>
<td class="text-right">{{currency this.cumulBalance ../metadata.enterprise.currency_id}}</td>
</tr>
{{else}}
{{> emptyTable columns=5}}
{{> emptyTable columns=7}}
{{/each}}
</tbody>
<tfoot>
<tr style="background-color: #ddd;">
<td colspan="3"><strong>{{translate "FORM.LABELS.TOTAL" }}</strong></td>
<td colspan="4"><strong>{{translate "FORM.LABELS.TOTAL" }}</strong></td>
<td class="text-right"><strong>{{currency sum.debit metadata.enterprise.currency_id}}</strong></td>
<td class="text-right"><strong>{{currency sum.credit metadata.enterprise.currency_id}}</strong></td>
<td class="text-right"><strong>{{currency sum.balance metadata.enterprise.currency_id}}</strong></td>
Expand All @@ -54,7 +56,7 @@
</tr>
<tr>
<th colspan="5" class="text-right">
<i>{{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }}</i>
<i>{{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }}</i>
</th>
</tr>
</table>
Expand Down

0 comments on commit 2154748

Please sign in to comment.