The Compras module manages the full purchase-order lifecycle in Tiendas Mi Cholo — from creating an order with a supplier (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/interezante456-pixel/Miercoles-Proyecto/llms.txt
Use this file to discover all available pages before exploring further.
PENDIENTE) through confirming physical receipt of goods (RECIBIDA). When a purchase is marked received, the service automatically increments stockActual for each product and writes an Inventario ENTRADA movement, all within one database transaction. Roles ADMIN and ALMACENERO can create and receive orders; all authenticated roles can read purchase data.
GET /api/compras
List all purchase orders recorded in the system. Returns all orders regardless of status.GET http://localhost:8080/api/compras
Authorization
Bearer token —
Authorization: Bearer <token>Response 200 OK
Internal database identifier.
Auto-generated purchase order number in the format
C-{year}-{sequence} (e.g. C-2024-0001).Current state:
PENDIENTE, RECIBIDA, PARCIAL, or ANULADA.Pre-tax subtotal computed from line items (
precio × cantidad).18% tax:
subtotal × 0.18.Grand total:
subtotal + igv.Optional free-text notes attached to the order.
Embedded supplier snapshot:
id, razonSocial, ruc.Embedded user who created the order:
id, nombre, apellido.Timestamp when the order was created (
@PrePersist).Expected delivery date, if provided at creation time.
Example response
cURL
GET /api/compras/{id}
Retrieve a single purchase order by its database ID.GET http://localhost:8080/api/compras/{id}
Authorization
Bearer token —
Authorization: Bearer <token>Path Parameters
The internal ID of the purchase order to retrieve.
Response 200 OK
Returns the same purchase object shape as GET /api/compras.
Error Codes
| Status | Error |
|---|---|
401 Unauthorized | Token missing, invalid, or expired. |
404 Not Found | "Compra no encontrada: {id}" |
cURL
POST /api/compras
Create a new purchase order. The order is saved immediately with statePENDIENTE. Stock is not modified at this stage — it is only incremented when the order is confirmed as received via PATCH /api/compras/{id}/recibir.
POST http://localhost:8080/api/compras
Authorization
Bearer token — requires
ADMIN or ALMACENERO role.Request Body
ID of the supplier for this order.
Optional notes (e.g. urgency, contact instructions).
Expected delivery date in
YYYY-MM-DD format (e.g. "2024-01-25"). Optional.Line items. Must contain at least one item (
@NotEmpty).The server computes
subtotal, igv (18%), and total automatically from the provided line items. The numeroCompra is auto-generated using the pattern C-{year}-{sequence}.Response 200 OK
Returns the persisted Compra object with "estado": "PENDIENTE" and the auto-generated numeroCompra.
Error Codes
| Status | Meaning |
|---|---|
400 Bad Request | Validation failure (missing required fields). |
401 Unauthorized | Token missing or invalid. |
403 Forbidden | User does not have ADMIN or ALMACENERO role. |
404 Not Found | proveedorId or any productoId does not exist. |
cURL — Create purchase order
Response — 200 OK
PATCH /api/compras/{id}/recibir
Mark a purchase order as received. This transition is only allowed fromPENDIENTE state. On success, the service:
- Increments
stockActualfor each ordered product. - Creates an
InventarioENTRADA movement per line item, referencing thiscompraId. - Transitions the order state to
RECIBIDA.
PATCH http://localhost:8080/api/compras/{id}/recibir
Authorization
Bearer token — requires
ADMIN or ALMACENERO role.Path Parameters
ID of the purchase order to receive.
Response 200 OK
Returns the updated Compra object with "estado": "RECIBIDA".
Purchase Order State Machine
| From | To | Trigger |
|---|---|---|
PENDIENTE | RECIBIDA | PATCH /recibir |
PENDIENTE | ANULADA | Manual cancellation (future) |
RECIBIDA | — | Terminal state |
ANULADA | — | Terminal state |
PARCIAL | RECIBIDA | Future partial-receipt flow |
Error Codes
| Status | Meaning |
|---|---|
400 Bad Request | Order is not in PENDIENTE state (already received or cancelled). |
401 Unauthorized | Token missing or invalid. |
403 Forbidden | User does not have ADMIN or ALMACENERO role. |
404 Not Found | Purchase ID does not exist. |
400 — Already received
cURL
Response — 200 OK