# OpenForAdvanceEntry

## Overview

openForAdvanceEntry transitions an accounting period from NEVER_OPENED to FUTURE_ENTERABLE status. This allows advance postings such as recurring journals, accruals, and depreciation entries to be recorded in the period before it is fully opened. This is commonly used when automated entries need to be posted to upcoming periods in advance of the period start date.

## Business Rules

- Period must exist and be in NEVER_OPENED status
- Only NEVER_OPENED periods can transition to FUTURE_ENTERABLE
- After transition, the period accepts advance journal postings (e.g., recurring journals, accruals)
- Emits an audit event recording the status transition, acting user, and timestamp

## Process Flow

```mermaid
flowchart TD
    A[Receive openForAdvanceEntry request] --> B{Period exists?}
    B -->|No| C[Return error: period not found]
    B -->|Yes| D{Period status is NEVER_OPENED?}
    D -->|No| E[Return error: invalid status transition]
    D -->|Yes| F[Transition period to FUTURE_ENTERABLE]
    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**: Period is not in NEVER_OPENED status; only NEVER_OPENED can transition to FUTURE_ENTERABLE

## Test Cases

- returns error when accounting period does not exist
- returns error when period is in FUTURE_ENTERABLE status
- 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 to FUTURE_ENTERABLE
- emits audit event recording status transition from NEVER_OPENED to FUTURE_ENTERABLE and acting user
