Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Eleazarguitar18/kantuta_pos_front/llms.txt

Use this file to discover all available pages before exploring further.

The Purchases module lets you record the intake of goods from suppliers. When a purchase is created, the backend automatically increments the stock_actual of every product listed in the detalles array, keeping your inventory counts accurate without a separate update call. All routes require a valid Bearer Token JWT in the Authorization header.

Interface Reference

export interface BaseEntityAudit {
  estado: boolean;
  id_user_create: number | null;
  id_user_update?: number | null;
  created_at: string; // ISO Date String
  updated_at: string; // ISO Date String
}

export interface DetalleCompra extends BaseEntityAudit {
  id: number;
  cantidad: number;
  costo_unitario: number;
  subtotal: number; // Calculated: cantidad * costo_unitario
  id_producto: number;
  producto?: Producto; // Pre-loaded in GET /compras responses
}

export interface Compra extends BaseEntityAudit {
  id: number;
  total: number;            // Sum of all detalle subtotals
  proveedor: string | null; // Supplier name, or null if not specified
  pagado_con_caja: boolean; // Whether payment was drawn from a cash session
  id_sesion_caja: number | null;
  fecha: string;            // ISO Date String
  detalles: DetalleCompra[];
}

POST /compras

Records a new purchase order, increments stock for each product in detalles, and optionally registers an automatic cash outflow (EGRESO) in the specified SesionCaja. Authentication: Required — Authorization: Bearer <access_token>
When pagar_con_caja is set to true, the backend automatically creates an EGRESO (cash outflow) movement in the SesionCaja identified by id_sesion_caja. The movement amount equals the calculated total of the purchase. Make sure the target cash session is ABIERTA before submitting, or the request will fail. Always pass id_sesion_caja when pagar_con_caja is true.

Request Body

proveedor
string
Name of the supplier or vendor. Optional — pass null or omit for anonymous purchases.
pagar_con_caja
boolean
required
Set to true if the purchase total should be paid from the POS cash register, which creates an automatic EGRESO movement in the specified caja session.
id_sesion_caja
number
ID of the open cash register session to deduct from. Required when pagar_con_caja is true. Ignored when pagar_con_caja is false.
detalles
DetalleCompraInput[]
required
Array of line items for this purchase. Must contain at least one entry.
id_user_create
number
required
ID of the authenticated user creating the purchase record. Used for audit tracking.

Response Fields

id
number
required
Auto-generated unique identifier for the purchase.
total
number
required
Sum of all (cantidad * costo_unitario) subtotals, calculated by the backend.
proveedor
string | null
Supplier name or null.
pagado_con_caja
boolean
required
Whether the purchase triggered a cash outflow.
id_sesion_caja
number | null
The cash session used for payment, or null.
fecha
string
required
ISO 8601 timestamp of when the purchase was recorded.
detalles
DetalleCompra[]
required
The saved purchase line items, each with a computed subtotal.
estado
boolean
required
Active flag, defaults to true.
created_at
string
required
ISO 8601 creation timestamp.
curl --request POST \
  --url http://localhost:3000/compras \
  --header "Authorization: Bearer <access_token>" \
  --header "Content-Type: application/json" \
  --data '{
    "proveedor": "Distribuidora Central",
    "pagar_con_caja": true,
    "id_sesion_caja": 5,
    "detalles": [
      {
        "id_producto": 7,
        "cantidad": 48,
        "costo_unitario": 3.20
      },
      {
        "id_producto": 12,
        "cantidad": 24,
        "costo_unitario": 8.50
      }
    ],
    "id_user_create": 1
  }'

GET /compras

Returns the full purchase history. Each Compra record includes its detalles array, and each detail includes the nested producto object so you can display product names and details without additional requests. Authentication: Required — Authorization: Bearer <access_token>

Response Fields

id
number
required
Unique identifier of the purchase record.
total
number
required
Total cost of the purchase (sum of all line-item subtotals).
proveedor
string | null
Supplier name, or null if not recorded.
pagado_con_caja
boolean
required
Whether a cash outflow was created for this purchase.
id_sesion_caja
number | null
The cash session that was charged, or null.
fecha
string
required
ISO 8601 timestamp of the purchase.
detalles
DetalleCompra[]
required
Line items for the purchase.
estado
boolean
required
Active flag for the purchase record.
created_at
string
required
ISO 8601 creation timestamp.
curl --request GET \
  --url http://localhost:3000/compras \
  --header "Authorization: Bearer <access_token>"

Build docs developers (and LLMs) love