# ReopenPeriod

## Permission Scope

periodManagement

## Overview

reopenPeriod transitions an accounting period from CLOSED back to OPEN status, allowing journal entry postings to resume. This supports scenarios where late-arriving transactions or corrections need to be recorded after initial close. The reopen operation emits an audit event for compliance tracking, as reopening a closed period is a sensitive action that auditors monitor.

## Business Rules

- Period must exist and be in CLOSED status
- Only CLOSED periods can be reopened; PERMANENTLY_CLOSED periods cannot be reopened
- After transition, the period resumes accepting journal entry postings
- Reopening a period emits an audit event recording the status transition, acting user, and timestamp
- The audit event is critical for compliance as reopening is a monitored action

## Process Flow

```mermaid
flowchart TD
    A[Receive reopenPeriod request] --> B{Period exists?}
    B -->|No| C[Return error: period not found]
    B -->|Yes| D{Period status is CLOSED?}
    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 NEVER_OPENED status
- returns error when period is in OPEN status
- returns error when period is in FUTURE_ENTERABLE status
- returns error when period is in PERMANENTLY_CLOSED status
- transitions CLOSED period back to OPEN
- emits audit event recording status transition from CLOSED to OPEN and acting user
