> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comforthub.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How purchase order numbers work

> One numbering sequence for stocking orders and counter purchase orders, handed out before you save

export const Touches = ({systems}) => <p>
    <strong>Systems involved:</strong>{" "}
    {systems.split(",").map((s, i) => <span key={s}>
        {i > 0 ? " · " : ""}
        <a href={"/systems/" + s.trim()}>{s.trim().replace(/-/g, " ")}</a>
      </span>)}
  </p>;

<Touches systems="the-7am-app, supabase-backend" />

Every purchase order number, on a stocking order or a counter purchase order, comes from one numbering sequence in the engine, and you get it before you save.

## The shape of it

```mermaid theme={null}
flowchart LR
  A[Open a sheet] --> B[The engine hands out the next number]
  B --> C{Save or cancel?}
  C -->|Save| D[The number is stored on the order]
  C -->|Cancel| E[The app hands the number back]
```

1. You open a counter purchase order, or reach the order screen from a stock list. The app asks the engine for the next number and shows it, so you can write it on the paperwork at the counter.
2. The engine hands numbers out one at a time. Two people opening a sheet in the same second get two different numbers. A number is the letters PO followed by the count.
3. You save, and the number is stored with the order.
4. You close a counter purchase order without saving, and the app hands the number back. The engine takes a number back only if it is still the newest one handed out and no saved order carries it. Otherwise the number stays used.
5. A stocking order screen you leave without sending does not hand its number back. Deleting a saved order does not either.

## Why it works this way

* The number is ready before saving because the supplier needs it on the paper before the order is placed.
* Stocking orders and counter purchase orders share one sequence so there is one series to look up.
* Only the newest number can go back, because handing back an older one could give two orders the same number.

## What can go wrong

* Gaps. A number handed out and never used leaves a gap in the series. Gaps are harmless; what matters is that no number repeats, and the sequence never repeats one.

## Related

* [How ordering parts works](/handbook/parts/how-ordering-parts-works)
* [Delete a purchase order](/handbook/parts/delete-a-purchase-order)
* [Order stock from a supplier](/handbook/parts/order-stock)
* [Record a return](/handbook/parts/record-a-return)
* [The engine](/systems/supabase-backend)
