# Employment Management

## Overview

Employment Management maintains the **effective-dated employment relationship** between a Worker and a legal entity (organization Company). It opens an employment at hire, records changes to employment type (full-time/executive/contractor/part-time/fixed-term/dispatch/other) and work type (flex/discretionary/manager/executive) as new generations, and closes it at termination — never overwriting, so the full employment history and future-dated changes are preserved (ADR-013).

Because employment type and work type drive downstream eligibility (which pay/work rules apply, whether someone is a manager/supervisor exempt from overtime), the calculated-time layer always reads the employment generation effective on the date being calculated (ADR-014, ADR-015).

## Business Purpose

- Model the "employed by whom, as what, from when" relationship as a versioned series, enabling retroactive correction and future-dated changes (e.g. a contract-to-permanent conversion scheduled ahead)
- Support re-hire and concurrent employment across legal entities without losing prior history (the seam for future multi-entity support, ADR-018)
- Provide the authoritative employment/work-type inputs that work-rules and time-tracking consume on the correct as-of date
- Preserve an auditable employment timeline without relying on the deprecated audit module (ADR-013)

## Process Flow

```mermaid
flowchart TD
    A[Open employment at hire] --> B[Generation 1: effectiveStart = hireDate, effectiveEnd = null]
    B --> C{Attribute change e.g. contractor to full-time}
    C -- Change on date D --> E[Close current: effectiveEnd = D - 1]
    E --> F[Insert new generation: effectiveStart = D, effectiveEnd = null]
    C -- No change --> G[Current generation stays open]
    F --> H{Termination}
    G --> H
    H -- Terminate on date T --> I[Set terminationDate = T, close open generation]
```

## Scenario Patterns

- **Hire**: open an initial generation with `effectiveStart = hireDate` and no end; the Worker is now employable to a Position
- **Employment-type change**: converting a contractor to full-time closes the current generation and inserts a new one effective on the change date; prior periods remain queryable
- **Future-dated change**: a change with a future `effectiveStart` is scheduled and does not affect the current employment until its start date
- **Retroactive correction**: inserting a generation with a past `effectiveStart` triggers recalculation of affected calculated time (ADR-014)
- **Concurrent employment**: a Worker holds two open employments at different Companies simultaneously (future multi-entity)
- **Termination**: setting a termination date closes the open generation; no open generation exists beyond termination

## Test Cases

- opening an employment creates a single open generation from the hire date
- changing employment type closes the prior generation and inserts a new one with no range overlap
- a future-dated change is not returned as the current employment until its start date
- querying `asOf` a past date returns the generation effective then
- terminating an employment leaves no open generation beyond the termination date
- work-type MANAGERIAL is stored with normalized enum naming (not the legacy MANEGERIAL)

## Reference Links

- Data-model design research (effective dating, Work Relationship tier): https://github.com/tailor-sandbox/Omakase-ERP-attendance/issues/7
- Customization reality (rule/attribute changes absorbed by configuration, not code): https://github.com/tailor-sandbox/Omakase-ERP-attendance/issues/13
