# ConfirmSalesOrder

## Permission Scope

salesOrder

## Overview

ConfirmSalesOrder freezes the commercial commitment and makes the sales order executable. It snapshots the applied price, payment-term, and customer-facing context that downstream shipment and invoice flows must honor.

## Business Rules

- Only SUBMITTED orders may be confirmed.
- Customer must still be ACTIVE and valid for sales use at confirmation time.
- Each line must preserve a final unit price and currency before confirmation succeeds.
- Confirmation freezes mutable commercial fields until an explicit revision workflow exists.

## Process Flow

```mermaid
flowchart TD
    A[Receive confirm request] --> B[Load submitted order]
    B --> C[Revalidate customer, lines, pricing, and payment term]
    C --> D[Snapshot final commercial context]
    D --> E[Set status to CONFIRMED]
    E --> F[Return confirmed order]
```

## External Dependencies

- [business-partner::GetPartner](../../../business-partner/docs/query/GetPartner.md) - Revalidate customer activity and role status.
- [getApplicableSalesPrice](../query/GetApplicableSalesPrice.md) - Validate matched pricing context where a default rule exists.
- [getSalesPaymentTerm](../query/GetSalesPaymentTerm.md) - Revalidate payment-term assignment before snapshotting.

## Error Scenarios

- **SALES_ORDER_NOT_FOUND**: Referenced sales order does not exist.
- **INVALID_ORDER_STATUS**: Sales order status does not allow this operation
- **CUSTOMER_NOT_ACTIVE**: Referenced customer is not in ACTIVE status
- **MISSING_FINAL_PRICE**: A line lacks final price or currency information.

## Test Cases

- confirms a submitted order and snapshots commercial context
- throws when order is not submitted
- throws when customer became inactive before confirmation
- throws when a line lacks final pricing data
