Clientes: alta y edicion directa; cobros: registrar pagos a mano y anular
- /clientes: "Nuevo cliente" y edicion por fila (nombre, puesto, empresa, correo, telefono, RFC) sin pasar por una cotizacion. POST /api/clientes y PATCH /api/clientes/[id] rechazan el duplicado nombre+empresa (409), que es como las cotizaciones reconocen al cliente. Nuevo campo Cliente.puesto. - /cobros: "Registrar pago" (verificado sin comprobante, con fecha y nota interna), "Anular" (estado anulado = sin cargo) y "Reabrir". Sirve para clientes sin cuenta de panel que pagan por transferencia o efectivo. "Pagos por cobrar" filtra la tabla a lo que debe cada cliente. - Corrige el filtro "Cliente" de la tabla de cobros: la API ignoraba clienteId. Agrega estado=por_pagar. - Panel de cliente: los anulados aparecen como "Sin cargo" y no aceptan comprobante. - Modal reutilizable (Escape, clic fuera, foco) para los formularios. - Movil: el sr-only del encabezado ensanchaba toda la pagina de /clientes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4b1408052a
commit
78385a8ac8
@@ -8,6 +8,7 @@ import { formatFechaCorta, formatTotales } from "@/lib/cobros-fechas";
|
||||
import { ProgramasTabla } from "./ProgramasTabla";
|
||||
import { PagosTabla } from "./PagosTabla";
|
||||
import { PorCobrarTabla } from "./PorCobrarTabla";
|
||||
import { RegistrarPagoDialog } from "./RegistrarPagoDialog";
|
||||
import type {
|
||||
ProgramaRow,
|
||||
ClienteOpt,
|
||||
@@ -88,6 +89,7 @@ export function CobrosClient({
|
||||
const [desdeFiltro, setDesdeFiltro] = useState("");
|
||||
const [hastaFiltro, setHastaFiltro] = useState("");
|
||||
const [enviandoRecordatorio, setEnviandoRecordatorio] = useState<string | null>(null);
|
||||
const [registrando, setRegistrando] = useState<PagoRow | null>(null);
|
||||
|
||||
const cargarPagos = useCallback(async () => {
|
||||
setCargandoPagos(true);
|
||||
@@ -287,6 +289,76 @@ export function CobrosClient({
|
||||
}
|
||||
};
|
||||
|
||||
// Desde "Pagos por cobrar": filtra la tabla a lo que debe ese cliente para
|
||||
// registrarle los pagos que hizo por fuera del panel.
|
||||
const verPorPagar = (saldo: SaldoClienteRow) => {
|
||||
setClienteFiltro(saldo.clienteId);
|
||||
setEstadoFiltro("por_pagar");
|
||||
setDesdeFiltro("");
|
||||
setHastaFiltro("");
|
||||
document.getElementById("comprobantes")?.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
};
|
||||
|
||||
const alRegistrar = () => {
|
||||
setRegistrando(null);
|
||||
cargarPagos();
|
||||
router.refresh();
|
||||
};
|
||||
|
||||
const anular = async (pago: PagoRow) => {
|
||||
const motivo = await showPrompt({
|
||||
title: "Anular cobro",
|
||||
message: `El cobro del ${formatFechaCorta(new Date(pago.fecha))} de ${pago.programa.cliente.nombre} quedará sin cargo y dejará de contar como adeudo. Puedes reabrirlo después.`,
|
||||
label: "Motivo",
|
||||
placeholder: "Ej. semana sin servicio, cortesía...",
|
||||
confirmText: "Anular cobro",
|
||||
});
|
||||
if (motivo === null) return;
|
||||
try {
|
||||
const res = await fetch(`/api/cobros/pagos/${pago.id}/anular`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ motivo: motivo.trim() }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
toast(data.error || "Error al anular", "error");
|
||||
return;
|
||||
}
|
||||
toast("Cobro anulado", "success");
|
||||
cargarPagos();
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexión", "error");
|
||||
}
|
||||
};
|
||||
|
||||
const reabrir = async (pago: PagoRow) => {
|
||||
const ok = await showConfirm({
|
||||
title: "Reabrir cobro",
|
||||
message:
|
||||
pago.estado === "anulado"
|
||||
? `El cobro del ${formatFechaCorta(new Date(pago.fecha))} volverá a pendiente y contará otra vez como adeudo.`
|
||||
: `Se quitará el pago registrado del ${formatFechaCorta(new Date(pago.fecha))} y el cobro volverá a pendiente.`,
|
||||
confirmText: "Reabrir",
|
||||
danger: pago.estado !== "anulado",
|
||||
});
|
||||
if (!ok) return;
|
||||
try {
|
||||
const res = await fetch(`/api/cobros/pagos/${pago.id}/reabrir`, { method: "POST" });
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
toast(data.error || "Error al reabrir", "error");
|
||||
return;
|
||||
}
|
||||
toast("Cobro reabierto", "success");
|
||||
cargarPagos();
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexión", "error");
|
||||
}
|
||||
};
|
||||
|
||||
const totalPorCobrar: Record<string, number> = {};
|
||||
for (const s of saldos) {
|
||||
for (const [moneda, total] of Object.entries(s.totales)) {
|
||||
@@ -343,6 +415,7 @@ export function CobrosClient({
|
||||
diasRecordatorio={diasRecordatorio}
|
||||
enviando={enviandoRecordatorio}
|
||||
onRecordar={recordar}
|
||||
onVerPorPagar={verPorPagar}
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -351,7 +424,8 @@ export function CobrosClient({
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">Comprobantes y cobros</h2>
|
||||
<p className="text-muted text-sm mt-1">
|
||||
Revisa los comprobantes que suben tus clientes y consulta cualquier cobro generado.
|
||||
Aprueba los comprobantes que suben tus clientes, registra los pagos que recibes por
|
||||
fuera del panel y consulta cualquier cobro.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
@@ -372,10 +446,12 @@ export function CobrosClient({
|
||||
className="px-3 py-2 border border-border rounded-lg text-sm bg-card-bg"
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
<option value="por_pagar">Por pagar (pendiente o rechazado)</option>
|
||||
<option value="pendiente">Pendiente</option>
|
||||
<option value="en_revision">En revisión</option>
|
||||
<option value="verificado">Verificado</option>
|
||||
<option value="rechazado">Rechazado</option>
|
||||
<option value="anulado">Anulado</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
@@ -388,7 +464,7 @@ export function CobrosClient({
|
||||
<option value="">Todos</option>
|
||||
{clientes.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
{c.nombre}
|
||||
{c.empresa ? `${c.nombre} — ${c.empresa}` : c.nombre}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -418,6 +494,9 @@ export function CobrosClient({
|
||||
cargando={cargandoPagos}
|
||||
onAprobar={aprobar}
|
||||
onRechazar={rechazar}
|
||||
onRegistrar={setRegistrando}
|
||||
onAnular={anular}
|
||||
onReabrir={reabrir}
|
||||
/>
|
||||
</section>
|
||||
|
||||
@@ -428,6 +507,14 @@ export function CobrosClient({
|
||||
onToggleActivo={toggleActivo}
|
||||
/>
|
||||
</section>
|
||||
|
||||
{registrando && (
|
||||
<RegistrarPagoDialog
|
||||
pago={registrando}
|
||||
onClose={() => setRegistrando(null)}
|
||||
onRegistrado={alRegistrar}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ESTADOS_PAGO } from "@/lib/cobros-fechas";
|
||||
|
||||
// Badges de estado de cobro (colores locales, no reutiliza EstadoBadge que es
|
||||
// para cotizaciones). pendiente=amber, en_revision=azul, verificado=verde,
|
||||
// rechazado=rojizo.
|
||||
// rechazado=rojizo, anulado=gris.
|
||||
const ESTILOS: Record<string, { cls: string; label: string }> = {
|
||||
[ESTADOS_PAGO.PENDIENTE]: {
|
||||
cls: "bg-amber-100 text-amber-800",
|
||||
@@ -22,6 +22,10 @@ const ESTILOS: Record<string, { cls: string; label: string }> = {
|
||||
cls: "bg-red-100 text-red-800",
|
||||
label: "Rechazado",
|
||||
},
|
||||
[ESTADOS_PAGO.ANULADO]: {
|
||||
cls: "bg-gray-100 text-gray-700",
|
||||
label: "Anulado",
|
||||
},
|
||||
};
|
||||
|
||||
export function EstadoPagoBadge({ estado }: { estado: string }) {
|
||||
|
||||
@@ -1,20 +1,49 @@
|
||||
"use client";
|
||||
|
||||
import { Check, X, FileText } from "lucide-react";
|
||||
import { formatFechaCorta, formatMonto } from "@/lib/cobros-fechas";
|
||||
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";
|
||||
|
||||
// Detalle bajo el estado: motivo de rechazo, dia del pago y nota interna.
|
||||
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 (
|
||||
@@ -28,79 +57,99 @@ export function PagosTabla({
|
||||
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">
|
||||
Genera cobros con el boton o ajusta los filtros
|
||||
</p>
|
||||
<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-[52rem] text-sm tabular-nums">
|
||||
<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-center px-5 py-3 font-medium text-muted">Estado</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-center px-5 py-3 font-medium text-muted">Acciones</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{pagos.map((p) => (
|
||||
<tr key={p.id} className="border-b border-border hover:bg-gray-50">
|
||||
<td className="px-5 py-3">{formatFechaCorta(new Date(p.fecha))}</td>
|
||||
<td className="px-5 py-3">{p.programa.concepto}</td>
|
||||
<td className="px-5 py-3">{p.programa.cliente.nombre}</td>
|
||||
<td className="px-5 py-3 text-right">{formatMonto(p.monto, p.programa.moneda)}</td>
|
||||
<td className="px-5 py-3 text-center">
|
||||
<EstadoPagoBadge estado={p.estado} />
|
||||
{p.estado === "rechazado" && p.rechazoMotivo && (
|
||||
<div className="text-xs text-muted mt-1">{p.rechazoMotivo}</div>
|
||||
)}
|
||||
</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">—</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
{p.estado === "en_revision" ? (
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<button
|
||||
onClick={() => onAprobar(p)}
|
||||
className="text-xs text-success hover:underline flex items-center gap-1"
|
||||
{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"
|
||||
>
|
||||
<Check className="w-3 h-3" />
|
||||
Aprobar
|
||||
</button>
|
||||
<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={() => onRechazar(p)}
|
||||
className="text-xs text-danger hover:underline flex items-center gap-1"
|
||||
onClick={() => onReabrir(p)}
|
||||
className={`${claseAccion} text-muted`}
|
||||
title="Devolver el cobro a pendiente"
|
||||
>
|
||||
<X className="w-3 h-3" />
|
||||
Rechazar
|
||||
<RotateCcw className="w-3 h-3" />
|
||||
Reabrir
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-muted text-xs">—</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
) : (
|
||||
<span className="text-muted text-xs">—</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { BellRing, Send } from "lucide-react";
|
||||
import { BellRing, HandCoins, Send } from "lucide-react";
|
||||
import { formatFechaCorta, formatTotales } from "@/lib/cobros-fechas";
|
||||
import type { SaldoClienteRow } from "./types";
|
||||
|
||||
@@ -12,12 +12,15 @@ export function PorCobrarTabla({
|
||||
diasRecordatorio,
|
||||
enviando,
|
||||
onRecordar,
|
||||
onVerPorPagar,
|
||||
}: {
|
||||
saldos: SaldoClienteRow[];
|
||||
diasRecordatorio: number;
|
||||
// clienteId en envio, "*" para todos, null si no hay envio en curso.
|
||||
enviando: string | null;
|
||||
onRecordar: (saldo: SaldoClienteRow | null) => void;
|
||||
// Filtra la tabla de cobros a lo que debe el cliente (para registrar pagos).
|
||||
onVerPorPagar: (saldo: SaldoClienteRow) => void;
|
||||
}) {
|
||||
const totalGeneral: Record<string, number> = {};
|
||||
for (const s of saldos) {
|
||||
@@ -56,7 +59,7 @@ export function PorCobrarTabla({
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-x-auto">
|
||||
<table className="w-full min-w-[48rem] text-sm tabular-nums">
|
||||
<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>
|
||||
@@ -64,7 +67,7 @@ export function PorCobrarTabla({
|
||||
<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-center px-5 py-3 font-medium text-muted">Acción</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -91,20 +94,30 @@ export function PorCobrarTabla({
|
||||
? formatFechaCorta(new Date(s.ultimoRecordatorio))
|
||||
: "Nunca"}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-center">
|
||||
<button
|
||||
onClick={() => onRecordar(s)}
|
||||
disabled={enviando !== null || !s.contactable}
|
||||
title={
|
||||
s.contactable
|
||||
? "Enviar estado de cuenta por correo y push"
|
||||
: "El cliente no tiene email ni cuenta de panel"
|
||||
}
|
||||
className="inline-flex items-center gap-1 text-xs text-primary hover:underline disabled:opacity-40 disabled:no-underline disabled:cursor-not-allowed"
|
||||
>
|
||||
<Send className="w-3 h-3" />
|
||||
{enviando === s.clienteId ? "Enviando..." : "Enviar recordatorio"}
|
||||
</button>
|
||||
<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>
|
||||
))}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Pencil, Power, Plus } from "lucide-react";
|
||||
import { useToast } from "@/components/ui/DialogProvider";
|
||||
@@ -268,6 +269,13 @@ export function ProgramasTabla({
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<p className="text-xs text-muted mt-1">
|
||||
¿No aparece?{" "}
|
||||
<Link href="/clientes?nuevo=1" className="text-primary hover:underline">
|
||||
Da de alta al cliente
|
||||
</Link>{" "}
|
||||
sin hacerle una cotización.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
@@ -340,6 +348,9 @@ export function ProgramasTabla({
|
||||
onChange={(e) => set("fechaInicio", e.target.value)}
|
||||
className="w-full px-3 py-2 border border-border rounded-lg text-sm"
|
||||
/>
|
||||
<p className="text-xs text-muted mt-1">
|
||||
Si es una fecha pasada, se generan como pendientes todos los cobros desde ese día.
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs text-muted mb-1">
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useToast } from "@/components/ui/DialogProvider";
|
||||
import {
|
||||
Modal,
|
||||
claseBotonPrimario,
|
||||
claseBotonSecundario,
|
||||
claseCampo,
|
||||
claseEtiqueta,
|
||||
} from "@/components/ui/Modal";
|
||||
import { formatFechaCorta, formatMonto, hoyCalendario } from "@/lib/cobros-fechas";
|
||||
import type { PagoRow } from "./types";
|
||||
|
||||
// Registrar a mano un pago recibido fuera del panel (transferencia avisada por
|
||||
// WhatsApp, efectivo...). El cobro queda verificado sin comprobante.
|
||||
export function RegistrarPagoDialog({
|
||||
pago,
|
||||
onClose,
|
||||
onRegistrado,
|
||||
}: {
|
||||
pago: PagoRow;
|
||||
onClose: () => void;
|
||||
onRegistrado: () => void;
|
||||
}) {
|
||||
const toast = useToast();
|
||||
const hoy = hoyCalendario().toISOString().slice(0, 10);
|
||||
const [fecha, setFecha] = useState(hoy);
|
||||
const [nota, setNota] = useState("");
|
||||
const [guardando, setGuardando] = useState(false);
|
||||
|
||||
const guardar = async () => {
|
||||
if (!fecha) {
|
||||
toast("Indica la fecha del pago", "error");
|
||||
return;
|
||||
}
|
||||
setGuardando(true);
|
||||
try {
|
||||
const res = await fetch(`/api/cobros/pagos/${pago.id}/registrar`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ fecha, nota: nota.trim() || undefined }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
toast(data.error || "Error al registrar el pago", "error");
|
||||
return;
|
||||
}
|
||||
toast("Pago registrado", "success");
|
||||
onRegistrado();
|
||||
} catch {
|
||||
toast("Error de conexión", "error");
|
||||
} finally {
|
||||
setGuardando(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
titulo="Registrar pago"
|
||||
descripcion={
|
||||
<>
|
||||
{pago.programa.cliente.nombre} · cobro del {formatFechaCorta(new Date(pago.fecha))} por{" "}
|
||||
<span className="font-medium text-foreground tabular-nums">
|
||||
{formatMonto(pago.monto, pago.programa.moneda)}
|
||||
</span>
|
||||
</>
|
||||
}
|
||||
onClose={onClose}
|
||||
onSubmit={guardar}
|
||||
acciones={
|
||||
<>
|
||||
<button type="button" onClick={onClose} className={claseBotonSecundario}>
|
||||
Cancelar
|
||||
</button>
|
||||
<button type="submit" disabled={guardando} className={claseBotonPrimario}>
|
||||
{guardando ? "Guardando..." : "Registrar pago"}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<div>
|
||||
<label htmlFor="registrar-fecha" className={claseEtiqueta}>
|
||||
Fecha en que pagó
|
||||
</label>
|
||||
<input
|
||||
id="registrar-fecha"
|
||||
type="date"
|
||||
value={fecha}
|
||||
max={hoy}
|
||||
required
|
||||
onChange={(e) => setFecha(e.target.value)}
|
||||
className={claseCampo}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="registrar-nota" className={claseEtiqueta}>
|
||||
Nota interna (opcional)
|
||||
</label>
|
||||
<input
|
||||
id="registrar-nota"
|
||||
type="text"
|
||||
value={nota}
|
||||
maxLength={500}
|
||||
onChange={(e) => setNota(e.target.value)}
|
||||
placeholder="Ej. transferencia, efectivo, pagó en dos partes..."
|
||||
className={claseCampo}
|
||||
/>
|
||||
<p className="text-xs text-muted mt-1">Solo la ves tú; el cliente no la ve.</p>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -91,6 +91,8 @@ export default async function CobrosPage() {
|
||||
monto: p.monto,
|
||||
estado: p.estado,
|
||||
rechazoMotivo: p.rechazoMotivo,
|
||||
verificadoAt: p.verificadoAt ? p.verificadoAt.toISOString() : null,
|
||||
nota: p.nota,
|
||||
programa: {
|
||||
concepto: p.programa.concepto,
|
||||
moneda: p.programa.moneda,
|
||||
|
||||
@@ -36,6 +36,10 @@ export type PagoRow = {
|
||||
monto: number;
|
||||
estado: string;
|
||||
rechazoMotivo: string | null;
|
||||
// Dia del pago (manual) o de la aprobacion del comprobante; null si no se pago.
|
||||
verificadoAt: string | null;
|
||||
// Nota interna del admin: abonos/forma de pago, o motivo de anulacion.
|
||||
nota: string | null;
|
||||
programa: {
|
||||
concepto: string;
|
||||
moneda: string;
|
||||
|
||||
Reference in New Issue
Block a user