# Demand-based replenishment

Some businesses replenish stock at fixed intervals or produce goods on demand. In both cases, it's often necessary to accept customer orders before the purchase order is placed or the production schedule is defined. This page describes how to configure fulfillmenttools to accept orders without being limited by current stock levels in these scenarios.&#x20;

{% hint style="info" %}
An alternative approach is to configure the out-of-stock behavior using the `restockable` property. For more information, see the [Out of stock behavior and configuration article](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/out-of-stock-behavior-and-configuration).
{% endhint %}

The described use case is mapped by creating purchase orders with a very high amount of products and allowing shop systems to access the thereby created expected stock.

{% hint style="info" %}
If you know the stock quantites, follow the steps in the [Expected stock in availiability article](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/expected-stock-in-availability/..#implementation-in-fulfillmenttools).
{% endhint %}

{% stepper %}
{% step %}
**Create listings for products that should be available in large quantities**

In most set-ups, listings should already be created for all products that are managed via fulfillmenttools' systems. Still, make sure that a listing exists for each relevant product. If goods are perishable and/or should only be available for a certain time frame, [stock properties](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/stock-properties) and/or [stockAvailableUntil](https://docs.fulfillmenttools.com/documentation/by-pillar/listing#stock-available-until) must be configured.

{% tabs %}
{% tab title="Endpoint" %}

```http
PUT https://{your-tenant-name}.api.fulfillmenttools.com/api/facilities/{facilityId}/listings
```

{% endtab %}

{% tab title="Request" %}

```http
{
  "listings": [
    {
      "tenantArticleId": "4711",
      "title": "Chocolate Santa",
      "titleLocalized": {
        "de_DE": "Schoko Weihnachtsmann",
        "en_US": "Chocolate Santa"
      },
      "stockProperties": {
        "expiry": {
          "inputType": "DATE",
          "required": true
        }
      },
      "stockAvailableUntil": {
        "calculationBase": "EXPIRY",
        "modifier": "-P30D"
      },
      "version": 1
    }
  ]
}
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}
**Create a purchase order**

A [purchase order](https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/inbound-process/purchase-order) needs to be created and include all items that have not been ordered yet but should be already available for sale and not be limited by current stock levels.

* Choose a high number for the `quantity.value` of `requestedItems`
* Define the date when the delivery is expected to arrive in `requestedDate.value` and set `requestedDate.type` to `TIMEPOINT`
* Include as many items as possible in one purchase order rather than creating one purchase order for each item for that a very high stock should be assumed

{% hint style="warning" %}
Each purchase order is limited to 200 tenantArticleIds.
{% endhint %}

{% tabs %}
{% tab title="Endpoint" %}

```http
PUT https://{your-tenant-name}.api.fulfillmenttools.com/api/inboundprocesses/{inboundProcessId}/purchaseorder
```

{% endtab %}

{% tab title="Request example" %}

```json
{
  "orderDate": "2024-08-12T12:59:37.192Z",
  "requestedDate": {
    "type": "TIME_POINT",
    "value": "2024-08-19T12:59:37.192Z"
  },
  "requestedItems": [
    {
      "tenantArticleId": "4711",
      "quantity": {
        "value": 10000
      },
      "stockProperties": {
        "expiry": "2025-02-19T12:59:37.192Z"
      }
    }
  ],
  "facilityRef": "warehouse-cgn"
}

```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}
**Enable shop systems to communicate expected stock in sales availability**

Use one of the below endpoints to query stock availability in your shop's detail pages and in the checkout journey. By that, it's ensured that expected stock is considered in the shop availability.

See the [Availability and Promising section](https://docs.fulfillmenttools.com/documentation/by-pillar/availability-and-promising) for more information on the checkout options endpoints.

{% hint style="warning" %}
Before using the [delivery/earliest REST API](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/checkoutoptions/delivery/earliest) and [delivery/timeperiod REST API](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#post-/api/promises/checkoutoptions/delivery/timeperiod) endpoints, the transit time in the [carrier country service mapping](https://docs.fulfillmenttools.com/documentation/store-operations/carrier-management/carrier-features-and-requirements#country-service-mapping) for the requested carrier(s) must be configured.
{% endhint %}
{% endstep %}

{% step %}
**Create a new purchase order**

{% hint style="info" %}
You only need to do this if the quantity delivered is less than the reserved stock.
{% endhint %}

Create another new purchase order with large quantities, like you did in [step 2](#id-2.-create-a-purchaseorder). This ensures that the systems can continue to accept customer orders that should be fulfilled within next production or replenishment cycle.
{% endstep %}

{% step %}
**Patch purchase order with actual quantity**

Once the purchase order was placed or the production schedule was defined, patch requested items in the purchase order with quantities that were actually ordered or planned to be produced. Adjust stock properties such as expiry date if necessary.

{% hint style="info" %}
If there are more reservations than (expected) stock for reasons such as problems during production or defective items in a delivery, our systems try to distribute these abandoned reservations to other stock. If no alternative stock is available, the reservation is still tracked and will be shifted to a stock as soon as some stock becomes available.
{% endhint %}

{% tabs %}
{% tab title="Endpoint" %}

```http
PATCH https://{your-tenant-name}.api.fulfillmenttools.com/api/purchaseorders/{purchaseOrderId}
```

{% endtab %}

{% tab title="Request example" %}

```json
{
  "version": 2,
  "requestedItems": [
    {
      "tenantArticleId": "4711",
      "quantity": {
        "value": 150
      },
      "stockProperties": {
        "expiry": "2025-02-19T12:59:37.192Z"
      }
    }
  ],
  "facilityRef": "warehouse-cgn"
}

```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}
**Create stock after delivery has arrived or products are produced**

If the ordered products have arrived or production has been completed, a receipt needs to be added to the purchase order's inbound process to create stock.&#x20;

If you're not sure about which inbound process the purchase order belongs to, use the [purchase order REST API](https://fulfillmenttools.github.io/fulfillmenttools-api-reference-ui/#get-/api/purchaseorders/-purchaseOrderId-) endpoint to query the `inboundProcessRef`.

{% tabs %}
{% tab title="Endpoint" %}

```http
POST https://{your-tenant-name}.api.fulfillmenttools.com/api/inboundprocesses/{inboundProcessId}/receipts
```

{% endtab %}

{% tab title="Request example" %}

```json
{
  "receivedDate": "2024-08-18T13:40:05.864Z",
  "receivedItems": [
    {
      "tenantArticleId": "4711",
      "acceptedQuantity": {
        "value": 149
      },
      "rejectedQuantity": {
        "value": 1
      },
      "stockProperties": {
        "expiry": "2025-02-19T12:59:37.192Z"
      },
      "comments": [
        {
          "content": "One item was broken."
        }
      ]
    }
  ],
  "status": "FINISHED"
}

```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}


---

# Agent Instructions: 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:

```
GET https://docs.fulfillmenttools.com/documentation/by-pillar/global-inventory-hub/stock/expected-stock-in-availability/demand-driven-replenishment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
