From 2b79fd7844a47211f96921464222db2e4e426ad5 Mon Sep 17 00:00:00 2001 From: lomamech Date: Tue, 25 Jan 2022 11:32:37 +0100 Subject: [PATCH] refactor: Add multi currency support --- .../recovery_capacity.config.js | 10 +++++++--- .../recovery_capacity/recovery_capacity.html | 5 +++++ .../unpaid_invoice_payments.html | 2 -- .../finance/reports/recovery_capacity/index.js | 8 ++++++++ .../reports/recovery_capacity/report.handlebars | 16 ++++++++-------- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.config.js b/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.config.js index 1bbe499a7b..6ed760ce40 100644 --- a/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.config.js +++ b/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.config.js @@ -3,21 +3,25 @@ angular.module('bhima.controllers') recoveryCapacityController.$inject = [ '$sce', 'NotifyService', 'BaseReportService', - 'AppCache', 'reportData', '$state', + 'AppCache', 'reportData', '$state', 'SessionService', ]; -function recoveryCapacityController($sce, Notify, SavedReports, AppCache, reportData, $state) { +function recoveryCapacityController($sce, Notify, SavedReports, AppCache, reportData, $state, Session) { const vm = this; const cache = new AppCache('recovery_capacity'); const reportUrl = 'reports/finance/recovery_capacity'; vm.previewGenerated = false; - vm.reportDetails = { includeUnpostedValues : 0 }; + vm.reportDetails = { includeUnpostedValues : 0, currencyId : Session.enterprise.currency_id }; vm.onChangeUnpostedValues = value => { vm.reportDetails.includeUnpostedValues = value; }; + vm.onSelectCurrency = currency => { + vm.reportDetails.currencyId = currency.id; + }; + vm.clearPreview = function clearPreview() { vm.previewGenerated = false; vm.previewResult = null; diff --git a/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.html b/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.html index c4f8d6693c..0e5bf24f7d 100644 --- a/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.html +++ b/client/src/modules/reports/generate/recovery_capacity/recovery_capacity.html @@ -29,6 +29,11 @@

REPORT.RECOVERY_CAPACITY.TITLE

limit-min-fiscal> + + + REPORT.UNPAID_INVOICE_PAYMENTS_REPORT.TITL - REPORT.UNPAID_INVOICE_PAYMENTS_REPORT.TITL on-change="ReportConfigCtrl.onSelectCurrency(currency)"> - REPORT.UTIL.PREVIEW diff --git a/server/controllers/finance/reports/recovery_capacity/index.js b/server/controllers/finance/reports/recovery_capacity/index.js index 520dad1294..5c9fb9532d 100644 --- a/server/controllers/finance/reports/recovery_capacity/index.js +++ b/server/controllers/finance/reports/recovery_capacity/index.js @@ -7,6 +7,7 @@ const moment = require('moment'); const ReportManager = require('../../../../lib/ReportManager'); const db = require('../../../../lib/db'); +const Exchange = require('../../exchange'); module.exports.report = report; @@ -29,6 +30,9 @@ async function report(req, res, next) { const { dateFrom, dateTo } = req.query; const metadata = _.clone(req.session); + const { enterprise } = req.session; + const currencyId = Number(req.query.currencyId); + const rpt = new ReportManager(TEMPLATE, metadata, qs); const CASH_PAYMENT_TRANSACTION_TYPE = 2; @@ -158,10 +162,14 @@ async function report(req, res, next) { const rows = await db.exec(query, parameters); const totals = await db.one(queryTotals, parameters); + const getExchangeRateData = await Exchange.getExchangeRate(enterprise.id, currencyId, new Date(dateTo)); + const exchangeRate = getExchangeRateData.rate || 1; const result = await rpt.render({ dateFrom, dateTo, + currencyId, + exchangeRate, rows, totals, includeUnpostedValues, diff --git a/server/controllers/finance/reports/recovery_capacity/report.handlebars b/server/controllers/finance/reports/recovery_capacity/report.handlebars index 4b93296bf8..004ecbd94f 100644 --- a/server/controllers/finance/reports/recovery_capacity/report.handlebars +++ b/server/controllers/finance/reports/recovery_capacity/report.handlebars @@ -19,6 +19,8 @@ {{date dateFrom}} - {{date dateTo}} + {{> exchangeRate rate=exchangeRate currencyId=currencyId date=dateTo}} + - - - + + + - - - + + +
@@ -52,9 +54,9 @@
{{date row.date}} {{row.registrations}}{{debcred row.total_invoiced ../metadata.enterprise.currency_id}}{{debcred row.avg_cost ../metadata.enterprise.currency_id}}{{debcred row.total_paid ../metadata.enterprise.currency_id}}{{debcred (multiply row.total_invoiced ../exchangeRate) ../currencyId}}{{debcred (multiply row.avg_cost ../exchangeRate) ../currencyId}}{{debcred (multiply row.total_paid ../exchangeRate) ../currencyId}} {{translate 'TABLE.COLUMNS.TOTAL'}} {{totals.registrations}}{{debcred totals.total_invoiced metadata.enterprise.currency_id}}{{debcred totals.avg_cost metadata.enterprise.currency_id}}{{debcred totals.total_paid metadata.enterprise.currency_id}}{{debcred (multiply totals.total_invoiced exchangeRate) currencyId}}{{debcred (multiply totals.avg_cost exchangeRate) currencyId}}{{debcred (multiply totals.total_paid exchangeRate) currencyId}}
- -