The Purchase Orders API lets you manage the full lifecycle of supplier orders within your tenant. Orders begin as BORRADOR (draft), where items can be set and reviewed. When goods arrive, you call theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/juadariasmar/inventory_project/llms.txt
Use this file to discover all available pages before exploring further.
recibir endpoint, which atomically creates Movimiento (entrada) records for each line item and increments each product’s stock count. Orders can also be cancelled before receiving. A built-in PDF renderer generates a print-ready document for any order, and a suggestions endpoint surfaces products whose current stock has dropped at or below their configured minimum threshold.
All write operations (POST) and the purchase-suggestion endpoint require the ADMIN role. Read operations are available to any active user belonging to the tenant.
Endpoints
| Method | Path | Description |
|---|---|---|
| GET | /api/ordenes-compra | List all purchase orders for the tenant |
| POST | /api/ordenes-compra | Create a new draft purchase order |
| GET | /api/ordenes-compra/[id] | Get a single purchase order with items and supplier |
| POST | /api/ordenes-compra/[id]/recibir | Mark an order as received; creates stock movements |
| POST | /api/ordenes-compra/[id]/cancelar | Cancel a draft order |
| GET | /api/pdf/orden-compra/[id] | Download a PDF of the purchase order |
| GET | /api/compras/sugerencias | List products at or below their minimum stock level |
| POST | /api/compras/sugerencias | Create a draft order directly from suggestion data |
GET /api/ordenes-compra
Returns all purchase orders for the authenticated user’s tenant, sorted newest first. Each record includes the supplier name and a count of line items.Response fields
Unique identifier for the purchase order.
ID of the supplier linked to this order.
Partial supplier object. Contains
nombre (string).Current state of the order:
BORRADOR, RECIBIDA, or CANCELADA.Computed total cost of all line items (sum of
cantidad × costoUnitario per item).Optional free-text notes on the order.
ISO 8601 timestamp of when the order was created.
ISO 8601 timestamp of when the order was received.
null if not yet received.Number of line items in the order.
POST /api/ordenes-compra
Creates a new purchase order with statusBORRADOR. Requires ADMIN role. The total field is computed automatically from the submitted items.
Request body
ID of the supplier. Must belong to the same tenant.
Array of line items. Must contain at least one entry.
ID of the product to order.
Integer quantity to order. Must be greater than
0.Unit cost for the product. Must be a non-negative number.
Optional free-text notes.
Response fields
Returns the createdOrdenCompra object (HTTP 201), including all items and the linked proveedor.
Assigned order ID.
Always
BORRADOR on creation.Sum of all item subtotals.
Array of
OrdenCompraItem objects.Product ID.
Ordered quantity.
Unit cost.
Line subtotal (
cantidad × costoUnitario).GET /api/ordenes-compra/[id]
Returns a single purchase order identified by its numericid, including all line items (with product nombre and codigo) and full supplier details.
Path parameters
Numeric purchase order ID.
Response fields
Purchase order ID.
Order state:
BORRADOR, RECIBIDA, or CANCELADA.Order total.
Free-text notes.
Creation timestamp (ISO 8601).
Reception timestamp, or
null.Supplier details:
id, nombre, nit, telefono, contacto, direccion, email.Array of line items, each with
productoId, cantidad, costoUnitario, subtotal, and a nested producto object containing nombre and codigo.POST /api/ordenes-compra/[id]/recibir
Marks aBORRADOR order as RECIBIDA. This operation runs inside a database transaction and performs the following steps atomically:
- Acquires a row-level lock on all affected
Productorows (ordered by ID to prevent deadlocks). - Creates one
Movimientoof typeentradaper line item, linked to the order. - Increments each product’s
cantidadby the ordered amount. - Sets the order’s
estadotoRECIBIDAand recordsrecibidaEn.
409 Conflict if the order is already received or cancelled.
Path parameters
Numeric purchase order ID.
Response fields
Order ID.
Always
RECIBIDA on success.Timestamp when reception was recorded (ISO 8601).
Updated array of line items.
POST /api/ordenes-compra/[id]/cancelar
Cancels a purchase order. Only orders inBORRADOR state can be cancelled — calling this on a RECIBIDA or already CANCELADA order returns 409 Conflict. No request body is required. Requires ADMIN role.
Path parameters
Numeric purchase order ID.
Response fields
Order ID.
Always
CANCELADA on success.GET /api/pdf/orden-compra/[id]
Generates and streams a PDF document for the specified purchase order directly in memory usingpdf-lib. The document includes supplier details, order metadata (date, status), a formatted line-item table with product codes and names, and the order total formatted in Colombian pesos. The response content type is application/pdf with an inline content-disposition header.
Path parameters
Numeric purchase order ID.
Response
Returns a binary PDF stream. Save to a file using the-o flag or open directly in a browser.
GET /api/compras/sugerencias
Returns a list of products whose currentcantidad is at or below their stockMinimo threshold. This endpoint is intended to drive the “create order from suggestion” workflow. Requires ADMIN role.
The response is generated by SugerenciasCompraService.generarSugerencias, which also computes a recommended purchase quantity based on 30-day consumption history.
Response fields
Product ID.
Product name.
Product SKU code.
Current stock level.
Configured minimum stock threshold.
Average daily consumption over the last 30 days (rounded to 2 decimal places).
Recommended reorder quantity calculated to cover 14 days of projected demand.
POST /api/compras/sugerencias
Creates a draftOrdenCompra directly from suggestion data. Requires ADMIN role. Returns the created order (HTTP 201).
Request body
ID of the supplier to assign to the new draft order.
Array of line items to include. Each entry requires
productoId, cantidad, and costoUnitario.