Skip to main content

Documentation 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.

The Analytics API exposes computed inventory and sales metrics for your tenant. All calculations are performed server-side by obtenerTodoAnalisis in src/lib/analisis.ts, which runs multiple Prisma queries in parallel to minimize latency. The primary endpoint returns a rich JSON payload suitable for driving chart components. A companion export endpoint streams the same data as a multi-sheet Excel workbook (.xlsx) for offline analysis or stakeholder reporting. Access to the analytics data requires the VER_ANALISIS permission. Downloading reports requires the EXPORTAR_REPORTES permission. Both permissions must be granted explicitly by an admin — they are not implicitly held by any role.

Endpoints

MethodPathDescription
GET/api/analisisReturn analytics JSON payload for the tenant
GET/api/analisis/exportarDownload a multi-sheet Excel analytics report

GET /api/analisis

Returns the full analytics dataset for the tenant. All time-windowed calculations use a fixed 30-day lookback window. Sales counts exclude cancelled sales to ensure accurate consumption and revenue figures. Up to 500 products are included in the inventory-general and dormant-product analyses. Required permission: VER_ANALISIS

Response fields

inventarioGeneral
array
Complete product catalogue with stock status, valuation, and activity age. Up to 500 products, ordered alphabetically by name.
inventarioGeneral[].productoId
number
Product ID.
inventarioGeneral[].codigo
string
Product SKU code.
inventarioGeneral[].nombre
string
Product name.
inventarioGeneral[].categoria
string
Category name. Defaults to "Sin categoría" if unassigned.
inventarioGeneral[].cantidad
number
Current stock quantity.
inventarioGeneral[].stockMinimo
number
Configured minimum stock threshold.
inventarioGeneral[].precio
number
Unit sale price.
inventarioGeneral[].valorEnStock
number
Total stock value (precio × cantidad).
inventarioGeneral[].estado
string
Stock health: "Sin stock", "Stock bajo", or "Normal".
inventarioGeneral[].diasDesdeUltimaActividad
number | null
Days since the last recorded movement. null if no movement has ever been recorded.
stockAgotarse
array
Products projected to run out within 7 days based on 30-day average daily consumption, plus any product already below the minimum threshold with no consumption history.
stockAgotarse[].productoId
number
Product ID.
stockAgotarse[].nombre
string
Product name.
stockAgotarse[].codigo
string
SKU code.
stockAgotarse[].cantidadActual
number
Current stock level.
stockAgotarse[].stockMinimo
number
Minimum stock threshold.
stockAgotarse[].consumoDiarioPromedio
number
Average daily consumption (2 decimal places).
stockAgotarse[].diasParaAgotarse
number | null
Projected days until stock reaches zero. null when there is no consumption history but stock is already in the critical zone.
sinMovimientos
array
Products with stock greater than zero that have had no incoming or outgoing movements in the last 30 days. Sorted by valorInmovilizado descending.
sinMovimientos[].productoId
number
Product ID.
sinMovimientos[].nombre
string
Product name.
sinMovimientos[].codigo
string
SKU code.
sinMovimientos[].cantidadActual
number
Current stock level.
sinMovimientos[].diasSinMovimiento
number
Number of days since the last movement.
sinMovimientos[].valorInmovilizado
number
Tied-up capital value (precio × cantidad).
altaRotacion
array
Top 10 products by total units sold (outgoing movements excluding cancelled sales) in the last 30 days.
altaRotacion[].productoId
number
Product ID.
altaRotacion[].nombre
string
Product name.
altaRotacion[].codigo
string
SKU code.
altaRotacion[].totalSalidas
number
Number of outgoing movement records.
altaRotacion[].cantidadVendida
number
Total units sold across all outgoing movements.
stockCritico
array
Products where cantidad <= stockMinimo + MARGEN_ALERTA_STOCK. Sorted by sugerenciaCompra descending to prioritize the most urgent replenishment needs.
stockCritico[].productoId
number
Product ID.
stockCritico[].nombre
string
Product name.
stockCritico[].codigo
string
SKU code.
stockCritico[].cantidadActual
number
Current stock level.
stockCritico[].stockMinimo
number
Minimum stock threshold.
stockCritico[].consumoDiarioPromedio
number
Average daily consumption (2 decimal places).
stockCritico[].sugerenciaCompra
number
Recommended reorder quantity to cover 14 days of projected demand, calculated by calcularSugerenciaCompraInteligente.
resumen
array
Daily movement summary for the last 30 days. Every calendar day in the range is included, even if activity was zero.
resumen[].fecha
string
Date in YYYY-MM-DD format.
resumen[].entradas
number
Total units received (incoming movements) on that day.
resumen[].salidas
number
Total units dispatched (outgoing movements) on that day.
ventasPorDia
array
Daily sales metrics for the last 30 days. Excludes cancelled sales.
ventasPorDia[].fecha
string
Date in YYYY-MM-DD format.
ventasPorDia[].numeroVentas
number
Number of completed sales on that day.
ventasPorDia[].totalIngreso
number
Total revenue on that day (rounded to the nearest integer).
ventasPorCategoria
array
Top 8 product categories by total revenue in the last 30 days, excluding cancelled sales.
ventasPorCategoria[].categoria
string
Category name.
ventasPorCategoria[].unidadesVendidas
number
Total units sold across all products in this category.
ventasPorCategoria[].ingresoTotal
number
Total revenue from this category (rounded).
distribucionStock
array
Count of products in each stock-health bucket across the entire catalogue.
distribucionStock[].estado
string
Stock health bucket: "Sin stock", "Stock bajo", or "Normal".
distribucionStock[].cantidad
number
Number of products in this bucket.
curl -b 'session=...' \
  'https://your-domain.com/api/analisis'

GET /api/analisis/exportar

Generates and streams a multi-sheet Excel workbook (.xlsx) containing the full analytics dataset. The file is named with a timestamp suffix in Colombia time (e.g., analisis_inventario_20250115_143022.xlsx). The workbook includes seven sheets: Resumen, Inventario general, Por agotarse, Sin movimientos, Alta rotación, Stock crítico, and Movimientos diarios. Monetary columns are formatted as currency; decimal columns are formatted to two decimal places. Required permission: EXPORTAR_REPORTES

Response

Returns a binary .xlsx stream with:
  • Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • Content-Disposition: attachment; filename="analisis_inventario_YYYYMMDD_HHMMSS.xlsx"
  • Cache-Control: no-store
curl -b 'session=...' \
  'https://your-domain.com/api/analisis/exportar' \
  -o analisis_inventario.xlsx

Build docs developers (and LLMs) love