feat: Improve currency conversion logic in BillingManager to handle multiple currencies and enhance accuracy in RUB calculations
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 6m11s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 6m11s
This commit is contained in:
@@ -292,8 +292,18 @@ function BillingManager() {
|
|||||||
|
|
||||||
function convertToRUB(amount, currency) {
|
function convertToRUB(amount, currency) {
|
||||||
if (!amount) return 0;
|
if (!amount) return 0;
|
||||||
const rate = exchangeRates[currency] || 1;
|
// Курсы получены с базой USD (1 USD = rates[CCY])
|
||||||
return amount * rate * exchangeRates.RUB;
|
const rubPerUsd = Number(exchangeRates.RUB) || 1;
|
||||||
|
if (!currency || currency === 'RUB') return amount; // уже в рублях
|
||||||
|
if (currency === 'USD') return amount * rubPerUsd;
|
||||||
|
const ccyPerUsd = Number(exchangeRates[currency]);
|
||||||
|
if (!ccyPerUsd || ccyPerUsd === 0) {
|
||||||
|
// нет курса — возвращаем как есть
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
// amount в валюте CCY -> USD -> RUB
|
||||||
|
const amountUsd = amount / ccyPerUsd;
|
||||||
|
return amountUsd * rubPerUsd;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatCurrencyInRUB(amount, currency) {
|
function formatCurrencyInRUB(amount, currency) {
|
||||||
|
|||||||
Reference in New Issue
Block a user