# PermanentlyClosePeriod

## Permission Scope

periodManagement

## Overview

permanentlyClosePeriod transitions an accounting period from CLOSED to PERMANENTLY_CLOSED status. This is an irreversible operation -- once permanently closed, no further journal entries can be posted to the period regardless of user role, and the period cannot be reopened. This enforces financial statement integrity after external audit finalization and satisfies GAAP/IFRS requirements for period locking.

## Business Rules

- Period must exist and be in CLOSED status
- Only CLOSED periods can transition to PERMANENTLY_CLOSED
- The transition is irreversible; PERMANENTLY_CLOSED periods cannot be changed to any other status
- After transition, all journal entry postings to this period are rejected regardless of user role
- Emits an audit event recording the irreversible transition, acting user, and timestamp

## Process Flow

```mermaid
flowchart TD
    A[Receive permanentlyClosePeriod 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 PERMANENTLY_CLOSED]
    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 already PERMANENTLY_CLOSED
- transitions CLOSED period to PERMANENTLY_CLOSED
- emits audit event recording the irreversible transition and acting user
