Panel de cliente y /cobros: pulido de interfaz, movil y contraste
Panel de cliente - Mis pagos: primero lo que hay que pagar (mas antiguo primero, atraso y motivo de rechazo) con su boton de comprobante; datos bancarios con boton de copiar; historial compacto por programa con los pagos viejos plegados. En movil la tabla anterior recortaba "Subir comprobante": ya no hay tablas. - Inicio: estado de cuenta con saldo, cobro mas antiguo y accion de pagar. Las dobles propuestas muestran el total de cada opcion (antes se sumaban ambas en uno solo). - Mis cotizaciones: lista responsive compartida con el inicio (FilaCotizacion). - Montos respetan la moneda del programa (USD ya no sale como "$"). - Esqueleto de carga para que la navegacion responda al instante. - Avisos push como boton secundario; login con encabezado propio en ?panel=cliente y etiquetas en espanol. /cobros (admin) - Franja de resumen: por cobrar, comprobantes por revisar, programas activos. - Orden por frecuencia de uso: cobrar, revisar comprobantes, programas. - Un solo boton primario; tablas con scroll horizontal en movil (Aprobar y Rechazar quedaban fuera de pantalla); montos por moneda; acentos. Global: --muted pasa de slate-400 (2.6:1) a slate-500 (4.8:1), foco de teclado visible y seleccion de texto con la paleta. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
76e93e6615
commit
6402128dfc
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState, useEffect, useCallback, useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { useConfirm, usePrompt, useToast } from "@/components/ui/DialogProvider";
|
||||
import { formatFechaCorta, formatTotales } from "@/lib/cobros-fechas";
|
||||
import { ProgramasTabla } from "./ProgramasTabla";
|
||||
@@ -25,17 +26,17 @@ export function frecuenciaLegible(p: {
|
||||
"domingo",
|
||||
"lunes",
|
||||
"martes",
|
||||
"miercoles",
|
||||
"miércoles",
|
||||
"jueves",
|
||||
"viernes",
|
||||
"sabado",
|
||||
"sábado",
|
||||
];
|
||||
if (p.frecuencia === "semanal") {
|
||||
const d = p.diaSemana ?? 0;
|
||||
return `Cada ${dias[d]}`;
|
||||
}
|
||||
if (p.frecuencia === "quincenal") return "Cada 1 y 15";
|
||||
return `Cada dia ${p.diaMes ?? 1}`;
|
||||
return `Cada día ${p.diaMes ?? 1}`;
|
||||
}
|
||||
|
||||
// Por que un recordatorio no llego a nadie, en palabras del admin.
|
||||
@@ -46,14 +47,14 @@ function motivoNoEntregado(
|
||||
if (!canales.correo && !canales.push) {
|
||||
return "No hay SMTP (correo) ni VAPID (push) configurados en el servidor";
|
||||
}
|
||||
if (r.correo === "error") return "Fallo el envio del correo; revisa el log del servidor";
|
||||
if (r.correo === "error") return "Falló el envío del correo; revisa el log del servidor";
|
||||
if (r.correo === "sin_email") {
|
||||
return "El cliente no tiene email y no activo las notificaciones push";
|
||||
return "El cliente no tiene correo y no activó los avisos push";
|
||||
}
|
||||
if (r.correo === "omitido") {
|
||||
return "SMTP no configurado y el cliente no activo las notificaciones push";
|
||||
return "SMTP no configurado y el cliente no activó los avisos push";
|
||||
}
|
||||
return "No se pudo entregar por ningun canal";
|
||||
return "No se pudo entregar por ningún canal";
|
||||
}
|
||||
|
||||
export function CobrosClient({
|
||||
@@ -62,12 +63,15 @@ export function CobrosClient({
|
||||
pagosIniciales,
|
||||
saldos,
|
||||
diasRecordatorio,
|
||||
enRevision,
|
||||
}: {
|
||||
programas: ProgramaRow[];
|
||||
clientes: ClienteOpt[];
|
||||
pagosIniciales: PagoRow[];
|
||||
saldos: SaldoClienteRow[];
|
||||
diasRecordatorio: number;
|
||||
// Comprobantes esperando aprobacion (para la franja de resumen).
|
||||
enRevision: number;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const showConfirm = useConfirm();
|
||||
@@ -119,7 +123,7 @@ export function CobrosClient({
|
||||
const ok = await showConfirm({
|
||||
title: "Generar cobros",
|
||||
message:
|
||||
"Se generaran los cobros pendientes de todos los programas activos hasta hoy. Continuar?",
|
||||
"Se generarán los cobros pendientes de todos los programas activos hasta hoy. ¿Continuar?",
|
||||
confirmText: "Generar",
|
||||
});
|
||||
if (!ok) return;
|
||||
@@ -136,13 +140,13 @@ export function CobrosClient({
|
||||
}
|
||||
const n = data.generados ?? 0;
|
||||
toast(
|
||||
n > 0 ? `Se generaron ${n} cobros` : "No habia cobros pendientes",
|
||||
n > 0 ? `Se generaron ${n} cobros` : "No había cobros pendientes",
|
||||
"success"
|
||||
);
|
||||
cargarPagos();
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexion", "error");
|
||||
toast("Error de conexión", "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -151,8 +155,8 @@ export function CobrosClient({
|
||||
const ok = await showConfirm({
|
||||
title: "Enviar recordatorio de pago",
|
||||
message: saldo
|
||||
? `Se enviara a ${saldo.nombre} su estado de cuenta: ${saldo.pagos} ${saldo.pagos === 1 ? "cobro pendiente" : "cobros pendientes"} por ${formatTotales(saldo.totales)}, por correo y notificacion push.`
|
||||
: `Se enviara el estado de cuenta a ${saldos.length} ${saldos.length === 1 ? "cliente" : "clientes"} con pagos vencidos, por correo y notificacion push.`,
|
||||
? `Se enviará a ${saldo.nombre} su estado de cuenta: ${saldo.pagos} ${saldo.pagos === 1 ? "cobro pendiente" : "cobros pendientes"} por ${formatTotales(saldo.totales)}, por correo y aviso push.`
|
||||
: `Se enviará el estado de cuenta a ${saldos.length} ${saldos.length === 1 ? "cliente" : "clientes"} con pagos vencidos, por correo y aviso push.`,
|
||||
confirmText: "Enviar",
|
||||
});
|
||||
if (!ok) return;
|
||||
@@ -189,14 +193,14 @@ export function CobrosClient({
|
||||
} else {
|
||||
toast(
|
||||
resultados.length === 1
|
||||
? `No se envio: ${motivoNoEntregado(resultados[0], canales)}`
|
||||
: `No se envio a ningun cliente: ${motivoNoEntregado(resultados[0], canales)}`,
|
||||
? `No se envió: ${motivoNoEntregado(resultados[0], canales)}`
|
||||
: `No se envió a ningún cliente: ${motivoNoEntregado(resultados[0], canales)}`,
|
||||
"error"
|
||||
);
|
||||
}
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexion", "error");
|
||||
toast("Error de conexión", "error");
|
||||
} finally {
|
||||
setEnviandoRecordatorio(null);
|
||||
}
|
||||
@@ -207,8 +211,8 @@ export function CobrosClient({
|
||||
const ok = await showConfirm({
|
||||
title: activar ? "Activar programa" : "Desactivar programa",
|
||||
message: activar
|
||||
? `Activar el programa "${p.concepto}"? Se generaran cobros en sus proximos periodos.`
|
||||
: `Desactivar el programa "${p.concepto}"? No se generaran mas cobros, pero los existentes se conservan.`,
|
||||
? `¿Activar el programa "${p.concepto}"? Se generarán cobros en sus próximos periodos.`
|
||||
: `¿Desactivar el programa "${p.concepto}"? No se generarán más cobros, pero los existentes se conservan.`,
|
||||
confirmText: activar ? "Activar" : "Desactivar",
|
||||
danger: !activar,
|
||||
});
|
||||
@@ -227,7 +231,7 @@ export function CobrosClient({
|
||||
toast(activar ? "Programa activado" : "Programa desactivado", "success");
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexion", "error");
|
||||
toast("Error de conexión", "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -249,8 +253,9 @@ export function CobrosClient({
|
||||
}
|
||||
toast("Cobro verificado", "success");
|
||||
cargarPagos();
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexion", "error");
|
||||
toast("Error de conexión", "error");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -278,13 +283,61 @@ export function CobrosClient({
|
||||
// El cobro vuelve a estar por pagar: refresca el saldo por cliente.
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexion", "error");
|
||||
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)) {
|
||||
totalPorCobrar[moneda] = (totalPorCobrar[moneda] ?? 0) + total;
|
||||
}
|
||||
}
|
||||
const programasActivos = programas.filter((p) => p.activo).length;
|
||||
const resumen = [
|
||||
{
|
||||
href: "#por-cobrar",
|
||||
label: "Por cobrar",
|
||||
valor: saldos.length ? formatTotales(totalPorCobrar) : "$0",
|
||||
detalle: saldos.length
|
||||
? `${saldos.length} ${saldos.length === 1 ? "cliente con adeudo" : "clientes con adeudo"}`
|
||||
: "Nadie tiene pagos vencidos",
|
||||
alerta: saldos.length > 0,
|
||||
},
|
||||
{
|
||||
href: "#comprobantes",
|
||||
label: "Comprobantes por revisar",
|
||||
valor: String(enRevision),
|
||||
detalle: enRevision ? "Esperan tu aprobación" : "Todo revisado",
|
||||
alerta: enRevision > 0,
|
||||
},
|
||||
{
|
||||
href: "#programas",
|
||||
label: "Programas activos",
|
||||
valor: String(programasActivos),
|
||||
detalle: `${programas.length - programasActivos} inactivos`,
|
||||
alerta: false,
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="space-y-10">
|
||||
<section>
|
||||
<nav
|
||||
aria-label="Resumen de cobros"
|
||||
className="grid grid-cols-1 sm:grid-cols-3 bg-card-bg rounded-xl border border-border divide-y sm:divide-y-0 sm:divide-x divide-border overflow-hidden"
|
||||
>
|
||||
{resumen.map((r) => (
|
||||
<a key={r.href} href={r.href} className="block px-5 py-4 hover:bg-gray-50 transition-colors">
|
||||
<p className="text-xs font-medium text-muted">{r.label}</p>
|
||||
<p className={`text-xl font-semibold tracking-tight tabular-nums mt-1 ${r.alerta ? "text-foreground" : "text-muted"}`}>
|
||||
{r.valor}
|
||||
</p>
|
||||
<p className={`text-xs mt-0.5 ${r.alerta ? "text-amber-700" : "text-muted"}`}>{r.detalle}</p>
|
||||
</a>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<section id="por-cobrar" className="scroll-mt-20">
|
||||
<PorCobrarTabla
|
||||
saldos={saldos}
|
||||
diasRecordatorio={diasRecordatorio}
|
||||
@@ -293,21 +346,19 @@ export function CobrosClient({
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<ProgramasTabla
|
||||
programas={programas}
|
||||
clientes={clientes}
|
||||
onToggleActivo={toggleActivo}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<section id="comprobantes" className="scroll-mt-20">
|
||||
<div className="flex flex-wrap items-end justify-between gap-3 mb-4">
|
||||
<h2 className="text-lg font-semibold">Cobros generados</h2>
|
||||
<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.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={generarAhora}
|
||||
className="px-4 py-2 rounded-lg text-sm text-white bg-primary hover:opacity-90"
|
||||
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"
|
||||
>
|
||||
<RefreshCw className="w-4 h-4" />
|
||||
Generar cobros ahora
|
||||
</button>
|
||||
</div>
|
||||
@@ -322,7 +373,7 @@ export function CobrosClient({
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
<option value="pendiente">Pendiente</option>
|
||||
<option value="en_revision">En revision</option>
|
||||
<option value="en_revision">En revisión</option>
|
||||
<option value="verificado">Verificado</option>
|
||||
<option value="rechazado">Rechazado</option>
|
||||
</select>
|
||||
@@ -369,6 +420,14 @@ export function CobrosClient({
|
||||
onRechazar={rechazar}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section id="programas" className="scroll-mt-20">
|
||||
<ProgramasTabla
|
||||
programas={programas}
|
||||
clientes={clientes}
|
||||
onToggleActivo={toggleActivo}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ const ESTILOS: Record<string, { cls: string; label: string }> = {
|
||||
},
|
||||
[ESTADOS_PAGO.EN_REVISION]: {
|
||||
cls: "bg-blue-100 text-blue-800",
|
||||
label: "En revision",
|
||||
label: "En revisión",
|
||||
},
|
||||
[ESTADOS_PAGO.VERIFICADO]: {
|
||||
cls: "bg-green-100 text-green-800",
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { Check, X, FileText } from "lucide-react";
|
||||
import { formatCurrency } from "@/lib/calculators";
|
||||
import { formatFechaCorta } from "@/lib/cobros-fechas";
|
||||
import { formatFechaCorta, formatMonto } from "@/lib/cobros-fechas";
|
||||
import { EstadoPagoBadge } from "./EstadoPagoBadge";
|
||||
import type { PagoRow } from "./types";
|
||||
|
||||
@@ -37,8 +36,8 @@ export function PagosTabla({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||
<table className="w-full text-sm">
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-x-auto">
|
||||
<table className="w-full min-w-[52rem] 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>
|
||||
@@ -56,7 +55,7 @@ export function PagosTabla({
|
||||
<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">{formatCurrency(p.monto)}</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 && (
|
||||
|
||||
@@ -33,15 +33,15 @@ export function PorCobrarTabla({
|
||||
<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 reenvia solo cada ${diasRecordatorio} ${diasRecordatorio === 1 ? "dia" : "dias"} a partir de las 9:00.`
|
||||
: "Cobros vencidos sin pago o con comprobante rechazado. El recordatorio automatico esta desactivado (COBROS_RECORDATORIO_DIAS=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="px-4 py-2 rounded-lg text-sm text-white bg-primary hover:opacity-90 disabled:opacity-50 flex items-center gap-2"
|
||||
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"}
|
||||
@@ -52,19 +52,19 @@ export function PorCobrarTabla({
|
||||
{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">Ningun cliente tiene cobros pendientes de pago.</p>
|
||||
<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 text-sm">
|
||||
<table className="w-full min-w-[48rem] 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">Mas antiguo</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Ultimo recordatorio</th>
|
||||
<th className="text-center px-5 py-3 font-medium text-muted">Accion</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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -83,7 +83,7 @@ export function PorCobrarTabla({
|
||||
<div className={`text-xs ${s.diasAtraso > 0 ? "text-danger" : "text-muted"}`}>
|
||||
{s.diasAtraso === 0
|
||||
? "vence hoy"
|
||||
: `${s.diasAtraso} ${s.diasAtraso === 1 ? "dia" : "dias"} de atraso`}
|
||||
: `${s.diasAtraso} ${s.diasAtraso === 1 ? "día" : "días"} de atraso`}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-5 py-3 text-muted">
|
||||
|
||||
@@ -4,18 +4,17 @@ import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Pencil, Power, Plus } from "lucide-react";
|
||||
import { useToast } from "@/components/ui/DialogProvider";
|
||||
import { formatCurrency } from "@/lib/calculators";
|
||||
import { formatFechaCorta } from "@/lib/cobros-fechas";
|
||||
import { formatFechaCorta, formatMonto } from "@/lib/cobros-fechas";
|
||||
import type { ProgramaRow, ClienteOpt } from "./types";
|
||||
|
||||
const DIAS = [
|
||||
"Domingo",
|
||||
"Lunes",
|
||||
"Martes",
|
||||
"Miercoles",
|
||||
"Miércoles",
|
||||
"Jueves",
|
||||
"Viernes",
|
||||
"Sabado",
|
||||
"Sábado",
|
||||
];
|
||||
|
||||
function frecuenciaTexto(p: {
|
||||
@@ -25,7 +24,7 @@ function frecuenciaTexto(p: {
|
||||
}): string {
|
||||
if (p.frecuencia === "semanal") return `Cada ${DIAS[p.diaSemana ?? 0]}`;
|
||||
if (p.frecuencia === "quincenal") return "Cada 1 y 15";
|
||||
return `Cada dia ${p.diaMes ?? 1}`;
|
||||
return `Cada día ${p.diaMes ?? 1}`;
|
||||
}
|
||||
|
||||
function EstadoProgramaBadge({ activo }: { activo: boolean }) {
|
||||
@@ -154,7 +153,7 @@ export function ProgramasTabla({
|
||||
setDialogo(null);
|
||||
router.refresh();
|
||||
} catch {
|
||||
toast("Error de conexion", "error");
|
||||
toast("Error de conexión", "error");
|
||||
} finally {
|
||||
setGuardando(false);
|
||||
}
|
||||
@@ -162,7 +161,7 @@ export function ProgramasTabla({
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 mb-4">
|
||||
<h2 className="text-lg font-semibold">Programas de pago</h2>
|
||||
<button
|
||||
onClick={abrirNuevo}
|
||||
@@ -181,15 +180,15 @@ export function ProgramasTabla({
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||
<table className="w-full text-sm">
|
||||
<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">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">Frecuencia</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Proximo cobro</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Próximo cobro</th>
|
||||
<th className="text-center px-5 py-3 font-medium text-muted">Estado</th>
|
||||
<th className="text-center px-5 py-3 font-medium text-muted">Acciones</th>
|
||||
</tr>
|
||||
@@ -204,7 +203,7 @@ export function ProgramasTabla({
|
||||
<div className="text-xs text-muted">{p.cliente.empresa}</div>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right">{formatCurrency(p.monto)}</td>
|
||||
<td className="px-5 py-3 text-right">{formatMonto(p.monto, p.moneda)}</td>
|
||||
<td className="px-5 py-3">{frecuenciaTexto(p)}</td>
|
||||
<td className="px-5 py-3">
|
||||
{p.proximaFecha
|
||||
|
||||
@@ -133,9 +133,9 @@ export default async function CobrosPage() {
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold">Cobros recurrentes</h1>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Cobros recurrentes</h1>
|
||||
<p className="text-muted text-sm mt-1">
|
||||
Programa cobros periodicos y revisa los comprobantes de tus clientes
|
||||
Cobra a tiempo, revisa comprobantes y programa cobros periódicos
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -145,6 +145,7 @@ export default async function CobrosPage() {
|
||||
pagosIniciales={pagosData}
|
||||
saldos={saldosData}
|
||||
diasRecordatorio={diasRecordatorio()}
|
||||
enRevision={pagosData.length}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -172,10 +172,12 @@ export function ClienteShell({ nombre }: { nombre: string }) {
|
||||
type="button"
|
||||
onClick={activarNotificaciones}
|
||||
disabled={activas || activando}
|
||||
className={`flex items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors ${
|
||||
aria-label={activas ? "Notificaciones activas" : "Activar notificaciones"}
|
||||
title={activas ? "Recibirás avisos de cobros en este navegador" : "Recibe avisos de cobros en este navegador"}
|
||||
className={`flex items-center gap-1.5 rounded-lg border px-3 py-2 text-sm font-medium transition-colors ${
|
||||
activas
|
||||
? "bg-gray-100 text-muted cursor-not-allowed"
|
||||
: "bg-primary text-white hover:opacity-90"
|
||||
? "border-green-200 bg-green-50 text-green-700 cursor-default"
|
||||
: "border-border hover:bg-gray-50 disabled:opacity-60"
|
||||
}`}
|
||||
>
|
||||
{activas ? (
|
||||
@@ -184,16 +186,14 @@ export function ClienteShell({ nombre }: { nombre: string }) {
|
||||
<Bell className="w-4 h-4" />
|
||||
)}
|
||||
<span className="hidden sm:inline">
|
||||
{activas ? "Notificaciones activas" : "Activar notificaciones"}
|
||||
</span>
|
||||
<span className="sm:hidden">
|
||||
{activas ? "Activas" : "Avisos"}
|
||||
{activas ? "Avisos activos" : activando ? "Activando…" : "Activar avisos"}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={cerrarSesion}
|
||||
aria-label="Cerrar sesión"
|
||||
className="flex items-center gap-1.5 rounded-lg border border-border px-3 py-2 text-sm font-medium hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<LogOut className="w-4 h-4" />
|
||||
@@ -209,6 +209,7 @@ export function ClienteShell({ nombre }: { nombre: string }) {
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
aria-current={activa ? "page" : undefined}
|
||||
className={`flex items-center gap-1.5 whitespace-nowrap border-b-2 px-3 py-2.5 text-sm font-medium transition-colors ${
|
||||
activa
|
||||
? "border-primary text-primary"
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import Link from "next/link";
|
||||
import { ChevronRight } from "lucide-react";
|
||||
import { formatCurrency, formatDate } from "@/lib/calculators";
|
||||
import { EstadoBadge } from "@/components/EstadoBadge";
|
||||
|
||||
// Montos YA con IVA cuando la cotizacion lo incluye: quien llama decide.
|
||||
export type MontosCotizacion = { unico: number; mensual: number };
|
||||
|
||||
function Montos({ montos }: { montos: MontosCotizacion }) {
|
||||
return (
|
||||
<>
|
||||
{montos.unico > 0 && <span className="font-semibold">{formatCurrency(montos.unico)}</span>}
|
||||
{montos.unico > 0 && montos.mensual > 0 && <span className="text-muted"> + </span>}
|
||||
{montos.mensual > 0 && (
|
||||
<span className={montos.unico > 0 ? "text-muted" : "font-semibold"}>
|
||||
{formatCurrency(montos.mensual)}/mes
|
||||
</span>
|
||||
)}
|
||||
{montos.unico === 0 && montos.mensual === 0 && <span className="text-muted">—</span>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// Fila de cotizacion del panel cliente (inicio y listado). Lista, no tabla:
|
||||
// en el telefono los montos bajan debajo del titulo en lugar de recortarse.
|
||||
export function FilaCotizacion({
|
||||
id,
|
||||
numero,
|
||||
proyecto,
|
||||
fecha,
|
||||
estado,
|
||||
montos,
|
||||
opciones,
|
||||
}: {
|
||||
id: string;
|
||||
numero: string;
|
||||
proyecto: string;
|
||||
fecha: Date;
|
||||
estado: string;
|
||||
montos: MontosCotizacion;
|
||||
// Doble propuesta: un total por opcion en lugar del total combinado.
|
||||
opciones?: Array<{ clave: string; montos: MontosCotizacion }>;
|
||||
}) {
|
||||
return (
|
||||
<li>
|
||||
<Link
|
||||
href={`/cliente/cotizaciones/${id}`}
|
||||
className="group flex items-center gap-4 px-5 py-4 transition-colors hover:bg-gray-50"
|
||||
>
|
||||
<div className="flex min-w-0 flex-1 flex-col gap-2 sm:flex-row sm:items-center sm:justify-between sm:gap-6">
|
||||
<div className="min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="font-medium text-primary">{numero}</span>
|
||||
<EstadoBadge estado={estado} />
|
||||
{opciones && (
|
||||
<span className="rounded-full bg-primary-light px-2 py-0.5 text-[11px] font-semibold text-primary">
|
||||
Doble propuesta
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-0.5 text-sm text-muted sm:truncate">
|
||||
{proyecto} · {formatDate(fecha)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-sm tabular-nums sm:text-right">
|
||||
{opciones ? (
|
||||
opciones.map((o) => (
|
||||
<p key={o.clave}>
|
||||
<span className="text-muted">Opción {o.clave}: </span>
|
||||
<Montos montos={o.montos} />
|
||||
</p>
|
||||
))
|
||||
) : (
|
||||
<p>
|
||||
<Montos montos={montos} />
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<ChevronRight className="h-4 w-4 shrink-0 text-muted transition-transform group-hover:translate-x-0.5" />
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export default async function ClienteCotizacionDetallePage({
|
||||
<ArrowLeft className="w-5 h-5" />
|
||||
</Link>
|
||||
<div className="min-w-0">
|
||||
<h1 className="text-2xl font-bold">{cot.numero}</h1>
|
||||
<h1 className="text-2xl font-bold tracking-tight">{cot.numero}</h1>
|
||||
<p className="text-muted text-sm truncate">
|
||||
{cot.proyecto} · {formatDate(cot.fecha)}
|
||||
</p>
|
||||
@@ -168,11 +168,11 @@ export default async function ClienteCotizacionDetallePage({
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<table className="w-full text-sm">
|
||||
<table className="w-full text-sm tabular-nums">
|
||||
<thead>
|
||||
<tr className="border-b border-border">
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Servicio</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Tipo de pago</th>
|
||||
<th className="hidden sm:table-cell text-left px-5 py-3 font-medium text-muted">Tipo de pago</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted">Precio</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -181,8 +181,11 @@ export default async function ClienteCotizacionDetallePage({
|
||||
<tr key={s.id} className="border-b border-border last:border-0">
|
||||
<td className="px-5 py-3">
|
||||
{s.servicioCatalogo?.nombre || s.nombre || "Servicio"}
|
||||
<span className="block text-xs text-muted sm:hidden">
|
||||
{TIPO_PAGO_LABEL[s.tipoPago] || s.tipoPago}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-5 py-3 text-muted">
|
||||
<td className="hidden sm:table-cell px-5 py-3 text-muted">
|
||||
{TIPO_PAGO_LABEL[s.tipoPago] || s.tipoPago}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right font-medium">
|
||||
@@ -193,9 +196,9 @@ export default async function ClienteCotizacionDetallePage({
|
||||
</tbody>
|
||||
</table>
|
||||
{g.totales && (
|
||||
<div className="px-5 py-4 border-t border-border grid grid-cols-2 gap-4 text-sm">
|
||||
<div className="px-5 py-4 border-t border-border grid grid-cols-1 sm:grid-cols-2 gap-x-8 gap-y-2 text-sm tabular-nums">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted">Total unico{cot.incluirIva ? " (c/IVA)" : ""}</span>
|
||||
<span className="text-muted">Total único{cot.incluirIva ? " (c/IVA)" : ""}</span>
|
||||
<span className="font-semibold">
|
||||
{formatCurrency(totalConIva(g.totales.totalUnico))}
|
||||
</span>
|
||||
@@ -221,11 +224,11 @@ export default async function ClienteCotizacionDetallePage({
|
||||
Esta cotización no tiene servicios registrados.
|
||||
</div>
|
||||
) : (
|
||||
<table className="w-full text-sm">
|
||||
<table className="w-full 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">Servicio</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Tipo de pago</th>
|
||||
<th className="hidden sm:table-cell text-left px-5 py-3 font-medium text-muted">Tipo de pago</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted">Precio</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -234,8 +237,11 @@ export default async function ClienteCotizacionDetallePage({
|
||||
<tr key={s.id} className="border-b border-border hover:bg-gray-50 transition-colors">
|
||||
<td className="px-5 py-3">
|
||||
{s.servicioCatalogo?.nombre || s.nombre || "Servicio"}
|
||||
<span className="block text-xs text-muted sm:hidden">
|
||||
{TIPO_PAGO_LABEL[s.tipoPago] || s.tipoPago}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-5 py-3 text-muted">
|
||||
<td className="hidden sm:table-cell px-5 py-3 text-muted">
|
||||
{TIPO_PAGO_LABEL[s.tipoPago] || s.tipoPago}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right font-medium">
|
||||
@@ -262,10 +268,10 @@ export default async function ClienteCotizacionDetallePage({
|
||||
Opción {op}
|
||||
{meta?.titulo ? `: ${meta.titulo}` : ""}
|
||||
</h3>
|
||||
<div className="mt-3 space-y-1 text-sm">
|
||||
<div className="mt-3 space-y-1 text-sm tabular-nums">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted">
|
||||
Total unico{cot.incluirIva ? " (c/IVA)" : ""}
|
||||
Total único{cot.incluirIva ? " (c/IVA)" : ""}
|
||||
</span>
|
||||
<span className="font-semibold">
|
||||
{formatCurrency(totalConIva(t.totalUnico))}
|
||||
@@ -285,11 +291,11 @@ export default async function ClienteCotizacionDetallePage({
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<div className="max-w-sm space-y-2 text-sm">
|
||||
<div className="max-w-sm space-y-2 text-sm tabular-nums">
|
||||
{totales.incluyeIva && (
|
||||
<>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-muted">Subtotal unico</span>
|
||||
<span className="text-muted">Subtotal único</span>
|
||||
<span>{formatCurrency(totales.subtotalUnico)}</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
@@ -299,7 +305,7 @@ export default async function ClienteCotizacionDetallePage({
|
||||
</>
|
||||
)}
|
||||
<div className="flex justify-between font-semibold text-base border-t border-border pt-2">
|
||||
<span>Total unico</span>
|
||||
<span>Total único</span>
|
||||
<span>{formatCurrency(totales.totalUnico)}</span>
|
||||
</div>
|
||||
{totales.incluyeIva && (
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { ArrowRight, FileText } from "lucide-react";
|
||||
import { FileText } from "lucide-react";
|
||||
import { requireRole } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/db";
|
||||
import {
|
||||
IVA_RATE,
|
||||
calcularTotalesCotizacion,
|
||||
calcularTotalesOpcion,
|
||||
formatCurrency,
|
||||
formatDate,
|
||||
} from "@/lib/calculators";
|
||||
import { EstadoBadge } from "@/components/EstadoBadge";
|
||||
import { calcularTotalesCotizacion, calcularTotalesOpcion, conIva } from "@/lib/calculators";
|
||||
import { FilaCotizacion } from "../FilaCotizacion";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// Lista de cotizaciones del cliente: numero, proyecto, fecha, estado y totales.
|
||||
// Lista de cotizaciones del cliente: numero, proyecto, fecha, estado y totales
|
||||
// (con IVA cuando la cotizacion lo incluye; por opcion si es doble propuesta).
|
||||
export default async function ClienteCotizacionesPage() {
|
||||
const session = await requireRole("cliente");
|
||||
if (!session) redirect("/login?panel=cliente");
|
||||
@@ -38,116 +32,53 @@ export default async function ClienteCotizacionesPage() {
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold">Mis cotizaciones</h1>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Mis cotizaciones</h1>
|
||||
<p className="text-muted text-sm mt-1">
|
||||
{cotizaciones.length === 0
|
||||
? "Aún no tienes cotizaciones"
|
||||
: `${cotizaciones.length} cotizacion${cotizaciones.length === 1 ? "" : "es"} a tu nombre`}
|
||||
: `${cotizaciones.length} ${cotizaciones.length === 1 ? "cotización" : "cotizaciones"} a tu nombre`}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{cotizaciones.length === 0 ? (
|
||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
||||
<FileText className="w-16 h-16 text-muted mx-auto mb-4" />
|
||||
<FileText className="w-12 h-12 text-muted mx-auto mb-4" />
|
||||
<h2 className="text-lg font-semibold mb-2">No hay cotizaciones todavía</h2>
|
||||
<p className="text-muted">
|
||||
Cuando tengas una cotización disponible aparecerá en esta sección.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-border bg-gray-50">
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">No. Cotizacion</th>
|
||||
<th className="text-left px-5 py-3 font-medium text-muted">Proyecto</th>
|
||||
<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">Estado</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted">Total Unico</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted">Total Mensual</th>
|
||||
<th className="text-right px-5 py-3 font-medium text-muted"> </th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{cotizaciones.map((c) => {
|
||||
const totales = calcularTotalesCotizacion(c.servicios, {
|
||||
incluirIva: c.incluirIva,
|
||||
});
|
||||
const conIva = (m: number) =>
|
||||
c.incluirIva ? Math.round(m * (1 + IVA_RATE) * 100) / 100 : m;
|
||||
return (
|
||||
<tr key={c.id} className="border-b border-border hover:bg-gray-50 transition-colors">
|
||||
<td className="px-5 py-3">
|
||||
<Link
|
||||
href={`/cliente/cotizaciones/${c.id}`}
|
||||
className="font-medium text-primary hover:underline"
|
||||
>
|
||||
{c.numero}
|
||||
</Link>
|
||||
{c.esDoble && (
|
||||
<span className="ml-2 text-[11px] font-semibold uppercase tracking-wide px-2 py-0.5 rounded-full bg-primary-light text-primary">
|
||||
Doble propuesta
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-muted">{c.proyecto}</td>
|
||||
<td className="px-5 py-3 text-muted">{formatDate(c.fecha)}</td>
|
||||
<td className="px-5 py-3">
|
||||
<EstadoBadge estado={c.estado} />
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right font-medium">
|
||||
{c.esDoble ? (
|
||||
<div className="space-y-0.5">
|
||||
{(["1", "2"] as const).map((op) => {
|
||||
const t = calcularTotalesOpcion(c.servicios, op);
|
||||
return (
|
||||
<p key={op} className="text-xs">
|
||||
<span className="text-muted">Op {op}:</span>{" "}
|
||||
{t.totalUnico > 0 ? formatCurrency(conIva(t.totalUnico)) : "-"}
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : totales.totalUnico > 0 ? (
|
||||
formatCurrency(totales.totalUnico)
|
||||
) : (
|
||||
"-"
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right font-medium">
|
||||
{c.esDoble ? (
|
||||
<div className="space-y-0.5">
|
||||
{(["1", "2"] as const).map((op) => {
|
||||
const t = calcularTotalesOpcion(c.servicios, op);
|
||||
return (
|
||||
<p key={op} className="text-xs">
|
||||
<span className="text-muted">Op {op}:</span>{" "}
|
||||
{t.totalMensual > 0 ? formatCurrency(conIva(t.totalMensual)) : "-"}
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : totales.totalMensual > 0 ? (
|
||||
formatCurrency(totales.totalMensual)
|
||||
) : (
|
||||
"-"
|
||||
)}
|
||||
</td>
|
||||
<td className="px-5 py-3 text-right">
|
||||
<Link
|
||||
href={`/cliente/cotizaciones/${c.id}`}
|
||||
className="text-xs text-primary hover:underline inline-flex items-center gap-1"
|
||||
>
|
||||
Ver
|
||||
<ArrowRight className="w-3 h-3" />
|
||||
</Link>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<ul className="bg-card-bg rounded-xl border border-border divide-y divide-border overflow-hidden">
|
||||
{cotizaciones.map((c) => {
|
||||
const totales = calcularTotalesCotizacion(c.servicios, { incluirIva: c.incluirIva });
|
||||
return (
|
||||
<FilaCotizacion
|
||||
key={c.id}
|
||||
id={c.id}
|
||||
numero={c.numero}
|
||||
proyecto={c.proyecto}
|
||||
fecha={c.fecha}
|
||||
estado={c.estado}
|
||||
montos={{ unico: totales.totalUnico, mensual: totales.totalMensual }}
|
||||
opciones={
|
||||
c.esDoble
|
||||
? (["1", "2"] as const).map((op) => {
|
||||
const t = calcularTotalesOpcion(c.servicios, op);
|
||||
return {
|
||||
clave: op,
|
||||
montos: {
|
||||
unico: conIva(t.totalUnico, c.incluirIva),
|
||||
mensual: conIva(t.totalMensual, c.incluirIva),
|
||||
},
|
||||
};
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// Esqueleto del panel de cliente: las paginas son force-dynamic, asi que sin
|
||||
// esto el clic en la navegacion no da senal hasta que responde el servidor.
|
||||
export default function Loading() {
|
||||
const bloque = "rounded-lg bg-gray-200/70 motion-safe:animate-pulse";
|
||||
return (
|
||||
<div aria-busy="true" aria-label="Cargando">
|
||||
<div className={`${bloque} h-7 w-56 mb-2`} />
|
||||
<div className={`${bloque} h-4 w-72 mb-8`} />
|
||||
<div className="bg-card-bg rounded-xl border border-border p-6 mb-8">
|
||||
<div className={`${bloque} h-5 w-48 mb-3`} />
|
||||
<div className={`${bloque} h-8 w-40`} />
|
||||
</div>
|
||||
<div className="bg-card-bg rounded-xl border border-border divide-y divide-border">
|
||||
{[0, 1, 2].map((i) => (
|
||||
<div key={i} className="flex items-center justify-between gap-4 px-5 py-4">
|
||||
<div className="space-y-2">
|
||||
<div className={`${bloque} h-4 w-44`} />
|
||||
<div className={`${bloque} h-3 w-28`} />
|
||||
</div>
|
||||
<div className={`${bloque} h-5 w-20`} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+129
-137
@@ -1,19 +1,18 @@
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import {
|
||||
ArrowRight,
|
||||
CalendarClock,
|
||||
ClipboardList,
|
||||
Clock3,
|
||||
FileText,
|
||||
Inbox,
|
||||
ShieldCheck,
|
||||
} from "lucide-react";
|
||||
import { ArrowRight, CalendarClock, CircleCheck, Clock3, FileText, Inbox } from "lucide-react";
|
||||
import { requireRole } from "@/lib/auth";
|
||||
import { formatCurrency, formatDate } from "@/lib/calculators";
|
||||
import { formatFechaCorta, formatTotales } from "@/lib/cobros";
|
||||
import { EstadoBadge } from "@/components/EstadoBadge";
|
||||
import { conIva } from "@/lib/calculators";
|
||||
import {
|
||||
describirVencimiento,
|
||||
diasHasta,
|
||||
formatFechaBreve,
|
||||
formatMonto,
|
||||
formatTotales,
|
||||
hoyCalendario,
|
||||
} from "@/lib/cobros";
|
||||
import { obtenerResumenCliente } from "./resumen-data";
|
||||
import { FilaCotizacion } from "./FilaCotizacion";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -28,7 +27,7 @@ export default async function ClienteInicioPage() {
|
||||
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" />
|
||||
<Inbox className="w-12 h-12 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
|
||||
@@ -38,179 +37,172 @@ export default async function ClienteInicioPage() {
|
||||
);
|
||||
}
|
||||
|
||||
const tarjetas: Array<{
|
||||
label: string;
|
||||
value: number;
|
||||
detalle?: string;
|
||||
icon: typeof FileText;
|
||||
bg: string;
|
||||
color: string;
|
||||
}> = [
|
||||
{
|
||||
label: "Cotizaciones activas",
|
||||
value: resumen.cotizacionesActivas,
|
||||
icon: FileText,
|
||||
bg: "bg-primary-light",
|
||||
color: "text-primary",
|
||||
},
|
||||
{
|
||||
label: "Pagos pendientes",
|
||||
value: resumen.pagos.pendientes,
|
||||
detalle:
|
||||
resumen.pagos.pendientes > 0
|
||||
? `${formatTotales(resumen.pagos.saldoPendiente)} por pagar`
|
||||
: undefined,
|
||||
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",
|
||||
},
|
||||
const hoy = hoyCalendario();
|
||||
const { pagos } = resumen;
|
||||
const debe = pagos.pendientes > 0;
|
||||
const proximo = pagos.proximos[0];
|
||||
|
||||
const indicadores = [
|
||||
{ label: "En revisión", value: pagos.enRevision },
|
||||
{ label: "Verificados este mes", value: pagos.verificadosMes },
|
||||
{ label: "Cotizaciones activas", value: resumen.cotizacionesActivas },
|
||||
];
|
||||
|
||||
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>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Hola, {resumen.cliente.nombre}</h1>
|
||||
{resumen.cliente.empresa && (
|
||||
<p className="text-muted text-sm mt-1">{resumen.cliente.empresa}</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>
|
||||
{t.detalle && (
|
||||
<Link
|
||||
href="/cliente/pagos"
|
||||
className="text-xs font-medium text-amber-700 hover:underline"
|
||||
>
|
||||
{t.detalle}
|
||||
</Link>
|
||||
<section
|
||||
aria-label="Estado de tus pagos"
|
||||
className="bg-card-bg rounded-xl border border-border overflow-hidden mb-8"
|
||||
>
|
||||
<div className="flex flex-col gap-5 p-5 sm:flex-row sm:items-center sm:justify-between sm:p-6">
|
||||
{debe ? (
|
||||
<div className="flex items-start gap-4">
|
||||
<span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-amber-50 text-amber-600">
|
||||
<Clock3 className="w-6 h-6" />
|
||||
</span>
|
||||
<div>
|
||||
<h2 className="font-semibold">
|
||||
Tienes {pagos.pendientes} {pagos.pendientes === 1 ? "pago pendiente" : "pagos pendientes"}
|
||||
</h2>
|
||||
<p className="text-2xl font-bold tracking-tight tabular-nums mt-1">
|
||||
{formatTotales(pagos.saldoPendiente)}
|
||||
</p>
|
||||
{pagos.masAntiguo && (
|
||||
<p className="text-sm text-muted mt-1">
|
||||
El más antiguo es del {formatFechaBreve(pagos.masAntiguo, hoy)}
|
||||
{diasHasta(pagos.masAntiguo, hoy) <= 0 &&
|
||||
` (${describirVencimiento(pagos.masAntiguo, hoy)})`}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-start gap-4">
|
||||
<span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-green-50 text-green-600">
|
||||
<CircleCheck className="w-6 h-6" />
|
||||
</span>
|
||||
<div>
|
||||
<h2 className="font-semibold">Estás al día con tus pagos</h2>
|
||||
<p className="text-sm text-muted mt-1">
|
||||
{proximo
|
||||
? `Tu próximo cobro es el ${formatFechaBreve(proximo.fecha, hoy)} por ${formatMonto(proximo.monto, proximo.moneda)}.`
|
||||
: "No tienes cobros pendientes."}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Link
|
||||
href="/cliente/pagos"
|
||||
className={`inline-flex shrink-0 items-center justify-center gap-2 rounded-lg px-4 py-2.5 text-sm font-medium transition-colors ${
|
||||
debe
|
||||
? "bg-primary text-white hover:bg-primary-dark"
|
||||
: "border border-border hover:bg-gray-50"
|
||||
}`}
|
||||
>
|
||||
{debe ? "Pagar y subir comprobante" : "Ver mis pagos"}
|
||||
<ArrowRight className="w-4 h-4" />
|
||||
</Link>
|
||||
</div>
|
||||
<dl className="grid grid-cols-3 divide-x divide-border border-t border-border bg-gray-50/60">
|
||||
{indicadores.map((i) => (
|
||||
<div key={i.label} className="px-4 py-3 sm:px-6">
|
||||
<dt className="text-xs text-muted">{i.label}</dt>
|
||||
<dd className="text-lg font-semibold tabular-nums">{i.value}</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<div className="bg-card-bg rounded-xl border border-border mb-8">
|
||||
<section 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">
|
||||
<h2 className="font-semibold 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"
|
||||
className="text-sm text-primary hover:underline underline-offset-2 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>
|
||||
{pagos.proximos.length === 0 ? (
|
||||
<p className="px-5 py-8 text-center text-sm text-muted">
|
||||
No tienes cobros programados por ahora.
|
||||
</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-border">
|
||||
{resumen.pagos.proximos.map((p) => (
|
||||
{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 className="min-w-0">
|
||||
<p className="font-medium text-sm truncate">{p.concepto}</p>
|
||||
<p className="text-xs text-muted">
|
||||
{formatFechaBreve(p.fecha, hoy)} · {describirVencimiento(p.fecha, hoy)}
|
||||
</p>
|
||||
</div>
|
||||
<p className="font-semibold">{formatCurrency(p.monto)}</p>
|
||||
<p className="font-semibold tabular-nums">{formatMonto(p.monto, p.moneda)}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div className="bg-card-bg rounded-xl border border-border">
|
||||
<section 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>
|
||||
<h2 className="font-semibold flex items-center gap-2">
|
||||
<FileText className="w-5 h-5 text-primary" />
|
||||
Últimas cotizaciones
|
||||
</h2>
|
||||
<Link
|
||||
href="/cliente/cotizaciones"
|
||||
className="text-sm text-primary hover:underline flex items-center gap-1"
|
||||
className="text-sm text-primary hover:underline underline-offset-2 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>
|
||||
<p className="px-5 py-8 text-center text-sm text-muted">
|
||||
Todavía no tienes cotizaciones. En cuanto el administrador la envíe, aparecerá aquí.
|
||||
</p>
|
||||
) : (
|
||||
<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>
|
||||
<FilaCotizacion
|
||||
key={c.id}
|
||||
id={c.id}
|
||||
numero={c.numero}
|
||||
proyecto={c.proyecto}
|
||||
fecha={c.fecha}
|
||||
estado={c.estado}
|
||||
montos={{ unico: c.totales.totalUnico, mensual: c.totales.totalMensual }}
|
||||
opciones={
|
||||
c.totalesOpciones
|
||||
? (["1", "2"] as const).map((op) => ({
|
||||
clave: op,
|
||||
montos: {
|
||||
unico: conIva(c.totalesOpciones![op].totalUnico, c.incluirIva),
|
||||
mensual: conIva(c.totalesOpciones![op].totalMensual, c.incluirIva),
|
||||
},
|
||||
}))
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Check, Copy } from "lucide-react";
|
||||
|
||||
// Fila de dato bancario con boton de copiar: en el telefono, pegar la CLABE en
|
||||
// la app del banco es el paso que mas falla si hay que transcribirla.
|
||||
export function CopiarDato({ etiqueta, valor }: { etiqueta: string; valor: string }) {
|
||||
const [copiado, setCopiado] = useState(false);
|
||||
|
||||
const copiar = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(valor.replace(/\s+/g, ""));
|
||||
setCopiado(true);
|
||||
setTimeout(() => setCopiado(false), 1800);
|
||||
} catch {
|
||||
// Sin permiso de portapapeles el dato sigue visible y seleccionable.
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="py-2.5">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<p className="text-xs text-muted">{etiqueta}</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={copiar}
|
||||
aria-label={`Copiar ${etiqueta}`}
|
||||
className={`shrink-0 inline-flex items-center gap-1 rounded-md border px-2 py-1 text-xs font-medium transition-colors ${
|
||||
copiado
|
||||
? "border-green-200 bg-green-50 text-green-700"
|
||||
: "border-border text-foreground hover:bg-gray-50"
|
||||
}`}
|
||||
>
|
||||
{copiado ? <Check className="w-3.5 h-3.5" /> : <Copy className="w-3.5 h-3.5" />}
|
||||
{copiado ? "Copiado" : "Copiar"}
|
||||
</button>
|
||||
</div>
|
||||
<p className="mt-0.5 font-medium tabular-nums tracking-wide select-all [overflow-wrap:anywhere]">
|
||||
{valor}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -7,7 +7,14 @@ import { useToast } from "@/components/ui/DialogProvider";
|
||||
|
||||
// Subida de comprobante para un cobro pendiente o rechazado. multipart/form-data
|
||||
// a POST /api/cliente/pagos/[id]/comprobante; en error muestra el {error} del server.
|
||||
export function SubirComprobante({ pagoId }: { pagoId: string }) {
|
||||
export function SubirComprobante({
|
||||
pagoId,
|
||||
variante = "secundario",
|
||||
}: {
|
||||
pagoId: string;
|
||||
// "primario" en la lista de lo que hay que pagar, donde es LA accion.
|
||||
variante?: "primario" | "secundario";
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const toast = useToast();
|
||||
const [subiendo, setSubiendo] = useState(false);
|
||||
@@ -41,11 +48,11 @@ export function SubirComprobante({ pagoId }: { pagoId: string }) {
|
||||
|
||||
return (
|
||||
<label
|
||||
className={`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-sm font-medium transition-colors ${
|
||||
subiendo
|
||||
? "opacity-60 cursor-wait text-muted"
|
||||
: "cursor-pointer hover:bg-gray-50"
|
||||
}`}
|
||||
className={`inline-flex shrink-0 items-center justify-center gap-1.5 rounded-lg px-3.5 py-2 text-sm font-medium transition-colors ${
|
||||
variante === "primario"
|
||||
? "bg-primary-light/70 text-primary-dark hover:bg-primary hover:text-white"
|
||||
: "border border-border hover:bg-gray-50"
|
||||
} ${subiendo ? "opacity-60 cursor-wait" : "cursor-pointer"}`}
|
||||
>
|
||||
{subiendo ? (
|
||||
<Loader2 className="w-4 h-4 animate-spin" />
|
||||
|
||||
+235
-151
@@ -1,17 +1,22 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { CalendarClock, Inbox } from "lucide-react";
|
||||
import { Check, CircleCheck, Clock3, FileText, Inbox } from "lucide-react";
|
||||
import { requireRole } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { formatCurrency } from "@/lib/calculators";
|
||||
import { getConfigBancaria } from "@/lib/config-helpers";
|
||||
import {
|
||||
ESTADOS_PAGO,
|
||||
describirVencimiento,
|
||||
diasHasta,
|
||||
esPorPagar,
|
||||
formatFechaCorta,
|
||||
formatFechaBreve,
|
||||
formatMonto,
|
||||
formatTotales,
|
||||
hoyCalendario,
|
||||
proximaFecha,
|
||||
totalesPorMoneda,
|
||||
} from "@/lib/cobros";
|
||||
import { SubirComprobante } from "./SubirComprobante";
|
||||
import { CopiarDato } from "./CopiarDato";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -25,56 +30,70 @@ const DIAS_SEMANA = [
|
||||
"sábado",
|
||||
];
|
||||
|
||||
// Pagos ya registrados que se ven sin desplegar el historial de cada programa.
|
||||
const HISTORIAL_VISIBLE = 4;
|
||||
|
||||
function frecuenciaLegible(p: {
|
||||
frecuencia: string;
|
||||
diaSemana?: number | null;
|
||||
diaMes?: number | null;
|
||||
}): string {
|
||||
if (p.frecuencia === "semanal") {
|
||||
return `Semanal (${DIAS_SEMANA[p.diaSemana ?? 0]})`;
|
||||
}
|
||||
if (p.frecuencia === "quincenal") {
|
||||
return "Quincenal (días 1 y 15)";
|
||||
}
|
||||
if (p.frecuencia === "mensual") {
|
||||
return `Mensual (día ${p.diaMes ?? 1})`;
|
||||
}
|
||||
if (p.frecuencia === "semanal") return `cada ${DIAS_SEMANA[p.diaSemana ?? 0]}`;
|
||||
if (p.frecuencia === "quincenal") return "los días 1 y 15";
|
||||
if (p.frecuencia === "mensual") return `el día ${p.diaMes ?? 1} de cada mes`;
|
||||
return p.frecuencia;
|
||||
}
|
||||
|
||||
function EstadoPagoBadge({
|
||||
estado,
|
||||
rechazoMotivo,
|
||||
}: {
|
||||
estado: string;
|
||||
rechazoMotivo?: string | null;
|
||||
}) {
|
||||
let cls = "bg-amber-100 text-amber-700";
|
||||
let label = "Pendiente de pago";
|
||||
if (estado === ESTADOS_PAGO.EN_REVISION) {
|
||||
cls = "bg-blue-100 text-blue-700";
|
||||
label = "En revisión";
|
||||
} else if (estado === ESTADOS_PAGO.VERIFICADO) {
|
||||
cls = "bg-green-100 text-green-700";
|
||||
label = "Verificado ✓";
|
||||
} else if (estado === ESTADOS_PAGO.RECHAZADO) {
|
||||
cls = "bg-red-100 text-red-700";
|
||||
label = "Rechazado";
|
||||
function EstadoHistorial({ estado }: { estado: string }) {
|
||||
if (estado === ESTADOS_PAGO.VERIFICADO) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-green-50 px-2.5 py-0.5 text-xs font-medium text-green-700">
|
||||
<Check className="w-3 h-3" />
|
||||
Verificado
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<span className={`inline-block px-2.5 py-0.5 rounded-full text-xs font-medium ${cls}`}>
|
||||
{label}
|
||||
</span>
|
||||
{estado === ESTADOS_PAGO.RECHAZADO && rechazoMotivo && (
|
||||
<p className="text-xs text-muted mt-1">Motivo: {rechazoMotivo}</p>
|
||||
)}
|
||||
</div>
|
||||
<span className="inline-flex items-center gap-1 rounded-full bg-blue-50 px-2.5 py-0.5 text-xs font-medium text-blue-700">
|
||||
<Clock3 className="w-3 h-3" />
|
||||
En revisión
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
// Guia de pagos recurrentes: un bloque por programa y su tabla de cobros,
|
||||
// con subida de comprobante para los pendientes/rechazados.
|
||||
type FilaHistorial = {
|
||||
id: string;
|
||||
fecha: Date;
|
||||
monto: number;
|
||||
estado: string;
|
||||
comprobante: { archivoNombre: string } | null;
|
||||
};
|
||||
|
||||
function FilaPago({ pago, moneda, hoy }: { pago: FilaHistorial; moneda: string; hoy: Date }) {
|
||||
return (
|
||||
<li className="flex flex-wrap items-center gap-x-4 gap-y-1.5 px-5 py-3 text-sm">
|
||||
<span className="w-28 shrink-0">{formatFechaBreve(pago.fecha, hoy)}</span>
|
||||
<EstadoHistorial estado={pago.estado} />
|
||||
<span className="ml-auto font-medium tabular-nums">{formatMonto(pago.monto, moneda)}</span>
|
||||
{pago.comprobante ? (
|
||||
<a
|
||||
href={`/api/comprobantes/${pago.id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="inline-flex items-center gap-1 text-primary hover:underline underline-offset-2"
|
||||
title={pago.comprobante.archivoNombre}
|
||||
>
|
||||
<FileText className="w-3.5 h-3.5" />
|
||||
Comprobante
|
||||
</a>
|
||||
) : null}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
// Lo primero es lo que el cliente tiene que pagar (mas antiguo primero) con su
|
||||
// boton de comprobante; al lado, los datos bancarios para copiar; abajo, el
|
||||
// historial de cada programa.
|
||||
export default async function ClientePagosPage() {
|
||||
const session = await requireRole("cliente");
|
||||
if (!session) redirect("/login?panel=cliente");
|
||||
@@ -87,143 +106,208 @@ export default async function ClientePagosPage() {
|
||||
include: {
|
||||
pagos: {
|
||||
orderBy: { fecha: "desc" },
|
||||
include: { comprobante: { select: { archivoNombre: true, subidoAt: true } } },
|
||||
include: { comprobante: { select: { archivoNombre: true } } },
|
||||
},
|
||||
},
|
||||
}),
|
||||
getConfigBancaria(),
|
||||
]);
|
||||
|
||||
// Lo que el cliente debe hoy: pendientes + comprobantes rechazados.
|
||||
const porPagar = programas.flatMap((prog) =>
|
||||
prog.pagos
|
||||
.filter((pago) => esPorPagar(pago.estado))
|
||||
.map((pago) => ({ monto: pago.monto, programa: { moneda: prog.moneda } }))
|
||||
const hoy = hoyCalendario();
|
||||
|
||||
// Lo que el cliente debe: pendientes + comprobantes rechazados.
|
||||
const porPagar = programas
|
||||
.flatMap((prog) =>
|
||||
prog.pagos
|
||||
.filter((pago) => esPorPagar(pago.estado))
|
||||
.map((pago) => ({ ...pago, programa: { concepto: prog.concepto, moneda: prog.moneda } }))
|
||||
)
|
||||
.sort((a, b) => a.fecha.getTime() - b.fecha.getTime());
|
||||
const enRevision = programas.reduce(
|
||||
(n, prog) => n + prog.pagos.filter((p) => p.estado === ESTADOS_PAGO.EN_REVISION).length,
|
||||
0
|
||||
);
|
||||
|
||||
const datosPago = [
|
||||
["Titular", banco.razon_social],
|
||||
["CLABE", banco.clabe_interbancaria],
|
||||
["Cuenta", banco.cuenta_nacional],
|
||||
].filter((par): par is [string, string] => Boolean(par[1]));
|
||||
|
||||
if (programas.length === 0) {
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold tracking-tight mb-8">Mis pagos</h1>
|
||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
||||
<Inbox className="w-12 h-12 text-muted mx-auto mb-4" />
|
||||
<h2 className="text-lg font-semibold mb-2">Sin cobros programados</h2>
|
||||
<p className="text-muted max-w-md mx-auto">
|
||||
Cuando se configure un programa de pagos para ti, aparecerá aquí junto con cada
|
||||
cobro generado.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-8">
|
||||
<h1 className="text-2xl font-bold">Mis pagos</h1>
|
||||
<h1 className="text-2xl font-bold tracking-tight">Mis pagos</h1>
|
||||
<p className="text-muted text-sm mt-1">
|
||||
Historial de cobros recurrentes y carga de comprobantes
|
||||
Paga tus cobros y sube el comprobante para que quede registrado.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{porPagar.length > 0 && (
|
||||
<div className="mb-4 rounded-xl border border-amber-200 bg-amber-50 p-4">
|
||||
<p className="font-semibold text-amber-800">
|
||||
Tienes {porPagar.length}{" "}
|
||||
{porPagar.length === 1 ? "pago pendiente" : "pagos pendientes"} por{" "}
|
||||
{formatTotales(totalesPorMoneda(porPagar))}
|
||||
</p>
|
||||
<p className="text-sm text-amber-800 mt-1">
|
||||
Realiza tu pago y sube el comprobante en el cobro correspondiente.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mb-6 rounded-xl border border-border bg-card-bg p-4 text-sm text-muted">
|
||||
Sube tu comprobante de pago (imagen o PDF). El administrador lo revisará y
|
||||
quedará como verificado.
|
||||
{datosPago.length > 0 && (
|
||||
<div className="mt-3 pt-3 border-t border-border">
|
||||
<p className="font-medium text-foreground mb-1">Datos para tu pago</p>
|
||||
{datosPago.map(([etiqueta, valor]) => (
|
||||
<p key={etiqueta}>
|
||||
{etiqueta}: <span className="font-medium text-foreground">{valor}</span>
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{programas.length === 0 ? (
|
||||
<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">Sin cobros programados</h2>
|
||||
<p className="text-muted">
|
||||
Cuando se configure un programa de pagos para ti, aparecerá aquí junto
|
||||
con cada cobro generado.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
programas.map((prog) => (
|
||||
<section key={prog.id} className="mb-8">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 mb-3">
|
||||
<div>
|
||||
<h2 className="font-semibold text-lg flex items-center gap-2">
|
||||
<CalendarClock className="w-5 h-5 text-primary" />
|
||||
{prog.concepto}
|
||||
<div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_18rem]">
|
||||
<section aria-labelledby="titulo-por-pagar" className="min-w-0 lg:col-start-1 lg:row-start-1">
|
||||
{porPagar.length > 0 ? (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||
<div className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 px-5 py-4 border-b border-border">
|
||||
<h2 id="titulo-por-pagar" className="text-lg font-semibold">
|
||||
Por pagar
|
||||
</h2>
|
||||
<p className="text-sm text-muted mt-0.5">
|
||||
{formatCurrency(prog.monto)} · {frecuenciaLegible(prog)} · {prog.moneda}
|
||||
<p className="text-sm text-muted">
|
||||
{porPagar.length} {porPagar.length === 1 ? "cobro" : "cobros"} ·{" "}
|
||||
<span className="font-semibold text-foreground tabular-nums">
|
||||
{formatTotales(totalesPorMoneda(porPagar))}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
{!prog.activo && (
|
||||
<span className="inline-block px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-600">
|
||||
Programa inactivo
|
||||
</span>
|
||||
)}
|
||||
<ul className="divide-y divide-border">
|
||||
{porPagar.map((pago) => {
|
||||
const vencido = diasHasta(pago.fecha, hoy) < 0;
|
||||
const rechazado = pago.estado === ESTADOS_PAGO.RECHAZADO;
|
||||
return (
|
||||
<li
|
||||
key={pago.id}
|
||||
className="flex flex-col gap-3 px-5 py-4 sm:flex-row sm:items-center sm:justify-between"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<p className="font-medium">{pago.programa.concepto}</p>
|
||||
<p className="text-sm text-muted mt-0.5">
|
||||
{formatFechaBreve(pago.fecha, hoy)} ·{" "}
|
||||
<span className={vencido ? "font-medium text-red-600" : "font-medium text-amber-700"}>
|
||||
{describirVencimiento(pago.fecha, hoy)}
|
||||
</span>
|
||||
</p>
|
||||
{rechazado && (
|
||||
<p className="text-sm text-red-700 mt-1.5">
|
||||
Rechazamos el comprobante
|
||||
{pago.rechazoMotivo ? `: ${pago.rechazoMotivo}` : ""}. Sube uno nuevo.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center justify-between gap-4 sm:justify-end">
|
||||
<span className="text-lg font-semibold tabular-nums">
|
||||
{formatMonto(pago.monto, pago.programa.moneda)}
|
||||
</span>
|
||||
<SubirComprobante pagoId={pago.id} variante="primario" />
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-card-bg rounded-xl border border-border p-5 flex items-center gap-4">
|
||||
<span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-green-50 text-green-600">
|
||||
<CircleCheck className="w-6 h-6" />
|
||||
</span>
|
||||
<div>
|
||||
<h2 id="titulo-por-pagar" className="font-semibold">
|
||||
Estás al día
|
||||
</h2>
|
||||
<p className="text-sm text-muted">
|
||||
No tienes cobros pendientes de pago.
|
||||
{enRevision > 0 &&
|
||||
` ${enRevision} ${enRevision === 1 ? "comprobante está" : "comprobantes están"} en revisión.`}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{prog.pagos.length === 0 ? (
|
||||
<div className="bg-card-bg rounded-xl border border-border p-8 text-center text-sm text-muted">
|
||||
Aún no se han generado cobros de este programa.
|
||||
<aside className="space-y-4 lg:col-start-2 lg:row-start-1 lg:row-span-2 lg:self-start lg:sticky lg:top-32">
|
||||
{datosPago.length > 0 && (
|
||||
<div className="bg-card-bg rounded-xl border border-border px-5 py-4">
|
||||
<h2 className="font-semibold mb-1">Datos para tu pago</h2>
|
||||
<div className="divide-y divide-border">
|
||||
{datosPago.map(([etiqueta, valor]) => (
|
||||
<CopiarDato key={etiqueta} etiqueta={etiqueta} valor={valor} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||
<table className="w-full text-sm">
|
||||
<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-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-left px-5 py-3 font-medium text-muted">Acción</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{prog.pagos.map((pago) => (
|
||||
<tr key={pago.id} className="border-b border-border hover:bg-gray-50 transition-colors">
|
||||
<td className="px-5 py-3">{formatFechaCorta(pago.fecha)}</td>
|
||||
<td className="px-5 py-3 text-right font-medium">
|
||||
{formatCurrency(pago.monto)}
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
<EstadoPagoBadge
|
||||
estado={pago.estado}
|
||||
rechazoMotivo={pago.rechazoMotivo}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-5 py-3">
|
||||
{pago.estado === ESTADOS_PAGO.PENDIENTE ||
|
||||
pago.estado === ESTADOS_PAGO.RECHAZADO ? (
|
||||
<SubirComprobante pagoId={pago.id} />
|
||||
) : (
|
||||
<a
|
||||
href={`/api/comprobantes/${pago.id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-primary text-sm hover:underline"
|
||||
>
|
||||
Ver comprobante
|
||||
</a>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
<div className="bg-card-bg rounded-xl border border-border px-5 py-4 text-sm">
|
||||
<h2 className="font-semibold mb-2">Cómo se registra tu pago</h2>
|
||||
<ol className="list-decimal space-y-1.5 pl-4 text-muted marker:text-muted">
|
||||
<li>Haz la transferencia por el monto del cobro.</li>
|
||||
<li>Sube el comprobante (imagen o PDF, hasta 10 MB) en ese cobro.</li>
|
||||
<li>Lo revisamos y te avisamos cuando quede verificado.</li>
|
||||
</ol>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<section aria-labelledby="titulo-historial" className="min-w-0 lg:col-start-1 lg:row-start-2">
|
||||
<h2 id="titulo-historial" className="text-lg font-semibold mb-3 mt-2">
|
||||
Historial
|
||||
</h2>
|
||||
<div className="space-y-4">
|
||||
{programas.map((prog) => {
|
||||
const registrados = prog.pagos.filter((p) => !esPorPagar(p.estado));
|
||||
const visibles = registrados.slice(0, HISTORIAL_VISIBLE);
|
||||
const anteriores = registrados.slice(HISTORIAL_VISIBLE);
|
||||
const proximo = prog.activo ? proximaFecha(prog, hoy) : null;
|
||||
return (
|
||||
<div key={prog.id} className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||
<div className="flex flex-wrap items-start justify-between gap-2 px-5 py-4 border-b border-border">
|
||||
<div className="min-w-0">
|
||||
<h3 className="font-semibold">{prog.concepto}</h3>
|
||||
<p className="text-sm text-muted mt-0.5">
|
||||
<span className="tabular-nums">{formatMonto(prog.monto, prog.moneda)}</span>{" "}
|
||||
{frecuenciaLegible(prog)}
|
||||
{proximo && ` · próximo: ${formatFechaBreve(proximo, hoy)}`}
|
||||
</p>
|
||||
</div>
|
||||
{!prog.activo && (
|
||||
<span className="rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-600">
|
||||
Programa inactivo
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{registrados.length === 0 ? (
|
||||
<p className="px-5 py-4 text-sm text-muted">Aún no hay pagos registrados.</p>
|
||||
) : (
|
||||
<>
|
||||
<ul className="divide-y divide-border">
|
||||
{visibles.map((pago) => (
|
||||
<FilaPago key={pago.id} pago={pago} moneda={prog.moneda} hoy={hoy} />
|
||||
))}
|
||||
</ul>
|
||||
{anteriores.length > 0 && (
|
||||
<details className="group border-t border-border">
|
||||
<summary className="cursor-pointer list-none px-5 py-3 text-sm font-medium text-primary hover:bg-gray-50 [&::-webkit-details-marker]:hidden">
|
||||
<span className="group-open:hidden">
|
||||
Ver {anteriores.length} {anteriores.length === 1 ? "pago anterior" : "pagos anteriores"}
|
||||
</span>
|
||||
<span className="hidden group-open:inline">Ocultar pagos anteriores</span>
|
||||
</summary>
|
||||
<ul className="divide-y divide-border border-t border-border">
|
||||
{anteriores.map((pago) => (
|
||||
<FilaPago key={pago.id} pago={pago} moneda={prog.moneda} hoy={hoy} />
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface ResumenCotizacion {
|
||||
fecha: Date;
|
||||
estado: string;
|
||||
esDoble: boolean;
|
||||
incluirIva: boolean;
|
||||
totales: ReturnType<typeof calcularTotalesCotizacion>;
|
||||
totalesOpciones?: {
|
||||
"1": ReturnType<typeof calcularTotalesOpcion>;
|
||||
@@ -34,9 +35,11 @@ export interface ResumenCliente {
|
||||
// por moneda.
|
||||
pendientes: number;
|
||||
saldoPendiente: Record<string, number>;
|
||||
// Fecha del cobro por pagar mas antiguo (null si no debe nada).
|
||||
masAntiguo: Date | null;
|
||||
enRevision: number;
|
||||
verificadosMes: number;
|
||||
proximos: Array<{ fecha: Date; monto: number; concepto: string }>;
|
||||
proximos: Array<{ fecha: Date; monto: number; moneda: string; concepto: string }>;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -74,7 +77,8 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
||||
}),
|
||||
prisma.pagoRecurrente.findMany({
|
||||
where: { estado: { in: ESTADOS_POR_PAGAR }, programa: { clienteId } },
|
||||
select: { monto: true, programa: { select: { moneda: true } } },
|
||||
orderBy: { fecha: "asc" },
|
||||
select: { fecha: true, monto: true, programa: { select: { moneda: true } } },
|
||||
}),
|
||||
prisma.pagoRecurrente.count({
|
||||
where: { estado: ESTADOS_PAGO.EN_REVISION, programa: { clienteId } },
|
||||
@@ -98,6 +102,7 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
||||
fecha: c.fecha,
|
||||
estado: c.estado,
|
||||
esDoble: c.esDoble,
|
||||
incluirIva: c.incluirIva,
|
||||
totales,
|
||||
...(c.esDoble
|
||||
? {
|
||||
@@ -113,9 +118,9 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
||||
const proximos = programas
|
||||
.map((p) => {
|
||||
const fecha = proximaFecha(p);
|
||||
return fecha ? { fecha, monto: p.monto, concepto: p.concepto } : null;
|
||||
return fecha ? { fecha, monto: p.monto, moneda: p.moneda, concepto: p.concepto } : null;
|
||||
})
|
||||
.filter((x): x is { fecha: Date; monto: number; concepto: string } => x !== null)
|
||||
.filter((x): x is { fecha: Date; monto: number; moneda: string; concepto: string } => x !== null)
|
||||
.sort((a, b) => a.fecha.getTime() - b.fecha.getTime())
|
||||
.slice(0, 3);
|
||||
|
||||
@@ -126,6 +131,7 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
||||
pagos: {
|
||||
pendientes: porPagar.length,
|
||||
saldoPendiente: totalesPorMoneda(porPagar),
|
||||
masAntiguo: porPagar[0]?.fecha ?? null,
|
||||
enRevision,
|
||||
verificadosMes,
|
||||
proximos,
|
||||
|
||||
+18
-1
@@ -16,7 +16,9 @@
|
||||
--sidebar-active: #2563eb;
|
||||
--card-bg: #ffffff;
|
||||
--border: #e2e8f0;
|
||||
--muted: #94a3b8;
|
||||
/* Texto secundario: slate-500 da 4.8:1 sobre blanco (slate-400 se quedaba en
|
||||
2.6:1, ilegible para cifras y fechas). */
|
||||
--muted: #64748b;
|
||||
}
|
||||
|
||||
@theme inline {
|
||||
@@ -49,3 +51,18 @@ body {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #cbd5e1 transparent;
|
||||
}
|
||||
|
||||
::selection {
|
||||
background: var(--primary-light);
|
||||
color: var(--primary-dark);
|
||||
}
|
||||
|
||||
/* Foco de teclado visible y consistente; el mouse no lo dispara. */
|
||||
a:focus-visible,
|
||||
button:focus-visible,
|
||||
summary:focus-visible,
|
||||
label:focus-within:has(input[type="file"]) {
|
||||
outline: 2px solid var(--primary);
|
||||
outline-offset: 2px;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
+35
-14
@@ -1,10 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Suspense, useState } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
// useSearchParams exige un limite de Suspense para que /login siga siendo
|
||||
// estatica en el build.
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<Suspense>
|
||||
<LoginForm />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
|
||||
function LoginForm() {
|
||||
const router = useRouter();
|
||||
// /login?panel=cliente: el middleware manda aqui a quien abre /cliente sin
|
||||
// sesion; el formulario es el mismo, solo cambia el encabezado.
|
||||
const esCliente = useSearchParams().get("panel") === "cliente";
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [error, setError] = useState("");
|
||||
@@ -30,37 +43,43 @@ export default function LoginPage() {
|
||||
router.refresh();
|
||||
} else {
|
||||
const data = await res.json();
|
||||
setError(data.error || "Error al iniciar sesion");
|
||||
setError(data.error || "No se pudo iniciar sesión");
|
||||
}
|
||||
} catch {
|
||||
setError("Error de conexion");
|
||||
setError("Sin conexión con el servidor. Intenta de nuevo.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center bg-gray-50">
|
||||
<div className="min-h-screen flex items-center justify-center bg-background px-4">
|
||||
<div className="w-full max-w-sm">
|
||||
<div className="bg-white rounded-xl shadow-lg border border-border p-8">
|
||||
<h1 className="text-2xl font-bold text-center mb-2">Cotizador</h1>
|
||||
<div className="bg-white rounded-xl shadow-[0_8px_30px_-12px_rgba(15,23,42,0.18)] p-8">
|
||||
<h1 className="text-2xl font-bold tracking-tight text-center mb-1">
|
||||
{esCliente ? "Portal de clientes" : "Cotizador"}
|
||||
</h1>
|
||||
<p className="text-center text-muted text-sm mb-6">
|
||||
Uriel Jareth Consulting
|
||||
{esCliente
|
||||
? "Consulta tus cotizaciones y registra tus pagos"
|
||||
: "Uriel Jareth Consulting"}
|
||||
</p>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-50 border border-red-200 text-red-700 text-sm rounded-lg px-4 py-3 mb-4">
|
||||
<div role="alert" className="bg-red-50 border border-red-200 text-red-700 text-sm rounded-lg px-4 py-3 mb-4">
|
||||
{error}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-muted mb-1">
|
||||
Email
|
||||
<label htmlFor="login-email" className="block text-sm font-medium mb-1">
|
||||
Correo
|
||||
</label>
|
||||
<input
|
||||
id="login-email"
|
||||
type="email"
|
||||
autoComplete="email"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
@@ -70,15 +89,17 @@ export default function LoginPage() {
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-muted mb-1">
|
||||
Password
|
||||
<label htmlFor="login-password" className="block text-sm font-medium mb-1">
|
||||
Contraseña
|
||||
</label>
|
||||
<input
|
||||
id="login-password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
placeholder="Tu contrasena"
|
||||
placeholder="Tu contraseña"
|
||||
suppressHydrationWarning
|
||||
className="w-full px-3 py-2 border border-border rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
|
||||
/>
|
||||
|
||||
@@ -105,18 +105,48 @@ export function formatFechaCobro(date: Date): string {
|
||||
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||
}
|
||||
|
||||
// Totales por moneda en una linea: "$2,250" o "$1,500 + USD 100.00".
|
||||
// Monto en su moneda: "$4,500" / "$4,500.50" / "USD 25". Sin decimales si es
|
||||
// entero, como formatCurrency; a diferencia de este, respeta USD.
|
||||
export function formatMonto(monto: number, moneda: string = "MXN"): string {
|
||||
return new Intl.NumberFormat("es-MX", {
|
||||
style: "currency",
|
||||
currency: moneda || "MXN",
|
||||
minimumFractionDigits: Number.isInteger(monto) ? 0 : 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format(monto);
|
||||
}
|
||||
|
||||
// Totales por moneda en una linea: "$2,250" o "$1,500 + USD 100".
|
||||
export function formatTotales(totales: Record<string, number>): string {
|
||||
const partes = Object.entries(totales).map(([moneda, total]) =>
|
||||
new Intl.NumberFormat("es-MX", {
|
||||
style: "currency",
|
||||
currency: moneda || "MXN",
|
||||
maximumFractionDigits: 2,
|
||||
}).format(total)
|
||||
);
|
||||
const partes = Object.entries(totales).map(([moneda, total]) => formatMonto(total, moneda));
|
||||
return partes.length ? partes.join(" + ") : "$0";
|
||||
}
|
||||
|
||||
const fmtDiaSemana = new Intl.DateTimeFormat("es-MX", { weekday: "short", timeZone: "UTC" });
|
||||
const fmtMesCorto = new Intl.DateTimeFormat("es-MX", { month: "short", timeZone: "UTC" });
|
||||
|
||||
// "sáb 31 oct" (agrega el año si no es el de `hoy`). Para listas de cobros.
|
||||
export function formatFechaBreve(date: Date, hoy: Date = hoyCalendario()): string {
|
||||
const dia = fmtDiaSemana.format(date).replace(".", "");
|
||||
const mes = fmtMesCorto.format(date).replace(".", "");
|
||||
const anio = date.getUTCFullYear() !== hoy.getUTCFullYear() ? ` ${date.getUTCFullYear()}` : "";
|
||||
return `${dia} ${date.getUTCDate()} ${mes}${anio}`;
|
||||
}
|
||||
|
||||
// Dias de `hoy` a `fecha` (negativo si ya paso). Ambas son fechas de calendario.
|
||||
export function diasHasta(fecha: Date, hoy: Date = hoyCalendario()): number {
|
||||
return Math.round((fecha.getTime() - hoy.getTime()) / 86400000);
|
||||
}
|
||||
|
||||
// "vence hoy" / "mañana" / "en 5 días" / "hace 1 día" / "hace 12 días".
|
||||
export function describirVencimiento(fecha: Date, hoy: Date = hoyCalendario()): string {
|
||||
const d = diasHasta(fecha, hoy);
|
||||
if (d === 0) return "vence hoy";
|
||||
if (d === 1) return "mañana";
|
||||
if (d > 1) return `en ${d} días`;
|
||||
return d === -1 ? "hace 1 día" : `hace ${-d} días`;
|
||||
}
|
||||
|
||||
// Version corta: "04/07/2026".
|
||||
export function formatFechaCorta(date: Date): string {
|
||||
const { y, m, d } = aCalendario(date);
|
||||
|
||||
Reference in New Issue
Block a user