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 { money } from "../lib/constants"; import { EJECUTIVOS_VENTA, agg, hayClasif } from "../lib/derive"; export const dynamic = "force-dynamic"; export default async function TuberiaPage({ searchParams }) { const session = await auth(); if (!session?.email) return ; const { owner } = await searchParams; const scope = ownerFilter(session, owner); let rows, allUsers; try { [rows, 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 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 estancadas = rows.filter((r) => r.estanc).length; return (

Tubería Activa

{rows.length} Oportunidades activas
{money(totalEst)} Estimado total
{money(totalFc)} Forecast ponderado
{estancadas} Estancadas
{sorted.length === 0 ? (

No hay oportunidades activas para este filtro.

) : ( <>
Indicadores y detalle
{hayClasif(rows) && } o.est)} cls="alerta" top={7} /> o.est)} /> o.est)} top={7} /> o.est)} top={7} /> o.est)} /> o.est)} top={7} />

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

)}
); }