feat(#19): registro manual de transações e recorrências fixas

Adiciona CRUD manual de transações (income/expense) com filtro mensal, CRUD de
recorrências fixas com verificação mensal de cobertura (±10% por categoria),
endpoint de ignore/unignore e telas Vue para Transações e Configurações.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
2026-05-26 20:26:48 -03:00
co-authored by Claude Sonnet 4.6
parent 83dff2de78
commit 12e8500827
17 changed files with 1351 additions and 8 deletions
+81
View File
@@ -0,0 +1,81 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { api } from '@/services/api'
import type { Category } from './categories'
export interface RecurringExpense {
id: number
name: string
expected_amount: number
day_of_month: number
category_id: number | null
active: boolean
created_at: string
updated_at: string
}
export interface RecurringStatus extends RecurringExpense {
covered: boolean
ignored: boolean
reason?: string
}
export const useRecurringStore = defineStore('recurring', () => {
const items = ref<RecurringExpense[]>([])
const monthlyStatus = ref<RecurringStatus[]>([])
const loading = ref(false)
const error = ref<string | null>(null)
async function fetchAll() {
loading.value = true
error.value = null
try {
items.value = await api.get<RecurringExpense[]>('/recurring')
} catch (e: any) {
error.value = e.message
} finally {
loading.value = false
}
}
async function fetchMonthlyStatus(month: string) {
try {
monthlyStatus.value = await api.get<RecurringStatus[]>(`/recurring/status?month=${month}`)
} catch {
monthlyStatus.value = []
}
}
async function create(input: Omit<RecurringExpense, 'id' | 'active' | 'created_at' | 'updated_at'>) {
const item = await api.post<RecurringExpense>('/recurring', input)
items.value.push(item)
return item
}
async function update(id: number, input: Omit<RecurringExpense, 'id' | 'active' | 'created_at' | 'updated_at'>) {
const item = await api.put<RecurringExpense>(`/recurring/${id}`, input)
const idx = items.value.findIndex((x) => x.id === id)
if (idx !== -1) items.value[idx] = item
return item
}
async function remove(id: number) {
await api.delete(`/recurring/${id}`)
items.value = items.value.filter((x) => x.id !== id)
}
async function ignore(id: number, month: string, reason: string) {
await api.post(`/recurring/${id}/ignore`, { month, reason })
await fetchMonthlyStatus(month)
}
async function unignore(id: number, month: string) {
await api.delete(`/recurring/${id}/ignore?month=${month}`)
await fetchMonthlyStatus(month)
}
const pendingCount = (month: string) =>
monthlyStatus.value.filter((s) => !s.covered).length
return { items, monthlyStatus, loading, error, fetchAll, fetchMonthlyStatus, create, update, remove, ignore, unignore, pendingCount }
})
+62
View File
@@ -0,0 +1,62 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { api } from '@/services/api'
export interface Transaction {
id: number
date: string
amount: number
description: string
type: 'income' | 'expense'
source: 'manual' | 'import'
category_id: number | null
created_at: string
updated_at: string
}
export interface TransactionInput {
date: string
amount: number
description: string
type: 'income' | 'expense'
category_id: number | null
}
export const useTransactionsStore = defineStore('transactions', () => {
const transactions = ref<Transaction[]>([])
const loading = ref(false)
const error = ref<string | null>(null)
async function fetchAll(month?: string) {
loading.value = true
error.value = null
try {
const q = month ? `?month=${month}` : ''
transactions.value = await api.get<Transaction[]>(`/transactions${q}`)
} catch (e: any) {
error.value = e.message
} finally {
loading.value = false
}
}
async function create(input: TransactionInput) {
const t = await api.post<Transaction>('/transactions', input)
transactions.value.unshift(t)
return t
}
async function update(id: number, input: TransactionInput) {
const t = await api.put<Transaction>(`/transactions/${id}`, input)
const idx = transactions.value.findIndex((x) => x.id === id)
if (idx !== -1) transactions.value[idx] = t
return t
}
async function remove(id: number) {
await api.delete(`/transactions/${id}`)
transactions.value = transactions.value.filter((x) => x.id !== id)
}
return { transactions, loading, error, fetchAll, create, update, remove }
})