Skip to content

Commit b29e0b5

Browse files
authored
Merge pull request #647 from AOEpeople/feature/272818_balancing-an-account
Balancing an account to the cent
2 parents 281aa7e + bdc4d6b commit b29e0b5

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
lines changed

src/Resources/src/components/balance/TransactionPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class="w-[300px] p-2 text-center align-middle sm:w-[420px]"
1212
>
1313
<div class="mb-8 flex justify-center gap-1">
14-
<h5 class="m-0 self-center text-[14px] text-black sm:text-[18px]">{{ t('balance.amount') }}:</h5>
14+
<h5 class="m-0 self-center text-[14px] text-black sm:text-[18px]">{{ t('balance.amount') }}:</h5>
1515
<MoneyInput v-model="amountFieldValue" />
1616
</div>
1717
<div

src/Resources/src/components/costs/CashPaymentPanel.vue

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
<template>
22
<form
3-
class="w-[300px] p-4 sm:w-[400px]"
3+
class="flex w-[300px] flex-col p-4 sm:w-[400px]"
44
@submit.prevent="onSubmit"
55
>
66
<h3 class="w-full text-center">
77
{{ t('costs.payment').replace('#name#', getFullNameByUser(username)) }}
88
</h3>
9-
<InputLabel
10-
v-model="amount"
11-
:type="'number'"
12-
:min="1"
13-
:required="true"
14-
/>
9+
<MoneyInput v-model="amount" />
1510
<SubmitButton />
1611
</form>
1712
</template>
1813

1914
<script setup lang="ts">
2015
import { useI18n } from 'vue-i18n';
2116
import { useCosts } from '@/stores/costsStore';
22-
import InputLabel from '../misc/InputLabel.vue';
2317
import { ref } from 'vue';
2418
import SubmitButton from '../misc/SubmitButton.vue';
19+
import MoneyInput from '@/components/misc/MoneyInput.vue';
2520
2621
const { t } = useI18n();
2722
const { sendCashPayment, getFullNameByUser } = useCosts();
2823
29-
const amount = ref('1');
24+
const amount = ref(0);
3025
3126
const props = defineProps<{
3227
username: string;
@@ -35,7 +30,7 @@ const props = defineProps<{
3530
const emit = defineEmits(['closePanel']);
3631
3732
async function onSubmit() {
38-
const parsedAmount = parseFloat(amount.value);
33+
const parsedAmount = amount.value;
3934
if (parsedAmount > 0) {
4035
await sendCashPayment(props.username, parsedAmount);
4136
}

src/Resources/src/components/misc/MoneyInput.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313

1414
<script setup lang="ts">
1515
import { computed, ref } from 'vue';
16+
import { useI18n } from 'vue-i18n';
1617
1718
const props = defineProps<{
1819
modelValue: number;
1920
}>();
2021
22+
const { t } = useI18n();
2123
const emit = defineEmits(['update:modelValue']);
2224
const isFocused = ref(false);
2325
const rawValue = ref(props.modelValue.toString());
@@ -48,7 +50,9 @@ function round(value: number) {
4850
}
4951
5052
function formatMoney(value: number) {
51-
return value.toLocaleString('de-DE', {
53+
return value.toLocaleString(t('languageCode'), {
54+
style: 'currency',
55+
currency: 'EUR',
5256
minimumFractionDigits: 2,
5357
maximumFractionDigits: 2
5458
});

src/Resources/src/locales/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"languageCode": "de-DE",
23
"Friday": "Freitag",
34
"Monday": "Montag",
45
"Saturday": "Samstag",

src/Resources/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"languageCode": "en-US",
23
"Friday": "Friday",
34
"Monday": "Monday",
45
"Saturday": "Saturday",

src/Resources/tests/unit/misc/MoneyInput.spec.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import { describe, it, expect} from 'vitest';
1+
import { describe, it, expect, vi} from 'vitest';
22
import MoneyInput from '../../../src/components/misc/MoneyInput.vue';
33
import {mount} from '@vue/test-utils';
4+
5+
vi.mock('vue-i18n', () => ({
6+
useI18n: () => ({
7+
t: (key: string) => {
8+
if (key === 'languageCode') return 'de-DE';
9+
return key;
10+
},
11+
}),
12+
}));
13+
414
describe('Test MoneyInput', () => {
515
it('should input number and convert to money', async () => {
616
const wrapper = mount(MoneyInput, {
@@ -11,13 +21,13 @@ describe('Test MoneyInput', () => {
1121

1222
const input = wrapper.get('input');
1323

14-
expect((input.element as HTMLInputElement).value).toBe('1.234,57');
24+
expect((input.element as HTMLInputElement).value).toBe('1.234,57\u00A0€');
1525

1626
await input.trigger('focus');
1727
expect((input.element as HTMLInputElement).value).toBe('1234.567');
1828

1929
await input.trigger('blur');
20-
expect((input.element as HTMLInputElement).value).toBe('1.234,57');
30+
expect((input.element as HTMLInputElement).value).toBe('1.234,57\u00A0€');
2131
});
2232

2333
it('should input number with 30 cents and convert to money', async () => {
@@ -36,7 +46,7 @@ describe('Test MoneyInput', () => {
3646
expect((input.element as HTMLInputElement).value).toBe('12.3');
3747

3848
await input.trigger('blur');
39-
expect((input.element as HTMLInputElement).value).toBe('12,30');
49+
expect((input.element as HTMLInputElement).value).toBe('12,30\u00A0€');
4050
});
4151

4252
it('should input negative number and not convert to money', async () => {
@@ -56,6 +66,6 @@ describe('Test MoneyInput', () => {
5666
expect((input.element as HTMLInputElement).value).toBe('1234.5');
5767

5868
await input.trigger('blur');
59-
expect((input.element as HTMLInputElement).value).toBe('1.234,50');
69+
expect((input.element as HTMLInputElement).value).toBe('1.234,50\u00A0€');
6070
});
6171
});

0 commit comments

Comments
 (0)