import { auth } from "../../lib/auth"; import { ownerFilter } from "../../lib/authz"; import { getRenovClosed, getMotivosCierre, getSystemUsers } from "../../lib/queries"; import { agg, EJECUTIVOS_RENOV } from "../../lib/derive"; import LoginPrompt from "../../components/LoginPrompt"; import OwnerControl from "../../components/OwnerControl"; import ErrorNotice from "../../components/ErrorNotice"; import Panel from "../../components/pipeline/Panel"; import { DYN, money, money2 } from "../../lib/constants"; export const dynamic = "force-dynamic"; function currentMonth() { const d = new Date(); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`; } export default async function RenovPerdidasPage({ searchParams }) { const session = await auth(); if (!session?.email) return ; const { owner } = await searchParams; const scope = ownerFilter(session, owner); const mes = currentMonth(); let lost, allUsers; try { [lost, allUsers] = await Promise.all([ getRenovClosed(session.accessToken, scope, 2, mes), getSystemUsers(session.accessToken), ]); const motivos = await getMotivosCierre(lost.map((o) => o.id), session.accessToken); lost = lost.map((o) => ({ ...o, motivo: motivos[o.id]?.motivo || "Sin registrar", competidor: motivos[o.id]?.competidor })); } catch (error) { return ; } const owners = allUsers.filter((u) => EJECUTIVOS_RENOV.includes(u.name)); const mrrPerdido = lost.reduce((a, o) => a + (o.est || 0), 0); return (

Renovaciones Perdidas — {mes}

{lost.length} Renovaciones perdidas
{money(mrrPerdido)} MRR estimado perdido

No hay seguimiento registrado en el CRM ≠ no hubo seguimiento — la mayoría del contacto comercial se hace por WhatsApp, que no está integrado a Dynamics (ver CLAUDE.md).

o.est)} /> o.est)} />

Detalle de renovaciones perdidas

Clic en el nombre abre la oportunidad en Dynamics 365

{lost.length === 0 ? (

No hay renovaciones perdidas en este período para este filtro.

) : (
{!scope.locked && } {[...lost].sort((a, b) => (b.est || 0) - (a.est || 0)).map((o) => ( {!scope.locked && } ))}
Cliente Oportunidad Motivo de cierre Línea de NegocioEjecutivoMRR est.
{o.cliente || "—"} {o.name} {o.motivo} {o.linea || "—"}{o.owner}{o.est ? money2(o.est) : "—"}
)}
); }