# DeleteAccountingPeriod

## Permission Scope

periodManagement

## Overview

deleteAccountingPeriod permanently removes an accounting period record. Deletion is only permitted when the period has no associated journal entries, regardless of their status (DRAFT or POSTED). This prevents orphaned financial data and maintains referential integrity within the general ledger.

## Business Rules

- Accounting period must exist and be identified by `id`
- Accounting period cannot be deleted if it has any associated journal entries regardless of status
- Deletion is a hard delete — the record is permanently removed

## Process Flow

```mermaid
flowchart TD
    A[Receive delete accounting period request] --> B{Accounting period exists?}
    B -->|No| C[Return error: period not found]
    B -->|Yes| D{Journal entries exist for this period?}
    D -->|Yes| E[Return error: has associated journal entries]
    D -->|No| H[Delete accounting period record]
    H --> J[Return success]
```

## External Dependencies

- None (same-module read for period and journal entry lookup)

## Error Scenarios

- **ACCOUNTING_PERIOD_NOT_FOUND**: Referenced accounting period does not exist
- **HAS_ASSOCIATED_JOURNAL_ENTRIES**: Accounting period has one or more journal entries and cannot be deleted

## Test Cases

- returns error when accounting period does not exist
- returns error when accounting period has associated journal entries
- deletes accounting period with no associated journal entries
