This commit is contained in:
seb
2026-10-15 20:14:54 +02:00
parent e462a3d250
commit 508e1b6d7a
18 changed files with 859 additions and 333 deletions

View File

@@ -70,7 +70,8 @@ List of shipments
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
]
}

View File

@@ -4,9 +4,12 @@ Protected. Requires a valid session cookie (`credentials: 'include'`).
Create shipment for an order
Creates a new partial or full shipment manifest for the order.
Validates that article positions belong to the order and cumulative shipped quantities
do not exceed ordered quantities.
Creates a new shipment manifest (Lieferschein) for an order containing one, some, or all items from the order.
If `lines` is omitted or empty, all remaining unshipped items from the order are included automatically.
On individual line items, `amount` is optional and defaults to the remaining unshipped quantity for that article.
Auto-assigns the shipment number formatted as `<order_number><shipment_prefix><index>`, e.g. `AUF-000001-L-1`.
Updates the materialized `ordersummary` table (`shipped_quantity`, `is_shipped`) and emits SSE events
(`order`, `shipment`) so that the order list and summary tables are rerendered in real time.
## Path parameters
@@ -15,15 +18,15 @@ do not exceed ordered quantities.
|-------|----------|------|-------------|
| `id` | yes | integer | Order ID |
## Body (JSON)
## Body (JSON) — _optional_
| Field | Required | Type | Description |
|-------|----------|------|-------------|
| `date` | no | string | |
| `externalNumber` | no | string | |
| `lines` | yes | object[] | |
| `lines[].sku` | yes | string | |
| `lines[].amount` | yes | number | |
| `date` | no | string | Optional shipment date (defaults to current date) |
| `externalNumber` | no | string | Optional external delivery note reference (defaults to order.externalNumber or order.number) |
| `lines` | no | object[] | Optional positions to ship. If omitted, all remaining unshipped items are shipped. |
| `lines[].sku` | yes | string | Article SKU |
| `lines[].amount` | no | number | Quantity to ship. Defaults to remaining unshipped quantity for this SKU. |
| `lines[].name` | no | string | |
| `lines[].pu` | no | number | |
| `lines[].net` | no | number | |
@@ -107,7 +110,8 @@ Created shipment
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
}
```
@@ -119,7 +123,7 @@ Created shipment
| 400 | Validation error or article not in order — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 404 | Order not found — `{"error":"…"}` |
| 409 | Cumulative shipment amount exceeds ordered amount — `{"error":"…"}` |
| 409 | Cumulative shipment amount exceeds ordered amount, or all items are already shipped — `{"error":"…"}` |
---

View File

@@ -160,7 +160,8 @@ Created order
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
],
"files": [

View File

@@ -134,7 +134,8 @@ Order
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
],
"files": [

View File

@@ -143,7 +143,8 @@ Order list
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
],
"files": [

View File

@@ -154,7 +154,8 @@ Updated order
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
],
"files": [

View File

@@ -5,8 +5,10 @@ Protected. Requires a valid session cookie (`credentials: 'include'`).
Create order from quote
Creates a sales order from an existing quote for the authenticated user's selected company.
Copies lines, customer entity, and external number from the quote unless explicitly overridden.
Copies lines and customer entity from the quote.
Sets external reference (externalNumber) to the quote number unless explicitly overridden.
If the order number is omitted, it is auto-allocated from the sequence.
Fails with 400 (No entity selected) if neither the quote nor the request body specifies a customer entity.
## Path parameters
@@ -23,7 +25,7 @@ If the order number is omitted, it is auto-allocated from the sequence.
| `date` | no | string | Optional order date (ISO format). Defaults to current date. |
| `createdAt` | no | string | Optional creation timestamp. |
| `entityId` | no | integer | Customer entity ID override. Defaults to quote's entityId. |
| `externalNumber` | no | string | External customer reference override. Defaults to quote's externalNumber. |
| `externalNumber` | no | string | External customer reference override. Defaults to quote's number. |
| `lines` | no | ManifestLineInput[] | Optional line items override. Defaults to quote's lines. |
```json
@@ -170,7 +172,8 @@ Created order
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
],
"files": [
@@ -199,7 +202,7 @@ Created order
| Status | Description |
|--------|-------------|
| 400 | No company selected, invalid quote id, or invalid order data — `{"error":"…"}` |
| 400 | No company selected, no entity selected, invalid quote id, or invalid order data — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized for company — `{"error":"…"}` |
| 404 | Quote not found or entity not found — `{"error":"…"}` |

View File

@@ -0,0 +1,64 @@
# `GET /shipment`
Protected. Requires a valid session cookie (`credentials: 'include'`).
List shipments
Company-wide paginated list of shipment manifests (`manifest` rows with `type = 'shipment'`)
with delivery state, package tracking info, and order references.
## Query parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `offset` | no | integer | Number of shipments to skip |
| `limit` | no | integer | Number of shipments to return |
| `search` | no | string | Free-text search matching shipment number, order number, external number, tracking code, or customer name |
| `state` | no | string | Optional filter by delivery state |
| `seekMonths` | no | integer | Negative integer for cutoff months ago (e.g. -1 for shipments older than 1 month) |
## Response `200`
Paginated shipment list
```json
{
"shipments": [
{
"id": 1,
"number": "…",
"type": "shipment",
"entityId": 1,
"externalNumber": "…",
"date": "…",
"createdAt": "…",
"orderId": 1,
"orderNumber": "…",
"customerName": "…",
"positions": 1,
"totalQuantity": 1,
"packageCount": 1,
"carrier": "…",
"trackingCode": "…",
"state": "new"
}
],
"total": 1,
"unfilteredTotal": 1,
"offset": 1,
"limit": 1
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Invalid query parameters or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

View File

@@ -69,7 +69,8 @@ Shipment details
"thumby": 1,
"meta": {}
}
]
],
"state": "new"
}
}
```

View File

@@ -0,0 +1,106 @@
# `PATCH /shipment/{id}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Update shipment state or metadata
Updates delivery state (`new`, `delivered`, `returned`) for the shipment.
Emits SSE events (`shipment`, `order`) so connected clients rerender in real time.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `id` | yes | integer | Shipment ID |
## Body (JSON)
| Field | Required | Type | Description |
|-------|----------|------|-------------|
| `state` | no | string | Delivery state |
```json
{
"state": "delivered"
}
```
## Signals
On success, emits SSE signals: `shipment`, `order` (see [`GET /events`](../events.md)).
## Response `200`
Updated shipment
```json
{
"shipment": {
"id": 1,
"number": "…",
"type": "shipment",
"entityId": 1,
"externalNumber": "…",
"date": "…",
"createdAt": "…",
"lineCount": 1,
"packageCount": 1,
"lines": [
{
"id": 1,
"sku": "…",
"name": "…",
"pu": 1,
"amount": 1,
"net": 1,
"rebate": 1,
"taxrate": 1,
"comment": "…"
}
],
"shippings": [
{
"id": 1,
"manifestId": 1,
"number": "…",
"trackingCode": "…",
"carrier": "…",
"type": "…",
"state": "…"
}
],
"files": [
{
"id": 1,
"manifestId": 1,
"fileId": 1,
"sort": 1,
"hash": "…",
"mimetype": "…",
"name": "…",
"size": 1,
"created": "2026-08-10T00:00:00.000Z",
"modified": "2026-08-10T00:00:00.000Z",
"skeledash": "…",
"thumbx": 1,
"thumby": 1,
"meta": {}
}
],
"state": "new"
}
}
```
## Errors
| Status | Description |
|--------|-------------|
| 400 | Invalid state, invalid ID, or no company selected — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 404 | Shipment not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._