# GetInventorySupplyPlan

## Overview

GetInventorySupplyPlan retrieves one supply projection by `id` or by source line, including CLOSED rows. The returned record includes computed `openQuantity`; OPEN rows use `max(expectedQuantity - receivedQuantity, 0)`, and CLOSED rows return `openQuantity = 0`.

## Business Rules

- Accepts either `id` or `{ sourceType, sourceLineId }`
- Source-line lookup returns the unique supply plan linked to that source line
- Returns null if no plan exists
- Computes `openQuantity` from the stored expected and received quantities for OPEN rows, clamped to zero
- Returns `openQuantity = 0` for CLOSED rows

## Process Flow

```mermaid
flowchart TD
    A[Receive lookup input] --> B[Find matching InventorySupplyPlan]
    B --> C{Record found?}
    C -->|No| D[Return null]
    C -->|Yes| E{Status OPEN?}
    E -->|Yes| F[Compute max expectedQuantity minus receivedQuantity, 0]
    E -->|No| G[Set openQuantity to 0]
    F --> H[Return plan]
    G --> H
```

## External Dependencies

- None

## Error Scenarios

None - returns null when no matching supply plan exists.

## Test Cases

- returns supply plan by id
- returns supply plan by source line
- returns null when not found
- computes open quantity
- returns zero open quantity when received quantity exceeds expected quantity
- returns closed supply plan with zero open quantity
