# OpenPeriod

## Permission Scope

periodManagement

## Overview

openPeriod transitions an accounting period to OPEN status, enabling standard journal entry postings. The period can transition from either NEVER_OPENED (skipping FUTURE_ENTERABLE) or FUTURE_ENTERABLE. An OPEN period is the primary active state for accepting routine transactional postings from both manual entry and subledger integrations.

## Business Rules

- Period must exist and be in NEVER_OPENED or FUTURE_ENTERABLE status
- NEVER_OPENED periods can transition directly to OPEN (skipping FUTURE_ENTERABLE)
- FUTURE_ENTERABLE periods can transition to OPEN
- After transition, the period accepts all journal entry postings
- Emits an audit event recording the status transition, acting user, and timestamp

## Process Flow

```mermaid
flowchart TD
    A[Receive openPeriod request] --> B{Period exists?}
    B -->|No| C[Return error: period not found]
    B -->|Yes| D{Period status is NEVER_OPENED or FUTURE_ENTERABLE?}
    D -->|No| E[Return error: invalid status transition]
    D -->|Yes| F[Transition period to OPEN]
    F --> G[Emit audit event]
    G --> H[Return updated period]
```

## External Dependencies

- None

## Error Scenarios

- **ACCOUNTING_PERIOD_NOT_FOUND**: Referenced accounting period does not exist
- **INVALID_STATUS_TRANSITION**: Requested status transition is not allowed from the current status

## Test Cases

- returns error when accounting period does not exist
- returns error when period is in OPEN status
- returns error when period is in CLOSED status
- returns error when period is in PERMANENTLY_CLOSED status
- transitions NEVER_OPENED period directly to OPEN
- transitions FUTURE_ENTERABLE period to OPEN
- emits audit event recording status transition and acting user
