# DeleteFiscalYear

## Permission Scope

periodManagement

## Overview

deleteFiscalYear permanently removes a fiscal year record. Deletion is only permitted when the fiscal year has no associated accounting periods, ensuring that period data and any downstream journal entries are never orphaned.

## Business Rules

- Fiscal year must exist and be identified by `id`
- Fiscal year cannot be deleted if it has any associated accounting periods
- Deletion is a hard delete — the record is permanently removed

## Process Flow

```mermaid
flowchart TD
    A[Receive delete fiscal year request] --> B{Fiscal year exists?}
    B -->|No| C[Return error: fiscal year not found]
    B -->|Yes| D{Accounting periods exist for this fiscal year?}
    D -->|Yes| E[Return error: has associated periods]
    D -->|No| F[Delete fiscal year record]
    F --> H[Return success]
```

## External Dependencies

- None (same-module read for fiscal year and period lookup)

## Error Scenarios

- **FISCAL_YEAR_NOT_FOUND**: Referenced fiscal year does not exist or does not belong to the specified company
- **HAS_ASSOCIATED_PERIODS**: Fiscal year has one or more accounting periods and cannot be deleted

## Test Cases

- returns error when fiscal year does not exist
- returns error when fiscal year has associated accounting periods
- deletes fiscal year with no associated accounting periods
