From 215474833efa5260a1cbee55ebf17cbb1ac9cce9 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Fri, 24 Feb 2017 11:34:39 +0100 Subject: [PATCH] fix(report): accounts report gives the document 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. --- .../finance/reports/reportAccounts/index.js | 15 ++++++++------ .../reports/reportAccounts/report.handlebars | 20 ++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/server/controllers/finance/reports/reportAccounts/index.js b/server/controllers/finance/reports/reportAccounts/index.js index 89357db6d1..968b23d5e1 100644 --- a/server/controllers/finance/reports/reportAccounts/index.js +++ b/server/controllers/finance/reports/reportAccounts/index.js @@ -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 = ` @@ -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) diff --git a/server/controllers/finance/reports/reportAccounts/report.handlebars b/server/controllers/finance/reports/reportAccounts/report.handlebars index ecceaa243a..5d0aedacb4 100644 --- a/server/controllers/finance/reports/reportAccounts/report.handlebars +++ b/server/controllers/finance/reports/reportAccounts/report.handlebars @@ -15,12 +15,13 @@ - - - - - - + + + + + + + @@ -28,18 +29,19 @@ + {{else}} - {{> emptyTable columns=5}} + {{> emptyTable columns=7}} {{/each}} - + @@ -54,7 +56,7 @@
{{translate "TABLE.COLUMNS.DATE" }}{{translate "TABLE.COLUMNS.TRANSACTION" }}{{translate "TABLE.COLUMNS.DESCRIPTION" }}{{translate "TABLE.COLUMNS.DEBIT" }}{{translate "TABLE.COLUMNS.CREDIT" }}{{translate "TABLE.COLUMNS.BALANCE" }}{{translate "TABLE.COLUMNS.DATE" }}{{translate "TABLE.COLUMNS.TRANSACTION" }}{{translate "TABLE.COLUMNS.DOCUMENT" }}{{translate "TABLE.COLUMNS.DESCRIPTION" }}{{translate "TABLE.COLUMNS.DEBIT" }}{{translate "TABLE.COLUMNS.CREDIT" }}{{translate "TABLE.COLUMNS.BALANCE" }}
{{date this.trans_date}} {{this.trans_id}}{{this.document_reference}} {{this.description}} {{currency this.debit ../metadata.enterprise.currency_id}} {{currency this.credit ../metadata.enterprise.currency_id}} {{currency this.cumulBalance ../metadata.enterprise.currency_id}}
{{translate "FORM.LABELS.TOTAL" }}{{translate "FORM.LABELS.TOTAL" }} {{currency sum.debit metadata.enterprise.currency_id}} {{currency sum.credit metadata.enterprise.currency_id}} {{currency sum.balance metadata.enterprise.currency_id}}
- {{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }} + {{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }}