Skip to content

Commit

Permalink
O3-2778 Add config for different currency types (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
CynthiaKamau authored Feb 8, 2024
1 parent b92b8c2 commit 06e71d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/config-schema.ts
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 6 additions & 2 deletions src/helpers/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Payment, type LineItem } from '../types';
import { configSchema } from '../config-schema';

// amount already paid
export function calculateTotalAmountTendered(payments: Array<Payment>) {
Expand Down Expand Up @@ -32,9 +33,12 @@ export function calculateTotalAmount(lineItems: Array<LineItem>) {
}

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,
});

Expand Down

0 comments on commit 06e71d4

Please sign in to comment.