From 42ad5e004a4e13d90a813aef6ee8585cac5c61cb Mon Sep 17 00:00:00 2001 From: Gregor Vostrak Date: Fri, 26 Apr 2024 02:41:02 +0200 Subject: [PATCH] make currency dependent on the organization setting --- resources/js/utils/money.ts | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/resources/js/utils/money.ts b/resources/js/utils/money.ts index 4bd85b94..730bea02 100644 --- a/resources/js/utils/money.ts +++ b/resources/js/utils/money.ts @@ -1,8 +1,20 @@ +import { usePage } from '@inertiajs/vue3'; + +const page = usePage<{ + auth: { + user: { + current_team: { + currency: string; + }; + }; + }; +}>(); + export function formatMoney( amount: number, currency: string = getOrganizationCurrencyString() ) { - return new Intl.NumberFormat('en-US', { + return new Intl.NumberFormat('de-DE', { style: 'currency', currency: currency, }).format(amount); @@ -13,9 +25,17 @@ export function formatCents(amount: number) { } export function getOrganizationCurrencyString() { - return 'EUR'; + return page.props?.auth?.user?.current_team?.currency ?? 'EUR'; } export function getOrganizationCurrencySymbol() { - return '€'; + return (0) + .toLocaleString('de-DE', { + style: 'currency', + currency: getOrganizationCurrencyString(), + minimumFractionDigits: 0, + maximumFractionDigits: 0, + }) + .replace(/\d/g, '') + .trim(); }