diff --git a/src/config-schema.ts b/src/config-schema.ts index 090a18b..cd260a7 100644 --- a/src/config-schema.ts +++ b/src/config-schema.ts @@ -1,3 +1,12 @@ -export interface BillingConfig {} +import { Type } from '@openmrs/esm-framework'; -export const configSchema = {}; +export const configSchema = { + defaultCurrency: { + _type: Type.String, + _description: 'The default currency for the application. Specify the currency code (e.g., KES, UGX, GBP).', + _default: 'KES', + }, +}; +export interface ConfigObject { + defaultCurrency: string; +} \ No newline at end of file diff --git a/src/helpers/functions.ts b/src/helpers/functions.ts index 896f4e0..1370b41 100644 --- a/src/helpers/functions.ts +++ b/src/helpers/functions.ts @@ -1,4 +1,5 @@ import { type Payment, type LineItem } from '../types'; +import { configSchema } from '../config-schema'; // amount already paid export function calculateTotalAmountTendered(payments: Array) { @@ -32,9 +33,12 @@ export function calculateTotalAmount(lineItems: Array) { } export const convertToCurrency = (amountToConvert: number) => { - const formatter = new Intl.NumberFormat('en-KE', { + const locale = window.i18next?.language?.substring(0, 2) ?? ''; + const currencySymbol = configSchema.defaultCurrency._default; + + const formatter = new Intl.NumberFormat(locale, { style: 'currency', - currency: 'KES', + currency: currencySymbol, minimumFractionDigits: 2, });