# SubmitSalesOrder

## Permission Scope

salesOrder

## Overview

SubmitSalesOrder moves a draft sales order into SUBMITTED status so it can be reviewed and confirmed. Submission validates that the commercial document is complete enough for approval and downstream execution checks.

## Business Rules

- Only DRAFT orders may be submitted.
- The order must contain at least one line.
- If any line requires physical fulfillment, a shipping address snapshot must be present.
- Assigned payment term and customer context must remain valid at submission time.

## Process Flow

```mermaid
flowchart TD
    A[Receive submit request] --> B[Load draft order]
    B --> C[Validate lines, addresses, and customer context]
    C --> D{Validation passed?}
    D -->|No| E[Return validation error]
    D -->|Yes| F[Set status to SUBMITTED]
    F --> G[Return submitted order]
```

## External Dependencies

- [business-partner::GetDefaultPartnerAddress](../../../business-partner/docs/query/GetDefaultPartnerAddress.md) - Resolve or validate shipping and billing address context.
- [getSalesPaymentTerm](../query/GetSalesPaymentTerm.md) - Revalidate active payment-term assignment.

## Error Scenarios

- **SALES_ORDER_NOT_FOUND**: Referenced sales order does not exist.
- **INVALID_ORDER_STATUS**: Sales order status does not allow this operation
- **EMPTY_ORDER_NOT_ALLOWED**: Sales order has no lines
- **SHIPPING_ADDRESS_REQUIRED**: A shipping address is required for shippable lines.

## Test Cases

- submits a complete draft order
- throws when the order is not in DRAFT status
- throws when the order has no lines
- throws when shipping address is missing for physical fulfillment lines
