Skip to content

Commit

Permalink
fix(accounts): fix rendering bugs
Browse files Browse the repository at this point in the history
This commit fixes two bugs in the account report where cumulative
summation and the description were not rendering due to incorrect SQL.
It also ensures that the JS file passes lint.
  • Loading branch information
Jonathan Niles authored and sfount committed Feb 23, 2017
1 parent 518e586 commit 0db0bb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions client/src/partials/reports/modals/report_accounts.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

<!-- Inclure Date interval -->
<div class="checkbox">
<label class="control-label">
<label>
<input type="checkbox" ng-model="ReportConfigCtrl.dateInterval" ng-true-value="1" ng-false-value="0">
<strong translate> FORM.LABELS.INCLUDE_DATE_INTERVAL </strong>
</label>
</div>

<!-- Date interval -->
<div ng-if="ReportConfigCtrl.dateInterval === 1">
<div ng-if="ReportConfigCtrl.dateInterval === 1">
<bh-date-interval
date-from="ReportConfigCtrl.dateFrom"
date-to="ReportConfigCtrl.dateTo">
Expand Down
34 changes: 17 additions & 17 deletions server/controllers/finance/reports/reportAccounts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function document(req, res, next) {
accountLabel : params.account_label,
source : params.sourceLabel,
dateFrom : params.dateFrom,
dateTo : params.dateTo
dateTo : params.dateTo,
};

params.user = req.session.user;
Expand Down Expand Up @@ -73,41 +73,41 @@ function getAccountTransactions(accountId, source, dateFrom, dateTo) {
const params = [accountId];
let dateCondition = '';

if(dateFrom && dateTo){
dateCondition = `AND DATE(trans_date) BETWEEN ? AND ?`
if (dateFrom && dateTo) {
dateCondition = 'AND DATE(trans_date) BETWEEN DATE(?) AND DATE(?)';
params.push(dateFrom, dateTo);
}

const csum = `SET @csum := 0`;
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
FROM(
SELECT trans_id, BUID(entity_uuid) AS entity_uuid, description, trans_date,
SELECT a.trans_id, a.debit, a.credit, a.balance, a.trans_date, (@csum := @csum + a.balance) AS cumulBalance,
a.description
FROM (
SELECT trans_id, BUID(entity_uuid) AS entity_uuid, description, trans_date,
SUM(debit_equiv) as debit, SUM(credit_equiv) as credit, (SUM(debit_equiv) - SUM(credit_equiv)) AS balance
FROM ${tableName}
WHERE account_id = ? ${dateCondition}
GROUP BY trans_id
ORDER BY trans_date ASC
GROUP BY trans_id
ORDER BY trans_date ASC
) AS a`;


const sqlAggrega = ` SELECT SUM(t.debit) AS debit, SUM(t.credit) AS credit, SUM(t.debit - t.credit) AS balance
const sqlAggrega = `
SELECT SUM(t.debit) AS debit, SUM(t.credit) AS credit, SUM(t.debit - t.credit) AS balance
FROM (
SELECT trans_id, BUID(entity_uuid) AS entity_uuid, description, trans_date,
SELECT trans_id, BUID(entity_uuid) AS entity_uuid, description, trans_date,
SUM(debit_equiv) as debit, SUM(credit_equiv) as credit
FROM ${tableName}
WHERE account_id = ? ${dateCondition}
GROUP BY trans_id
GROUP BY trans_id
ORDER BY trans_date ASC
) AS t
) AS t
`;

const bundle = {};
return db.exec(csum)
.then((err) => {
return db.exec(sql, params);
})
.then(() => db.exec(sql, params))
.then((transactions) => {
_.extend(bundle, { transactions });
return db.one(sqlAggrega, params);
Expand All @@ -118,4 +118,4 @@ function getAccountTransactions(accountId, source, dateFrom, dateTo) {
});
}

exports.document = document;
exports.document = document;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<h3 style="margin:15px; font-weight:bold" class="text-center text-uppercase">
<small>{{date title.dateFrom }} - {{date title.dateTo }}</small>
</h3>
{{/if}}
{{/if}}

<section>
<table class="table table-condensed table-striped table-report table-bordered">
Expand Down

0 comments on commit 0db0bb9

Please sign in to comment.