Multi-Currency & Future Extensibility
While the Kloyst Pricing Engine operates natively in Indian Rupees (INR) for its standard launch, the database models and services have been designed to easily support multi-currency calculations and exchange rate adjustments in the future.
🛠️ Multi-Currency Database Foundation
All pricing tables include currency fields to support future international expansion:
model PricingRate {
id String @id @default(uuid()) @db.Uuid
category TemplateCategory
regionGroup String @db.VarChar(100)
ratePerUnit Decimal @db.Decimal(12, 6)
currency String @default("INR") @db.VarChar(10) // e.g. "USD", "EUR"
// ... other fields
}
model Quotation {
id String @id @default(uuid()) @db.Uuid
quoteNumber String @unique @db.VarChar(50)
estimatedMetaCost Decimal @db.Decimal(12, 4)
platformFee Decimal @db.Decimal(12, 4)
estimatedTotal Decimal @db.Decimal(12, 4)
currency String @default("INR") @db.VarChar(10) // e.g. "USD"
// ... other fields
}
🚀 Future Currency Converter Integration
To support multiple currencies, the calculation pipeline can be extended with an exchange rate conversion step:
@Injectable()
export class CurrencyConverterService {
/**
* Converts a value from one currency to another using active exchange rates.
* Rates can be fetched from a third-party API or cached database table.
*/
async convert(
amount: Prisma.Decimal,
from: string,
to: string,
): Promise<Prisma.Decimal> {
if (from === to) return amount;
// 1. Fetch exchange rate (e.g. INR_USD)
const rate = await this.getExchangeRate(from, to);
// 2. Convert and return
return amount.mul(rate);
}
}
🔒 Freezing Exchange Rates in Snapshots
To prevent changes in exchange rates from modifying generated quotations, currency conversion rates are frozen in the immutable quotation snapshot:
const assumptions = {
pricingModel: "PER_MESSAGE",
baseCurrency: "INR",
targetCurrency: "USD",
exchangeRateSnapshot: {
pair: "USD_INR",
rate: "83.4500",
fetchedAt: new Date().toISOString()
}
};