informe-comercial-alfa/app/components/pipeline/TablaPrevision.js

91 lines
4.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import PrioridadBadge from "./PrioridadBadge";
import { DYN, ACT_COLOR, money, nuevaActividadUrl, TIPOS_NUEVA_ACTIVIDAD } from "../../lib/constants";
import { nomCorto } from "../../lib/derive";
const PLAN_LETRA = {
"Plan A - En firma": "A", "Plan B - En Negociación": "B", "Plan C - En seguimiento": "C",
"Plan D - Recalificar": "D", "Sin plan de cierre": "—",
};
const cierreVencido = (o) => !!o.close && o.close < new Date().toISOString().slice(0, 10);
// Tabla única de Previsión de Ventas: la usan la lista principal («Oportunidades con cierre estimado en
// esta ventana») y las tres de «Oportunidades para accionar». Mismas columnas, mismo orden y mismos
// anchos, para que se alineen de arriba hacia abajo. Sin scroll horizontal en escritorio (anchos
// en `.fit-all`, components.css).
const COLS = [
"14%", "34px", "7%", "8%", "58px", "66px", "16%", "66px", "82px", "190px", "54px",
];
export default function TablaPrevision({ arr }) {
const sorted = [...arr].sort((a, b) => b.est - a.est);
return (
<div className="tw split">
<div className="ts">
<table className="fix fit-all">
<colgroup>{COLS.map((w, i) => <col key={i} style={{ width: w }} />)}</colgroup>
<thead>
<tr>
<th>Cliente / Oportunidad</th>
<th title="Plan de cierre">Plan</th>
<th>Línea</th>
<th>Ejecutivo</th>
<th className="num">MRR est.</th>
<th>Prioridad</th>
<th>Nota de negociación</th>
<th>Fecha Est. de cierre</th>
<th title="Si ya tiene una Tarea/Cita/Llamada agendada en la ventana">Agenda</th>
<th>Agendar</th>
<th title="Días desde la última actividad registrada">Actividad</th>
</tr>
</thead>
<tbody>
{sorted.map((o) => (
<tr key={o.id} style={!o.actFecha ? { boxShadow: "inset 3px 0 0 var(--pierde, #B23A2E)" } : undefined}>
<td className="dual-cel">
<a className="opp" href={`${DYN}${o.id}`} target="_blank" rel="noopener" title={o.name}>{o.name}</a>
<span className="sub" title={o.cliente || ""}>{o.cliente || "—"}</span>
</td>
<td>
<span className={`plan-b p${PLAN_LETRA[o.plan] || "x"}`} title={o.plan || "Sin plan de cierre"}>{PLAN_LETRA[o.plan] || "—"}</span>
</td>
<td className="elip" title={o.linea || ""}>{o.linea || "—"}</td>
<td className="elip" title={o.owner}>{nomCorto(o.owner)}</td>
<td className="num">{money(o.est)}</td>
<td><PrioridadBadge o={o} /></td>
<td className="nota-cel" title={o.estado || ""}>{o.estado ? (o.estado.length > 110 ? `${o.estado.slice(0, 110)}…` : o.estado) : "—"}</td>
<td className={`num${cierreVencido(o) ? " venc" : ""}`} title={cierreVencido(o) ? "Fecha de cierre vencida al corte" : ""}>
{o.close ? `${o.close.slice(8, 10)}/${o.close.slice(5, 7)}/${o.close.slice(2, 4)}` : "—"}{cierreVencido(o) ? " ⚠" : ""}
</td>
<td>
{o.actFecha ? (
<span style={{ color: "#3f7d5c", fontWeight: 700 }} title={`Actividad agendada para el ${o.actFecha}`}>📅 {o.actFecha.split("-").reverse().slice(0, 2).join("/")}</span>
) : (
<span style={{ color: "#B23A2E", fontWeight: 700 }} title="Sin Tarea/Cita/Llamada agendada en la ventana">Sin agenda</span>
)}
</td>
<td>
<span className="plan-agenda-btns">
{TIPOS_NUEVA_ACTIVIDAD.map((t) => (
<a key={t.etn} className="plan-agendar" href={nuevaActividadUrl({ id: o.id, nombre: o.name, ownerId: o.ownerId, owner: o.owner }, t.etn)} target="_blank" rel="noopener" title={t.ayuda}>+ {t.label}</a>
))}
</span>
</td>
<td style={{ textAlign: "center" }}>
<span style={{ color: ACT_COLOR[o.actividad] || "#9db4c9", fontWeight: 700 }} title={`${o.actividad}${o.estanc ? " · estancada" : ""}`}>●</span>
</td>
</tr>
))}
</tbody>
<tfoot>
<tr className="tot-fila">
<td>Total ({sorted.length} oport.)</td>
<td colSpan={3} />
<td className="num">{money(sorted.reduce((a, o) => a + o.est, 0))}</td>
<td colSpan={6} />
</tr>
</tfoot>
</table>
</div>
</div>
);
}