# GetStockLevel

## Overview

GetStockLevel retrieves the stock position for a specific item at a specific storage location. The input requires both an itemId and a storageLocationId. It returns on-hand, reserved, blocked, in-transit, and computed available quantity. This serves as the core stock inquiry for availability checks and reservation validation; future inbound supply planning is read from InventorySupplyPlan.

## Business Rules

- Requires both `itemId` and `storageLocationId`
- Returns a single StockLevel record containing:
  - `onHand` — physical quantity present
  - `reserved` — sum of location-specific open reservation quantity from StockReservation
  - `blocked` — quantity held for quality or other reasons
  - `availableQuantity` — computed as `StockLevel(AVAILABLE).quantity - location-specific open reservation quantity`
- Returns null if no stock level record exists for the item-location pair

## Process Flow

```mermaid
flowchart TD
    A[Receive itemId and storageLocationId] --> B[SELECT from StockLevel where itemId and storageLocationId match]
    B --> C{Record found?}
    C -->|Yes| D[Read location-specific StockReservations and compute availableQuantity = AVAILABLE quantity - open reserved]
    D --> E[Return StockLevel record]
    C -->|No| F[Return null]
```

## External Dependencies

- None

## Error Scenarios

None — returns null when no stock level record exists for the given item-location pair.

## Test Cases

- returns stock level when found
- returns null when not found
- correctly computes available quantity
- sums multiple open reservations for the location
- available equals AVAILABLE stock type minus location-specific open reservation quantity
