+
+ {{translate "FORM.LABELS.EMPLOYEE_NAME"}} : {{ employee.display_name }}
+ {{translate "FORM.LABELS.REFERENCE"}} : {{ employee.reference }}
+ {{translate "FORM.LABELS.REGISTRATION_NUMBER"}} : {{ employee.code }}
+
{{translate balanceCreditorText}} = {{debcred (multiply ./creditorAggregates.balance exchangeRate) currencyId}}
- {{#unless isEnterpriseCurrency}}
-
-
{{translate "REPORT.REPORT_ACCOUNTS.WARN_CURRENCY"}}
-
- {{/unless}}
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId date=dateExchangeRate}}
{{#if includeMedicalCare }}
@@ -30,8 +27,8 @@
{{translate "TABLE.COLUMNS.TOTAL_MEDICAL_CARE_EMPLOYEE"}} = {{debcred (multiply ./debtorAggregates.balance exchangeRate) currencyId}}
- {{/if}}
+ {{/if}}
{{#if includeMedicalCare }}
diff --git a/server/controllers/finance/reports/financial.employee.js b/server/controllers/finance/reports/financial.employee.js
index 28a0260358..f8fd06dec6 100644
--- a/server/controllers/finance/reports/financial.employee.js
+++ b/server/controllers/finance/reports/financial.employee.js
@@ -56,8 +56,7 @@ async function build(req, res, next) {
const data = {};
- data.currencyId = options.currency_id;
- data.isEnterpriseCurrency = req.session.enterprise.currency_id === Number(options.currency_id);
+ const currencyId = Number(options.currency_id);
const sql = `
SELECT BUID(p.debtor_uuid) as debtor_uuid
@@ -70,12 +69,14 @@ async function build(req, res, next) {
db.one(sql, db.bid(options.employee_uuid)),
Exchange.getExchangeRate(
req.session.enterprise.id,
- Number(options.currency_id),
+ currencyId,
dateExchangeRate,
),
]);
+ data.currencyId = currencyId;
data.exchangeRate = exchange.rate || 1;
+ data.dateExchangeRate = dateExchangeRate;
// get debtor/creditor information
const [creditorOperations, debtorOperations] = await Promise.all([
diff --git a/server/controllers/finance/reports/monthly_balance/index.js b/server/controllers/finance/reports/monthly_balance/index.js
index e74b29d9ce..24905d4e51 100644
--- a/server/controllers/finance/reports/monthly_balance/index.js
+++ b/server/controllers/finance/reports/monthly_balance/index.js
@@ -3,10 +3,10 @@ const Tree = require('@ima-worldhealth/tree');
const db = require('../../../../lib/db');
const util = require('../../../../lib/util');
-const ReportManager = require('../../../../lib/ReportManager');
+const fiscal = require('../../fiscal');
const Exchange = require('../../../finance/exchange');
-const fiscal = require('../../fiscal');
+const ReportManager = require('../../../../lib/ReportManager');
const TEMPLATE = './server/controllers/finance/reports/monthly_balance/report.handlebars';
@@ -24,12 +24,14 @@ const DECIMAL_PRECISION = 2; // ex: 12.4567 => 12.46
*/
async function reporting(opts, session) {
const params = opts;
+ const { enterprise } = session;
+ const currencyId = Number(opts.currencyId);
params.allAccount = parseInt(params.allAccount, 10);
const accountNumber = params.allAccount ? `` : params.accountNumber;
const accountLabel = params.allAccount ? `` : params.accountLabel;
- const enterpriseId = session.enterprise.id;
+ const enterpriseId = enterprise.id;
const exchangeRate = await Exchange.getExchangeRate(enterpriseId, params.currencyId, new Date());
const rate = exchangeRate.rate || 1;
@@ -112,10 +114,11 @@ async function reporting(opts, session) {
dateFrom : range.dateFrom,
dateTo : range.dateTo,
periodLabel : params.periodLabel,
- currencyId : params.currencyId,
accountLabel,
accountNumber,
allAccount : params.allAccount,
+ currencyId,
+ exchangeRate : rate,
};
formatData(context.exploitation, context.totalExploitation, DECIMAL_PRECISION);
diff --git a/server/controllers/finance/reports/monthly_balance/report.handlebars b/server/controllers/finance/reports/monthly_balance/report.handlebars
index 08c01b07f0..b50a9088e7 100644
--- a/server/controllers/finance/reports/monthly_balance/report.handlebars
+++ b/server/controllers/finance/reports/monthly_balance/report.handlebars
@@ -13,6 +13,8 @@
{{this.accountNumber}}: {{this.accountLabel}}
{{/if}}
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId}}
+
{{translate 'FORM.LABELS.ACCOUNT_NUMBER'}} |
diff --git a/server/controllers/finance/reports/reportAccounts/index.js b/server/controllers/finance/reports/reportAccounts/index.js
index faeeb5e1b6..70d661a85e 100644
--- a/server/controllers/finance/reports/reportAccounts/index.js
+++ b/server/controllers/finance/reports/reportAccounts/index.js
@@ -27,7 +27,7 @@ function document(req, res, next) {
const params = req.query;
params.user = req.session.user;
params.enterprise_id = req.session.enterprise.id;
- params.isEnterpriseCurrency = (req.session.enterprise.currency_id === Number(params.currency_id));
+ params.isEnterpriseCurrency = req.session.enterprise.currency_id === Number(params.currency_id);
params.includeUnpostedValues = params.includeUnpostedValues ? Number(params.includeUnpostedValues) : 0;
try {
diff --git a/server/controllers/finance/reports/unpaid_invoice_payments/index.js b/server/controllers/finance/reports/unpaid_invoice_payments/index.js
index 7288cdf1bf..92a50c647b 100644
--- a/server/controllers/finance/reports/unpaid_invoice_payments/index.js
+++ b/server/controllers/finance/reports/unpaid_invoice_payments/index.js
@@ -1,7 +1,10 @@
const _ = require('lodash');
-const ReportManager = require('../../../../lib/ReportManager');
const db = require('../../../../lib/db');
const util = require('../../../../lib/util');
+const Exchange = require('../../exchange');
+
+const ReportManager = require('../../../../lib/ReportManager');
+
// path to the template to render
const TEMPLATE = './server/controllers/finance/reports/unpaid_invoice_payments/report.handlebars';
@@ -14,12 +17,14 @@ exports.document = build;
exports.reporting = reporting;
async function build(req, res, next) {
+ const { dateTo } = req.query;
+ const { enterprise } = req.session;
+ const currencyId = Number(req.query.currencyId);
+
const qs = _.extend(req.query, DEFAULT_OPTIONS);
const metadata = _.clone(req.session);
- qs.isEnterpriseCurrency = !!(parseInt(qs.currencyId, 10) === metadata.enterprise.currency_id);
-
let report;
let results;
@@ -50,6 +55,12 @@ async function build(req, res, next) {
const data = _.extend({}, qs, results);
+ const exchangeRate = await Exchange.getExchangeRate(enterprise.id, currencyId, new Date(dateTo));
+
+ data.dateTo = dateTo;
+ data.currencyId = currencyId;
+ data.exchangeRate = exchangeRate.rate || 1;
+
const compiled = await report.render(data);
res.set(compiled.headers).send(compiled.report);
}
diff --git a/server/controllers/finance/reports/unpaid_invoice_payments/report.handlebars b/server/controllers/finance/reports/unpaid_invoice_payments/report.handlebars
index cf88e41924..5a2a3c0355 100644
--- a/server/controllers/finance/reports/unpaid_invoice_payments/report.handlebars
+++ b/server/controllers/finance/reports/unpaid_invoice_payments/report.handlebars
@@ -21,11 +21,7 @@
{{date dateFrom "DD/MM/YYYY"}} - {{date dateTo "DD/MM/YYYY"}}
- {{#unless isEnterpriseCurrency}}
-
-
{{translate "REPORT.REPORT_ACCOUNTS.WARN_CURRENCY"}}
-
- {{/unless}}
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId date=dateTo}}
+
{{/if}}
-
-
{{#if includeServiceExit}}
@@ -118,10 +111,9 @@
{{translate 'STOCK.NO_DATA'}} |
{{/if}}
+
{{/if}}
-
-
{{#if includeGroupedServiceExit}}
@@ -172,10 +164,9 @@
{{translate 'STOCK.NO_DATA'}} |
{{/if}}
+
{{/if}}
-
-
{{#if includeDepotExit}}
@@ -217,10 +208,9 @@
{{translate 'STOCK.NO_DATA'}} |
{{/if}}
+
{{/if}}
-
-
{{#if includeLossExit}}
@@ -262,10 +252,9 @@
{{translate 'STOCK.NO_DATA'}} |
{{/if}}
+
{{/if}}
-
-
{{#if includeAggregateConsumption}}
@@ -307,10 +296,9 @@
{{translate 'STOCK.NO_DATA'}} |
{{/if}}
+
{{/if}}
-
-
*{{translate 'STOCK.STOCK_COST_DESCRIPTION'}}
*{{translate 'STOCK.STOCK_UNIT_COST_ROUNDED'}}
diff --git a/server/controllers/stock/reports/stock_expiration_report.handlebars b/server/controllers/stock/reports/stock_expiration_report.handlebars
index 833de399ba..54348dacc7 100644
--- a/server/controllers/stock/reports/stock_expiration_report.handlebars
+++ b/server/controllers/stock/reports/stock_expiration_report.handlebars
@@ -16,7 +16,7 @@
margin-bottom: 5px;
}
.card .value {
- font-size: 3em;
+ font-size: 2em;
}
@@ -29,15 +29,11 @@
{{depot.text}}
{{/if}}
-
+
{{date today}}
-
+
- {{#unless isEnterpriseCurrency}}
-
-
{{translate "REPORT.REPORT_ACCOUNTS.WARN_CURRENCY"}}
-
- {{/unless}}
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId}}
diff --git a/server/controllers/stock/reports/stock_lost_stock.report.handlebars b/server/controllers/stock/reports/stock_lost_stock.report.handlebars
index 08ceb5d5f4..e455546195 100644
--- a/server/controllers/stock/reports/stock_lost_stock.report.handlebars
+++ b/server/controllers/stock/reports/stock_lost_stock.report.handlebars
@@ -13,12 +13,12 @@
{{date dateFrom}} - {{date dateTo}}
-
+
{{#if isDestDepot}}{{translate 'REPORT.LOST_STOCK_REPORT.DESTINATION_DEPOT'}}: {{depotName}}{{/if}}
{{#if isSrcDepot}}{{translate 'REPORT.LOST_STOCK_REPORT.SOURCE_DEPOT'}}: {{depotName}}{{/if}}
-
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId}}
diff --git a/server/controllers/stock/reports/stock_sheet.report.handlebars b/server/controllers/stock/reports/stock_sheet.report.handlebars
index 5e466cff4d..5901685f7b 100644
--- a/server/controllers/stock/reports/stock_sheet.report.handlebars
+++ b/server/controllers/stock/reports/stock_sheet.report.handlebars
@@ -23,13 +23,7 @@
{{#if dateTo}}{{date dateTo}}{{/if}}
-
-
- {{#unless isEnterpriseCurrency}}
-
-
{{translate "REPORT.REPORT_ACCOUNTS.WARN_CURRENCY"}}
-
- {{/unless}}
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId}}
diff --git a/server/controllers/stock/reports/stock_value.report.handlebars b/server/controllers/stock/reports/stock_value.report.handlebars
index 072add49e8..1af976bbcc 100644
--- a/server/controllers/stock/reports/stock_value.report.handlebars
+++ b/server/controllers/stock/reports/stock_value.report.handlebars
@@ -21,7 +21,7 @@
{{date dateTo}}
-
+ {{> exchangeRate rate=exchangeRate currencyId=currencyId}}
diff --git a/server/lib/template/helpers/math.js b/server/lib/template/helpers/math.js
index 4a528b97a4..2726d51a74 100644
--- a/server/lib/template/helpers/math.js
+++ b/server/lib/template/helpers/math.js
@@ -2,7 +2,7 @@ function add(a, b) {
return a + b;
}
-function substract(a, b) {
+function subtract(a, b) {
return a - b;
}
@@ -10,6 +10,10 @@ function multiply(a, b) {
return (a * b) || 0;
}
+function divide(a, b) {
+ return (a / b) || 0;
+}
+
/**
* @function sum
* @desc This function is responsible to calculate the sum of an array given
@@ -37,6 +41,7 @@ function sum(array, column, ponderation) {
}
exports.multiply = multiply;
+exports.divide = divide;
exports.add = add;
exports.sum = sum;
-exports.substract = substract;
+exports.subtract = subtract;
diff --git a/server/lib/template/index.js b/server/lib/template/index.js
index 4180f56602..376c8849bf 100644
--- a/server/lib/template/index.js
+++ b/server/lib/template/index.js
@@ -30,9 +30,10 @@ const hbs = exphbs.create({
timestamp : dates.timestamp,
age : dates.age,
multiply : math.multiply,
+ divide : math.divide,
sum : math.sum,
add : math.add,
- substract : math.substract,
+ subtract : math.subtract,
currency : finance.currency,
numberToText : finance.numberToText,
indentAccount : finance.indentAccount,
diff --git a/server/lib/template/partials/exchangeRate.handlebars b/server/lib/template/partials/exchangeRate.handlebars
index d5f96544d1..9e39d3d1a2 100644
--- a/server/lib/template/partials/exchangeRate.handlebars
+++ b/server/lib/template/partials/exchangeRate.handlebars
@@ -1,7 +1,18 @@
+{{#equal currencyId metadata.enterprise.currency_id}}
+{{else}}
- {{#if this.lastRateUsed}}
- {{translate 'EXCHANGE.EXCHANGE_RATES'}} :
- {{currency 1 this.firstCurrency}} = {{currency this.lastRateUsed this.secondCurrency}}
- ({{translate 'EXCHANGE.AT_THE_DATE'}} {{date this.dateTo}})
+ {{#gt rate 1}}
+ {{translate 'FORM.LABELS.EXCHANGE_RATE'}}: {{currency rate currencyId 4}}
+ {{translate 'FORM.INFO.PER'}} {{currency 1 metadata.enterprise.currency_id 0}}
+ {{else}}
+ {{translate 'FORM.LABELS.EXCHANGE_RATE'}}: {{currency (divide 1 rate) metadata.enterprise.currency_id 4}}
+ {{translate 'FORM.INFO.PER'}} {{currency 1 currencyId 0}}
+ {{/gt}}
+ {{#if date}}
+ ({{translate 'EXCHANGE.AT_THE_DATE'}} {{date date}})
{{/if}}
-
\ No newline at end of file
+
+
+
{{translate "REPORT.REPORT_ACCOUNTS.WARN_CURRENCY"}}
+
+{{/equal}}
\ No newline at end of file