Files
carvalho-finances/apps/api/internal/migration/sql/011_credit_bills.sql
T
Mlcavalho1andClaude Sonnet 4.6 e3b3433703 feat(#37): módulo de cartão de crédito com faturas mensais
- Migration 011: closing_day/due_day em accounts + tabela credit_bills
- CreditBillService: cria/atualiza fatura corrente on-demand no GET /accounts
- Widget FATURA ATUAL no dashboard com total e botão PAGAR
- AccountsView: campos closing_day/due_day para contas credit + painel fatura
- Dashboard: current_bills lista faturas não pagas de todos os cartões

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-05-27 15:12:53 -03:00

20 lines
923 B
SQL

-- Credit card billing period configuration per account
ALTER TABLE accounts
ADD COLUMN IF NOT EXISTS closing_day INTEGER CHECK (closing_day BETWEEN 1 AND 28),
ADD COLUMN IF NOT EXISTS due_day INTEGER CHECK (due_day BETWEEN 1 AND 28);
-- Materialized bill metadata (calculated from transactions)
-- One row per (account, billing period start date)
CREATE TABLE IF NOT EXISTS credit_bills (
id SERIAL PRIMARY KEY,
account_id INTEGER NOT NULL REFERENCES accounts(id) ON DELETE CASCADE,
period_start DATE NOT NULL,
period_end DATE NOT NULL,
due_date DATE NOT NULL,
paid BOOLEAN NOT NULL DEFAULT FALSE,
paid_at TIMESTAMP WITH TIME ZONE,
payment_account_id INTEGER REFERENCES accounts(id) ON DELETE SET NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
UNIQUE(account_id, period_start)
);