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 @@
{{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}} | @@ -54,7 +56,7 @@||||||||
- {{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }} + {{translate "TABLE.COLUMNS.DATA_SOURCE" }} : {{translate title.source }} |