Phase 1: Financial audit logging foundation

- Add FinancialAuditLog model to track all financial changes
- Log action (CREATE, UPDATE, DELETE) with before/after values
- Capture who made changes (IP address)
- Record timestamp and reason for change
- Create /admin/financial-audit page to view audit trail
- Add filtering by entity type, action, date range
- Show summary stats (total changes, deletions, etc)
- Integrate with purchases: log create and delete operations
- Red-flag deletions for security awareness
- Add "Financial audit trail" link to admin menu

This provides foundation for Phase 2 (reporting UI) and Phase 3 (bank reconciliation).
All financial changes are now traceable and auditable for compliance.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-17 15:23:05 +01:00
co-authored by Claude Haiku 4.5
parent e69759081c
commit d56f942a88
5 changed files with 386 additions and 1 deletions
+13
View File
@@ -404,3 +404,16 @@ model CustomerLoginLog {
userAgent String?
success Boolean @default(true) // false for failed login attempts
}
// Audit log for financial transactions — tracks all changes to financial data
model FinancialAuditLog {
id String @id @default(cuid())
action String // CREATE, UPDATE, DELETE
entityType String // "ORDER", "MANUAL_SALE", "PURCHASE", "EXPENSE"
entityId String // ID of the order/sale/purchase/expense
changes String // JSON: {field: {old: X, new: Y}, ...}
amount Int? // cents, for quick filtering of high-value changes
changedAt DateTime @default(now())
changedBy String? // "SYSTEM" or IP address if admin
reason String? // why was this changed
}