89 lines
3.8 KiB
JavaScript
89 lines
3.8 KiB
JavaScript
|
|
"use client";
|
||
|
|
import { actividadUrl, money } from "../../lib/constants";
|
||
|
|
import GestionarActividad from "../actividades/GestionarActividad";
|
||
|
|
|
||
|
|
const TIPOS = [
|
||
|
|
["Cita", "Citas"],
|
||
|
|
["Llamada", "Llamadas"],
|
||
|
|
["Tarea", "Tareas"],
|
||
|
|
];
|
||
|
|
const ESTADO_COLOR = {
|
||
|
|
Completada: "var(--gana)",
|
||
|
|
Vencida: "var(--pierde)",
|
||
|
|
Pendiente: "var(--alerta)",
|
||
|
|
Cancelada: "var(--tinta-suave)",
|
||
|
|
};
|
||
|
|
|
||
|
|
// Detalle de TODAS las actividades del período (no solo las del plan), agrupado por tipo y plegado por
|
||
|
|
// defecto: es para consultar o auditar una actividad, no para leerlo de corrido. Solo pantalla.
|
||
|
|
export default function DetalleActividades({ actividades, locked }) {
|
||
|
|
const hay = actividades.length > 0;
|
||
|
|
return (
|
||
|
|
<section className="no-print" style={{ marginTop: 26 }}>
|
||
|
|
<div className="sec-div"><span>Detalle de actividades del período ({actividades.length})</span></div>
|
||
|
|
{!hay && <p className="hint">No hay actividades en este período.</p>}
|
||
|
|
{TIPOS.map(([tipo, plural]) => {
|
||
|
|
const rows = actividades
|
||
|
|
.filter((a) => a.tipo === tipo)
|
||
|
|
.sort((a, b) => (a.scheduledstart || a.scheduledend || "").localeCompare(b.scheduledstart || b.scheduledend || ""));
|
||
|
|
if (!rows.length) return null;
|
||
|
|
const totalIngreso = rows.reduce((s, a) => s + (a.ingresoEstimado || 0), 0);
|
||
|
|
const propioLabel = rows[0]?.campoPropio?.label || "";
|
||
|
|
return (
|
||
|
|
<details className="tw" key={tipo} style={{ marginBottom: 16 }}>
|
||
|
|
<summary className="tw-title" style={{ cursor: "pointer" }}>
|
||
|
|
<span className="tw-chevron">▼</span>
|
||
|
|
<h3>{plural}</h3>
|
||
|
|
<span className="tw-count">{rows.length} · {money(totalIngreso)} Ingreso Est. total</span>
|
||
|
|
</summary>
|
||
|
|
<div className="ts">
|
||
|
|
<table>
|
||
|
|
<thead>
|
||
|
|
<tr>
|
||
|
|
<th>#</th>
|
||
|
|
<th>Referente a</th>
|
||
|
|
<th>Asunto</th>
|
||
|
|
<th>Objetivo</th>
|
||
|
|
<th>Fecha Inicio</th>
|
||
|
|
<th>Fecha Vencimiento</th>
|
||
|
|
<th className="num">Ingreso Est.</th>
|
||
|
|
<th>{propioLabel}</th>
|
||
|
|
<th>Estado</th>
|
||
|
|
<th></th>
|
||
|
|
{!locked && <th>Propietario</th>}
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tbody>
|
||
|
|
{rows.map((a, i) => (
|
||
|
|
<tr key={a.id} style={a.estadoFinal === "Vencida" ? { background: "var(--pierde-soft)" } : undefined}>
|
||
|
|
<td>{i + 1}</td>
|
||
|
|
<td>{a.referente?.nombre || "—"}</td>
|
||
|
|
<td>
|
||
|
|
<a className="opp" href={actividadUrl(a)} target="_blank" rel="noopener">{a.asunto}</a>
|
||
|
|
</td>
|
||
|
|
<td>{a.objetivo || "—"}</td>
|
||
|
|
<td>{a.scheduledstartFmt || "—"}</td>
|
||
|
|
<td>{a.scheduledendFmt || "—"}</td>
|
||
|
|
<td className="num">{a.ingresoEstimado ? money(a.ingresoEstimado) : "—"}</td>
|
||
|
|
<td>{a.campoPropio?.valor || "—"}</td>
|
||
|
|
<td>
|
||
|
|
<span style={{ color: ESTADO_COLOR[a.estadoFinal] || "var(--tinta-suave)", fontWeight: 700 }}>● {a.estadoFinal}</span>
|
||
|
|
</td>
|
||
|
|
<td>
|
||
|
|
{a.estadoFinal === "Completada" || a.estadoFinal === "Cancelada" ? null : (
|
||
|
|
<GestionarActividad a={a} className="gst-act">Gestionar</GestionarActividad>
|
||
|
|
)}
|
||
|
|
</td>
|
||
|
|
{!locked && <td>{a.owner}</td>}
|
||
|
|
</tr>
|
||
|
|
))}
|
||
|
|
</tbody>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
</details>
|
||
|
|
);
|
||
|
|
})}
|
||
|
|
</section>
|
||
|
|
);
|
||
|
|
}
|