438 lines
21 KiB
JavaScript
438 lines
21 KiB
JavaScript
|
|
import { auth } from "../lib/auth";
|
|||
|
|
import { ownerFilter } from "../lib/authz";
|
|||
|
|
import { getPipeline, getSystemUsers, getActividades, getStageDurations } from "../lib/queries";
|
|||
|
|
import { agg, aggOrd, EJECUTIVOS_VENTA, hayClasif, decorarActividadVentana, ACTAGENDADA_ORDEN, pipeVelFor } from "../lib/derive";
|
|||
|
|
import { getMetaGlobal, getMetas } 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 VelPanel from "../components/pipeline/VelPanel";
|
|||
|
|
import SegTabs from "../components/SegTabs";
|
|||
|
|
import FilterChips from "../components/FilterChips";
|
|||
|
|
import ReportModal from "../components/ReportModal";
|
|||
|
|
import PanelesCalidad from "../components/pipeline/PanelesCalidad";
|
|||
|
|
import AccionTable from "../components/pipeline/AccionTable";
|
|||
|
|
import { DYN, money, money2 } from "../lib/constants";
|
|||
|
|
import { parseFiltParam, applyFilt } from "../lib/filterState";
|
|||
|
|
|
|||
|
|
const MESLBL_CAP = {
|
|||
|
|
"01": "Enero", "02": "Febrero", "03": "Marzo", "04": "Abril", "05": "Mayo", "06": "Junio",
|
|||
|
|
"07": "Julio", "08": "Agosto", "09": "Septiembre", "10": "Octubre", "11": "Noviembre", "12": "Diciembre",
|
|||
|
|
};
|
|||
|
|
function mesSiguiente(m) {
|
|||
|
|
const [y, mm] = m.split("-").map(Number);
|
|||
|
|
const d = new Date(y, mm, 1);
|
|||
|
|
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const dynamic = "force-dynamic";
|
|||
|
|
|
|||
|
|
const IND_TABS = [
|
|||
|
|
{ k: "owner", lbl: "Ejecutivo" },
|
|||
|
|
{ k: "tipo", lbl: "Tipo" },
|
|||
|
|
{ k: "origen", lbl: "Origen" },
|
|||
|
|
{ k: "vel", lbl: "Velocidad" },
|
|||
|
|
];
|
|||
|
|
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", actAgendada: "Agendado" };
|
|||
|
|
|
|||
|
|
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")}`;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Ventana de fechas del mes 'YYYY-MM' seleccionado, para cruzar con Actividades — puerto de
|
|||
|
|
// ventanaDeMes() (App Informe/assets/js/utils.js). Atrasadas no tiene fin natural (ya venció): se
|
|||
|
|
// lee como "¿ya se agendó algo desde hoy en adelante para corregirla?".
|
|||
|
|
function ventanaDeMes(win, hoyIso) {
|
|||
|
|
if (win === ATRASADAS) return { ini: hoyIso, fin: "9999-12-31" };
|
|||
|
|
const [y, m] = win.split("-").map(Number);
|
|||
|
|
const fin = new Date(y, m, 0);
|
|||
|
|
return { ini: `${win}-01`, fin: `${fin.getFullYear()}-${String(fin.getMonth() + 1).padStart(2, "0")}-${String(fin.getDate()).padStart(2, "0")}` };
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export default async function PrevisionPage({ searchParams }) {
|
|||
|
|
const session = await auth();
|
|||
|
|
if (!session?.email) return <LoginPrompt />;
|
|||
|
|
|
|||
|
|
const sp = await searchParams;
|
|||
|
|
const { owner, w: winParam } = sp;
|
|||
|
|
const scope = ownerFilter(session, owner);
|
|||
|
|
const hoy = currentMonth();
|
|||
|
|
const filt = parseFiltParam(sp.f);
|
|||
|
|
const indActive = IND_TABS.some((t) => t.k === sp.ind) ? sp.ind : "owner";
|
|||
|
|
const mze = sp.mze;
|
|||
|
|
|
|||
|
|
let allRows, allUsers, actividades;
|
|||
|
|
try {
|
|||
|
|
[allRows, allUsers, actividades] = await Promise.all([
|
|||
|
|
getPipeline(session.accessToken, scope),
|
|||
|
|
session.isAdmin ? getSystemUsers(session.accessToken) : Promise.resolve([]),
|
|||
|
|
getActividades(session.accessToken, scope),
|
|||
|
|
]);
|
|||
|
|
} catch (error) {
|
|||
|
|
return <ErrorNotice error={error} />;
|
|||
|
|
}
|
|||
|
|
const owners = allUsers.filter((u) => EJECUTIVOS_VENTA.includes(u.name));
|
|||
|
|
|
|||
|
|
const base = allRows.filter((o) => PREVIS_TIPOS.includes(o.tipo) && !PREVIS_PLANES_EXCL.includes(o.plan));
|
|||
|
|
const futuros = [...new Set(base.map((o) => o.mesCierre).filter((m) => m && m >= hoy))].sort();
|
|||
|
|
const atrasadas = base.filter((o) => !o.mesCierre || o.mesCierre < hoy);
|
|||
|
|
const win = winParam === ATRASADAS ? ATRASADAS : futuros.includes(winParam) ? winParam : futuros[0] || hoy;
|
|||
|
|
const hoyIso = new Date().toISOString().slice(0, 10);
|
|||
|
|
const { ini, fin } = ventanaDeMes(win, hoyIso);
|
|||
|
|
const pWinRaw = win === ATRASADAS ? atrasadas : base.filter((o) => o.mesCierre === win);
|
|||
|
|
const pWin = decorarActividadVentana(pWinRaw, actividades, ini, fin);
|
|||
|
|
const p = applyFilt(pWin, filt);
|
|||
|
|
const stageDurations = indActive === "vel" ? await getStageDurations(p.map((o) => o.id), session.accessToken) : [];
|
|||
|
|
|
|||
|
|
const est = p.reduce((a, o) => a + o.est, 0);
|
|||
|
|
const fc = p.reduce((a, o) => a + o.fc, 0);
|
|||
|
|
const estanc = p.filter((o) => o.estanc);
|
|||
|
|
const metaGlobal = getMetaGlobal();
|
|||
|
|
const coverage = metaGlobal ? Math.round((fc / metaGlobal) * 100) : null;
|
|||
|
|
|
|||
|
|
// Informe de Previsión — solo con un único propietario seleccionado (ver mismo criterio en
|
|||
|
|
// tuberia/page.js). Usa `base` (todo lo elegible de previsión para esa persona, sin la ventana
|
|||
|
|
// de mes ni el filtro `f` activos) para no mezclar el snapshot del informe con lo que se esté
|
|||
|
|
// mirando en pantalla.
|
|||
|
|
const ownerName = scope.emails?.length === 1
|
|||
|
|
? session.isAdmin
|
|||
|
|
? allUsers.find((u) => u.email === scope.emails[0])?.name
|
|||
|
|
: session.user?.name
|
|||
|
|
: null;
|
|||
|
|
let previsionReportContent = null;
|
|||
|
|
if (ownerName) {
|
|||
|
|
const meta = getMetas()[scope.emails[0]] || null;
|
|||
|
|
const baseOwner = base.filter((o) => o.owner === ownerName);
|
|||
|
|
const proxMes = mesSiguiente(hoy);
|
|||
|
|
const pMes = baseOwner.filter((o) => o.mesCierre === hoy);
|
|||
|
|
const pProx = baseOwner.filter((o) => o.mesCierre === proxMes);
|
|||
|
|
const fcMes = pMes.reduce((a, o) => a + o.fc, 0);
|
|||
|
|
const fcProx = pProx.reduce((a, o) => a + o.fc, 0);
|
|||
|
|
const estMes = pMes.reduce((a, o) => a + o.est, 0);
|
|||
|
|
const coberturaMes = meta ? Math.round((fcMes / meta) * 100) : null;
|
|||
|
|
const brecha = meta ? Math.max(0, meta - fcMes) : 0;
|
|||
|
|
const bloqueadas = { precio: [], aprobacion: [], licitacion: [] };
|
|||
|
|
pMes.forEach((o) => {
|
|||
|
|
const cat = classifyBlocker(o.estado);
|
|||
|
|
if (cat) bloqueadas[cat].push(o);
|
|||
|
|
});
|
|||
|
|
const subibles = pMes
|
|||
|
|
.filter((o) => (o.plan === "Plan B - En Negociación" || o.plan === "Plan C - En seguimiento") && !o.estanc && !bloqueadas.precio.includes(o) && !bloqueadas.aprobacion.includes(o))
|
|||
|
|
.sort((a, b) => b.fc - a.fc);
|
|||
|
|
const estancSinBloqueo = pMes.filter((o) => o.estanc && !classifyBlocker(o.estado));
|
|||
|
|
const upsideNoPonderado = estMes - fcMes;
|
|||
|
|
const faltante = Math.max(0, brecha - upsideNoPonderado);
|
|||
|
|
const pipelineNuevoNecesario = faltante > 0 ? Math.round(faltante / 0.3) : 0;
|
|||
|
|
const diagClass = meta == null ? "info" : coberturaMes >= 100 ? "info" : coberturaMes >= 70 ? "warn" : "bad";
|
|||
|
|
const nombre = ownerName.split(" ")[0];
|
|||
|
|
const lblMesCap = MESLBL_CAP[hoy.slice(5, 7)] || hoy;
|
|||
|
|
const lblProxCap = MESLBL_CAP[proxMes.slice(5, 7)] || proxMes;
|
|||
|
|
|
|||
|
|
previsionReportContent = (
|
|||
|
|
<>
|
|||
|
|
<div style={{ borderBottom: "3px solid var(--ancla)", paddingBottom: 16, marginBottom: 20, display: "flex", justifyContent: "space-between", alignItems: "flex-end", flexWrap: "wrap", gap: 10 }}>
|
|||
|
|
<div>
|
|||
|
|
<div style={{ fontSize: 11, textTransform: "uppercase", letterSpacing: ".06em", color: "var(--tinta-suave)" }}>Informe de previsión — {lblMesCap}</div>
|
|||
|
|
<h2 style={{ margin: "4px 0 0", color: "var(--ancla)", fontSize: 24 }}>{ownerName}</h2>
|
|||
|
|
</div>
|
|||
|
|
<div style={{ textAlign: "right", fontSize: 12, color: "var(--tinta-suave)" }}>Solo Plan de Cierre A, B o C</div>
|
|||
|
|
</div>
|
|||
|
|
<div className="kpis" style={{ marginBottom: 18 }}>
|
|||
|
|
{meta && <div className="kpi"><span className="n">{money(meta)}</span><span className="l">Meta de {lblMesCap}</span></div>}
|
|||
|
|
<div className="kpi"><span className="n">{money(fcMes)}</span><span className="l">Forecast ponderado {lblMesCap}</span></div>
|
|||
|
|
{meta && <div className="kpi"><span className={`n ${coberturaMes < 100 ? "pierde" : ""}`}>{coberturaMes}%</span><span className="l">Cobertura de meta</span></div>}
|
|||
|
|
{meta && brecha > 0 && <div className="kpi"><span className="n pierde">{money(brecha)}</span><span className="l">Brecha a la meta</span></div>}
|
|||
|
|
<div className="kpi"><span className="n">{money(fcProx)}</span><span className="l">Forecast ponderado {lblProxCap}</span></div>
|
|||
|
|
</div>
|
|||
|
|
<PanelesCalidad p={baseOwner} />
|
|||
|
|
<div className={`callout ${diagClass}`}>
|
|||
|
|
{meta == null ? (
|
|||
|
|
<><b>{nombre} aún no tiene meta individual cargada</b> — este informe muestra el forecast pero no puede calcular cobertura ni brecha.</>
|
|||
|
|
) : coberturaMes >= 100 ? (
|
|||
|
|
<><b>{nombre} va bien encaminada: el forecast ponderado ({money(fcMes)}) ya cubre el {coberturaMes}% de su meta ({money(meta)}).</b> El foco esta semana es consolidar lo que sigue abierto, no solo cubrir el número.</>
|
|||
|
|
) : (
|
|||
|
|
<><b>Hay una brecha de {money(brecha)} para llegar a la meta de {lblMesCap} ({money(meta)}).</b> Así se cierra, en orden de impacto:</>
|
|||
|
|
)}
|
|||
|
|
</div>
|
|||
|
|
{bloqueadas.precio.length > 0 && (
|
|||
|
|
<div className="panel" style={{ marginBottom: 14 }}>
|
|||
|
|
<h3>1. Palanca de precio — {bloqueadas.precio.length} oport. · {money(bloqueadas.precio.reduce((a, o) => a + o.fc, 0))} ponderado en juego</h3>
|
|||
|
|
<p className="hint">{BLOCKER_INFO.precio.accion}</p>
|
|||
|
|
<AccionTable list={bloqueadas.precio} />
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{bloqueadas.aprobacion.length > 0 && (
|
|||
|
|
<div className="panel" style={{ marginBottom: 14 }}>
|
|||
|
|
<h3>2. Palanca de aprobación interna — {bloqueadas.aprobacion.length} oport. · {money(bloqueadas.aprobacion.reduce((a, o) => a + o.fc, 0))} ponderado en juego</h3>
|
|||
|
|
<p className="hint">{BLOCKER_INFO.aprobacion.accion}</p>
|
|||
|
|
<AccionTable list={bloqueadas.aprobacion} />
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{subibles.length > 0 && (
|
|||
|
|
<div className="panel" style={{ marginBottom: 14 }}>
|
|||
|
|
<h3>3. Subir de plan esta semana — {subibles.length} oport. en Plan B/C activas</h3>
|
|||
|
|
<p className="hint">Sin bloqueo identificado y sin estancarse — ordenadas por forecast ponderado. Mover estas a Plan A es lo que más rápido sube la cobertura.</p>
|
|||
|
|
<AccionTable list={subibles} />
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{estancSinBloqueo.length > 0 && (
|
|||
|
|
<div className="panel" style={{ marginBottom: 14 }}>
|
|||
|
|
<h3>4. Reactivar sin motivo claro — {estancSinBloqueo.length} oport. estancadas</h3>
|
|||
|
|
<p className="hint">Sin una razón identificada en las notas — necesitan un toque esta semana para no perder el mes.</p>
|
|||
|
|
<AccionTable list={estancSinBloqueo} />
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{bloqueadas.licitacion.length > 0 && (
|
|||
|
|
<div className="callout info">
|
|||
|
|
<b>{bloqueadas.licitacion.length} oportunidad(es) en licitación externa</b> ({money(bloqueadas.licitacion.reduce((a, o) => a + o.fc, 0))} ponderado) — fuera de control directo este mes, mantener la relación.
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{meta && faltante > 0 && (
|
|||
|
|
<div className="callout bad">
|
|||
|
|
<b>Aun empujando todas las palancas de arriba, el pipeline actual de {lblMesCap} no alcanza la meta.</b> Con las oportunidades ya en tubería, el máximo realista (si todo cerrara) es {money(estMes)} — faltarían {money(faltante)} para cubrir la brecha. Se necesitaría generar aproximadamente <b>{money(pipelineNuevoNecesario)}</b> de MRR nuevo en oportunidades esta semana para tener chance de llegar a la meta.
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
<div className="callout warn" style={{ marginTop: 22 }}>
|
|||
|
|
<b>{lblProxCap}: {money(fcProx)} de forecast ({pProx.length} oport.)</b>{meta && ` vs. una meta de ${money(meta)} — ${Math.round((fcProx / meta) * 100)}% cubierto hoy.`} Si no se genera pipeline nuevo esta semana, {lblProxCap} arranca con el mismo problema que {lblMesCap}.
|
|||
|
|
</div>
|
|||
|
|
<p className="hint" style={{ marginTop: 24, borderTop: "1px solid var(--linea)", paddingTop: 12 }}>Generado desde Analítica Comercial ALFA+ · Datos Dynamics 365 · en vivo.</p>
|
|||
|
|
</>
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const groups = { precio: [], aprobacion: [], licitacion: [] };
|
|||
|
|
p.forEach((o) => {
|
|||
|
|
const cat = classifyBlocker(o.estado);
|
|||
|
|
if (cat) groups[cat].push(o);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
const accionablesBlock = (
|
|||
|
|
<>
|
|||
|
|
{Object.entries(groups).some(([, v]) => v.length > 0) && (
|
|||
|
|
<div className="panel" style={{ marginTop: 18 }}>
|
|||
|
|
<h3>Oportunidades para accionar esta semana</h3>
|
|||
|
|
<p className="hint">Clasificado por palabras clave en "Estado de la Negociación" de Dynamics.</p>
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
{Object.entries(groups)
|
|||
|
|
.filter(([, list]) => list.length > 0)
|
|||
|
|
.map(([key, list]) => {
|
|||
|
|
const gEst = list.reduce((a, o) => a + o.est, 0);
|
|||
|
|
const gFc = list.reduce((a, o) => a + o.fc, 0);
|
|||
|
|
return (
|
|||
|
|
<div className="panel" style={{ marginBottom: 14 }} key={key}>
|
|||
|
|
<h3>
|
|||
|
|
{BLOCKER_INFO[key].label} — {list.length} oport. · {money(gEst)} est. · {money(gFc)} ponderado
|
|||
|
|
</h3>
|
|||
|
|
<p className="hint">{BLOCKER_INFO[key].accion}</p>
|
|||
|
|
<div className="tw">
|
|||
|
|
<div className="ts">
|
|||
|
|
<table>
|
|||
|
|
<thead>
|
|||
|
|
<tr>
|
|||
|
|
<th>Cliente</th>
|
|||
|
|
<th>Oportunidad</th>
|
|||
|
|
<th>Ejecutivo</th>
|
|||
|
|
<th className="num">MRR</th>
|
|||
|
|
<th>Nota de negociación</th>
|
|||
|
|
</tr>
|
|||
|
|
</thead>
|
|||
|
|
<tbody>
|
|||
|
|
{[...list].sort((a, b) => b.est - a.est).map((o) => (
|
|||
|
|
<tr key={o.id}>
|
|||
|
|
<td>{o.cliente || "—"}</td>
|
|||
|
|
<td>
|
|||
|
|
<a className="opp" href={`${DYN}${o.id}`} target="_blank" rel="noopener">
|
|||
|
|
{o.name}
|
|||
|
|
</a>
|
|||
|
|
</td>
|
|||
|
|
<td>{o.owner}</td>
|
|||
|
|
<td className="num">{money2(o.est)}</td>
|
|||
|
|
<td style={{ color: "var(--tinta-suave)", fontSize: 12 }}>
|
|||
|
|
{(o.estado || "").slice(0, 100)}
|
|||
|
|
{(o.estado || "").length > 100 ? "…" : ""}
|
|||
|
|
</td>
|
|||
|
|
</tr>
|
|||
|
|
))}
|
|||
|
|
</tbody>
|
|||
|
|
</table>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
})}
|
|||
|
|
</>
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
const linkFor = (w) => {
|
|||
|
|
const params = new URLSearchParams();
|
|||
|
|
if (owner) params.set("owner", owner);
|
|||
|
|
params.set("w", w);
|
|||
|
|
return `/prevision?${params.toString()}`;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
return (
|
|||
|
|
<div style={{ padding: 24 }}>
|
|||
|
|
<div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 12 }}>
|
|||
|
|
<h2>Previsión de Ventas</h2>
|
|||
|
|
<div style={{ display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" }}>
|
|||
|
|
<ReportModal
|
|||
|
|
buttonLabel="📈 Informe de Previsión"
|
|||
|
|
disabled={!ownerName}
|
|||
|
|
disabledTitle="Selecciona un solo ejecutivo en Propietario para generar su informe individual."
|
|||
|
|
>
|
|||
|
|
{previsionReportContent}
|
|||
|
|
</ReportModal>
|
|||
|
|
<OwnerControl
|
|||
|
|
owners={owners}
|
|||
|
|
current={scope.locked ? [session.email] : scope.emails}
|
|||
|
|
locked={scope.locked}
|
|||
|
|
lockedLabel={session.email}
|
|||
|
|
/>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<p className="hint" style={{ marginBottom: 8 }}>
|
|||
|
|
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).
|
|||
|
|
</p>
|
|||
|
|
|
|||
|
|
<div className="seg-tabs" style={{ marginBottom: 16, flexWrap: "wrap" }}>
|
|||
|
|
{atrasadas.length > 0 && (
|
|||
|
|
<a href={linkFor(ATRASADAS)}>
|
|||
|
|
<button className={win === ATRASADAS ? "on" : ""} type="button">
|
|||
|
|
⚠ Atrasadas ({atrasadas.length})
|
|||
|
|
</button>
|
|||
|
|
</a>
|
|||
|
|
)}
|
|||
|
|
{futuros.map((m) => (
|
|||
|
|
<a key={m} href={linkFor(m)}>
|
|||
|
|
<button className={win === m ? "on" : ""} type="button">
|
|||
|
|
{m}
|
|||
|
|
</button>
|
|||
|
|
</a>
|
|||
|
|
))}
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div className="kpis">
|
|||
|
|
<div className="kpi">
|
|||
|
|
<span className="n">{p.length}</span>
|
|||
|
|
<span className="l">Oportunidades en esta ventana</span>
|
|||
|
|
</div>
|
|||
|
|
<div className="kpi">
|
|||
|
|
<span className="n">{money(est)}</span>
|
|||
|
|
<span className="l">Valor estimado (MRR)</span>
|
|||
|
|
</div>
|
|||
|
|
<div className="kpi">
|
|||
|
|
<span className="n">{money(fc)}</span>
|
|||
|
|
<span className="l">Forecast ponderado</span>
|
|||
|
|
</div>
|
|||
|
|
<div className="kpi">
|
|||
|
|
<span className={coverage != null && coverage < 100 ? "n pierde" : "n"}>
|
|||
|
|
{coverage != null ? `${coverage}%` : "n/d"}
|
|||
|
|
</span>
|
|||
|
|
<span className="l">Coverage vs meta equipo ({money(metaGlobal)})</span>
|
|||
|
|
</div>
|
|||
|
|
<div className="kpi">
|
|||
|
|
<span className="n pierde">{estanc.length}</span>
|
|||
|
|
<span className="l">En riesgo (estancadas)</span>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div className="callout warn">
|
|||
|
|
<b>Forecast ponderado = Σ (MRR estimado × probabilidad del Plan de Cierre).</b> Pesos: Plan A 90% · Plan B
|
|||
|
|
60% · Plan C 30%. Este número no castiga la antigüedad — una oferta de hace 5 días pesa igual que una de 144
|
|||
|
|
días. Cruzar siempre con "Días en fase" antes de darlo por seguro.
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
{p.length > 0 && <ExecMatrix arr={p} titulo="Forecast por ejecutivo" valor={(o) => o.fc} hint="Forecast ponderado (MRR × peso del plan) por ejecutivo y Plan de Cierre" activeDim={mze} />}
|
|||
|
|
|
|||
|
|
<div className="sec-div"><span>Indicadores y detalle</span></div>
|
|||
|
|
<FilterChips dimLabels={DIM_LABELS} />
|
|||
|
|
{pWin.length === 0 ? (
|
|||
|
|
<p>No hay oportunidades en esta ventana.</p>
|
|||
|
|
) : (
|
|||
|
|
<div className="split23">
|
|||
|
|
<div className="split23-ind">
|
|||
|
|
{hayClasif(p) && <MatrizCalidad arr={p} />}
|
|||
|
|
<Panel
|
|||
|
|
title="Luz Amarilla — qué la detiene"
|
|||
|
|
hint="Bloqueador declarado por el ejecutivo"
|
|||
|
|
rows={agg(p, "luz", (o) => o.fc)}
|
|||
|
|
cls="alerta"
|
|||
|
|
top={7}
|
|||
|
|
byVal
|
|||
|
|
dimKey="luz"
|
|||
|
|
/>
|
|||
|
|
<Panel
|
|||
|
|
title="¿Ya se agendó algo?"
|
|||
|
|
hint={`Tarea/Cita/Llamada dentro de la ventana seleccionada`}
|
|||
|
|
rows={aggOrd(p, "actAgendada", ACTAGENDADA_ORDEN, (o) => o.fc)}
|
|||
|
|
cls="alerta"
|
|||
|
|
dimKey="actAgendada"
|
|||
|
|
/>
|
|||
|
|
<Panel title="Forecast por Plan de Cierre" rows={agg(p, "plan", (o) => o.fc)} byVal dimKey="plan" />
|
|||
|
|
<div className="panel" style={{ paddingBottom: 4 }}>
|
|||
|
|
<SegTabs tabs={IND_TABS} activeKey={indActive} paramName="ind" />
|
|||
|
|
</div>
|
|||
|
|
{indActive === "vel" ? (
|
|||
|
|
<VelPanel
|
|||
|
|
title="Velocidad de movimiento"
|
|||
|
|
hint={`Días promedio en cada fase ya completada, de las ${p.length} oportunidades con cierre en el período que ves ahora`}
|
|||
|
|
vel={pipeVelFor(p, stageDurations)}
|
|||
|
|
/>
|
|||
|
|
) : (
|
|||
|
|
<Panel
|
|||
|
|
title={IND_TITULOS[indActive]}
|
|||
|
|
hint="Ordenado por forecast ponderado"
|
|||
|
|
rows={agg(p, indActive, (o) => o.fc)}
|
|||
|
|
top={IND_TOP[indActive]}
|
|||
|
|
byVal
|
|||
|
|
dimKey={indActive}
|
|||
|
|
/>
|
|||
|
|
)}
|
|||
|
|
</div>
|
|||
|
|
<div>
|
|||
|
|
<div className="panel" style={{ paddingBottom: 6 }}>
|
|||
|
|
<h3>Oportunidades con cierre estimado en esta ventana</h3>
|
|||
|
|
<p className="hint">Forecast = MRR × peso del plan · scroll horizontal con la columna fija · clic en el nombre abre Dynamics</p>
|
|||
|
|
</div>
|
|||
|
|
<TablaPipe arr={p} tipo="fc" />
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
)}
|
|||
|
|
|
|||
|
|
{accionablesBlock}
|
|||
|
|
</div>
|
|||
|
|
);
|
|||
|
|
}
|