# amendConfirmedSalesOrder

## Overview

Amends a CONFIRMED sales order by applying line-level changes (ADD, MODIFY, REMOVE) and optional header-field changes. Each amendment increments the sales order's revisionNumber and records a `SalesOrderRevision` envelope with per-field `SalesOrderFieldChange` rows for audit history. Fulfillment and billing statuses are automatically recalculated after amendment.

Only sales orders in CONFIRMED status can be amended. Modifications and removals are subject to downstream constraints (fulfilled/billed quantities).

## Modules Commands Used

- [sales] AmendConfirmedSalesOrder

## Exception Handling

| Error Code | Description |
| --- | --- |
| SALES_SALES_ORDER_NOT_FOUND | The specified sales order does not exist |
| SALES_SALES_ORDER_NOT_CONFIRMED | The sales order is not in CONFIRMED status |
| SALES_EMPTY_AMENDMENT_CHANGES | At least one change (ADD, MODIFY, REMOVE, or header change) must be provided |
| SALES_LINE_NOT_FOUND | The specified line ID does not exist on this sales order |
| SALES_MODIFY_QUANTITY_BELOW_FULFILLED | Cannot reduce quantity below the already-fulfilled amount |
| SALES_MODIFY_QUANTITY_BELOW_BILLED | Cannot reduce quantity below the already-billed amount |
| SALES_REMOVE_LINE_HAS_FULFILLMENTS | Cannot remove a line that has posted outbound shipments |
| SALES_REMOVE_LINE_HAS_BILLS | Cannot remove a line that has been billed by a customer invoice |
| SALES_EMPTY_SALES_ORDER_LINES | A sales order must keep at least one line |
| SALES_ITEM_NOT_FOUND | The specified item does not exist |
| SALES_INVALID_QUANTITY | Quantity must be a valid positive number |
| SALES_INVALID_UNIT_PRICE | Unit price must be a valid non-negative number |
