TheDocumentation 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.
/stats/ endpoints provide operational analytics and report generation for the cafeteria management system. Dashboard and summary endpoints return JSON designed for display in the admin panel and mobile app — covering daily KPIs, monthly financial summaries, chart-ready time-series data, product performance rankings, and inventory status. Report endpoints return binary file downloads in PDF (via ReportLab) or XLSX (via openpyxl) format, with appropriate Content-Disposition headers so clients can save them directly to disk. All endpoints require authentication; role requirements vary per endpoint as documented below.
Dashboard and Summaries
Dashboard KPIs
Bearer <token> — Roles: admin, caja.Total sales revenue recorded today (sum of
monto_total across all sales with a fecha matching today’s date).Count of orders currently in an active state:
pendiente, en_preparacion, listo, or entregado. Paid and cancelled orders are excluded.Count of ingredients whose
stock_actual is at or below their stock_minimo threshold.Total expenses recorded today (sum of
monto across all expenses with a fecha matching today’s date).Top 5 products by total units sold in the last 30 days, across all paid orders. Each entry:
{id, nombre, total_vendido}.Monthly summary
Bearer <token> — Roles: admin, caja.Sum of all sale
monto_total values within the period.Number of sales (paid orders) within the period.
Average sale amount (
total_ventas / total_pedidos). Returns 0.0 if there are no sales.Sum of all expense
monto values within the period.Net gain:
total_ventas - gastos_totales. Does not include ingredient purchase costs (/compras/).First day of the current month in
YYYY-MM-DD format.Today’s date in
YYYY-MM-DD format.Chart Data
Daily sales chart
Bearer <token> — Roles: admin, caja.{fecha, total} entries suitable for rendering a bar or line chart. Each entry represents one day, and the array always covers exactly dias days ending today (including today), even if a day had no sales (in which case total is 0.0).
Query parameters
Number of days to look back, including today. Defaults to
7. For a 30-day view, pass ?dias=30.dias=7)
Day label formatted as
DD/MM (e.g. "15/01").Total sales revenue for that day.
0.0 for days with no sales.Daily expenses chart
Bearer <token> — Roles: admin, caja.GET /stats/ventas-diarias but aggregated from the expenses table. Each entry represents total operational expenses for that day.
Query parameters
Number of days to look back, including today. Defaults to
7.Product Analytics
Top products (last 30 days)
Bearer <token> — Role: admin.total_vendido.
Query parameters
Maximum number of products to return. Defaults to
10.Product ID.
Product name.
Total units sold in paid orders over the last 30 days.
Full product statistics
Bearer <token> — Role: admin.rentabilidad list is computed in Python by multiplying each ingredient’s costo_unitario by its quantity in the product’s recipe.
Example response
Top 10 products by total units sold across all paid orders (no 30-day limit for this endpoint). Each entry:
{id, nombre, total_vendido}.Bottom 5 products by total units sold across all paid orders. Useful for identifying underperforming items. Each entry:
{id, nombre, total_vendido}.Top 10 products by profit margin, calculated as
precio - costo_ingredientes. Each entry: {id, nombre, precio, costo, margen}. costo is the sum of (ingrediente.cantidad × ingrediente.costo_unitario) across all recipe items.Inventory and Activity
Inventory status
Bearer <token> — Roles: admin, cocina.Total number of ingredients configured in the system.
Count of ingredients where
stock_actual <= stock_minimo.Full ingredient list with current stock levels. Each entry:
{id, nombre, unidad, stock_actual, stock_minimo, estado}. estado is "Crítico" when stock_actual <= stock_minimo, otherwise "Ok".The 10 most recent supply purchases. Each entry:
{ingrediente, cantidad, costo_total, fecha}.Recent activity history
Bearer <token> — Role: admin.Maximum number of records to return per category. Defaults to
20. Each of pedidos, ventas, and gastos independently returns up to limite records.Sales list with filters
Bearer <token> — Roles: admin, caja.GET /ventas/, this endpoint returns denormalized strings for cashier name and payment method name rather than nested objects.
Query parameters
Start of the date range filter (
YYYY-MM-DD). Inclusive.End of the date range filter (
YYYY-MM-DD). Inclusive.Expenses list with filters
Bearer <token> — Roles: admin, caja."Sin categoría" when no category is assigned.
Query parameters
Start of the date range filter (
YYYY-MM-DD). Inclusive.End of the date range filter (
YYYY-MM-DD). Inclusive.Downloadable Reports
All report endpoints stream a binary file response. The response includes aContent-Disposition: attachment; filename=<name> header so browsers and HTTP clients can save the file automatically. All report endpoints require authentication via Authorization: Bearer <token>.
Report endpoints reference
| Endpoint | Format | Role | Filter Parameters |
|---|---|---|---|
GET /stats/reporte-ventas/pdf | application/pdf | admin | fecha_inicio, fecha_fin |
GET /stats/reporte-ventas/xlsx | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | admin | fecha_inicio, fecha_fin |
GET /stats/reporte-gastos/pdf | application/pdf | admin | fecha_inicio, fecha_fin |
GET /stats/reporte-gastos/xlsx | XLSX | admin | fecha_inicio, fecha_fin |
GET /stats/reporte-productos/pdf | application/pdf | admin | categoria_id, disponible |
GET /stats/reporte-productos/xlsx | XLSX | admin | categoria_id, disponible |
GET /stats/reporte-pedidos/pdf | application/pdf | admin | estado_id, fecha_inicio, fecha_fin |
GET /stats/reporte-pedidos/xlsx | XLSX | admin | estado_id, fecha_inicio, fecha_fin |
GET /stats/reporte-inventario/pdf | application/pdf | admin | none |
GET /stats/reporte-inventario/xlsx | XLSX | admin | none |
GET /stats/reporte-historial/pdf | application/pdf | admin | fecha_inicio, fecha_fin |
GET /stats/reporte-historial/xlsx | XLSX | admin | fecha_inicio, fecha_fin |
Report filter parameters
Date range filters (fecha_inicio, fecha_fin)Both are optional ISO date strings (
YYYY-MM-DD). When omitted, the report includes all records with no date boundary. Applied as inclusive >= / <= comparisons against the relevant date column.
Products filters
Filter the products report to a single category ID. Omit to include all categories.
Filter the products report by availability (
true = available, false = unavailable). Omit to include both.Filter the orders report to a single order status by its internal ID. Omit to include all statuses.
XLSX multi-sheet reports
The historial XLSX report (GET /stats/reporte-historial/xlsx) generates a workbook with three separate sheets:
| Sheet name | Contents |
|---|---|
Pedidos | Recent orders: ID, mesa, estado, fecha |
Ventas | Recent sales: ID, pedido, monto, fecha |
Gastos | Recent expenses: ID, descripción, monto, fecha |
PDF report structure
PDF reports are generated with ReportLab using US Letter-size pages (8.5” × 11”). Each report includes:- A bold title (e.g.
"Reporte de Ventas - Cafetería") - A generation timestamp (
"Generado: YYYY-MM-DD HH:MM") - Applied date filter range (when applicable)
- A styled table with grey header row and black cell borders
- A totals row at the bottom (for sales and expenses reports)
Download example
All report endpoints are restricted to the admin role, regardless of whether the equivalent JSON endpoint allows
caja or cocina. This ensures that exportable data copies remain under admin control.