import { auth } from "../lib/auth"; import { ownerFilter } from "../lib/authz"; import { getPipeline, getSystemUsers } from "../lib/queries"; import LoginPrompt from "../components/LoginPrompt"; import OwnerControl from "../components/OwnerControl"; import ErrorNotice from "../components/ErrorNotice"; import Panel from "../components/pipeline/Panel"; import MatrizCalidad from "../components/pipeline/MatrizCalidad"; import TablaPipe from "../components/pipeline/TablaPipe"; import ExecMatrix from "../components/pipeline/ExecMatrix"; import SegTabs from "../components/SegTabs"; import FilterChips from "../components/FilterChips"; import { money } from "../lib/constants"; import { EJECUTIVOS_VENTA, agg, hayClasif, cierreVencido } from "../lib/derive"; import { parseFiltParam, applyFilt } from "../lib/filterState"; export const dynamic = "force-dynamic"; const IND_TABS = [ { k: "tipo", lbl: "Tipo" }, { k: "origen", lbl: "Origen" }, { k: "competidor", lbl: "Competidor" }, { k: "linea", lbl: "Línea" }, { k: "servicio", lbl: "Servicio" }, ]; const IND_TITULOS = { tipo: "Por Tipo de Oportunidad", origen: "Por Origen de Oportunidad", competidor: "Por Competidor", linea: "Por Línea de Negocio", servicio: "Por Servicio / Producto", }; const IND_TOP = { tipo: undefined, origen: 7, competidor: 7, linea: undefined, servicio: 7 }; const DIM_LABELS = { tipo: "Tipo", origen: "Origen", competidor: "Competidor", linea: "Línea", servicio: "Servicio", luz: "Luz Amarilla", calidad: "Calidad", mov: "Movimiento" }; export default async function TuberiaPage({ searchParams }) { const session = await auth(); if (!session?.email) return ; const sp = await searchParams; const { owner } = sp; const scope = ownerFilter(session, owner); const filt = parseFiltParam(sp.f); const indActive = IND_TABS.some((t) => t.k === sp.ind) ? sp.ind : "tipo"; let allRows, allUsers; try { [allRows, allUsers] = await Promise.all([ getPipeline(session.accessToken, scope), session.isAdmin ? getSystemUsers(session.accessToken) : Promise.resolve([]), ]); } catch (error) { return ; } const owners = allUsers.filter((u) => EJECUTIVOS_VENTA.includes(u.name)); const rows = applyFilt(allRows, filt); const sorted = [...rows].sort((a, b) => b.est - a.est); const totalEst = rows.reduce((a, r) => a + r.est, 0); const totalFc = rows.reduce((a, r) => a + r.fc, 0); const estanc = rows.filter((r) => r.estanc); const estancadas = estanc.length; const estancEst = estanc.reduce((a, r) => a + r.est, 0); const sinPlan = rows.filter((r) => r.plan === "Sin plan de cierre"); const sinPlanEst = sinPlan.reduce((a, r) => a + r.est, 0); const vencidas = rows.filter(cierreVencido); const enOfertaONegociacion = rows.filter((r) => r.faseActual === "Oferta" || r.faseActual === "Negociación").length; return (

Tubería Activa

{rows.length} Oportunidades activas
{money(totalEst)} Estimado total
{money(totalFc)} Forecast ponderado
{estancadas} Estancadas (>14d sin actividad o >30d en fase)
{sinPlan.length} Sin plan de cierre · {money(sinPlanEst)}
{sorted.length === 0 ? (

No hay oportunidades activas para este filtro.

) : ( <>
¿Qué es estancamiento? Una oportunidad está estancada si lleva más de 14 días sin ninguna actividad (llamada/cita/correo) o más de 30 días atascada en la misma fase. Hoy hay{" "} {estancadas} de {rows.length} así ({rows.length ? Math.round((estancadas / rows.length) * 100) : 0}%) —{" "} {money(estancEst)} de MRR sin movimiento. {vencidas.length} ya pasaron su fecha estimada de cierre. Y {enOfertaONegociacion} de {rows.length} están en Oferta o Negociación: el embudo está cargado al final — casi no entra nada nuevo por arriba.
Indicadores y detalle
{hayClasif(rows) && } o.est)} cls="alerta" top={7} dimKey="luz" />
o.est)} top={IND_TOP[indActive]} dimKey={indActive} />

Detalle de la tubería activa

Scroll horizontal con la columna Cliente/Oportunidad fija · Plan: A en firma · B negociación · C seguimiento · D recalificar · Actividad: ● verde activa, ámbar tibia, naranja fría, rojo congelada · ⚠ cierre vencido · clic en el nombre abre Dynamics

)}
); }