# GetVarianceReport

## Overview

GetVarianceReport retrieves a single variance report record by id, returning all header fields (cost object reference, cost object type, accounting period reference, status, total planned, total actual, total variance) along with all associated VarianceReportLine detail records. Each detail line includes the cost element reference, accounting period, planned amount, actual amount, variance amount, variance percentage, and variance direction (FAVORABLE or UNFAVORABLE). This is the primary query for reviewing period-end variance analysis results, drilling into cost element-level deviations, and supporting management reporting workflows.

## Business Rules

- Accepts a single lookup parameter: `{ id }`
- Returns the full variance report record including all header fields and summary totals
- Includes all associated VarianceReportLine records with cost element-level detail
- Each detail line includes planned amount, actual amount, variance amount, variance percentage, and variance direction
- Variance direction is FAVORABLE when actual costs are below plan (for cost/expense elements) or actual revenue is above plan (for revenue elements)
- Variance direction is UNFAVORABLE when actual costs are above plan or actual revenue is below plan
- Summary totals (total planned, total actual, total variance) are the sums of the corresponding detail line amounts
- Returns null if no matching variance report is found
- Lookup is an exact match on id

## Process Flow

```mermaid
flowchart TD
    A[Receive input with id] --> B[SELECT from VarianceReport where id = input.id]
    B --> C{Variance report found?}
    C -->|Yes| D[Load all associated VarianceReportLine records]
    D --> E[Return variance report with summary totals and detail lines]
    C -->|No| F[Return null]
```

## External Dependencies

- None

## Error Scenarios

- **VARIANCE_REPORT_NOT_FOUND**: Variance report with the specified ID does not exist

## Test Cases

- returns variance report with all header fields and detail lines when found by id
- returns variance report with summary totals matching the sum of detail lines
- returns detail lines with planned amount, actual amount, variance amount, and variance percentage
- returns detail lines with variance direction FAVORABLE for cost elements where actual is below plan
- returns detail lines with variance direction UNFAVORABLE for cost elements where actual is above plan
- returns null when no variance report matches the given id
