feat: migrar backend unificado a Go 1.27 + SPA Vite embebido
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
import { Ban, Check, FileText, HandCoins, RotateCcw, X } from "lucide-react";
|
||||
import { calendarioDe, esPorPagar, formatFechaCorta, formatMonto } from "@/lib/cobros-fechas";
|
||||
import { EstadoPagoBadge } from "./EstadoPagoBadge";
|
||||
import type { PagoRow } from "./types";
|
||||
|
||||
const claseAccion = "text-xs hover:underline flex items-center gap-1 whitespace-nowrap";
|
||||
|
||||
function DetalleEstado({ p }: { p: PagoRow }) {
|
||||
const lineas: string[] = [];
|
||||
if (p.estado === "rechazado" && p.rechazoMotivo) lineas.push(p.rechazoMotivo);
|
||||
if (p.estado === "verificado" && p.verificadoAt) {
|
||||
const dia = formatFechaCorta(calendarioDe(new Date(p.verificadoAt)));
|
||||
lineas.push(p.comprobante ? `Aprobado el ${dia}` : `Pagado el ${dia}`);
|
||||
}
|
||||
if (p.nota) lineas.push(p.nota);
|
||||
if (lineas.length === 0) return null;
|
||||
return (
|
||||
<div className="mt-1 max-w-[16rem] space-y-0.5 text-xs text-muted">
|
||||
{lineas.map((l, i) => (
|
||||
<p key={i} className="line-clamp-2" title={l}>
|
||||
{l}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function PagosTabla({
|
||||
pagos,
|
||||
cargando,
|
||||
onAprobar,
|
||||
onRechazar,
|
||||
onRegistrar,
|
||||
onAnular,
|
||||
onReabrir,
|
||||
}: {
|
||||
pagos: PagoRow[];
|
||||
cargando: boolean;
|
||||
onAprobar: (p: PagoRow) => void;
|
||||
onRechazar: (p: PagoRow) => void;
|
||||
onRegistrar: (p: PagoRow) => void;
|
||||
onAnular: (p: PagoRow) => void;
|
||||
onReabrir: (p: PagoRow) => void;
|
||||
}) {
|
||||
if (cargando) {
|
||||
return (
|
||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
||||
<p className="text-muted">Cargando cobros...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (pagos.length === 0) {
|
||||
return (
|
||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
||||
<h3 className="text-lg font-semibold mb-2">No hay cobros</h3>
|
||||
<p className="text-muted">Ajusta los filtros para ver otros cobros.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-x-auto">
|
||||
<table className="w-full min-w-[56rem] text-sm tabular-nums">
|
||||
<thead>
|
||||
<tr className="border-b border-border bg-gray-50">
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Fecha</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Concepto</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Cliente</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted">Monto</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Estado</th>
|
||||
<th className="text-center px-5 py-3 font-medium text-muted">Comprobante</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pagos.map((p) => {
|
||||
const manual = p.estado === "verificado" && !p.comprobante;
|
||||
return (
|
||||
<tr key={p.id} className="border-b border-border hover:bg-gray-50 align-top">
|
||||
<td className="px-5 py-3 whitespace-nowrap">{formatFechaCorta(new Date(p.fecha))}</td>
|
||||
<td className="px-5 py-3">{p.programa.concepto}</td>
|
||||
<td className="px-5 py-3">
|
||||
<div>{p.programa.cliente.nombre}</div>
|
||||
{p.programa.cliente.empresa && (
|
||||
<div className="text-xs text-muted">{p.programa.cliente.empresa}</div>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right whitespace-nowrap">
|
||||
{formatMonto(p.monto, p.programa.moneda)}
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
<EstadoPagoBadge estado={p.estado} />
|
||||
<DetalleEstado p={p} />
|
||||
</td>
|
||||
<td className="px-5 py-3 text-center">
|
||||
{p.comprobante ? (
|
||||
<a
|
||||
href={`/api/comprobantes/${p.id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-xs text-primary hover:underline"
|
||||
>
|
||||
<FileText className="w-3 h-3" />
|
||||
Ver
|
||||
</a>
|
||||
) : (
|
||||
<span className="text-muted text-xs">{manual ? "Registro manual" : "—"}</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
{p.estado === "en_revision" ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<button onClick={() => onAprobar(p)} className={`${claseAccion} text-success`}>
|
||||
<Check className="w-3 h-3" />
|
||||
Aprobar
|
||||
</button>
|
||||
<button onClick={() => onRechazar(p)} className={`${claseAccion} text-danger`}>
|
||||
<X className="w-3 h-3" />
|
||||
Rechazar
|
||||
</button>
|
||||
</div>
|
||||
) : esPorPagar(p.estado) ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<button onClick={() => onRegistrar(p)} className={`${claseAccion} text-primary`}>
|
||||
<HandCoins className="w-3 h-3" />
|
||||
Registrar pago
|
||||
</button>
|
||||
<button onClick={() => onAnular(p)} className={`${claseAccion} text-muted`}>
|
||||
<Ban className="w-3 h-3" />
|
||||
Anular
|
||||
</button>
|
||||
</div>
|
||||
) : manual || p.estado === "anulado" ? (
|
||||
<button
|
||||
onClick={() => onReabrir(p)}
|
||||
className={`${claseAccion} text-muted`}
|
||||
title="Devolver el cobro a pendiente"
|
||||
>
|
||||
<RotateCcw className="w-3 h-3" />
|
||||
Reabrir
|
||||
</button>
|
||||
) : (
|
||||
<span className="text-muted text-xs">—</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user