# ConfirmSalesOrder

## Permission Scope

salesOrder

## Overview

ConfirmSalesOrder freezes the commercial commitment and makes the sales order executable. It freezes the applied price, any externally supplied payment-term snapshot, and customer-facing context that downstream fulfillment and accounts-receivable 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 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, and pricing]
    C --> D[Freeze final commercial context]
    D --> E[Set orderStatus to CONFIRMED and initialize projections]
    E --> F[Return confirmed order id]
```

## External Dependencies

- [business-partner::GetCustomerAccount](../../../business-partner/docs/query/GetCustomerAccount.md) - Revalidate customer company and transaction availability.

## 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 information.

## Test Cases

- rejects a customer account belonging to another company
- confirms an active account even when its partner is inactive

- confirms a submitted order and derives its progress statuses
- uses the same not-fulfilled status for a service-only order
- throws when order is not submitted
- throws when customer became inactive before confirmation
- throws when a line lacks final pricing data
- throws when the order does not exist
