# RAMA AG — Phase 06 — Time Calculation Engine

Status: **DONE (values are drafts while rules are unverified)** (branch `develop/v1`; not yet activated on `:3400`).

## Implemented features
- `App\Domain\Smgv\TimeEngine` is pure and deterministic (no database, no clock). It reads the facts from the existing `DurationEngine` intervals, which stay untouched.
- Integer minutes throughout. Time bands 00–06 / 06–20 / 20–24 per **local calendar date** (Europe/Zurich, the company setting). Minutes are measured from real UTC differences, so DST is handled correctly.
- Shifts that cross midnight are split across the dates.
- Open intervals (missing clock-out) are **never** filled in; they raise a warning and block closing.
- Target hours = daily target × weekday Pensum within the contract period. A holiday credit ('ft') equals that day's target hours.
- Absences by code (paid or unpaid). Corrections: replacing the day total or travel time (the factual value stays visible), flags (Karenz, exclude day), and monthly payouts and vacation adjustments.
- Week totals, month totals, Vergleich, cumulative balance; year roll-up with average employment %, vacation proration and carry-over.
- Warnings: no contract or Pensum, incomplete attendance, more than 24 hours a day, work outside the contract, work on a holiday.

## Modified / added files
`app/Domain/Smgv/TimeEngine.php`, `app/Services/Smgv/SmgvAccounting.php`, `app/Support/Hours.php`

## Database changes
None (computed); closed months are stored as snapshots (Phase 10).

## 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
The test vectors reproduce the verified reference relationships: January 22 × 8 h = 176 h; Vergleich +0.50; vacation 66.67 % → 117.35 h and 41.67 % → 73.35 h. Waiting time at the site before work starts is reported but not credited (policy unverified). Travel is reported; paid travel is **not** credited until the rule is confirmed.

## 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).
