diff --git a/apps/web/src/components/CurrencyInput.vue b/apps/web/src/components/CurrencyInput.vue new file mode 100644 index 0000000..02d5f4e --- /dev/null +++ b/apps/web/src/components/CurrencyInput.vue @@ -0,0 +1,95 @@ + + + + + diff --git a/apps/web/src/views/AccountsView.vue b/apps/web/src/views/AccountsView.vue index 50e4dbb..7a582f7 100644 --- a/apps/web/src/views/AccountsView.vue +++ b/apps/web/src/views/AccountsView.vue @@ -2,6 +2,7 @@ import { ref, onMounted } from 'vue' import { useAccountsStore, type AccountInput } from '@/stores/accounts' import NeonPanel from '@/components/NeonPanel.vue' +import CurrencyInput from '@/components/CurrencyInput.vue' const store = useAccountsStore() onMounted(() => store.fetchAll()) @@ -16,13 +17,8 @@ const typeLabels: Record = { const blank = (): AccountInput => ({ name: '', type: 'checking', initial_balance: 0, yield_type: 'none', closing_day: null, due_day: null }) const form = ref(blank()) const editId = ref(null) -const initialRaw = ref('') const formError = ref(null) -function parseAmount(s: string) { - return parseFloat(s.replace(/\./g, '').replace(',', '.')) || 0 -} - function startEdit(id: number) { const a = store.accounts.find((x) => x.id === id) if (!a) return @@ -33,7 +29,6 @@ function startEdit(id: number) { closing_day: a.closing_day ?? null, due_day: a.due_day ?? null, } - initialRaw.value = a.initial_balance.toLocaleString('pt-BR', { minimumFractionDigits: 2 }) formError.value = null } @@ -45,13 +40,11 @@ async function payBill(billId: number) { function cancelEdit() { editId.value = null form.value = blank() - initialRaw.value = '' formError.value = null } async function submit() { formError.value = null - form.value.initial_balance = parseAmount(initialRaw.value) try { if (editId.value !== null) { await store.update(editId.value, form.value) @@ -59,7 +52,6 @@ async function submit() { } else { await store.create(form.value) form.value = blank() - initialRaw.value = '' } } catch (e: any) { formError.value = e.message @@ -110,9 +102,8 @@ function totalBalance() { - diff --git a/apps/web/src/views/RecurringView.vue b/apps/web/src/views/RecurringView.vue index 4b8670e..c794436 100644 --- a/apps/web/src/views/RecurringView.vue +++ b/apps/web/src/views/RecurringView.vue @@ -3,6 +3,7 @@ import { ref, computed, onMounted } from 'vue' import { useRecurringStore } from '@/stores/recurring' import { useCategoriesStore } from '@/stores/categories' import NeonPanel from '@/components/NeonPanel.vue' +import CurrencyInput from '@/components/CurrencyInput.vue' const store = useRecurringStore() const catStore = useCategoriesStore() @@ -23,32 +24,24 @@ const blank = (): Omit(null) -const amountRaw = ref('') const formError = ref(null) -function parseAmount(s: string) { - return parseFloat(s.replace(/\./g, '').replace(',', '.')) || 0 -} - function startEdit(id: number) { const item = store.items.find((x) => x.id === id) if (!item) return editId.value = id form.value = { name: item.name, expected_amount: item.expected_amount, day_of_month: item.day_of_month, category_id: item.category_id, type: item.type } - amountRaw.value = item.expected_amount.toLocaleString('pt-BR', { minimumFractionDigits: 2 }) formError.value = null } function cancelEdit() { editId.value = null form.value = blank() - amountRaw.value = '' formError.value = null } async function submit() { formError.value = null - form.value.expected_amount = parseAmount(amountRaw.value) try { if (editId.value !== null) { await store.update(editId.value, form.value) @@ -56,7 +49,6 @@ async function submit() { } else { await store.create(form.value) form.value = blank() - amountRaw.value = '' } await store.fetchMonthlyStatus(currentMonth.value) } catch (e: any) { @@ -103,7 +95,7 @@ function getStatus(id: number) { - + Dia diff --git a/apps/web/src/views/TransactionsView.vue b/apps/web/src/views/TransactionsView.vue index 30c14b8..fdb62ec 100644 --- a/apps/web/src/views/TransactionsView.vue +++ b/apps/web/src/views/TransactionsView.vue @@ -5,6 +5,7 @@ import { useCategoriesStore } from '@/stores/categories' import { useAccountsStore } from '@/stores/accounts' import NeonPanel from '@/components/NeonPanel.vue' import MonthSwitcher from '@/components/MonthSwitcher.vue' +import CurrencyInput from '@/components/CurrencyInput.vue' const store = useTransactionsStore() const catStore = useCategoriesStore() @@ -37,31 +38,23 @@ const blank = (): TransactionInput => ({ const form = ref(blank()) const editId = ref(null) const formError = ref(null) -const amountRaw = ref('') - -function parseAmount(s: string): number { - return parseFloat(s.replace(/\./g, '').replace(',', '.')) || 0 -} function startEdit(id: number) { const t = store.transactions.find((x) => x.id === id) if (!t || t.source !== 'manual') return editId.value = id form.value = { date: t.date, amount: t.amount, description: t.description, type: t.type as any, category_id: t.category_id, account_id: t.account_id } - amountRaw.value = t.amount.toLocaleString('pt-BR', { minimumFractionDigits: 2 }) formError.value = null } function cancelEdit() { editId.value = null form.value = blank() - amountRaw.value = '' formError.value = null } async function submit() { formError.value = null - form.value.amount = parseAmount(amountRaw.value) try { if (editId.value !== null) { await store.update(editId.value, form.value) @@ -69,7 +62,6 @@ async function submit() { } else { await store.create(form.value) form.value = blank() - amountRaw.value = '' } } catch (e: any) { formError.value = e.message @@ -117,9 +109,8 @@ function monthLabel(ym: string) { Gasto Receita -