> For the complete documentation index, see [llms.txt](https://docs.dfc-standard.org/dfc-standard-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dfc-standard.org/dfc-standard-documentation/dfc-use-cases/use-cases/order-use-cases/wholesale-order-processing.md).

# Wholesale Order Processing

To manage wholesale ordering across platforms, we need to define a process to manage the stock as multiple orders come in from different traders, on different platforms, with different sales session cycles.

Traders will generate a single, consolidated Order for a producer, from multiple Customer orders within a Sales Session.

However, when a Customer Order is generated, we need to ensure stock is reserved/held, so that the Order can be fulfilled.

An example:

1. Supplier Jean is selling carrots through 2 hubs - Hub A & Hub B
2. Hub A has an order cycle that opens on Monday and closes on Friday
3. Hub B has an order cycle that opens on Tuesday and closes on Thursday
4. Jean has 10 kg of carrots to sell this week.
5. Customer Ali orders 1kg carrots through Hub A on Monday
6. Customer Paul orders 5 kg of carrots through Hub A on Tuesday
7. Customer David orders 3 kg of carrots through Hub B on Wednesday
8. Customer Michael orders 2 kg of carrots through Hub B on Thursday
9. When Hub B's order cycle closes on Thursday, it orders 5 kg of carrots from Jean.
10. When Hub A's order cycle closes on Friday, it orders 6 kg of carrots from Jean.
11. Jean is 1 kg of carrots short. If Hub A can only get 5 kg of carrots, Paul or Ali (who ordered earlier than David & Michael) won't get their order fulfilled.

To manage this, we need to ensure stock is reserved as the Customer Orders come in, but the Order is not completed until the Sales Session is finished.

This is managed (using Order & Fulfillment States) with the following flow:

**Trader Platform Process flow:**

1. When Customer initiates checkout: Create or Update an Order with the Producer to include all additional Products in Customer basket. Place Order in a `Held` `OrderState` (to reserve Producer stock), and with a `FulfilmentState` of `Held`, pending payment processing.
2. On successful completion of checkout of Customer Order: do nothing.
3. On unsuccessful completion of checkout of Customer Order: update Producer Order to remove additional Products required to fulfill that Order (or delete to newly created).
4. On completion of the Trader's [Sales Session](#user-content-fn-1)[^1]: submit the (aggregate) Producer Order by updating `OrderState` to `Complete` and the `FulfilmentState` to `Unfulfilled`.
5. Order Cancellation Processing: if a Customer Order is `Cancelled` within a Sales Session, is it necessary to immediately update the wholesale Order to reflect any reduced requirement. This allows stock to be available for other Customers in the network.

[^1]: **N.B.** This needs to be after any final Order updates the Trader makes, which may be later than the end of the Customer-facing Sales Session.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dfc-standard.org/dfc-standard-documentation/dfc-use-cases/use-cases/order-use-cases/wholesale-order-processing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
