# createRemainingInboundShipment

## Overview

BFF resolver that creates a draft inbound shipment for the remaining unreceived quantities on a purchase order. Calculates ordered quantity minus received quantity (from POSTED inbound shipments) per PO line, and creates a DRAFT inbound shipment with only the lines that have remaining quantity. Returns `{ id: "", docNumber: "", created: "false" }` if the PO is fully received.

Sets `quantity` (received) to the computed remaining as a default — the erp-kit command requires quantity > 0 on creation. The user is expected to adjust actual received quantities before settling the inbound shipment.

## Modules Commands Used

- [purchase] CreateInboundShipment

## Exception Handling

| Error Code | Description |
| --- | --- |
| PURCHASE_PURCHASE_ORDER_NOT_FOUND | The specified purchase order does not exist (thrown as untyped Error) |
| PURCHASE_PURCHASE_ORDER_NOT_RECEIVABLE | The purchase order is in CANCELLED or CLOSED status (thrown as untyped Error from pre-flight check) |
| PURCHASE_NO_OPEN_RECEIPT_QUANTITY | All quantities have already been received (inbound shipment not created, returns `created: "false"`) |
| Error | Unexpected error while creating remaining inbound shipment; see `message` for details |

## Return

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | Created inbound shipment ID, empty string if fully received |
| `docNumber` | string | Created inbound shipment document number, empty string if fully received |
| `created` | string | `"true"` if an inbound shipment was created, `"false"` otherwise |
