- Panel de cliente con acceso propio (role=cliente): resumen, cotizaciones con descarga PDF y guia de pagos recurrentes con subida de comprobante (imagen->WebP o PDF). - Módulo admin /cobros: programas de pago (semanal/quincenal/mensual), generación idempotente manual y automatica cada hora (scheduler en instrumentation, zona America/Mexico_City), revisión de comprobantes con aprobar/rechazar (el rechazo borra el archivo del servidor y permite re-subir). - Cuentas de cliente creadas/rotadas/revocadas desde la página de clientes. - Notificaciones: servicio SMTP configurable por env (se omite con aviso si no hay credenciales) y Web Push con VAPID + service worker. - Separación de roles en middleware (cliente solo ve /cliente, staff no entra al panel de cliente; PDF y comprobantes son rutas compartidas con validación de pertenencia). - Producción: volumen uploads_data en ambos compose, env vars documentadas en .env.example, migración 20261020000000.
198 lines
6.8 KiB
TypeScript
198 lines
6.8 KiB
TypeScript
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
import {
|
|
ArrowRight,
|
|
CalendarClock,
|
|
ClipboardList,
|
|
Clock3,
|
|
FileText,
|
|
Inbox,
|
|
ShieldCheck,
|
|
} from "lucide-react";
|
|
import { requireRole } from "@/lib/auth";
|
|
import { formatCurrency, formatDate } from "@/lib/calculators";
|
|
import { formatFechaCorta } from "@/lib/cobros";
|
|
import { EstadoBadge } from "@/components/EstadoBadge";
|
|
import { obtenerResumenCliente } from "./resumen-data";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export default async function ClienteInicioPage() {
|
|
const session = await requireRole("cliente");
|
|
if (!session) redirect("/login?panel=cliente");
|
|
|
|
const resumen = session.clienteId
|
|
? await obtenerResumenCliente(session.clienteId)
|
|
: null;
|
|
|
|
if (!resumen) {
|
|
return (
|
|
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
|
<Inbox className="w-16 h-16 text-muted mx-auto mb-4" />
|
|
<h2 className="text-lg font-semibold mb-2">Cuenta sin cliente asociado</h2>
|
|
<p className="text-muted">
|
|
Tu usuario no tiene un cliente vinculado. Contacta al administrador para
|
|
darlo de alta.
|
|
</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const tarjetas = [
|
|
{
|
|
label: "Cotizaciones activas",
|
|
value: resumen.cotizacionesActivas,
|
|
icon: FileText,
|
|
bg: "bg-primary-light",
|
|
color: "text-primary",
|
|
},
|
|
{
|
|
label: "Pagos pendientes",
|
|
value: resumen.pagos.pendientes,
|
|
icon: Clock3,
|
|
bg: "bg-amber-100",
|
|
color: "text-amber-600",
|
|
},
|
|
{
|
|
label: "En revisión",
|
|
value: resumen.pagos.enRevision,
|
|
icon: ClipboardList,
|
|
bg: "bg-blue-100",
|
|
color: "text-blue-600",
|
|
},
|
|
{
|
|
label: "Verificados este mes",
|
|
value: resumen.pagos.verificadosMes,
|
|
icon: ShieldCheck,
|
|
bg: "bg-green-100",
|
|
color: "text-green-600",
|
|
},
|
|
];
|
|
|
|
return (
|
|
<div>
|
|
<div className="mb-8">
|
|
<h1 className="text-2xl font-bold">Hola, {resumen.cliente.nombre}</h1>
|
|
<p className="text-muted text-sm mt-1">
|
|
{resumen.cliente.empresa
|
|
? resumen.cliente.empresa + " · "
|
|
: ""}
|
|
Consulta tus cotizaciones y el estado de tus pagos.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
|
|
{tarjetas.map((t) => (
|
|
<div key={t.label} className="bg-card-bg rounded-xl border border-border p-5">
|
|
<div className="flex items-center gap-3">
|
|
<div className={`${t.bg} p-2.5 rounded-lg`}>
|
|
<t.icon className={`w-5 h-5 ${t.color}`} />
|
|
</div>
|
|
<div className="min-w-0">
|
|
<p className="text-2xl font-bold">{t.value}</p>
|
|
<p className="text-muted text-sm">{t.label}</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<div className="bg-card-bg rounded-xl border border-border mb-8">
|
|
<div className="px-5 py-4 border-b border-border flex items-center justify-between">
|
|
<h2 className="font-semibold text-lg flex items-center gap-2">
|
|
<CalendarClock className="w-5 h-5 text-primary" />
|
|
Próximos cobros
|
|
</h2>
|
|
<Link
|
|
href="/cliente/pagos"
|
|
className="text-sm text-primary hover:underline flex items-center gap-1"
|
|
>
|
|
Ver todos
|
|
<ArrowRight className="w-4 h-4" />
|
|
</Link>
|
|
</div>
|
|
{resumen.pagos.proximos.length === 0 ? (
|
|
<div className="p-8 text-center">
|
|
<CalendarClock className="w-10 h-10 text-muted mx-auto mb-3" />
|
|
<p className="text-muted text-sm">
|
|
No tienes cobros programados por ahora.
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<ul className="divide-y divide-border">
|
|
{resumen.pagos.proximos.map((p) => (
|
|
<li
|
|
key={`${p.concepto}-${p.fecha.toISOString()}`}
|
|
className="flex items-center justify-between gap-3 px-5 py-3"
|
|
>
|
|
<div>
|
|
<p className="font-medium text-sm">{p.concepto}</p>
|
|
<p className="text-xs text-muted">{formatFechaCorta(p.fecha)}</p>
|
|
</div>
|
|
<p className="font-semibold">{formatCurrency(p.monto)}</p>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
|
|
<div className="bg-card-bg rounded-xl border border-border">
|
|
<div className="px-5 py-4 border-b border-border flex items-center justify-between">
|
|
<h2 className="font-semibold text-lg">Últimas cotizaciones</h2>
|
|
<Link
|
|
href="/cliente/cotizaciones"
|
|
className="text-sm text-primary hover:underline flex items-center gap-1"
|
|
>
|
|
Ver todas
|
|
<ArrowRight className="w-4 h-4" />
|
|
</Link>
|
|
</div>
|
|
{resumen.cotizaciones.length === 0 ? (
|
|
<div className="p-8 text-center">
|
|
<FileText className="w-10 h-10 text-muted mx-auto mb-3" />
|
|
<p className="text-muted text-sm">
|
|
Todavía no tienes cotizaciones. En cuanto el administrador la envíe,
|
|
aparecerá aquí.
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<ul className="divide-y divide-border">
|
|
{resumen.cotizaciones.map((c) => (
|
|
<li key={c.id}>
|
|
<Link
|
|
href={`/cliente/cotizaciones/${c.id}`}
|
|
className="flex items-center justify-between gap-3 px-5 py-3 hover:bg-gray-50 transition-colors"
|
|
>
|
|
<div className="min-w-0">
|
|
<p className="font-medium text-sm text-primary">{c.numero}</p>
|
|
<p className="text-xs text-muted truncate">{c.proyecto}</p>
|
|
</div>
|
|
<div className="flex items-center gap-4 shrink-0">
|
|
<span className="text-xs text-muted hidden sm:block">
|
|
{formatDate(c.fecha)}
|
|
</span>
|
|
<EstadoBadge estado={c.estado} />
|
|
<div className="text-right text-sm hidden md:block">
|
|
{c.totales.totalUnico > 0 && (
|
|
<p className="font-medium">
|
|
{formatCurrency(c.totales.totalUnico)}
|
|
</p>
|
|
)}
|
|
{c.totales.totalMensual > 0 && (
|
|
<p className="text-xs text-muted">
|
|
{formatCurrency(c.totales.totalMensual)}/mes
|
|
</p>
|
|
)}
|
|
</div>
|
|
<ArrowRight className="w-4 h-4 text-muted" />
|
|
</div>
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|