# ActivateBudget

## Permission Scope

accounting

## Overview

activateBudget transitions a budget from APPROVED status to ACTIVE status, enabling funds checking (budgetary control) for the associated cost object. Only one ACTIVE budget of type BUDGET can exist per cost object per fiscal year. Multiple FORECAST or SIMULATION versions can coexist.

## Business Rules

- Budget must exist
- Budget must be in APPROVED status to be activated
- Upon activation, funds checking is enabled for the cost object
- Only one ACTIVE budget of type BUDGET can exist per cost object per fiscal year
- Multiple ACTIVE FORECAST or SIMULATION plan versions can coexist for the same cost object and fiscal year
- Transitions status from APPROVED to ACTIVE
- Emits an audit event recording the status transition and acting user

## Process Flow

```mermaid
flowchart TD
    A[Receive activate budget request] --> B{Budget exists?}
    B -->|No| C[Return error: BUDGET_NOT_FOUND]
    B -->|Yes| D{Status is APPROVED?}
    D -->|No| E[Return error: INVALID_STATE]
    D -->|Yes| F{Plan version type is BUDGET?}
    F -->|Yes| G{Another ACTIVE BUDGET exists for same cost object and fiscal year?}
    G -->|Yes| H[Return error: DUPLICATE_ACTIVE_BUDGET]
    G -->|No| I[Transition status from APPROVED to ACTIVE]
    F -->|No| I
    I --> J[Enable funds checking]
    J --> K[Emit audit event]
    K --> L[Return activated budget]
```

## External Dependencies

- None

## Error Scenarios

- **BUDGET_NOT_FOUND**: Budget with the specified ID does not exist
- **INVALID_STATE**: Target entity is not in a valid status for this operation
- **DUPLICATE_ACTIVE_BUDGET**: Another ACTIVE budget of type BUDGET already exists for the same cost object and fiscal year

## Test Cases

- activates an APPROVED budget transitioning it to ACTIVE status
- enables funds checking upon activation
- returns error when budget does not exist
- returns error when budget is not in APPROVED status
- returns error when another ACTIVE BUDGET exists for the same cost object and fiscal year
- allows multiple ACTIVE FORECAST versions for the same cost object and fiscal year
- allows multiple ACTIVE SIMULATION versions for the same cost object and fiscal year
- emits audit event recording the status transition and acting user
