# RAMA AG — Phase 10 — Monthly Closing & Audit Trail

Status: **DONE** (branch `develop/v1`; not yet activated on `:3400`).

## Implemented features
- Lifecycle: draft → review → ready → closed → reopened (`/smgv/closing`), with an employee × month board.
- Validation before closing. Blocking: no contract or Pensum, incomplete attendance, open intervals, more than 24 hours, work outside the contract. Notices: unverified rules, work on a holiday, exclude-day flag.
- Closing writes an **immutable snapshot**: canonical JSON of the full result including source references, the rule-set ID, `rules_verified`, the closing administrator, a timestamp and a SHA-256 checksum. Closed months are always served from their snapshot.
- Reopening needs a reason of at least 10 characters, is recorded immutably, and the next close creates a new revision; previous revisions are kept.
- Correction ledger: employee, date, category, original value, corrected value, reason, administrator, timestamp. It is append-only, and the original attendance evidence is never changed.
- `/audit`: audit history (filter and pagination).

## Modified / added files
`app/Services/Smgv/SmgvLifecycle.php`, `app/Livewire/Smgv/Closing.php`, `app/Livewire/AuditHistory.php` + views, `app/Models/Smgv/{MonthState,MonthClosing,MonthReopening,Correction}.php`

## Database changes
`smgv_month_states`, `smgv_month_closings`, `smgv_month_reopenings`, `smgv_corrections`, plus 6 MariaDB triggers that refuse UPDATE/DELETE on snapshots, reopenings and corrections (tested: the database refuses a snapshot update).

## Test results
Unit `tests/Unit/SmgvTimeEngineTest.php` (8), feature `tests/Feature/SmgvAccountingTest.php` (8), `tests/Feature/SmgvCenterTest.php` (6). Full regression: main 562 (464 passed, 98 skipped by design), memory 97 (96 + 1 skipped), upgrade 2: **0 failures**.

## Security considerations
All user-facing actions are Administrator-only: `admin` route middleware plus a fresh database check on every Livewire request (`SmgvContext::bootSmgvContext`) and a service-level `Actor::admin()`. Audit entries never contain personal values (no AHV, address or birth date). Isolation is unchanged: RAMA database and account only, no outbound mail or HTTP, and Quality was never touched.

## Technical decisions, assumptions and limitations
See `RAMA_AG_MASTER_DEVELOPMENT_TRACKER.md` (Decisions, Known limitations).

## Outstanding blockers
The GAV/SMGV rule confirmations listed in `RAMA_AG_MASTER_DEVELOPMENT_TRACKER.md` remain open. Until they are answered, values are drafts (watermarked, with banners).
