# GetApplicableSalesPrice

## Overview

GetApplicableSalesPrice resolves the best matching commercial price for a draft sales-order line context. It evaluates active rules across price list, customer, channel, item, quantity, date, currency, unit of measure, and explicit priority to return a deterministic result or an unmatched outcome.

## Business Rules

- Only ACTIVE price lists and ACTIVE price rules participate in matching.
- Rule precedence is deterministic across company, customer, channel, item, quantity break, date, and priority.
- When no rule matches, the query returns an unmatched result rather than throwing so manual pricing remains possible.

## Process Flow

```mermaid
flowchart TD
    A[Receive draft pricing context] --> B[Load active price lists and rules]
    B --> C[Filter by company, item, customer, channel, date, quantity, currency, and UoM]
    C --> D{Match found?}
    D -->|No| E[Return unmatched result]
    D -->|Yes| F[Apply deterministic precedence]
    F --> G[Return selected rule and effective unit price]
```

## External Dependencies

- [primitives::ConvertQuantity](../../../primitives/docs/query/ConvertQuantity.md) - Support quantity-break comparison across compatible UoMs when needed.

## Error Scenarios

- **INVALID_PRICING_CONTEXT**: Required pricing inputs are missing or inconsistent.

## Test Cases

- returns the highest-precedence matching price rule
- returns unmatched result when no active rule applies
- resolves quantity-break pricing with compatible UoM conversion
- throws when required pricing context is missing
