Skip to content

Commit

Permalink
fix(report): aged debtor maths
Browse files Browse the repository at this point in the history
This commit fixes the aged debtor maths by ensuring that dates are
properly compared and ranges are restricted to avoid double-counting.

Closes #1169.
  • Loading branch information
Jonathan Niles authored and sfount committed Feb 16, 2017
1 parent 73b9265 commit 160123e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions client/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,9 @@
"DELETE" : "Delete Report",
"AGED_DEBTORS" : {
"TITLE": "Aged Debtors",
"THIRTY_DAYS" : "Less Than 30 Days",
"SIXTY_DAYS" : "Less Than 60 Days",
"NINETY_DAYS" : "Less Than 90 Days",
"ZERO_TO_THIRTY_DAYS" : "Less Than 30 Days",
"THIRTY_TO_SIXTY_DAYS" : "30 to 60 Days",
"SIXTY_TO_NINETY_DAYS" : "60 to 90 Days",
"OVER_NINETY_DAYS" : "Over 90 Days"
},
"CASH_EXPENSE" : "Expenses",
Expand Down
8 changes: 4 additions & 4 deletions client/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1199,10 +1199,10 @@
"BALANCE" : "Rapport de la Balance",
"AGED_DEBTORS" : {
"TITLE": "Aged Debtors",
"THIRTY_DAYS" : "Moins de 30 jours",
"SIXTY_DAYS" : "Moins de 60 jours",
"NINETY_DAYS" : "Moins de 90 jours",
"OVER_NINETY_DAYS" : "Audela de 90 jours"
"ZERO_TO_THIRTY_DAYS" : "Moins de 30 jours",
"THIRTY_TO_SIXTY_DAYS" : "30 a 60 jours",
"SIXTY_TO_NINETY_DAYS" : "60 a 90 jours",
"OVER_NINETY_DAYS" : "Plus de 90 jours"
},
"CASH_EXPENSE" : "Depenses",
"CASH_INCOME" : "Recettes",
Expand Down
6 changes: 3 additions & 3 deletions server/controllers/finance/reports/debtors/aged.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<tr class="text-capitalize">
<th class="text-center">{{translate "TABLE.COLUMNS.NAME"}}</th>
<th class="text-center" style="width:15%">{{translate "FORM.LABELS.ACCOUNT_NUMBER"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.THIRTY_DAYS"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.SIXTY_DAYS"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.NINETY_DAYS"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.ZERO_TO_THIRTY_DAYS"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.THIRTY_TO_SIXTY_DAYS"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.SIXTY_TO_NINETY_DAYS"}}</th>
<th class="text-center">{{translate "REPORT.AGED_DEBTORS.OVER_NINETY_DAYS"}}</th>
<th class="text-center">{{translate "TABLE.COLUMNS.TOTAL"}}</th>
</tr>
Expand Down
16 changes: 8 additions & 8 deletions server/controllers/finance/reports/debtors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ function queryContext(queryParams) {
// selects into columns of 30, 60, 90, and >90
const debtorSql = `
SELECT BUID(dg.uuid) AS id, dg.name, a.number,
SUM(IF(DATEDIFF(?, gl.trans_date) BETWEEN 0 AND 30, gl.debit_equiv - gl.credit_equiv, 0)) AS thirty,
SUM(IF(DATEDIFF(?, gl.trans_date) BETWEEN 30 AND 60, gl.debit_equiv - gl.credit_equiv, 0)) AS sixty,
SUM(IF(DATEDIFF(?, gl.trans_date) BETWEEN 60 AND 90, gl.debit_equiv - gl.credit_equiv, 0)) AS ninety,
SUM(IF(DATEDIFF(?, gl.trans_date) > 90, gl.debit_equiv - gl.credit_equiv, 0)) AS excess,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) BETWEEN 0 AND 29, gl.debit_equiv - gl.credit_equiv, 0)) AS thirty,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) BETWEEN 30 AND 59, gl.debit_equiv - gl.credit_equiv, 0)) AS sixty,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) BETWEEN 60 AND 89, gl.debit_equiv - gl.credit_equiv, 0)) AS ninety,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) > 90, gl.debit_equiv - gl.credit_equiv, 0)) AS excess,
SUM(gl.debit_equiv - gl.credit_equiv) AS total
FROM debtor_group AS dg JOIN debtor AS d ON dg.uuid = d.group_uuid
LEFT JOIN ${source} AS gl ON gl.entity_uuid = d.uuid
Expand All @@ -93,10 +93,10 @@ function queryContext(queryParams) {
// aggregates the data above as totals into columns of 30, 60, 90, and >90
const aggregateSql = `
SELECT
SUM(IF(DATEDIFF(?, gl.trans_date) BETWEEN 0 AND 30, gl.debit_equiv - gl.credit_equiv, 0)) AS thirty,
SUM(IF(DATEDIFF(?, gl.trans_date) BETWEEN 30 AND 60, gl.debit_equiv - gl.credit_equiv, 0)) AS sixty,
SUM(IF(DATEDIFF(?, gl.trans_date) BETWEEN 60 AND 90, gl.debit_equiv - gl.credit_equiv, 0)) AS ninety,
SUM(IF(DATEDIFF(?, gl.trans_date) > 90, gl.debit_equiv - gl.credit_equiv, 0)) AS excess,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) BETWEEN 0 AND 29, gl.debit_equiv - gl.credit_equiv, 0)) AS thirty,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) BETWEEN 30 AND 59, gl.debit_equiv - gl.credit_equiv, 0)) AS sixty,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) BETWEEN 60 AND 89, gl.debit_equiv - gl.credit_equiv, 0)) AS ninety,
SUM(IF(DATEDIFF(DATE(?), DATE(gl.trans_date)) > 90, gl.debit_equiv - gl.credit_equiv, 0)) AS excess,
SUM(gl.debit_equiv - gl.credit_equiv) AS total
FROM debtor_group AS dg JOIN debtor AS d ON dg.uuid = d.group_uuid
LEFT JOIN ${source} AS gl ON gl.entity_uuid = d.uuid
Expand Down

0 comments on commit 160123e

Please sign in to comment.