# createRemainingInboundShipment

## Overview

BFF (backend-for-frontend) resolver — a composite endpoint shaped for the inbound-shipment UI rather than a plain module command. Given a purchase order, it computes each line's remaining quantity (ordered − sum of POSTED inbound-shipment receipts) and creates a single DRAFT inbound shipment covering only the lines whose remainder is greater than zero. Every created receipt line carries the source-document link back to the PO line (`sourceDocumentType = PURCHASE_ORDER`, `sourceDocumentId`, `sourceLineId`). It returns `{ id, docNumber, created }`; when the PO is already fully received it returns `created = "false"` with empty `id` / `docNumber` (not an error), so the UI can surface "nothing left to receive".

## Modules Commands Used

- [inbound-shipment] CreateInboundShipment

## Exception Handling

| Error Code | Description |
| --- | --- |
| INBOUND_SHIPMENT_INVALID_QUANTITY | A computed remaining quantity is invalid. |
| INBOUND_SHIPMENT_ITEM_NOT_FOUND | A referenced item does not exist. |
| INBOUND_SHIPMENT_STORAGE_LOCATION_NOT_FOUND | A line's storage location could not be resolved. |
| INSUFFICIENT_PERMISSION | The caller does not have permission to perform this operation |
