Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ency07/B2B/llms.txt

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

The ERP dashboard (/dashboard) is the central operations hub. It shows role-specific KPIs, a real-time task queue, operations health scores, a business events feed, and an audit log — all filtered to the authenticated user’s tenant.

Role-adaptive KPIs

Every user lands on the same /dashboard route, but the KPIs, queue title, and notification bell are driven by their assigned role. getKpisForRole resolves the authenticated user’s role code to one of seven internal categories and fires the matching query set.
CategoryRole CodesKPIs ShownQueue Focus
adminSUPER_ADMIN, ADMIN_EMPRESA, ADMIN_DEVFacturación Emitida, Recaudo Cartera, Capacidad Activa, Conversión LeadsOverdue invoices
directorGERENTE_GENERAL, DIRECTOR_FINANCIERO, JEFE_FINANZAS, AUXILIAR_FINANZASFacturación Emitida, Recaudo Cartera, Capacidad Activa, Conversión LeadsOverdue invoices
comercialDIRECTOR_COMERCIAL, EJECUTIVO_COMERCIAL, INGENIERO_COMERCIALLeads Activos, Leads Calientes, Leads Nuevos (mes), Tasa de ConversiónHot leads
operacionesDIRECTOR_OPERACIONES, JEFE_PROYECTOSOTs Activas, OTs Vencidas, Vencen esta semana, OTs CompletadasOverdue work orders
tecnicoTECNICO_CAMPO, JEFE_MANTENIMIENTOOTs Activas, OTs Vencidas, Vencen Hoy, Prioridad AltaMy work orders
almacenistaALMACENISTA, JEFE_INVENTARIOItems Stock Bajo, Items en Stock, Unidades Reservadas, Items OKReorder pending
auditorAUDITOREventos (7d), Eventos Críticos (DELETE), Eventos Hoy, Usuarios ÚnicosRecent audit events

getKpisForRole(tenantCode)RoleDashboardData

This is the preferred action for the authenticated dashboard view. It calls getAuthContext() to resolve the current user’s role, validates tenant access, then dispatches to the category-specific query block.
interface RoleDashboardData {
  kpis: KpiValue[];          // 4 role-specific KPI cards
  pending: PendingItem[];    // Task queue items
  queueTitle: string;        // e.g. "Leads por atender"
  queueSubtitle: string;
  notificationsTitle: string;
  notificationsCount: number;
  notifications?: NotificationItem[];
}

interface KpiValue {
  id: string;
  label: string;
  value: string;
  sub?: string;
  trend?: "up" | "down" | "neutral";
  variant?: "success" | "info" | "warning" | "danger" | "neutral";
  link?: string;
}

interface PendingItem {
  id: string;
  description: string;
  value?: string | null;
  deadline: string;
  isOverdue: boolean;
  link: string;
}
All seven categories run their queries in a single Promise.all over invoices, leads, jobs, inventory_stock, audit_log, quotes, and requirements — each filtered by tenant_id for multi-tenant isolation.

getDashboardCommandCenter(tenantCode)DashboardCommandCenterData

This action powers the admin-level command center widget. It runs seven parallel Supabase queries and assembles the full operations picture for the tenant.
interface DashboardCommandCenterData {
  tenantName: string;
  outstanding: number;        // Total outstanding balance across pending invoices
  invoiceCount: number;       // Count of pending invoices
  hasOverdue: boolean;
  hasDueSoon: boolean;
  delta: number;              // MoM change in outstanding (e.g. 0.124 = +12.4%)
  sparkline: number[];        // 30-day sparkline data points
  kpis: {
    totalInvoiced: number;
    totalPayments: number;
    leadSlaBreachRate: number;
  };
  recentEvents: RecentEvent[];
  auditLog: AuditEntry[];
  operationsHealth: OperationsHealth;
  queueTasks: QueueTask[];
  userName: string;
}

Sparkline generation

The 30-element sparkline array is generated from the current outstanding balance using a sine wave plus a linear trend, giving a smooth visual representation of the balance curve over the past month.

KPI computation

totalInvoiced and totalPayments are calculated by the calculate_kpi PostgreSQL RPC (codes TOTAL_INVOICED and TOTAL_PAYMENTS), stored in kpi_history per tenant/period, then fetched back via a join on kpi_definitions. If the RPC fails, the action falls back to an in-memory calculation over the raw invoices data.

Operations health scores

Each of the four areas in operationsHealth carries a score (0–100) and an alerts count. Scores degrade based on live DB state:
AreaScore FormulaAlerts
inventorymax(0, 100 − lowStockCount × 10) — decreases by 10 for each SKU with available_quantity ≤ 10Count of low-stock SKUs
billingCollection rate: (totalPaid / totalInvoiced) × 100Count of VENCIDA invoices
crm(convertedLeads / totalLeads) × 100Count of NUEVO leads awaiting follow-up
purchasesmax(0, 100 − pendingCount × 8) — decreases by 8 for each requirement in BORRADOR or NUEVO statusCount of unprocessed requirements

Command center task queue

queueTasks is populated dynamically from live DB queries in priority order:
  1. Overdue invoices (status = "VENCIDA") — up to 2 tasks, each linking to /dashboard/invoices.
  2. HIGH-priority requirements in BORRADOR, NUEVO, or EN_REVISION — up to 2 tasks, linking to /dashboard/requirements.
  3. HIGH-priority jobs in PENDIENTE or EN_EJECUCION — up to 2 tasks, linking to /dashboard/jobs.
  4. New leads (status = "NUEVO") — up to 2 tasks for prospect qualification, linking to /dashboard/leads.
interface QueueTask {
  id: string;
  description: string;
  value: string | null;   // Formatted COP amount (invoices) or null
  deadline: string;       // e.g. "Vencido", "Hoy", "24h", "2h"
  isOverdue: boolean;
  link: string;
}

Notifications

Each role’s notification bell (notifications array) is populated from contextually relevant live alerts:
Role CategoryNotification Sources
admin / directorOverdue invoices, low stock, critical/overdue OTs, HIGH-priority requirements
comercialHot leads (risk_level = "CALIENTE") not yet converted
operacionesCritical/overdue OTs, HIGH-priority requirements
tecnicoCritical/overdue OTs assigned to the technician
almacenistaItems with available_quantity ≤ 10
auditorTotal audit event count for the past 7 days
Each NotificationItem carries an isDanger flag — set to true for overdue invoices, voided stock, and overdue OTs — which drives the red/amber badge in the top bar.

Build docs developers (and LLMs) love