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

79 lines
3.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 React from "react";
import { money } from "../../lib/constants";
import { PLAN_ORDER, nomCorto } from "../../lib/derive";
// Matriz de ejecutivos × Plan de Cierre — versión estática de mtzEjePanel() (assets/js/tables.js).
// El sitio HTML deja elegir la columna (Plan/Categoría Previsión/Actividad/Temperatura/Fase) con
// pestañas; acá queda fija en "Plan de Cierre" (la que trae por defecto), igual criterio que el
// resto de los paneles sin clic-para-filtrar de esta v1.
export default function ExecMatrix({ arr, titulo, hint, valor }) {
const val = valor || ((o) => o.est);
const cols = PLAN_ORDER.filter((k) => arr.some((o) => (o.plan || "Sin plan de cierre") === k));
const ejes = [...new Set(arr.map((o) => o.owner))].sort(
(a, b) => arr.filter((o) => o.owner === b).reduce((s, o) => s + val(o), 0) - arr.filter((o) => o.owner === a).reduce((s, o) => s + val(o), 0)
);
const cel = (ow, cv) => arr.filter((o) => o.owner === ow && (o.plan || "Sin plan de cierre") === cv);
const maxN = Math.max(...ejes.flatMap((ow) => cols.map((c) => cel(ow, c).length)), 1);
const corto = (s) => s.replace("Plan ", "").replace(" - ", " ");
return (
<div className="panel">
<h3>{titulo || "Tubería por ejecutivo"}</h3>
<p className="hint">{hint || "La intensidad del azul es la cantidad de oportunidades"}</p>
<div
className="mze"
style={{ gridTemplateColumns: `minmax(120px,1.4fr) repeat(${cols.length},minmax(58px,1fr)) minmax(74px,.9fr)` }}
>
<div className="mze-h eje" />
{cols.map((c) => <div className="mze-h" key={c} title={c}>{corto(c)}</div>)}
<div className="mze-h tot">Total</div>
{ejes.map((ow) => {
const tot = arr.filter((o) => o.owner === ow);
return (
<React.Fragment key={ow}>
<div className="mze-r">{nomCorto(ow)}</div>
{cols.map((c) => {
const e = cel(ow, c);
const alpha = e.length ? (0.1 + 0.55 * (e.length / maxN)).toFixed(2) : 0;
return (
<div
className={`mze-c${e.length ? "" : " vacia"}`}
key={`${ow}-${c}`}
style={e.length ? { background: `rgba(30,113,184,${alpha})` } : undefined}
>
{e.length ? (
<>
<span className="n">{e.length}</span>
<span className="v">{money(e.reduce((s, o) => s + val(o), 0))}</span>
</>
) : (
<span className="n vacio">·</span>
)}
</div>
);
})}
<div className="mze-c tot">
<span className="n">{tot.length}</span>
<span className="v">{money(tot.reduce((s, o) => s + val(o), 0))}</span>
</div>
</React.Fragment>
);
})}
<div className="mze-r tot">Total</div>
{cols.map((c) => {
const e = arr.filter((o) => (o.plan || "Sin plan de cierre") === c);
return (
<div className="mze-c tot" key={`pie-${c}`}>
<span className="n">{e.length}</span>
<span className="v">{money(e.reduce((s, o) => s + val(o), 0))}</span>
</div>
);
})}
<div className="mze-c tot">
<span className="n">{arr.length}</span>
<span className="v">{money(arr.reduce((s, o) => s + val(o), 0))}</span>
</div>
</div>
</div>
);
}