Overview
The analytics system provides comprehensive insights into lottery operations through multiple specialized endpoints. All endpoints support RBAC filtering, date ranges, and dimensional breakdowns.Dashboard Overview
The main dashboard endpoint aggregates all key metrics in a single response.src/api/v1/controllers/dashboard.controller.ts:44-74:
Query Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
date | string | today | yesterday | week | month | range | today |
fromDate | string | Start date (YYYY-MM-DD) for date=range | - |
toDate | string | End date (YYYY-MM-DD) for date=range | - |
dimension | string | ventana | loteria | vendedor | - |
ventanaId | string | Filter by ventana (ADMIN only) | - |
loteriaId | string | Filter by lottery | - |
betType | string | NUMERO | REVENTADO | - |
interval | string | day | hour | day |
scope | string | all | mine | all |
Response Structure
Ganancia (Profit) Analysis
Detailed profit breakdown with commission deduction.src/api/v1/controllers/dashboard.controller.ts:81-114:
Response Structure
Month-to-Date Ganancia
Accumulated profit from start of month to today.src/api/v1/controllers/dashboard.controller.ts:121-180:
Month-to-date calculation:
- Start: First day of current month at 00:00 CR time
- End: Current day at 23:59:59.999 CR time
- Automatically resolves month name in Spanish
CXC (Accounts Receivable)
Track amounts owed by customers.src/api/v1/controllers/dashboard.controller.ts:186-218:
Dimensions
dimension=ventana: CXC grouped by ventanadimension=vendedor: CXC grouped by vendedor
Response
CXP (Accounts Payable)
Track amounts owed to vendedores/ventanas.src/api/v1/controllers/dashboard.controller.ts:224-257:
Time Series
Sales and profit trends over time.src/api/v1/controllers/dashboard.controller.ts:263-303:
Intervals
interval=day: Daily aggregation (any period)interval=hour: Hourly aggregation (max 7 days)
Compare Mode
Whencompare=true, includes data from equivalent previous period.
Exposure Analysis
Financial risk analysis by number, showing potential payout if specific numbers win.src/api/v1/controllers/dashboard.controller.ts:309-344:
Response
Vendedor Rankings
Performance ranking with pagination.src/api/v1/controllers/dashboard.controller.ts:350-390:
Sorting Options
orderBy=sales: Sort by total salesorderBy=tickets: Sort by ticket countorderBy=payout: Sort by total payoutorderBy=net: Sort by net profitorderBy=commission: Sort by commission earned
Dashboard Summary (Unified)
Consolidated endpoint replacing multiple individual calls.src/api/v1/controllers/dashboard.controller.ts:547-567:
/ganancia/cxc?dimension=ventana/cxp?dimension=ventana/ganancia/month-to-date/accumulated-balances?dimension=ventana
Dashboard Entities (Vendedor Detail)
src/api/v1/controllers/dashboard.controller.ts:575-595:
/cxc?dimension=vendedor/cxp?dimension=vendedor/vendedores/accumulated-balances?dimension=vendedor
Export Dashboard
Export dashboard data in CSV, XLSX, or PDF format.src/api/v1/controllers/dashboard.controller.ts:431-539:
Export Formats
format=csv: UTF-8 CSV with BOM (Excel compatible)format=xlsx: Excel workbook with multiple sheetsformat=pdf: PDF report with charts
RBAC and Permissions
Role-Based Filtering
Fromsrc/api/v1/controllers/dashboard.controller.ts:20-37:
- VENDEDOR: ❌ No dashboard access
- VENTANA: ✅ Own ventana data only
- ADMIN: ✅ All data, filtered by active banca context
Best Practices
Use unified endpoints for performance
Use unified endpoints for performance
Prefer
/dashboard/summary and /dashboard/entities over multiple individual calls to reduce latency.Cache dashboard data client-side
Cache dashboard data client-side
Dashboard queries are expensive. Cache results for 1-5 minutes and refresh on user action.
Use hour interval sparingly
Use hour interval sparingly
interval=hour is only allowed for periods ≤7 days and generates 168+ data points. Use for tactical views only.Monitor exposure regularly
Monitor exposure regularly
Check
/dashboard/exposure before each major sorteo. Create restriction rules for numbers with >10x average exposure.Export for compliance
Export for compliance
Use
/export?format=xlsx for auditable financial reports. Include date ranges in filename.Compare periods for trends
Compare periods for trends
Use
compare=true in timeseries to identify growth/decline patterns quickly.Related Guides
- Ticket Creation - Source of sales data
- Sorteo Management - Understanding draw cycles
- Payments - Payment tracking in analytics
- Restriction Rules - Using exposure data to set limits