Skip to content

Commit

Permalink
make currency dependent on the organization setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Onatcer committed Apr 26, 2024
1 parent 212ee27 commit 42ad5e0
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions resources/js/utils/money.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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();
}

0 comments on commit 42ad5e0

Please sign in to comment.