# amendOrderedPurchaseOrder

## Overview

Amends an ORDERED purchase order by applying line-level changes (ADD, MODIFY, REMOVE). Replaces the former PurchaseChangeOrder workflow with a direct amendment approach. Each amendment increments the PO's revisionNumber and creates PurchaseOrderLineRevision records for audit history. Receipt and billing statuses are automatically recalculated after amendment.

Only POs in ORDERED status can be amended. Modifications and removals are subject to downstream constraints (received/billed quantities).

## Modules Commands Used

- [purchase] AmendOrderedPurchaseOrder

## Exception Handling

| Error Code | Description |
| --- | --- |
| PURCHASE_PO_NOT_FOUND | The specified purchase order does not exist |
| PURCHASE_PO_NOT_ORDERED | The purchase order is not in ORDERED status |
| PURCHASE_EMPTY_AMENDMENT_CHANGES | At least one change (ADD, MODIFY, or REMOVE) must be provided |
| PURCHASE_LINE_NOT_FOUND | The specified line ID does not exist on this purchase order |
| PURCHASE_MODIFY_QUANTITY_BELOW_RECEIVED | Cannot reduce quantity below the already-received amount |
| PURCHASE_MODIFY_QUANTITY_BELOW_BILLED | Cannot reduce quantity below the already-billed amount |
| PURCHASE_REMOVE_LINE_HAS_RECEIPTS | Cannot remove a line that has posted inbound shipments |
| PURCHASE_REMOVE_LINE_HAS_BILLS | Cannot remove a line that has been billed by a vendor invoice |
| PURCHASE_REMOVE_LINE_HAS_DOWNSTREAM_REFERENCES | Cannot remove a line referenced by other documents |
| PURCHASE_ADD_INVALID_QUANTITY | Quantity for new line must be greater than zero |
| PURCHASE_ITEM_NOT_FOUND | The specified item does not exist or is not active |
| PURCHASE_ITEM_NOT_PURCHASABLE | A referenced item has no purchasing record |
| PURCHASE_INVALID_QUANTITY | Quantity must be a valid positive number |
| PURCHASE_INVALID_UNIT_PRICE | Unit price must be a valid non-negative number |
| PURCHASE_RECEIVING_SITE_NOT_FOUND | The specified receiving site does not exist |
| PURCHASE_RECEIVING_SITE_REQUIRED | A receiving site is required for lines with physical receipt |
