feat: migrar backend unificado a Go 1.27 + SPA Vite embebido
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import { BellRing, HandCoins, Send } from "lucide-react";
|
||||
import { formatFechaCorta, formatTotales } from "@/lib/cobros-fechas";
|
||||
import type { SaldoClienteRow } from "./types";
|
||||
|
||||
export function PorCobrarTabla({
|
||||
saldos,
|
||||
diasRecordatorio,
|
||||
enviando,
|
||||
onRecordar,
|
||||
onVerPorPagar,
|
||||
}: {
|
||||
saldos: SaldoClienteRow[];
|
||||
diasRecordatorio: number;
|
||||
enviando: string | null;
|
||||
onRecordar: (saldo: SaldoClienteRow | null) => void;
|
||||
onVerPorPagar: (saldo: SaldoClienteRow) => void;
|
||||
}) {
|
||||
const totalGeneral: Record<string, number> = {};
|
||||
for (const s of saldos) {
|
||||
for (const [moneda, total] of Object.entries(s.totales)) {
|
||||
totalGeneral[moneda] = (totalGeneral[moneda] ?? 0) + total;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-wrap items-end justify-between gap-3 mb-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">Pagos por cobrar</h2>
|
||||
<p className="text-muted text-sm mt-1">
|
||||
{diasRecordatorio > 0
|
||||
? `Cobros vencidos sin pago o con comprobante rechazado. El recordatorio se reenvía solo cada ${diasRecordatorio} ${diasRecordatorio === 1 ? "día" : "días"} a partir de las 9:00.`
|
||||
: "Cobros vencidos sin pago o con comprobante rechazado. El recordatorio automático está desactivado (COBROS_RECORDATORIO_DIAS=0)."}
|
||||
</p>
|
||||
</div>
|
||||
{saldos.length > 0 && (
|
||||
<button
|
||||
onClick={() => onRecordar(null)}
|
||||
disabled={enviando !== null}
|
||||
className="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium border border-border bg-card-bg hover:bg-gray-50 disabled:opacity-50"
|
||||
>
|
||||
<BellRing className="w-4 h-4" />
|
||||
{enviando === "*" ? "Enviando..." : "Recordar a todos"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{saldos.length === 0 ? (
|
||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
||||
<h3 className="text-lg font-semibold mb-2">Sin pagos vencidos</h3>
|
||||
<p className="text-muted">Ningún cliente tiene cobros pendientes de pago.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-x-auto">
|
||||
<table className="w-full min-w-[54rem] 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">Cliente</th>
|
||||
<th className="text-center px-5 py-3 font-medium text-muted">Cobros</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted">Adeudo</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Más antiguo</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Último recordatorio</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{saldos.map((s) => (
|
||||
<tr key={s.clienteId} className="border-b border-border hover:bg-gray-50">
|
||||
<td className="px-5 py-3">
|
||||
<div className="font-medium">{s.nombre}</div>
|
||||
{s.empresa && <div className="text-xs text-muted">{s.empresa}</div>}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-center">{s.pagos}</td>
|
||||
<td className="px-5 py-3 text-right font-medium whitespace-nowrap">
|
||||
{formatTotales(s.totales)}
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
<div>{formatFechaCorta(new Date(s.masAntigua))}</div>
|
||||
<div className={`text-xs ${s.diasAtraso > 0 ? "text-danger" : "text-muted"}`}>
|
||||
{s.diasAtraso === 0
|
||||
? "vence hoy"
|
||||
: `${s.diasAtraso} ${s.diasAtraso === 1 ? "día" : "días"} de atraso`}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-5 py-3 text-muted">
|
||||
{s.ultimoRecordatorio
|
||||
? formatFechaCorta(new Date(s.ultimoRecordatorio))
|
||||
: "Nunca"}
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-1">
|
||||
<button
|
||||
onClick={() => onVerPorPagar(s)}
|
||||
title="Ver sus cobros por pagar para registrar los pagos recibidos"
|
||||
className="inline-flex items-center gap-1 text-xs text-primary hover:underline whitespace-nowrap"
|
||||
>
|
||||
<HandCoins className="w-3 h-3" />
|
||||
Registrar pagos
|
||||
</button>
|
||||
<button
|
||||
onClick={() => onRecordar(s)}
|
||||
disabled={enviando !== null || !s.contactable}
|
||||
title={
|
||||
s.contactable
|
||||
? "Enviar estado de cuenta por correo y push"
|
||||
: "El cliente no tiene correo ni cuenta de panel"
|
||||
}
|
||||
className="inline-flex items-center gap-1 text-xs text-primary hover:underline whitespace-nowrap disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
|
||||
>
|
||||
<Send className="w-3 h-3" />
|
||||
{enviando === s.clienteId ? "Enviando..." : "Enviar recordatorio"}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr className="bg-gray-50">
|
||||
<td className="px-5 py-3 font-medium" colSpan={2}>
|
||||
Total por cobrar
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right font-semibold whitespace-nowrap">
|
||||
{formatTotales(totalGeneral)}
|
||||
</td>
|
||||
<td colSpan={3} />
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user