# GetBudget

## Overview

GetBudget retrieves a single budget record by id, returning all header fields (name, budget holder, fiscal year reference, cost object reference, cost object type, status, plan version type, total amount) along with all associated budget line items. Each line item includes the cost element reference, accounting period reference, planned amount, and the GL account derived from the primary cost element's mapping. This is the primary query for viewing budget details, reviewing planned amounts by cost element and period, and supporting budget vs. actual comparison workflows.

## Business Rules

- Accepts a single lookup parameter: `{ id }`
- Returns the full budget record including all header fields
- Includes all associated BudgetLineItem records
- Each line item includes cost element reference, accounting period reference, planned amount, and derived GL account
- The GL account on each line item is derived from the referenced primary cost element's GL account mapping
- Returns null if no matching budget is found
- Lookup is an exact match on id

## Process Flow

```mermaid
flowchart TD
    A[Receive input with id] --> B[SELECT from Budget where id = input.id]
    B --> C{Budget found?}
    C -->|Yes| D[Load all associated BudgetLineItem records]
    D --> E[Return budget with all line items]
    C -->|No| F[Return null]
```

## External Dependencies

- None

## Error Scenarios

- **BUDGET_NOT_FOUND**: No budget matches the given id — caller receives null

## Test Cases

- returns budget with all header fields and line items when found by id
- returns budget line items with cost element, period, and planned amount
- returns budget line items with derived GL account from cost element mapping
- returns budget with empty line items when budget has no line items
- returns null when no budget matches the given id
