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

166 lines
7.5 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, money2, nuevaActividadUrl, TIPOS_NUEVA_ACTIVIDAD } from "../../lib/constants";
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 nomCorto = (n) => {
const p = (n || "").split(" ");
return p.length > 2 ? `${p[0]} ${p[p.length - 2]}` : n || "";
};
function cierreVencido(o) {
return !!o.close && o.close < new Date().toISOString().slice(0, 10);
}
// Tabla de tubería para el layout split23 (2/3 der.): columna Cliente/Oportunidad fija, scroll
// horizontal — mismo tratamiento que `tablePipe(arr,tipo,split=true,...)` del sitio HTML
// (assets/js/tables.js). Sin agrupado por actividad agendada todavía (necesita datos de
// Actividades, que esta app aún no consulta) y sin clic-para-agendar.
export default function TablaPipe({ arr, tipo, agendar = false, total = false }) {
const colFc = tipo === "fc";
const sorted = [...arr].sort((a, b) => b.est - a.est);
return (
<div className="tw split">
<div className="ts">
<table className={`fix${agendar ? " fit-all" : ""}`}>
<colgroup>
{agendar ? (
<>
<col style={{ width: "17%" }} />
<col style={{ width: "44px" }} />
<col style={{ width: "36px" }} />
<col style={{ width: "6%" }} />
<col style={{ width: "6%" }} />
<col style={{ width: "6%" }} />
<col style={{ width: "40px" }} />
<col style={{ width: "56px" }} />
<col style={{ width: "58px" }} />
<col style={{ width: "6%" }} />
<col style={{ width: "62px" }} />
{colFc && <col style={{ width: "66px" }} />}
<col style={{ width: "62px" }} />
<col style={{ width: "80px" }} />
<col style={{ width: "132px" }} />
</>
) : (
<>
<col style={{ width: "20%" }} />
<col style={{ width: "64px" }} />
<col style={{ width: "32px" }} />
<col style={{ width: "8.5%" }} />
<col style={{ width: "8.5%" }} />
<col style={{ width: "8.5%" }} />
<col style={{ width: "36px" }} />
<col style={{ width: "70px" }} />
<col style={{ width: "9%" }} />
<col style={{ width: "8.5%" }} />
{colFc && <col style={{ width: "7.5%" }} />}
<col style={{ width: "7%" }} />
</>
)}
</colgroup>
<thead>
<tr>
<th>Cliente / Oportunidad</th>
<th>Segmento</th>
<th title="Plan de cierre">Plan</th>
<th>Línea</th>
<th>Competidor</th>
<th>Fase</th>
<th className="num" title="Días en la fase actual">Días</th>
<th>Actividad</th>
{agendar && <th>Prioridad</th>}
<th>Ejecutivo</th>
<th className="num">MRR est.</th>
{colFc && <th className="num">Forecast</th>}
<th>Cierre</th>
{agendar && <th title="Si ya tiene una Tarea/Cita/Llamada agendada en la ventana">Agenda</th>}
{agendar && <th>Agendar</th>}
</tr>
</thead>
<tbody>
{sorted.map((o) => (
<tr key={o.id} style={agendar && !o.actFecha ? { boxShadow: "inset 3px 0 0 var(--pierde, #B23A2E)" } : undefined}>
<td className="dual-cel">
{o.actFecha && (
<span title={`Actividad agendada para el ${o.actFecha}`}>📅 </span>
)}
<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={`pill ${o.segmento === "Cartera Activa" ? "cartera" : "nuevo"}`} title={o.segmento}>
{o.segmento === "Cartera Activa" ? "CA" : "CN"}
</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.competidor || ""}>
{o.competidor === "Sin registrar" ? "—" : o.competidor || "—"}
</td>
<td className="elip" title={o.faseActual || ""}>{o.faseActual || "—"}</td>
<td className="num">{o.diasEnFase == null ? "—" : o.diasEnFase}</td>
<td style={{ textAlign: "center" }}>
<span
style={{ color: ACT_COLOR[o.actividad] || "#9db4c9", fontWeight: 700 }}
title={`${o.actividad}${o.estanc ? " · estancada" : ""}`}
>
●
</span>
</td>
{agendar && <td><PrioridadBadge o={o} /></td>}
<td className="elip" title={o.owner}>{nomCorto(o.owner)}</td>
<td className="num">{money(o.est)}</td>
{colFc && <td className="num">{money(o.fc)}</td>}
<td className={`num${cierreVencido(o) ? " venc" : ""}`} title={cierreVencido(o) ? "Fecha de cierre vencida al corte" : ""}>
{o.close ? o.close.slice(5) : "—"}
{cierreVencido(o) ? " ⚠" : ""}
</td>
{agendar && (
<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>
)}
{agendar && (
<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>
)}
</tr>
))}
</tbody>
{total && (
<tfoot>
<tr className="tot-fila">
<td>Total ({sorted.length} oport.)</td>
<td colSpan={agendar ? 9 : 8} />
<td className="num">{money(sorted.reduce((a, o) => a + o.est, 0))}</td>
{colFc && <td className="num">{money(sorted.reduce((a, o) => a + o.fc, 0))}</td>}
<td colSpan={agendar ? 3 : 1} />
</tr>
</tfoot>
)}
</table>
</div>
</div>
);
}