05 — Core Financial Operations: AP, AR, Cash, Reimbursement & Accounting
Domain: Transactional finance modules, payment processing, bank reconciliation Dependencies: 01-Data (schema), 03-ELT (connectors), 04-Security (RBAC, audit) Outputs: Feature specifications, API contracts, workflow diagrams, business rules
ROLE
You are a Senior Financial Systems Architect with deep expertise in Brazilian and US accounting systems, payment processing (Pix/Boleto/ACH/Wire), bank reconciliation, NF-e integration, and multi-currency transaction management. You design systems that accountants and controllers trust for month-end close.
OBJECTIVE
Design the complete specification for the five core financial operations modules, migrating and enhancing the existing Avivatec modules (F-006 through F-011) from Angular/.NET/SQL Server to the AI-first stack while preserving all existing user story functionality and adding AI-powered automation.
DELIVERABLES
D1. Accounts Payable (F-007 Enhanced)
Transaction Lifecycle:
Document Capture → AI Categorization → Approval Workflow → Scheduling → Payment → Reconciliation
Requirements:
- Multi-currency expense entry with live FX rates (PTAX for BRL, ECB for EUR)
- AI-powered document ingestion: PDF, email forward, mobile photo, NF-e XML
- SEFAZ NF-e automatic import via e-CNPJ certificate (Brazil)
- Invoice matching: 2-way (PO + invoice) and 3-way (PO + receipt + invoice)
- Payment method routing: Boleto, Pix, TED/DOC (BR) / ACH, Wire, Check (US)
- Installment scheduling with CDI/SELIC interest and early-payment discount
- Approval workflows: amount-based thresholds, separation of duties
- AP aging reports (30/60/90/120 days) with payment priority scoring
- Vendor master with spend analytics and duplicate detection
- Tax withholding calculation: ISS, IRRF, PIS/COFINS (BR) / 1099 tracking (US)
API Endpoints:
POST /ap/invoices— Create with optional OCR attachmentPATCH /ap/invoices/{id}/approve— Approval with OpenFGA checkPOST /ap/invoices/{id}/schedule-payment— Schedule with method selectionGET /ap/aging— Aging report with filters (entity, vendor, currency, status)POST /ap/bulk-import— NF-e XML batch import
D2. Accounts Receivable (F-008 Enhanced)
Transaction Lifecycle:
Invoice Creation → Delivery → Collection Tracking → Payment Receipt → Reconciliation → Revenue Recognition
Requirements:
- Customer master data with CRM integration (Salesforce, HubSpot, Pipedrive)
- Recurring revenue contract management with auto-invoicing
- Payment processor integration: Stone, Cielo, Rede, PagSeguro (BR) + Stripe, Square (US)
- MDR rate comparison engine: expected vs. actual fees, savings identification
- Card receivables forecasting: receivable schedule projection by processor
- AI-powered collection priority scoring (payment history, aging, amount)
- Aging reports with collection probability and DSO metrics
- Revenue recognition engine: ASC 606 (US) / CPC 47 (Brazil)
- Dunning workflow: automated payment reminders (email, WhatsApp, SMS)
- Credit analysis: customer risk scoring based on payment behavior
API Endpoints:
POST /ar/invoices— Create invoice with line itemsGET /ar/receivables/schedule— Card receivables projectionGET /ar/mdr-comparison— MDR analysis by processorGET /ar/aging— Aging with collection probability scoresPOST /ar/dunning/{customer_id}— Trigger dunning sequence
D3. Cash & Bank Management (F-009 Enhanced)
Requirements:
- Multi-bank statement import: OFX, CSV, API (Open Finance Brasil, Plaid)
- Automated bank reconciliation with AI matching (target: 90%+ auto-match rate)
- Matching rules: exact amount, date proximity, description similarity, reference number
- Unmatched item queue with AI-suggested matches and confidence scores
- Duplicate detection with explainability ("Duplicate: same amount, date, vendor")
- Open Finance Brasil integration: real-time balance, transaction sync (BACEN-regulated)
- Plaid integration for US bank accounts
- Investment portfolio tracking: CDB, LCA/LCI, Tesouro Direto (BR) / Money market, T-bills (US)
- Loan and financing management with amortization schedules (SAC, Price, American)
- Cash position dashboard: real-time balances across all accounts
- Intercompany cash management with netting and settlement
- Cash flow forecasting integration (feeds into Sub-Prompt 06)
API Endpoints:
POST /bank/statements/import— Upload OFX/CSV or trigger API syncPOST /bank/reconciliation/auto— Run AI reconciliationGET /bank/cash-position— Real-time multi-account balanceGET /bank/investments— Portfolio summary with yieldsPOST /bank/intercompany/transfer— Intercompany with dual-entry
D4. Expense Reimbursement (F-010 Enhanced)
Requirements:
- Mobile-first receipt capture: camera → OCR → AI extraction (vendor, amount, date, category)
- Corporate card integration: automatic transaction import and matching
- Per-policy expense validation: daily limits, category restrictions, per diem rates
- Multi-level approval routing based on amount and category
- Mileage calculator with Google Maps integration
- Per diem rates by city (Brazil ANTT rates, US GSA rates)
- Tax deductibility flagging per category
- Integration with AP for reimbursement payment
- Employee expense analytics: spending patterns, policy compliance rate
- Receipt archival with OCR searchability (7-year retention)
D5. Accounting Integration (F-011 Enhanced)
Connector Specifications:
| System | Sync Direction | Data Scope | Frequency |
|---|---|---|---|
| Tactus | Bi-directional | GL, trial balance, DRE | Nightly |
| Conta Azul | Bi-directional | Transactions, contacts, categories | Real-time (webhook) |
| Omie | Bi-directional | NF-e, AP, AR, bank, products | Hourly |
| Domínio | Import only | Accounting export, fiscal books | On-demand |
| QuickBooks | Bi-directional | COA, journals, invoices, payments | Real-time (CDC) |
| Xero | Bi-directional | Same as QBO | Real-time (webhook) |
| NetSuite | Bi-directional | Full ERP scope | Hourly |
COA Normalization:
- Each ERP has different COA structure (flat vs. hierarchical, numbered vs. named)
- Platform maintains a unified COA with mapping tables per source
- dbt macros handle normalization (from Sub-Prompt 03)
- Manual override UI for unmapped accounts
D6. Period Close Workflow
Month-End Close Checklist (AI-assisted):
- Bank reconciliation completion (all accounts matched within tolerance)
- AP accrual verification (outstanding invoices accrued)
- AR revenue recognition (ASC 606 / CPC 47 calculations)
- Intercompany elimination entries
- FX revaluation (unrealized gains/losses)
- Depreciation posting
- Payroll accrual
- Trial balance review (AI anomaly check)
- Journal entry approval (separation of duties)
- Period lock (prevent backdated entries)
CONSTRAINTS
- All amounts as NUMERIC(19,4) — never floating point
- Every transaction creates audit trail entry (forwarded to immudb)
- Brazilian tax calculations must follow current SEFAZ/RFB rules
- Bank reconciliation must handle timezone differences (BR vs US banks)
- Payment scheduling must respect banking calendars (holidays, cutoff times)
- Multi-entity transactions must create balanced intercompany entries
RESEARCH QUESTIONS
- What is the optimal AI matching algorithm for bank reconciliation (rule-based + ML hybrid)?
- How should the MDR comparison engine handle different processor fee structures (flat, tiered, interchange-plus)?
- What is the best approach for NF-e XML ingestion at scale (1000+ NF-e/day for large tenants)?
- How to model Brazilian tax withholding (ISS, IRRF, PIS/COFINS) across municipal, state, and federal jurisdictions?
- What is the recommended revenue recognition engine architecture for ASC 606 compliance?