Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/123048152-JJDS/CafeteriaPM_S203/llms.txt

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

The /gastos/ endpoints track day-to-day operational expenses that are not ingredient supply purchases. Typical use cases include utility bills, cleaning supplies, equipment maintenance, staff meals, or any other cost that should appear in the operational expenditure reports. Each expense is automatically attributed to the user who created it via the JWT token, so no id_usuario field is needed in the request body. Expenses can be assigned to a category and filtered by date range for reporting purposes.

Endpoints

List expenses

Authorization
string
required
Bearer <token> — Roles: admin, caja.

GET /gastos/
Returns all recorded expenses, ordered by fecha descending (most recent first). Optionally filtered by date range — both boundaries are inclusive and matched against the fecha date field. Query parameters
fecha_inicio
string
Start of the date filter in YYYY-MM-DD format (e.g. "2024-01-01"). Inclusive.
fecha_fin
string
End of the date filter in YYYY-MM-DD format (e.g. "2024-01-31"). Inclusive.
Example request
GET /gastos/?fecha_inicio=2024-01-01&fecha_fin=2024-01-31
Example response
[
  {
    "id": 14,
    "descripcion": "Pago de servicio eléctrico",
    "monto": 450.00,
    "categoria": { "id": 3, "nombre": "Servicios", "tipo": "gasto" },
    "usuario": {
      "id": 2,
      "nombre": "Carlos López",
      "email": "[email protected]",
      "activo": true,
      "created_at": "2023-10-15T08:00:00",
      "role": { "id": 2, "nombre": "caja", "descripcion": null }
    },
    "fecha": "2024-01-15",
    "created_at": "2024-01-15T10:22:41"
  }
]

Record an expense

Authorization
string
required
Bearer <token> — Roles: admin, caja.

POST /gastos/
Creates a new expense record. The id_usuario is populated automatically from the authenticated user in the JWT — it cannot be overridden in the request body. If id_categoria is provided, the category must exist; the endpoint returns 400 if the category ID is not found. Request body
descripcion
string
required
Description of the expense (e.g. "Gas cylinder refill", "Monthly internet bill"). Used in reports and activity history.
monto
float
required
Amount in currency units. Must be greater than 0.
id_categoria
integer
Optional category ID. For expense records, use a category with tipo = "gasto" or tipo = "ambos". Omit to leave the expense uncategorized.
fecha
string
required
Date the expense occurred, in YYYY-MM-DD format. Can be a past date for retroactive logging.
Example request
{
  "descripcion": "Pago de servicio eléctrico",
  "monto": 450.00,
  "id_categoria": 3,
  "fecha": "2024-01-15"
}
Response201 Created
{
  "id": 14,
  "descripcion": "Pago de servicio eléctrico",
  "monto": 450.00,
  "categoria": {
    "id": 3,
    "nombre": "Servicios",
    "tipo": "gasto"
  },
  "usuario": {
    "id": 2,
    "nombre": "Carlos López",
    "email": "[email protected]",
    "activo": true,
    "created_at": "2023-10-15T08:00:00",
    "role": { "id": 2, "nombre": "caja", "descripcion": null }
  },
  "fecha": "2024-01-15",
  "created_at": "2024-01-15T10:22:41.334Z"
}
Error responses
StatusDetail
400"Categoría no encontrada"id_categoria does not match any category.

The GastoOut object

id
integer
Internal expense ID.
descripcion
string
Free-text description of the expense as entered by the user.
monto
float
Expense amount in currency units.
categoria
object | null
Expanded category object {id, nombre, tipo}, or null if uncategorized.
id_usuario
integer
ID of the user who recorded the expense (set from JWT, not from request body).
usuario
object
Full user object for the recorder: {id, nombre, email, activo, created_at, role}.
fecha
date
Date the expense occurred (YYYY-MM-DD), as supplied by the caller.
created_at
datetime
Timestamp when the expense record was created in the system.

Usage notes

Expenses vs. purchases: The /gastos/ endpoint is for general operational costs. Ingredient procurement should be recorded through POST /compras/ instead — supply purchases automatically increment ingredient stock levels and appear in inventory reports, while expenses do not affect stock. Retroactive entries: The fecha field represents when the cost was incurred, not when it was entered into the system. created_at is always the actual database insertion time. This allows logging a bill for a past date without affecting the insertion audit trail. Date filtering: Both GET /gastos/ and the stats endpoints (GET /stats/gastos-lista, GET /stats/gastos-diarios) filter on the fecha column. Ensure consistent date entry to get accurate reports.

Build docs developers (and LLMs) love