import { auth } from "../lib/auth";
import { ownerFilter } from "../lib/authz";
import { getPipeline, getSystemUsers } from "../lib/queries";
import { agg, EJECUTIVOS_VENTA, hayClasif } from "../lib/derive";
import { getMetaGlobal } from "../lib/metas";
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 { DYN, money, money2 } from "../lib/constants";
import { parseFiltParam, applyFilt } from "../lib/filterState";
export const dynamic = "force-dynamic";
const IND_TABS = [
{ k: "owner", lbl: "Ejecutivo" },
{ k: "tipo", lbl: "Tipo" },
{ k: "origen", lbl: "Origen" },
];
const IND_TITULOS = {
owner: "Por Ejecutivo",
tipo: "Por Tipo de Oportunidad",
origen: "Por Origen de Oportunidad",
};
const IND_TOP = { owner: undefined, tipo: undefined, origen: 7 };
const DIM_LABELS = { owner: "Ejecutivo", tipo: "Tipo", origen: "Origen", luz: "Luz Amarilla", plan: "Plan de Cierre", calidad: "Calidad", mov: "Movimiento" };
const PREVIS_TIPOS = ["Venta - Cliente Nuevo", "Up-Selling", "Cross-Selling"];
const PREVIS_PLANES_EXCL = ["Sin plan de cierre", "Plan D - Recalificar"];
const ATRASADAS = "__ATRASADAS__";
const BLOCKER_INFO = {
precio: { label: "Precio / oferta no competitiva", accion: "Evaluar un acelerador puntual: descuento, mes de cortesía o ajuste de instalación." },
aprobacion: { label: "Esperando aprobación interna del cliente", accion: "Escalar con una llamada ejecutivo a gerente para destrabar la firma." },
licitacion: { label: "Proceso de licitación externo", accion: "Fuera de control directo por ahora — mantener la relación." },
};
function classifyBlocker(txt) {
txt = (txt || "").toLowerCase();
if (/licitaci|licitatorio/.test(txt)) return "licitacion";
if (/precio|tarifa|descuento|presupuesto|\bcost[oa]\b|\bcara\b|instalaci[oó]n/.test(txt)) return "precio";
if (/aprobaci|aprobar|aprob[oó]|gerencia|gerente|\bfirma\b|firmar|comit[eé]/.test(txt)) return "aprobacion";
return null;
}
function currentMonth() {
const d = new Date();
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
}
export default async function PrevisionPage({ searchParams }) {
const session = await auth();
if (!session?.email) return
Clasificado por palabras clave en "Estado de la Negociación" de Dynamics.
{BLOCKER_INFO[key].accion}
| Cliente | Oportunidad | Ejecutivo | MRR | Nota de negociación |
|---|---|---|---|---|
| {o.cliente || "—"} | {o.name} | {o.owner} | {money2(o.est)} | {(o.estado || "").slice(0, 100)} {(o.estado || "").length > 100 ? "…" : ""} |
Solo considera oportunidades con Plan de Cierre A, B o C (se excluyen "Sin plan de cierre" y "Plan D - Recalificar" por no tener compromiso de cierre real).
No hay oportunidades en esta ventana.
) : (Forecast = MRR × peso del plan · scroll horizontal con la columna fija · clic en el nombre abre Dynamics