"use client"; import { useState, useMemo } from "react"; import { agg, aggOrd, ETAPA_ORDER, EJECUTIVOS_VENTA } from "../../lib/derive"; import { actividadUrl } from "../../lib/constants"; import Panel from "../pipeline/Panel"; const HORIZONTES = [ ["hoy", "Hoy"], ["semana", "Esta semana"], ["semana_pasada", "Semana pasada"], ["mes", "Este mes"], ["mes_pasado", "Mes pasado"], ["todas", "Todas"], ]; function inicioSemana(d) { const x = new Date(d); const dow = (x.getDay() + 6) % 7; x.setDate(x.getDate() - dow); x.setHours(0, 0, 0, 0); return x; } function enRango(fecha, horizonte) { if (horizonte === "todas") return true; if (!fecha) return false; const f = new Date(fecha); f.setHours(0, 0, 0, 0); const hoy = new Date(); hoy.setHours(0, 0, 0, 0); if (horizonte === "hoy") return f.getTime() === hoy.getTime(); if (horizonte === "semana" || horizonte === "semana_pasada") { const lunes = inicioSemana(hoy); if (horizonte === "semana_pasada") lunes.setDate(lunes.getDate() - 7); const domingo = new Date(lunes); domingo.setDate(lunes.getDate() + (horizonte === "semana" ? 6 : 6)); if (horizonte === "semana_pasada") domingo.setDate(lunes.getDate() + 6); return f >= lunes && f <= domingo; } if (horizonte === "mes" || horizonte === "mes_pasado") { const base = new Date(hoy.getFullYear(), hoy.getMonth() - (horizonte === "mes_pasado" ? 1 : 0), 1); return f.getFullYear() === base.getFullYear() && f.getMonth() === base.getMonth(); } return true; } function TablaTipo({ titulo, rows, locked }) { if (!rows.length) return null; return (
| Asunto | Referente | Objetivo | {!locked &&Ejecutivo | }Estado | Fecha |
|---|---|---|---|---|---|
| {a.asunto} | {a.referente?.nombre || "—"} | {a.objetivo || "—"} | {!locked &&{a.owner} | }{a.estadoFinal} | {a.scheduledendFmt || a.scheduledstartFmt || "—"} |
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). Ventana de datos: últimos 90 días cerrados + todo lo que sigue abierto.
Con Objetivo de Actividad asignado: {conObjetivo} ({filtradas.length ? Math.round((conObjetivo / filtradas.length) * 100) : 0}%) — adopción real del campo. Referidas a Oportunidad: {conOportunidad.length} ({filtradas.length ? Math.round((conOportunidad.length / filtradas.length) * 100) : 0}%).
Completadas ÷ total de actividades (sin canceladas) de cada quien
{porEjecutivo.map((r) => (Oportunidades con más actividades referidas en este período
{oportunidadesRelacionadas.length ? oportunidadesRelacionadas.map((o) => (Ninguna actividad de este período está referida a una Oportunidad.
}