# Orders (F3) in IMS2 — business logic for the user

Orders track **what has been ordered from us**: an external customer wants
a certain quantity of items, we may not have that full quantity in stock
yet, and we ship it gradually, tracking "ordered / shipped".

---

## 1. Structure

- **Order** (header) — customer, period (a start and end date), comment.
- **Line** — any item from the reference (raw material or finished product
  — no restriction), with fields:
  - **Ordered** — how much the customer wants.
  - **Shipped** — how much has actually been sent so far,
    accumulates as shipments happen. Starts at 0.
  - **Remaining** — computed on screen as "Ordered minus Shipped", not
    stored separately.

---

## 2. How shipping happens

Orders does **not** ship from the Orders screen itself — it's a reference
list of "what's owed". Actual shipping happens through a normal expenditure
document (the "Order" button on the expenditure form) — you pick an open
order line, enter the quantity to ship, and process the document as usual.

When the document is processed the system automatically:
- adds the shipped quantity to the line's shipped total;
- if the shipped total reaches what was ordered — the line **closes automatically**;
- if all lines of the order are closed — the **order closes automatically**.

No separate "close" click is needed if shipping goes through in full.

Rolling back a shipment works in reverse: the shipped quantity goes back
down, and a line (and the order) closed by that shipment reopens.

## 3. Manual close

The **Close Order** button forcibly closes an order even if something is
not yet fully shipped (e.g. the customer canceled the remainder). This is
a separate action from auto-close-on-shipment — used only when the order
needs to be closed earlier than it's actually fulfilled.

---

## 4. Editing restrictions

- The ordered quantity of a line cannot be reduced below what's already
  shipped.
- A line cannot be deleted if anything has already been shipped against it.
- The whole order cannot be deleted if at least one line has shipments.

This protects against accidentally losing history — if something has
already left the warehouse against a line, its data can't be erased, only
closed.

---

## 5. Notifications

Closing a line/order is logged in the general event log (Tools → Events →
the Events tab) — you can see there when and what closed. **These
notifications do not pop up on the main-screen panel** — that panel only
shows stock shortages (see `docs/en/business-logic/events_en.md`); order
closures are intentionally left out to avoid distracting from the main
signal. The full order history is always available in the log itself.
