Skip to content

Commit

Permalink
fix(balance): render report in enterprise currency
Browse files Browse the repository at this point in the history
This commit updates the balance report to use the enterprise currency
instead of the default currency.

Closes #1168.
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 15, 2017
1 parent 9c7cd59 commit df912ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
30 changes: 13 additions & 17 deletions server/controllers/finance/reports/balance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
*/


const _ = require('lodash');
const moment = require('moment');
const db = require('../../../../lib/db');
const _ = require('lodash');
const db = require('../../../../lib/db');
const ReportManager = require('../../../../lib/ReportManager');
const BadRequest = require('../../../../lib/errors/BadRequest');

// report template
const TEMPLATE = './server/controllers/finance/reports/balance/report.handlebars';
Expand All @@ -31,7 +29,7 @@ exports.document = document;
function document(req, res, next) {
const params = req.query;

let session = {};
const session = {};
let report;
let data;

Expand Down Expand Up @@ -61,9 +59,7 @@ function document(req, res, next) {
params.enterpriseId = session.enterprise.id;

balanceReporting(params)
.then(balances => {
return processAccounts(balances, accounts, totals);
})
.then(balances => processAccounts(balances, accounts, totals))
.then(result => {
data = { accounts: result.accounts, totals: result.totals, session };
return report.render(data);
Expand Down Expand Up @@ -175,7 +171,7 @@ function getSold (item){
* @param {object} params An object which contains dates range and the account class
*/
function balanceReporting(params) {
let sql, hasClasse, dateRange, queryParameters,
let sql, hasClasse, dateRange, queryParameters,
query = params,
data = {};

Expand Down Expand Up @@ -224,21 +220,21 @@ function balanceReporting(params) {
return data;
})
.then(function (rows) {
// Manual mixing
// Manual mixing
const TITLE_ACCOUNT_TYPE = 4;
// fill with zero if all accounts
sql =
`SELECT a.number, a.id, a.label, a.type_id, a.is_charge, a.is_asset, '0' AS credit, '0' AS debit

// fill with zero if all accounts
sql =
`SELECT a.number, a.id, a.label, a.type_id, a.is_charge, a.is_asset, '0' AS credit, '0' AS debit
FROM account a WHERE a.type_id <> ${TITLE_ACCOUNT_TYPE} AND a.locked = 0;`;

return query.accountOption === 'all' ? db.exec(sql) : false;
})
.then(function (rows) {

if (!rows) { return data; }
// Naive manipulation for filling with zero

// Naive manipulation for filling with zero
let accounts = rows;
let touched = data.beginning.map(item => {
return item.id;
Expand Down
24 changes: 12 additions & 12 deletions server/controllers/finance/reports/balance/report.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@
<tr class="text-right">
<td class="text-left">{{ $index }}</td>
<td class="text-left"> {{ account.label }}</td>
<td>{{currency account.beginDebit session.enterprise.currency_id }}</td>
<td>{{currency account.beginCredit session.enterprise.currency_id }}</td>
<td>{{currency account.middleDebit session.enterprise.currency_id }}</td>
<td>{{currency account.middleCredit session.enterprise.currency_id }}</td>
<td>{{currency account.endDebit session.enterprise.currency_id }}</td>
<td>{{currency account.endCredit session.enterprise.currency_id }}</td>
<td>{{currency account.beginDebit ../metadata.enterprise.currency_id }}</td>
<td>{{currency account.beginCredit ../metadata.enterprise.currency_id }}</td>
<td>{{currency account.middleDebit ../metadata.enterprise.currency_id }}</td>
<td>{{currency account.middleCredit ../metadata.enterprise.currency_id }}</td>
<td>{{currency account.endDebit ../metadata.enterprise.currency_id }}</td>
<td>{{currency account.endCredit ../metadata.enterprise.currency_id }}</td>
</tr>
{{/each}}
</tbody>
<tfoot>
<tr class="text-right" style="font-weight: bold; background-color: #efefef;">
<th colspan="2">{{translate "FORM.LABELS.TOTAL"}}</th>
<td>{{currency totals.beginDebit session.enterprise.currency_id }}</td>
<td>{{currency totals.beginCredit session.enterprise.currency_id }}</td>
<td>{{currency totals.middleDebit session.enterprise.currency_id }}</td>
<td>{{currency totals.middleCredit session.enterprise.currency_id }}</td>
<td>{{currency totals.endDebit session.enterprise.currency_id }}</td>
<td>{{currency totals.endCredit session.enterprise.currency_id }}</td>
<td>{{currency totals.beginDebit metadata.enterprise.currency_id }}</td>
<td>{{currency totals.beginCredit metadata.enterprise.currency_id }}</td>
<td>{{currency totals.middleDebit metadata.enterprise.currency_id }}</td>
<td>{{currency totals.middleCredit metadata.enterprise.currency_id }}</td>
<td>{{currency totals.endDebit metadata.enterprise.currency_id }}</td>
<td>{{currency totals.endCredit metadata.enterprise.currency_id }}</td>
</tr>
</tfoot>
</table>
Expand Down

0 comments on commit df912ab

Please sign in to comment.