Skip to content

Commit

Permalink
fix(reports): clients report misc fixes
Browse files Browse the repository at this point in the history
This commit fixes a few bugs on the clients report:
 1. The i18n translations are now well defined.
 2. The currency is now rendered in the enterprise currency.

Closes #2366.
  • Loading branch information
jniles committed Dec 9, 2017
1 parent ca00de0 commit 88475e8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 62 deletions.
4 changes: 3 additions & 1 deletion client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
"AVG_MONTHLY_CONSUMPTION": "Monthly Average Consumption",
"MONTHLY_CONSUMPTION": "Monthly Consumption",
"BALANCE": "Balance",
"BALANCE_INTERMEDIATE" : "Intermediate Balance",
"BALANCE_FINAL" : "Final Balance",
"BALANCE_SECTION": "Balance Sheet Section",
"BANK": "Bank",
"BANK_ACCOUNT": "Bank Account",
Expand Down Expand Up @@ -668,4 +670,4 @@
"NO_CHANGES": "You haven't changed any form values. Nothing will be submitted to the server."
}
}
}
}
2 changes: 2 additions & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@
"AVG_MONTHLY_CONSUMPTION": "Consommation Mensuelle Moyenne",
"MONTHLY_CONSUMPTION": "Consommation Mensuelle",
"BALANCE": "Balance",
"BALANCE_INTERMEDIATE" : "Solde Intermediate",
"BALANCE_FINAL" : "Solde Finale",
"BALANCE_SECTION": "Section du Bilan",
"BANK": "Banque",
"BANK_ACCOUNT": "Compte Bancaire",
Expand Down
87 changes: 44 additions & 43 deletions server/controllers/finance/reports/clientsReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function buildComplexReport(opt) {
// removing the period filter
delete opt.period_id;

// fecth final balances
// fetch final balances
return getClientBalancesFromPeriodTotal(opt, false);
})
.then((data) => {
Expand All @@ -176,6 +176,7 @@ function buildComplexReport(opt) {
});
}
});

// fetch the final total for each row of the period total table
return getClientTotalsFromPeriodTotal(opt, false);
})
Expand All @@ -195,13 +196,13 @@ function buildComplexReport(opt) {
function getFiscalYearByDate(date, periodZeroNumber) {
var query =
`
SELECT
fy.id AS fiscal_year_id, fy.previous_fiscal_year_id, fy.start_date, fy.end_date, p.id AS period_id
FROM
fiscal_year fy
JOIN
SELECT
fy.id AS fiscal_year_id, fy.previous_fiscal_year_id, fy.start_date, fy.end_date, p.id AS period_id
FROM
fiscal_year fy
JOIN
period p ON p.fiscal_year_id = fy.id
WHERE
WHERE
p.number = ? AND
DATE(?) BETWEEN DATE(fy.start_date) AND DATE(fy.end_date)`;
return db.one(query, [periodZeroNumber, date]);
Expand Down Expand Up @@ -229,11 +230,11 @@ function getClientBalancesFromPeriodTotal(options, isInitial) {
const sql = `
SELECT
ac.number AS number, dg.name AS name, SUM(pt.debit) AS debit,
SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance
FROM
debtor_group dg
JOIN
account ac ON ac.id = dg.account_id
SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance
FROM
debtor_group dg
JOIN
account ac ON ac.id = dg.account_id
LEFT JOIN period_total pt ON ac.id = pt.account_id`;

filterParser.equals('fiscal_year_id', 'fiscal_year_id', 'pt');
Expand All @@ -260,9 +261,9 @@ function getClientBalancesFromPeriodTotal(options, isInitial) {

const finalQuery =
`
SELECT
${cols}
FROM
SELECT
${cols}
FROM
(${query}) AS t`;
return db.exec(finalQuery, parameters);
}
Expand All @@ -272,13 +273,13 @@ function getClientBalancesFromGeneralLedger(options) {
const filterParser = new FilterParser(options, { tableAlias : 'gl' });
const sql = `
SELECT
ac.number, dg.name, SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit,
SUM(gl.debit_equiv - gl.credit_equiv) AS balance
FROM
debtor_group dg
JOIN
ac.number, dg.name, SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit,
SUM(gl.debit_equiv - gl.credit_equiv) AS balance
FROM
debtor_group dg
JOIN
account ac ON ac.id = dg.account_id
LEFT JOIN
LEFT JOIN
general_ledger gl ON ac.id = gl.account_id`;

filterParser.dateFrom('dateFrom', 'trans_date');
Expand All @@ -291,10 +292,10 @@ function getClientBalancesFromGeneralLedger(options) {

// request to fetch the current fiscal year data of a client from the general ledger
const finalQuery = `
SELECT
t.number AS accountNumber, t.name, IFNULL(t.debit, 0) AS debit, IFNULL(t.credit, 0) AS credit,
SELECT
t.number AS accountNumber, t.name, IFNULL(t.debit, 0) AS debit, IFNULL(t.credit, 0) AS credit,
IFNULL(t.balance, 0) AS balance
FROM
FROM
(${query}) AS t`;
return db.exec(finalQuery, parameters);
}
Expand All @@ -305,10 +306,10 @@ function getClientTotalsFromPeriodTotal(options, isInitial) {

const sql = `
SELECT
SUM(pt.debit) AS debit, SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance
FROM
SUM(pt.debit) AS debit, SUM(pt.credit) AS credit, SUM(pt.debit - pt.credit) AS balance
FROM
period_total pt
JOIN
JOIN
debtor_group dg ON dg.account_id = pt.account_id`;

filterParser.equals('fiscal_year_id', 'fiscal_year_id', 'pt');
Expand All @@ -324,15 +325,15 @@ function getClientTotalsFromPeriodTotal(options, isInitial) {
cols = `IFNULL(t.balance, 0) AS balance`;
} else {
cols = (isInitial) ?
`IFNULL(debit, 0) AS totalInitDebit, IFNULL(credit, 0) AS totalInitCredit, IFNULL(balance, 0) AS totalInitBalance` :
`IFNULL(t.balance, 0) AS totalFinalBalance`;
'IFNULL(debit, 0) AS totalInitDebit, IFNULL(credit, 0) AS totalInitCredit, IFNULL(balance, 0) AS totalInitBalance' :
'IFNULL(t.balance, 0) AS totalFinalBalance';
}

const finalQuery =
`
SELECT
${cols}
FROM
SELECT
${cols}
FROM
(${query}) AS t`;

return db.one(finalQuery, parameters);
Expand All @@ -343,14 +344,14 @@ function getClientTotalsFromGeneralLedger(options) {
const filterParser = new FilterParser(options, { tableAlias : 'gl', autoParseStatements : false });
const sql =
`
SELECT
SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit,
SUM(gl.debit_equiv - gl.credit_equiv) AS balance
FROM
debtor_group dg
JOIN
account ac ON ac.id = dg.account_id
JOIN
SELECT
SUM(gl.debit_equiv) AS debit, SUM(gl.credit_equiv) AS credit,
SUM(gl.debit_equiv - gl.credit_equiv) AS balance
FROM
debtor_group dg
JOIN
account ac ON ac.id = dg.account_id
JOIN
general_ledger gl ON ac.id = gl.account_id`;

filterParser.dateFrom('dateFrom', 'trans_date');
Expand All @@ -361,10 +362,10 @@ function getClientTotalsFromGeneralLedger(options) {
const parameters = filterParser.parameters();

const finalQuery =
`SELECT
IFNULL(t.debit, 0) AS totalCurrentDebit, IFNULL(t.credit, 0) AS totalCurrentCredit,
`SELECT
IFNULL(t.debit, 0) AS totalCurrentDebit, IFNULL(t.credit, 0) AS totalCurrentCredit,
IFNULL(t.balance, 0) AS totalCurrentBalance
FROM
FROM
(${query}) AS t`;

return db.one(finalQuery, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
<td>{{this.accountNumber}}</td>
<td>{{this.name}}</td>
{{#if ../detailPrevious}}
<td class='text-right'> {{currency this.initDebit ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.initCredit ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.initDebit ../metadata.enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.initCredit ../metadata.enterprise.currency_id}} </td>
{{else}}
<td class='text-right'> {{currency this.initBalance ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.initBalance ../metadata.enterprise.currency_id}} </td>
{{/if}}
<td class='text-right'> {{currency this.debit ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.credit ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.currentBalance ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.finalBalance ../enterprise.currency_id}} </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.currentBalance ../metadata.enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.finalBalance ../metadata.enterprise.currency_id}} </td>
</tr>
{{else}}
{{>emptyTable columns=7}}
Expand All @@ -59,15 +59,15 @@
<tr style="background-color:#ddd;">
<th colspan="2">{{translate 'FORM.LABELS.TOTAL'}}</th>
{{#if detailPrevious}}
<th class="text-right">{{currency totalInitDebit enterprise.currency_id}}</th>
<th class="text-right">{{currency totalInitCredit enterprise.currency_id}}</th>
<th class="text-right">{{currency totalInitDebit metadata.enterprise.currency_id}}</th>
<th class="text-right">{{currency totalInitCredit metadata.enterprise.currency_id}}</th>
{{else}}
<th class="text-right">{{currency totalInitBalance enterprise.currency_id}}</th>
<th class="text-right">{{currency totalInitBalance metadata.enterprise.currency_id}}</th>
{{/if}}
<th class="text-right">{{currency totalCurrentDebit enterprise.currency_id}}</th>
<th class="text-right">{{currency totalCurrentCredit enterprise.currency_id}}</th>
<th class="text-right">{{currency totalCurrentBalance enterprise.currency_id}}</th>
<th class="text-right">{{currency totalFinalBalance enterprise.currency_id}}</th>
<th class="text-right">{{currency totalCurrentDebit metadata.enterprise.currency_id}}</th>
<th class="text-right">{{currency totalCurrentCredit metadata.enterprise.currency_id}}</th>
<th class="text-right">{{currency totalCurrentBalance metadata.enterprise.currency_id}}</th>
<th class="text-right">{{currency totalFinalBalance metadata.enterprise.currency_id}}</th>
</tr>
</tfoot>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
<tr>
<td>{{this.accountNumber}}</td>
<td>{{this.name}}</td>
<td class='text-right'> {{currency this.balance ../enterprise.currency_id}} </td>
<td class='text-right'> {{currency this.balance ../metadata.enterprise.currency_id}} </td>
</tr>
{{/each}}
</tbody>
<tfoot>
<tr style="background-color:#ddd;">
<th colspan="2">{{translate 'FORM.LABELS.TOTAL'}}</th>
<th class="text-right">{{currency totalBalance enterprise.currency_id}}</th>
<th colspan="2">{{translate 'FORM.LABELS.TOTAL'}}</th>
<th class="text-right">{{currency totalBalance ../metadata.enterprise.currency_id}}</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>

0 comments on commit 88475e8

Please sign in to comment.