# ClosePeriod

## Permission Scope

periodManagement

## Overview

closePeriod transitions an accounting period from OPEN to CLOSED status. A closed period no longer accepts routine journal entry postings. The transition is reversible -- a closed period can be reopened if adjustments are needed before permanent close. This supports the month-end close workflow where periods are closed after reconciliation but may need to be reopened for late-arriving transactions.

## Business Rules

- Period must exist and be in OPEN status
- Only OPEN periods can transition to CLOSED
- After transition, journal entry postings to this period are rejected
- The transition is reversible via reopenPeriod

## Process Flow

```mermaid
flowchart TD
    A[Receive closePeriod request] --> B{Period exists?}
    B -->|No| C[Return error: period not found]
    B -->|Yes| D{Period status is OPEN?}
    D -->|No| E[Return error: invalid status transition]
    D -->|Yes| F[Transition period to CLOSED]
    F --> 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 CLOSED status
- returns error when period is in PERMANENTLY_CLOSED status
- transitions OPEN period to CLOSED
