Files
carvalho-finances/apps/web/src/stores/dashboard.ts
T
Mlcavalho1andClaude Sonnet 4.6 2b8524dcde feat: #44 fatura de cartão com data futura fica pendente até confirmação
- Nova tabela pending_bill_imports (migration 016)
- ImportHandler.Confirm: quando is_credit_card=true e payment_date > hoje,
  salva como pending em vez de inserir transações
- Novos endpoints: GET /pending-bills, POST /pending-bills/:id/confirm,
  DELETE /pending-bills/:id
- Dashboard inclui pending_bill_imports no payload
- Frontend: resultado "fatura salva como pendente" no ImportView
- AccountsView exibe widget de faturas pendentes com ações de confirmar/descartar
- dashboard_test: mock de PendingBillRepo + TransactionRepository

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-28 22:26:42 -03:00

79 lines
1.7 KiB
TypeScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { api } from '@/services/api'
import type { CreditBill } from './accounts'
export interface CategoryTotal {
category_id: number | null
category_name: string
color: string
total: number
}
export interface MonthEvolution {
month: string
income: number
expenses: number
saved: number
}
export interface RecentTransaction {
id: number
date: string
description: string
category_name: string
amount: number
type: 'income' | 'expense'
}
export interface PendingIncome {
id: number
name: string
expected_amount: number
day_of_month: number
late: boolean
}
export interface PendingBillImport {
id: number
filename: string
payment_date: string
total: number
created_at: string
}
export interface DashboardData {
month: string
total_income: number
total_expenses: number
savings_pct: number
total_patrimony: number
by_category: CategoryTotal[]
monthly_evolution: MonthEvolution[]
recent_transactions: RecentTransaction[]
pending_recurring: number
pending_income_recurrings: PendingIncome[]
current_bills: CreditBill[]
pending_bill_imports: PendingBillImport[]
}
export const useDashboardStore = defineStore('dashboard', () => {
const data = ref<DashboardData | null>(null)
const loading = ref(false)
const error = ref<string | null>(null)
async function fetch(month: string) {
loading.value = true
error.value = null
try {
data.value = await api.get<DashboardData>(`/dashboard?month=${month}`)
} catch (e: any) {
error.value = e.message
} finally {
loading.value = false
}
}
return { data, loading, error, fetch }
})