HDB Service includes a full inventory management layer that tracks consumables and spare parts across every plant in your fleet. Each stock entry is anchored to a standardized material catalog, ensuring consistent naming and item metadata regardless of which plant holds the stock. The system enforces minimum and maximum levels, flags low-stock conditions automatically, supports serialized item tracking, facilitates inter-plant transfers, and records lending activity as formal debt records that can be resolved with a matching transfer.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/GianlucaBessone/HDB-Service/llms.txt
Use this file to discover all available pages before exploring further.
Material catalog
TheMaterialCatalog model defines every item that can exist in inventory. Catalog entries act as the source of truth for item metadata and are referenced by all stock entries, consumable records, and repair histories.
Unique internal code used as the primary lookup key across all inventory operations. All
StockEntry and Consumable records reference this field.Human-readable item name. Automatically copied to stock entries and consumable records at creation time.
Item classification:
CONSUMABLE or SPARE_PART. Determines the itemType set on the corresponding StockEntry.Optional shelf life expressed in months. When a consumable is installed on a dispenser, the system calculates
expiresAt as installedAt + expirationMonths.When
true, every unit added to inventory must have a unique serial number (uniqueId). See Serialized consumables below.Optional — when set, the catalog entry is private to a specific client. When
null, the entry is globally available across all clients.POST /api/stock request. Attempting to add stock for an unregistered materialCode returns a 400 error, preventing ad-hoc item creation that would break standardization.
Stock entries
TheStockEntry model is the per-plant inventory record. Each entry is uniquely identified by the composite key (plantId, itemType, materialCode), so there is at most one stock entry per item per plant.
Links the entry to a specific plant and its parent client.
Mirrors the catalog
type field: CONSUMABLE or SPARE_PART.References the corresponding
MaterialCatalog entry.Current quantity on hand.
Minimum acceptable quantity. When
cantidad < minLevel (and minLevel > 0), the entry is counted as a low-stock alert in the dashboard and triggers a STOCK_LOW notification.Target or maximum stocking quantity. Useful for determining reorder amounts.
Unit of measure (e.g.,
"unidad", "litro", "kg"). Defaults to "unidad".Querying stock
| Parameter | Type | Description |
|---|---|---|
plantId | string | Filter to a single plant. |
itemType | string | Filter to CONSUMABLE or SPARE_PART. |
lowStockOnly | boolean | When true, returns only entries where cantidad < minLevel. |
StockEntry objects. Serialized items include a serialNumbers array (see below).
Creating or updating stock
(plantId, itemType, materialCode):
- If no entry exists, it is created with the provided quantity.
- If an entry already exists,
cantidadis incremented by the given amount — this prevents accidentally overwriting existing stock with a lower number.
Serialized consumables
When aMaterialCatalog entry has requiresSerial: true, each physical unit must be tracked individually by a unique serial number (uniqueId).
Adding a serialized item to inventory follows this flow:
System creates a Consumable record
The API first checks that the
uniqueId is not already registered. If it is unique, it creates a Consumable record with the uniqueId, materialCode, nombre, plantId, and expirationMonths from the catalog.GET /api/stock response attaches a serialNumbers array to every serialized entry, listing all active uniqueId values registered for that (plantId, materialCode) combination:
If
requiresSerial is true but no uniqueId is provided in the request, the API returns 400 — Este material requiere un número de serie.Adjusting stock
For manual inventory corrections — such as reconciling a physical count against the system — use the stock adjustment endpoint.action field accepts two values:
| Action | Effect |
|---|---|
ADJUST_QTY | Sets cantidad to an absolute value (newCantidad). |
DELETE | Removes the stock entry and soft-deletes all associated Consumable records (active: false). |
justificacion (justification) string is required for both actions. Every adjustment is written to the AuditLog and triggers a push notification to ADMIN and SUPERVISOR users via OneSignal, with a message that includes the before/after quantity and the provided justification.
Inter-plant transfers
StockTransfer records move material from one plant (fromPlantId) to another (toPlantId). Both plants must belong to the same client.
Validates source stock
Confirms that
fromPlant has enough cantidad to cover the requested transfer. Returns 400 if insufficient.Increments destination stock
Upserts the
StockEntry at toPlantId, creating it if it does not yet exist.Creates a StockTransfer record
Persists the transfer with
status: COMPLETED and completedAt timestamp.Transfer lifecycle values:
PENDING, COMPLETED, or CANCELLED. All transfers created via the API are immediately marked COMPLETED; the PENDING and CANCELLED values are reserved for future workflow extensions.Inter-plant debts
InterPlantDebt records formalize situations where one plant lends a consumable to another plant — for example, a technician borrows a filter from a nearby plant to resolve an urgent ticket.
The plant that lent the material (the one owed a return).
The plant that received the material (the one that owes the return).
The material that was lent.
Quantity lent.
PENDING until the debtor plant transfers equivalent stock back to the creditor, at which point it becomes RESOLVED.Timestamp set when the debt is resolved, either manually or automatically by the transfer pipeline.
status=PENDING):
StockTransfer is posted from plant A to plant B, the system checks whether plant A has any outstanding InterPlantDebt records where plant B is the creditor for the same material. Debts are resolved FIFO using the transferred quantity. If the transfer only partially covers a debt, the debt record is split: the resolved portion is marked RESOLVED and the remainder stays PENDING.
Required permissions
| Permission | Roles |
|---|---|
stock:read | ADMIN, SUPERVISOR, TECHNICIAN, CLIENT_RESPONSIBLE, CLIENT_REQUESTER |
stock:write | ADMIN, SUPERVISOR, TECHNICIAN |
stock:transfer | ADMIN, SUPERVISOR |
CLIENT_REQUESTER users can read stock but their view is scoped to the plants listed in their UserPlantAccess records. CLIENT_RESPONSIBLE users see all plants belonging to their client.