# TANRAIL ONE — Phase 3.3 Financial Security

## 1. Accounting Invariant Enforcement
The most critical security feature of the Financial Core is mathematical absolute truth.
- `FinancialService` uses a strict equality check (`bccomp($totalDebits, $totalCredits, 4) === 0`) before initiating the database insert.
- Any discrepancy instantly aborts the transaction.

## 2. Immutability
- **Journal**: No direct `update()` allowed. Only the system can transition status to `REVERSED`. `delete()` is completely blocked.
- **JournalEntry**: `update()` and `delete()` throw `RuntimeException` unconditionally. The ledger is append-only.

## 3. Data Isolation (Phase 2 Compliance)
- `Journal` models are constrained by `BusinessUnitScope`. A user authenticated into BU A can never retrieve, view, or modify journals from BU B.
- This prevents horizontal privilege escalation where an attacker tries to manipulate the finances of another BU.

## 4. Closed Period Protection
- Even an Administrator cannot post into a `FiscalPeriod` that has `is_closed = true`. This ensures that finalized, audited financial statements cannot be silently modified by late-arriving operational data.

## 5. Audit Traceability
- Every Journal captures `created_by`.
- Every Journal captures the Polymorphic reference (`reference_type`, `reference_id`), mathematically proving exactly which operational event (e.g., Sales Payment #1234) caused the ledger entry.
