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

123 lines
4.8 KiB
JavaScript
Raw Normal View History

import { DYN, money2 } from "../../lib/constants";
import PrioridadBadge from "./PrioridadBadge";
// Tabla de "palancas" del Informe de Previsión — puerto de accionRowInforme()/accionTable()
// (App Informe/assets/js/modals.js). Sin columna Ejecutivo/Bloqueo/Agendar a propósito: el informe
// ya es de un solo dueño (va en el encabezado), y no es interactivo (es un snapshot para 1:1).
const PLAN_LETRA = { "Plan A - En firma": "A", "Plan B - En Negociación": "B", "Plan C - En seguimiento": "C", "Plan D - Recalificar": "D" };
const fechaTxt = (iso) => {
if (!iso) return "—";
const [y, m, d] = iso.split("-");
return `${d}/${m}/${y.slice(2)}`;
};
// `prevision`: columnas del informe imprimible de Previsión de Ventas (Cliente / Oportunidad, Plan,
// Línea, MRR est., Prioridad, Nota de negociación, Fecha est. de cierre; sin Forecast ni Ejecutivo).
export default function AccionTable({ list, prevision = false }) {
if (!list.length) return <p className="hint">Ninguna oportunidad en esta categoría — bien ahí.</p>;
const sorted = [...list].sort((a, b) => b.fc - a.fc);
if (prevision) {
return (
<div className="tw">
<div className="ts" style={{ maxHeight: "none" }}>
<table className="accion-tbl accion-prev">
<colgroup>
<col style={{ width: "25%" }} />
<col style={{ width: "6%" }} />
<col style={{ width: "12%" }} />
<col style={{ width: "9%" }} />
<col style={{ width: "10%" }} />
<col style={{ width: "25%" }} />
<col style={{ width: "13%" }} />
</colgroup>
<thead>
<tr>
<th>Cliente / Oportunidad</th>
<th>Plan</th>
<th>Línea</th>
<th className="num">MRR est.</th>
<th>Prioridad</th>
<th>Nota de negociación</th>
<th>Fecha Est. de cierre</th>
</tr>
</thead>
<tbody>
{sorted.map((o) => (
<tr key={o.id}>
<td className="dual-cel">
<a className="opp" href={`${DYN}${o.id}`} target="_blank" rel="noopener">{o.name}</a>
<span className="sub">{o.cliente || "—"}</span>
</td>
<td>{PLAN_LETRA[o.plan] || "—"}</td>
<td>{o.linea || "—"}</td>
<td className="num">{money2(o.est)}</td>
<td><PrioridadBadge o={o} /></td>
<td style={{ color: "var(--tinta-suave)", fontSize: 11 }}>
{(o.estado || "").slice(0, 110)}
{(o.estado || "").length > 110 ? "…" : ""}
</td>
<td style={{ whiteSpace: "nowrap" }}>{fechaTxt(o.close)}</td>
</tr>
))}
</tbody>
<tfoot>
<tr className="tot-fila">
<td colSpan={3}>Total ({sorted.length} oport.)</td>
<td className="num">{money2(sorted.reduce((a, o) => a + o.est, 0))}</td>
<td colSpan={3} />
</tr>
</tfoot>
</table>
</div>
</div>
);
}
return (
<div className="tw">
<div className="ts" style={{ maxHeight: "none" }}>
<table className="accion-tbl">
<thead>
<tr>
<th>Cliente</th>
<th>Oportunidad</th>
<th>Prioridad</th>
<th className="num">MRR est.</th>
<th className="num">Forecast</th>
<th>Nota de negociación</th>
</tr>
</thead>
<tbody>
{sorted.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>
<PrioridadBadge o={o} />
</td>
<td className="num">{money2(o.est)}</td>
<td className="num">{money2(o.fc)}</td>
<td style={{ color: "var(--tinta-suave)", fontSize: 12 }}>
{(o.estado || "").slice(0, 90)}
{(o.estado || "").length > 90 ? "…" : ""}
</td>
</tr>
))}
</tbody>
<tfoot>
<tr className="tot-fila">
<td colSpan={3}>Total ({sorted.length} oport.)</td>
<td className="num">{money2(sorted.reduce((a, o) => a + o.est, 0))}</td>
<td className="num">{money2(sorted.reduce((a, o) => a + o.fc, 0))}</td>
<td />
</tr>
</tfoot>
</table>
</div>
</div>
);
}