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 { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
import { RefreshCw } from "lucide-react";
|
||||||
import { useConfirm, usePrompt, useToast } from "@/components/ui/DialogProvider";
|
import { useConfirm, usePrompt, useToast } from "@/components/ui/DialogProvider";
|
||||||
import { formatFechaCorta, formatTotales } from "@/lib/cobros-fechas";
|
import { formatFechaCorta, formatTotales } from "@/lib/cobros-fechas";
|
||||||
import { ProgramasTabla } from "./ProgramasTabla";
|
import { ProgramasTabla } from "./ProgramasTabla";
|
||||||
@@ -25,17 +26,17 @@ export function frecuenciaLegible(p: {
|
|||||||
"domingo",
|
"domingo",
|
||||||
"lunes",
|
"lunes",
|
||||||
"martes",
|
"martes",
|
||||||
"miercoles",
|
"miércoles",
|
||||||
"jueves",
|
"jueves",
|
||||||
"viernes",
|
"viernes",
|
||||||
"sabado",
|
"sábado",
|
||||||
];
|
];
|
||||||
if (p.frecuencia === "semanal") {
|
if (p.frecuencia === "semanal") {
|
||||||
const d = p.diaSemana ?? 0;
|
const d = p.diaSemana ?? 0;
|
||||||
return `Cada ${dias[d]}`;
|
return `Cada ${dias[d]}`;
|
||||||
}
|
}
|
||||||
if (p.frecuencia === "quincenal") return "Cada 1 y 15";
|
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.
|
// Por que un recordatorio no llego a nadie, en palabras del admin.
|
||||||
@@ -46,14 +47,14 @@ function motivoNoEntregado(
|
|||||||
if (!canales.correo && !canales.push) {
|
if (!canales.correo && !canales.push) {
|
||||||
return "No hay SMTP (correo) ni VAPID (push) configurados en el servidor";
|
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") {
|
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") {
|
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({
|
export function CobrosClient({
|
||||||
@@ -62,12 +63,15 @@ export function CobrosClient({
|
|||||||
pagosIniciales,
|
pagosIniciales,
|
||||||
saldos,
|
saldos,
|
||||||
diasRecordatorio,
|
diasRecordatorio,
|
||||||
|
enRevision,
|
||||||
}: {
|
}: {
|
||||||
programas: ProgramaRow[];
|
programas: ProgramaRow[];
|
||||||
clientes: ClienteOpt[];
|
clientes: ClienteOpt[];
|
||||||
pagosIniciales: PagoRow[];
|
pagosIniciales: PagoRow[];
|
||||||
saldos: SaldoClienteRow[];
|
saldos: SaldoClienteRow[];
|
||||||
diasRecordatorio: number;
|
diasRecordatorio: number;
|
||||||
|
// Comprobantes esperando aprobacion (para la franja de resumen).
|
||||||
|
enRevision: number;
|
||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const showConfirm = useConfirm();
|
const showConfirm = useConfirm();
|
||||||
@@ -119,7 +123,7 @@ export function CobrosClient({
|
|||||||
const ok = await showConfirm({
|
const ok = await showConfirm({
|
||||||
title: "Generar cobros",
|
title: "Generar cobros",
|
||||||
message:
|
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",
|
confirmText: "Generar",
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
@@ -136,13 +140,13 @@ export function CobrosClient({
|
|||||||
}
|
}
|
||||||
const n = data.generados ?? 0;
|
const n = data.generados ?? 0;
|
||||||
toast(
|
toast(
|
||||||
n > 0 ? `Se generaron ${n} cobros` : "No habia cobros pendientes",
|
n > 0 ? `Se generaron ${n} cobros` : "No había cobros pendientes",
|
||||||
"success"
|
"success"
|
||||||
);
|
);
|
||||||
cargarPagos();
|
cargarPagos();
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch {
|
} catch {
|
||||||
toast("Error de conexion", "error");
|
toast("Error de conexión", "error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -151,8 +155,8 @@ export function CobrosClient({
|
|||||||
const ok = await showConfirm({
|
const ok = await showConfirm({
|
||||||
title: "Enviar recordatorio de pago",
|
title: "Enviar recordatorio de pago",
|
||||||
message: saldo
|
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 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 enviara el estado de cuenta a ${saldos.length} ${saldos.length === 1 ? "cliente" : "clientes"} con pagos vencidos, por correo y notificacion 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",
|
confirmText: "Enviar",
|
||||||
});
|
});
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
@@ -189,14 +193,14 @@ export function CobrosClient({
|
|||||||
} else {
|
} else {
|
||||||
toast(
|
toast(
|
||||||
resultados.length === 1
|
resultados.length === 1
|
||||||
? `No se envio: ${motivoNoEntregado(resultados[0], canales)}`
|
? `No se envió: ${motivoNoEntregado(resultados[0], canales)}`
|
||||||
: `No se envio a ningun cliente: ${motivoNoEntregado(resultados[0], canales)}`,
|
: `No se envió a ningún cliente: ${motivoNoEntregado(resultados[0], canales)}`,
|
||||||
"error"
|
"error"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch {
|
} catch {
|
||||||
toast("Error de conexion", "error");
|
toast("Error de conexión", "error");
|
||||||
} finally {
|
} finally {
|
||||||
setEnviandoRecordatorio(null);
|
setEnviandoRecordatorio(null);
|
||||||
}
|
}
|
||||||
@@ -207,8 +211,8 @@ export function CobrosClient({
|
|||||||
const ok = await showConfirm({
|
const ok = await showConfirm({
|
||||||
title: activar ? "Activar programa" : "Desactivar programa",
|
title: activar ? "Activar programa" : "Desactivar programa",
|
||||||
message: activar
|
message: activar
|
||||||
? `Activar el programa "${p.concepto}"? Se generaran cobros en sus proximos periodos.`
|
? `¿Activar el programa "${p.concepto}"? Se generarán cobros en sus próximos periodos.`
|
||||||
: `Desactivar el programa "${p.concepto}"? No se generaran mas cobros, pero los existentes se conservan.`,
|
: `¿Desactivar el programa "${p.concepto}"? No se generarán más cobros, pero los existentes se conservan.`,
|
||||||
confirmText: activar ? "Activar" : "Desactivar",
|
confirmText: activar ? "Activar" : "Desactivar",
|
||||||
danger: !activar,
|
danger: !activar,
|
||||||
});
|
});
|
||||||
@@ -227,7 +231,7 @@ export function CobrosClient({
|
|||||||
toast(activar ? "Programa activado" : "Programa desactivado", "success");
|
toast(activar ? "Programa activado" : "Programa desactivado", "success");
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch {
|
} catch {
|
||||||
toast("Error de conexion", "error");
|
toast("Error de conexión", "error");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -249,8 +253,9 @@ export function CobrosClient({
|
|||||||
}
|
}
|
||||||
toast("Cobro verificado", "success");
|
toast("Cobro verificado", "success");
|
||||||
cargarPagos();
|
cargarPagos();
|
||||||
|
router.refresh();
|
||||||
} catch {
|
} 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.
|
// El cobro vuelve a estar por pagar: refresca el saldo por cliente.
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch {
|
} 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 (
|
return (
|
||||||
<div className="space-y-10">
|
<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
|
<PorCobrarTabla
|
||||||
saldos={saldos}
|
saldos={saldos}
|
||||||
diasRecordatorio={diasRecordatorio}
|
diasRecordatorio={diasRecordatorio}
|
||||||
@@ -293,21 +346,19 @@ export function CobrosClient({
|
|||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section id="comprobantes" className="scroll-mt-20">
|
||||||
<ProgramasTabla
|
|
||||||
programas={programas}
|
|
||||||
clientes={clientes}
|
|
||||||
onToggleActivo={toggleActivo}
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section>
|
|
||||||
<div className="flex flex-wrap items-end justify-between gap-3 mb-4">
|
<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
|
<button
|
||||||
onClick={generarAhora}
|
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
|
Generar cobros ahora
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -322,7 +373,7 @@ export function CobrosClient({
|
|||||||
>
|
>
|
||||||
<option value="">Todos</option>
|
<option value="">Todos</option>
|
||||||
<option value="pendiente">Pendiente</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="verificado">Verificado</option>
|
||||||
<option value="rechazado">Rechazado</option>
|
<option value="rechazado">Rechazado</option>
|
||||||
</select>
|
</select>
|
||||||
@@ -369,6 +420,14 @@ export function CobrosClient({
|
|||||||
onRechazar={rechazar}
|
onRechazar={rechazar}
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="programas" className="scroll-mt-20">
|
||||||
|
<ProgramasTabla
|
||||||
|
programas={programas}
|
||||||
|
clientes={clientes}
|
||||||
|
onToggleActivo={toggleActivo}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const ESTILOS: Record<string, { cls: string; label: string }> = {
|
|||||||
},
|
},
|
||||||
[ESTADOS_PAGO.EN_REVISION]: {
|
[ESTADOS_PAGO.EN_REVISION]: {
|
||||||
cls: "bg-blue-100 text-blue-800",
|
cls: "bg-blue-100 text-blue-800",
|
||||||
label: "En revision",
|
label: "En revisión",
|
||||||
},
|
},
|
||||||
[ESTADOS_PAGO.VERIFICADO]: {
|
[ESTADOS_PAGO.VERIFICADO]: {
|
||||||
cls: "bg-green-100 text-green-800",
|
cls: "bg-green-100 text-green-800",
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Check, X, FileText } from "lucide-react";
|
import { Check, X, FileText } from "lucide-react";
|
||||||
import { formatCurrency } from "@/lib/calculators";
|
import { formatFechaCorta, formatMonto } from "@/lib/cobros-fechas";
|
||||||
import { formatFechaCorta } from "@/lib/cobros-fechas";
|
|
||||||
import { EstadoPagoBadge } from "./EstadoPagoBadge";
|
import { EstadoPagoBadge } from "./EstadoPagoBadge";
|
||||||
import type { PagoRow } from "./types";
|
import type { PagoRow } from "./types";
|
||||||
|
|
||||||
@@ -37,8 +36,8 @@ export function PagosTabla({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
<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-[52rem] text-sm tabular-nums">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b border-border bg-gray-50">
|
<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">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">{formatFechaCorta(new Date(p.fecha))}</td>
|
||||||
<td className="px-5 py-3">{p.programa.concepto}</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">{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">
|
<td className="px-5 py-3 text-center">
|
||||||
<EstadoPagoBadge estado={p.estado} />
|
<EstadoPagoBadge estado={p.estado} />
|
||||||
{p.estado === "rechazado" && p.rechazoMotivo && (
|
{p.estado === "rechazado" && p.rechazoMotivo && (
|
||||||
|
|||||||
@@ -33,15 +33,15 @@ export function PorCobrarTabla({
|
|||||||
<h2 className="text-lg font-semibold">Pagos por cobrar</h2>
|
<h2 className="text-lg font-semibold">Pagos por cobrar</h2>
|
||||||
<p className="text-muted text-sm mt-1">
|
<p className="text-muted text-sm mt-1">
|
||||||
{diasRecordatorio > 0
|
{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 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 automatico esta desactivado (COBROS_RECORDATORIO_DIAS=0)."}
|
: "Cobros vencidos sin pago o con comprobante rechazado. El recordatorio automático está desactivado (COBROS_RECORDATORIO_DIAS=0)."}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{saldos.length > 0 && (
|
{saldos.length > 0 && (
|
||||||
<button
|
<button
|
||||||
onClick={() => onRecordar(null)}
|
onClick={() => onRecordar(null)}
|
||||||
disabled={enviando !== 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" />
|
<BellRing className="w-4 h-4" />
|
||||||
{enviando === "*" ? "Enviando..." : "Recordar a todos"}
|
{enviando === "*" ? "Enviando..." : "Recordar a todos"}
|
||||||
@@ -52,19 +52,19 @@ export function PorCobrarTabla({
|
|||||||
{saldos.length === 0 ? (
|
{saldos.length === 0 ? (
|
||||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
<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>
|
<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>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-card-bg rounded-xl border border-border overflow-x-auto">
|
<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>
|
<thead>
|
||||||
<tr className="border-b border-border bg-gray-50">
|
<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-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-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-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">Más antiguo</th>
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Ultimo recordatorio</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">Accion</th>
|
<th className="text-center px-5 py-3 font-medium text-muted">Acción</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -83,7 +83,7 @@ export function PorCobrarTabla({
|
|||||||
<div className={`text-xs ${s.diasAtraso > 0 ? "text-danger" : "text-muted"}`}>
|
<div className={`text-xs ${s.diasAtraso > 0 ? "text-danger" : "text-muted"}`}>
|
||||||
{s.diasAtraso === 0
|
{s.diasAtraso === 0
|
||||||
? "vence hoy"
|
? "vence hoy"
|
||||||
: `${s.diasAtraso} ${s.diasAtraso === 1 ? "dia" : "dias"} de atraso`}
|
: `${s.diasAtraso} ${s.diasAtraso === 1 ? "día" : "días"} de atraso`}
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-5 py-3 text-muted">
|
<td className="px-5 py-3 text-muted">
|
||||||
|
|||||||
@@ -4,18 +4,17 @@ import { useState } from "react";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Pencil, Power, Plus } from "lucide-react";
|
import { Pencil, Power, Plus } from "lucide-react";
|
||||||
import { useToast } from "@/components/ui/DialogProvider";
|
import { useToast } from "@/components/ui/DialogProvider";
|
||||||
import { formatCurrency } from "@/lib/calculators";
|
import { formatFechaCorta, formatMonto } from "@/lib/cobros-fechas";
|
||||||
import { formatFechaCorta } from "@/lib/cobros-fechas";
|
|
||||||
import type { ProgramaRow, ClienteOpt } from "./types";
|
import type { ProgramaRow, ClienteOpt } from "./types";
|
||||||
|
|
||||||
const DIAS = [
|
const DIAS = [
|
||||||
"Domingo",
|
"Domingo",
|
||||||
"Lunes",
|
"Lunes",
|
||||||
"Martes",
|
"Martes",
|
||||||
"Miercoles",
|
"Miércoles",
|
||||||
"Jueves",
|
"Jueves",
|
||||||
"Viernes",
|
"Viernes",
|
||||||
"Sabado",
|
"Sábado",
|
||||||
];
|
];
|
||||||
|
|
||||||
function frecuenciaTexto(p: {
|
function frecuenciaTexto(p: {
|
||||||
@@ -25,7 +24,7 @@ function frecuenciaTexto(p: {
|
|||||||
}): string {
|
}): string {
|
||||||
if (p.frecuencia === "semanal") return `Cada ${DIAS[p.diaSemana ?? 0]}`;
|
if (p.frecuencia === "semanal") return `Cada ${DIAS[p.diaSemana ?? 0]}`;
|
||||||
if (p.frecuencia === "quincenal") return "Cada 1 y 15";
|
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 }) {
|
function EstadoProgramaBadge({ activo }: { activo: boolean }) {
|
||||||
@@ -154,7 +153,7 @@ export function ProgramasTabla({
|
|||||||
setDialogo(null);
|
setDialogo(null);
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch {
|
} catch {
|
||||||
toast("Error de conexion", "error");
|
toast("Error de conexión", "error");
|
||||||
} finally {
|
} finally {
|
||||||
setGuardando(false);
|
setGuardando(false);
|
||||||
}
|
}
|
||||||
@@ -162,7 +161,7 @@ export function ProgramasTabla({
|
|||||||
|
|
||||||
return (
|
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>
|
<h2 className="text-lg font-semibold">Programas de pago</h2>
|
||||||
<button
|
<button
|
||||||
onClick={abrirNuevo}
|
onClick={abrirNuevo}
|
||||||
@@ -181,15 +180,15 @@ export function ProgramasTabla({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
<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-[56rem] text-sm tabular-nums">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b border-border bg-gray-50">
|
<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">Concepto</th>
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Cliente</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-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">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">Estado</th>
|
||||||
<th className="text-center px-5 py-3 font-medium text-muted">Acciones</th>
|
<th className="text-center px-5 py-3 font-medium text-muted">Acciones</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -204,7 +203,7 @@ export function ProgramasTabla({
|
|||||||
<div className="text-xs text-muted">{p.cliente.empresa}</div>
|
<div className="text-xs text-muted">{p.cliente.empresa}</div>
|
||||||
)}
|
)}
|
||||||
</td>
|
</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">{frecuenciaTexto(p)}</td>
|
||||||
<td className="px-5 py-3">
|
<td className="px-5 py-3">
|
||||||
{p.proximaFecha
|
{p.proximaFecha
|
||||||
|
|||||||
@@ -133,9 +133,9 @@ export default async function CobrosPage() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-8">
|
<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">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -145,6 +145,7 @@ export default async function CobrosPage() {
|
|||||||
pagosIniciales={pagosData}
|
pagosIniciales={pagosData}
|
||||||
saldos={saldosData}
|
saldos={saldosData}
|
||||||
diasRecordatorio={diasRecordatorio()}
|
diasRecordatorio={diasRecordatorio()}
|
||||||
|
enRevision={pagosData.length}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -172,10 +172,12 @@ export function ClienteShell({ nombre }: { nombre: string }) {
|
|||||||
type="button"
|
type="button"
|
||||||
onClick={activarNotificaciones}
|
onClick={activarNotificaciones}
|
||||||
disabled={activas || activando}
|
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
|
activas
|
||||||
? "bg-gray-100 text-muted cursor-not-allowed"
|
? "border-green-200 bg-green-50 text-green-700 cursor-default"
|
||||||
: "bg-primary text-white hover:opacity-90"
|
: "border-border hover:bg-gray-50 disabled:opacity-60"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{activas ? (
|
{activas ? (
|
||||||
@@ -184,16 +186,14 @@ export function ClienteShell({ nombre }: { nombre: string }) {
|
|||||||
<Bell className="w-4 h-4" />
|
<Bell className="w-4 h-4" />
|
||||||
)}
|
)}
|
||||||
<span className="hidden sm:inline">
|
<span className="hidden sm:inline">
|
||||||
{activas ? "Notificaciones activas" : "Activar notificaciones"}
|
{activas ? "Avisos activos" : activando ? "Activando…" : "Activar avisos"}
|
||||||
</span>
|
|
||||||
<span className="sm:hidden">
|
|
||||||
{activas ? "Activas" : "Avisos"}
|
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={cerrarSesion}
|
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"
|
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" />
|
<LogOut className="w-4 h-4" />
|
||||||
@@ -209,6 +209,7 @@ export function ClienteShell({ nombre }: { nombre: string }) {
|
|||||||
<Link
|
<Link
|
||||||
key={item.href}
|
key={item.href}
|
||||||
href={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 ${
|
className={`flex items-center gap-1.5 whitespace-nowrap border-b-2 px-3 py-2.5 text-sm font-medium transition-colors ${
|
||||||
activa
|
activa
|
||||||
? "border-primary text-primary"
|
? "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" />
|
<ArrowLeft className="w-5 h-5" />
|
||||||
</Link>
|
</Link>
|
||||||
<div className="min-w-0">
|
<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">
|
<p className="text-muted text-sm truncate">
|
||||||
{cot.proyecto} · {formatDate(cot.fecha)}
|
{cot.proyecto} · {formatDate(cot.fecha)}
|
||||||
</p>
|
</p>
|
||||||
@@ -168,11 +168,11 @@ export default async function ClienteCotizacionDetallePage({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<table className="w-full text-sm">
|
<table className="w-full text-sm tabular-nums">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b border-border">
|
<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">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>
|
<th className="text-right px-5 py-3 font-medium text-muted">Precio</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -181,8 +181,11 @@ export default async function ClienteCotizacionDetallePage({
|
|||||||
<tr key={s.id} className="border-b border-border last:border-0">
|
<tr key={s.id} className="border-b border-border last:border-0">
|
||||||
<td className="px-5 py-3">
|
<td className="px-5 py-3">
|
||||||
{s.servicioCatalogo?.nombre || s.nombre || "Servicio"}
|
{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>
|
||||||
<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}
|
{TIPO_PAGO_LABEL[s.tipoPago] || s.tipoPago}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-5 py-3 text-right font-medium">
|
<td className="px-5 py-3 text-right font-medium">
|
||||||
@@ -193,9 +196,9 @@ export default async function ClienteCotizacionDetallePage({
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{g.totales && (
|
{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">
|
<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">
|
<span className="font-semibold">
|
||||||
{formatCurrency(totalConIva(g.totales.totalUnico))}
|
{formatCurrency(totalConIva(g.totales.totalUnico))}
|
||||||
</span>
|
</span>
|
||||||
@@ -221,11 +224,11 @@ export default async function ClienteCotizacionDetallePage({
|
|||||||
Esta cotización no tiene servicios registrados.
|
Esta cotización no tiene servicios registrados.
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<table className="w-full text-sm">
|
<table className="w-full text-sm tabular-nums">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b border-border bg-gray-50">
|
<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">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>
|
<th className="text-right px-5 py-3 font-medium text-muted">Precio</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</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">
|
<tr key={s.id} className="border-b border-border hover:bg-gray-50 transition-colors">
|
||||||
<td className="px-5 py-3">
|
<td className="px-5 py-3">
|
||||||
{s.servicioCatalogo?.nombre || s.nombre || "Servicio"}
|
{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>
|
||||||
<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}
|
{TIPO_PAGO_LABEL[s.tipoPago] || s.tipoPago}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-5 py-3 text-right font-medium">
|
<td className="px-5 py-3 text-right font-medium">
|
||||||
@@ -262,10 +268,10 @@ export default async function ClienteCotizacionDetallePage({
|
|||||||
Opción {op}
|
Opción {op}
|
||||||
{meta?.titulo ? `: ${meta.titulo}` : ""}
|
{meta?.titulo ? `: ${meta.titulo}` : ""}
|
||||||
</h3>
|
</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">
|
<div className="flex justify-between">
|
||||||
<span className="text-muted">
|
<span className="text-muted">
|
||||||
Total unico{cot.incluirIva ? " (c/IVA)" : ""}
|
Total único{cot.incluirIva ? " (c/IVA)" : ""}
|
||||||
</span>
|
</span>
|
||||||
<span className="font-semibold">
|
<span className="font-semibold">
|
||||||
{formatCurrency(totalConIva(t.totalUnico))}
|
{formatCurrency(totalConIva(t.totalUnico))}
|
||||||
@@ -285,11 +291,11 @@ export default async function ClienteCotizacionDetallePage({
|
|||||||
})}
|
})}
|
||||||
</div>
|
</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 && (
|
{totales.incluyeIva && (
|
||||||
<>
|
<>
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<span className="text-muted">Subtotal unico</span>
|
<span className="text-muted">Subtotal único</span>
|
||||||
<span>{formatCurrency(totales.subtotalUnico)}</span>
|
<span>{formatCurrency(totales.subtotalUnico)}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between">
|
<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">
|
<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>
|
<span>{formatCurrency(totales.totalUnico)}</span>
|
||||||
</div>
|
</div>
|
||||||
{totales.incluyeIva && (
|
{totales.incluyeIva && (
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
import Link from "next/link";
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { ArrowRight, FileText } from "lucide-react";
|
import { FileText } from "lucide-react";
|
||||||
import { requireRole } from "@/lib/auth";
|
import { requireRole } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/db";
|
import { prisma } from "@/lib/db";
|
||||||
import {
|
import { calcularTotalesCotizacion, calcularTotalesOpcion, conIva } from "@/lib/calculators";
|
||||||
IVA_RATE,
|
import { FilaCotizacion } from "../FilaCotizacion";
|
||||||
calcularTotalesCotizacion,
|
|
||||||
calcularTotalesOpcion,
|
|
||||||
formatCurrency,
|
|
||||||
formatDate,
|
|
||||||
} from "@/lib/calculators";
|
|
||||||
import { EstadoBadge } from "@/components/EstadoBadge";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
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() {
|
export default async function ClienteCotizacionesPage() {
|
||||||
const session = await requireRole("cliente");
|
const session = await requireRole("cliente");
|
||||||
if (!session) redirect("/login?panel=cliente");
|
if (!session) redirect("/login?panel=cliente");
|
||||||
@@ -38,116 +32,53 @@ export default async function ClienteCotizacionesPage() {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-8">
|
<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">
|
<p className="text-muted text-sm mt-1">
|
||||||
{cotizaciones.length === 0
|
{cotizaciones.length === 0
|
||||||
? "Aún no tienes cotizaciones"
|
? "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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{cotizaciones.length === 0 ? (
|
{cotizaciones.length === 0 ? (
|
||||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
<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>
|
<h2 className="text-lg font-semibold mb-2">No hay cotizaciones todavía</h2>
|
||||||
<p className="text-muted">
|
<p className="text-muted">
|
||||||
Cuando tengas una cotización disponible aparecerá en esta sección.
|
Cuando tengas una cotización disponible aparecerá en esta sección.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
<ul className="bg-card-bg rounded-xl border border-border divide-y divide-border overflow-hidden">
|
||||||
<table className="w-full text-sm">
|
{cotizaciones.map((c) => {
|
||||||
<thead>
|
const totales = calcularTotalesCotizacion(c.servicios, { incluirIva: c.incluirIva });
|
||||||
<tr className="border-b border-border bg-gray-50">
|
return (
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">No. Cotizacion</th>
|
<FilaCotizacion
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Proyecto</th>
|
key={c.id}
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Fecha</th>
|
id={c.id}
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Estado</th>
|
numero={c.numero}
|
||||||
<th className="text-right px-5 py-3 font-medium text-muted">Total Unico</th>
|
proyecto={c.proyecto}
|
||||||
<th className="text-right px-5 py-3 font-medium text-muted">Total Mensual</th>
|
fecha={c.fecha}
|
||||||
<th className="text-right px-5 py-3 font-medium text-muted"> </th>
|
estado={c.estado}
|
||||||
</tr>
|
montos={{ unico: totales.totalUnico, mensual: totales.totalMensual }}
|
||||||
</thead>
|
opciones={
|
||||||
<tbody>
|
c.esDoble
|
||||||
{cotizaciones.map((c) => {
|
? (["1", "2"] as const).map((op) => {
|
||||||
const totales = calcularTotalesCotizacion(c.servicios, {
|
const t = calcularTotalesOpcion(c.servicios, op);
|
||||||
incluirIva: c.incluirIva,
|
return {
|
||||||
});
|
clave: op,
|
||||||
const conIva = (m: number) =>
|
montos: {
|
||||||
c.incluirIva ? Math.round(m * (1 + IVA_RATE) * 100) / 100 : m;
|
unico: conIva(t.totalUnico, c.incluirIva),
|
||||||
return (
|
mensual: conIva(t.totalMensual, c.incluirIva),
|
||||||
<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}`}
|
: undefined
|
||||||
className="font-medium text-primary hover:underline"
|
}
|
||||||
>
|
/>
|
||||||
{c.numero}
|
);
|
||||||
</Link>
|
})}
|
||||||
{c.esDoble && (
|
</ul>
|
||||||
<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>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</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 Link from "next/link";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import {
|
import { ArrowRight, CalendarClock, CircleCheck, Clock3, FileText, Inbox } from "lucide-react";
|
||||||
ArrowRight,
|
|
||||||
CalendarClock,
|
|
||||||
ClipboardList,
|
|
||||||
Clock3,
|
|
||||||
FileText,
|
|
||||||
Inbox,
|
|
||||||
ShieldCheck,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { requireRole } from "@/lib/auth";
|
import { requireRole } from "@/lib/auth";
|
||||||
import { formatCurrency, formatDate } from "@/lib/calculators";
|
import { conIva } from "@/lib/calculators";
|
||||||
import { formatFechaCorta, formatTotales } from "@/lib/cobros";
|
import {
|
||||||
import { EstadoBadge } from "@/components/EstadoBadge";
|
describirVencimiento,
|
||||||
|
diasHasta,
|
||||||
|
formatFechaBreve,
|
||||||
|
formatMonto,
|
||||||
|
formatTotales,
|
||||||
|
hoyCalendario,
|
||||||
|
} from "@/lib/cobros";
|
||||||
import { obtenerResumenCliente } from "./resumen-data";
|
import { obtenerResumenCliente } from "./resumen-data";
|
||||||
|
import { FilaCotizacion } from "./FilaCotizacion";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -28,7 +27,7 @@ export default async function ClienteInicioPage() {
|
|||||||
if (!resumen) {
|
if (!resumen) {
|
||||||
return (
|
return (
|
||||||
<div className="bg-card-bg rounded-xl border border-border p-12 text-center">
|
<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>
|
<h2 className="text-lg font-semibold mb-2">Cuenta sin cliente asociado</h2>
|
||||||
<p className="text-muted">
|
<p className="text-muted">
|
||||||
Tu usuario no tiene un cliente vinculado. Contacta al administrador para
|
Tu usuario no tiene un cliente vinculado. Contacta al administrador para
|
||||||
@@ -38,179 +37,172 @@ export default async function ClienteInicioPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tarjetas: Array<{
|
const hoy = hoyCalendario();
|
||||||
label: string;
|
const { pagos } = resumen;
|
||||||
value: number;
|
const debe = pagos.pendientes > 0;
|
||||||
detalle?: string;
|
const proximo = pagos.proximos[0];
|
||||||
icon: typeof FileText;
|
|
||||||
bg: string;
|
const indicadores = [
|
||||||
color: string;
|
{ label: "En revisión", value: pagos.enRevision },
|
||||||
}> = [
|
{ label: "Verificados este mes", value: pagos.verificadosMes },
|
||||||
{
|
{ label: "Cotizaciones activas", value: resumen.cotizacionesActivas },
|
||||||
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",
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-8">
|
<div className="mb-8">
|
||||||
<h1 className="text-2xl font-bold">Hola, {resumen.cliente.nombre}</h1>
|
<h1 className="text-2xl font-bold tracking-tight">Hola, {resumen.cliente.nombre}</h1>
|
||||||
<p className="text-muted text-sm mt-1">
|
{resumen.cliente.empresa && (
|
||||||
{resumen.cliente.empresa
|
<p className="text-muted text-sm mt-1">{resumen.cliente.empresa}</p>
|
||||||
? resumen.cliente.empresa + " · "
|
)}
|
||||||
: ""}
|
|
||||||
Consulta tus cotizaciones y el estado de tus pagos.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
|
<section
|
||||||
{tarjetas.map((t) => (
|
aria-label="Estado de tus pagos"
|
||||||
<div key={t.label} className="bg-card-bg rounded-xl border border-border p-5">
|
className="bg-card-bg rounded-xl border border-border overflow-hidden mb-8"
|
||||||
<div className="flex items-center gap-3">
|
>
|
||||||
<div className={`${t.bg} p-2.5 rounded-lg`}>
|
<div className="flex flex-col gap-5 p-5 sm:flex-row sm:items-center sm:justify-between sm:p-6">
|
||||||
<t.icon className={`w-5 h-5 ${t.color}`} />
|
{debe ? (
|
||||||
</div>
|
<div className="flex items-start gap-4">
|
||||||
<div className="min-w-0">
|
<span className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-amber-50 text-amber-600">
|
||||||
<p className="text-2xl font-bold">{t.value}</p>
|
<Clock3 className="w-6 h-6" />
|
||||||
<p className="text-muted text-sm">{t.label}</p>
|
</span>
|
||||||
{t.detalle && (
|
<div>
|
||||||
<Link
|
<h2 className="font-semibold">
|
||||||
href="/cliente/pagos"
|
Tienes {pagos.pendientes} {pagos.pendientes === 1 ? "pago pendiente" : "pagos pendientes"}
|
||||||
className="text-xs font-medium text-amber-700 hover:underline"
|
</h2>
|
||||||
>
|
<p className="text-2xl font-bold tracking-tight tabular-nums mt-1">
|
||||||
{t.detalle}
|
{formatTotales(pagos.saldoPendiente)}
|
||||||
</Link>
|
</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>
|
) : (
|
||||||
))}
|
<div className="flex items-start gap-4">
|
||||||
</div>
|
<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">
|
<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" />
|
<CalendarClock className="w-5 h-5 text-primary" />
|
||||||
Próximos cobros
|
Próximos cobros
|
||||||
</h2>
|
</h2>
|
||||||
<Link
|
<Link
|
||||||
href="/cliente/pagos"
|
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
|
Ver todos
|
||||||
<ArrowRight className="w-4 h-4" />
|
<ArrowRight className="w-4 h-4" />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
{resumen.pagos.proximos.length === 0 ? (
|
{pagos.proximos.length === 0 ? (
|
||||||
<div className="p-8 text-center">
|
<p className="px-5 py-8 text-center text-sm text-muted">
|
||||||
<CalendarClock className="w-10 h-10 text-muted mx-auto mb-3" />
|
No tienes cobros programados por ahora.
|
||||||
<p className="text-muted text-sm">
|
</p>
|
||||||
No tienes cobros programados por ahora.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<ul className="divide-y divide-border">
|
<ul className="divide-y divide-border">
|
||||||
{resumen.pagos.proximos.map((p) => (
|
{pagos.proximos.map((p) => (
|
||||||
<li
|
<li
|
||||||
key={`${p.concepto}-${p.fecha.toISOString()}`}
|
key={`${p.concepto}-${p.fecha.toISOString()}`}
|
||||||
className="flex items-center justify-between gap-3 px-5 py-3"
|
className="flex items-center justify-between gap-3 px-5 py-3"
|
||||||
>
|
>
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
<p className="font-medium text-sm">{p.concepto}</p>
|
<p className="font-medium text-sm truncate">{p.concepto}</p>
|
||||||
<p className="text-xs text-muted">{formatFechaCorta(p.fecha)}</p>
|
<p className="text-xs text-muted">
|
||||||
|
{formatFechaBreve(p.fecha, hoy)} · {describirVencimiento(p.fecha, hoy)}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p className="font-semibold">{formatCurrency(p.monto)}</p>
|
<p className="font-semibold tabular-nums">{formatMonto(p.monto, p.moneda)}</p>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</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">
|
<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
|
<Link
|
||||||
href="/cliente/cotizaciones"
|
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
|
Ver todas
|
||||||
<ArrowRight className="w-4 h-4" />
|
<ArrowRight className="w-4 h-4" />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
{resumen.cotizaciones.length === 0 ? (
|
{resumen.cotizaciones.length === 0 ? (
|
||||||
<div className="p-8 text-center">
|
<p className="px-5 py-8 text-center text-sm text-muted">
|
||||||
<FileText className="w-10 h-10 text-muted mx-auto mb-3" />
|
Todavía no tienes cotizaciones. En cuanto el administrador la envíe, aparecerá aquí.
|
||||||
<p className="text-muted text-sm">
|
</p>
|
||||||
Todavía no tienes cotizaciones. En cuanto el administrador la envíe,
|
|
||||||
aparecerá aquí.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<ul className="divide-y divide-border">
|
<ul className="divide-y divide-border">
|
||||||
{resumen.cotizaciones.map((c) => (
|
{resumen.cotizaciones.map((c) => (
|
||||||
<li key={c.id}>
|
<FilaCotizacion
|
||||||
<Link
|
key={c.id}
|
||||||
href={`/cliente/cotizaciones/${c.id}`}
|
id={c.id}
|
||||||
className="flex items-center justify-between gap-3 px-5 py-3 hover:bg-gray-50 transition-colors"
|
numero={c.numero}
|
||||||
>
|
proyecto={c.proyecto}
|
||||||
<div className="min-w-0">
|
fecha={c.fecha}
|
||||||
<p className="font-medium text-sm text-primary">{c.numero}</p>
|
estado={c.estado}
|
||||||
<p className="text-xs text-muted truncate">{c.proyecto}</p>
|
montos={{ unico: c.totales.totalUnico, mensual: c.totales.totalMensual }}
|
||||||
</div>
|
opciones={
|
||||||
<div className="flex items-center gap-4 shrink-0">
|
c.totalesOpciones
|
||||||
<span className="text-xs text-muted hidden sm:block">
|
? (["1", "2"] as const).map((op) => ({
|
||||||
{formatDate(c.fecha)}
|
clave: op,
|
||||||
</span>
|
montos: {
|
||||||
<EstadoBadge estado={c.estado} />
|
unico: conIva(c.totalesOpciones![op].totalUnico, c.incluirIva),
|
||||||
<div className="text-right text-sm hidden md:block">
|
mensual: conIva(c.totalesOpciones![op].totalMensual, c.incluirIva),
|
||||||
{c.totales.totalUnico > 0 && (
|
},
|
||||||
<p className="font-medium">
|
}))
|
||||||
{formatCurrency(c.totales.totalUnico)}
|
: undefined
|
||||||
</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>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</div>
|
</section>
|
||||||
</div>
|
</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
|
// 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.
|
// 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 router = useRouter();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const [subiendo, setSubiendo] = useState(false);
|
const [subiendo, setSubiendo] = useState(false);
|
||||||
@@ -41,11 +48,11 @@ export function SubirComprobante({ pagoId }: { pagoId: string }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<label
|
<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 ${
|
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 ${
|
||||||
subiendo
|
variante === "primario"
|
||||||
? "opacity-60 cursor-wait text-muted"
|
? "bg-primary-light/70 text-primary-dark hover:bg-primary hover:text-white"
|
||||||
: "cursor-pointer hover:bg-gray-50"
|
: "border border-border hover:bg-gray-50"
|
||||||
}`}
|
} ${subiendo ? "opacity-60 cursor-wait" : "cursor-pointer"}`}
|
||||||
>
|
>
|
||||||
{subiendo ? (
|
{subiendo ? (
|
||||||
<Loader2 className="w-4 h-4 animate-spin" />
|
<Loader2 className="w-4 h-4 animate-spin" />
|
||||||
|
|||||||
+235
-151
@@ -1,17 +1,22 @@
|
|||||||
import { redirect } from "next/navigation";
|
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 { requireRole } from "@/lib/auth";
|
||||||
import { prisma } from "@/lib/db";
|
import { prisma } from "@/lib/db";
|
||||||
import { formatCurrency } from "@/lib/calculators";
|
|
||||||
import { getConfigBancaria } from "@/lib/config-helpers";
|
import { getConfigBancaria } from "@/lib/config-helpers";
|
||||||
import {
|
import {
|
||||||
ESTADOS_PAGO,
|
ESTADOS_PAGO,
|
||||||
|
describirVencimiento,
|
||||||
|
diasHasta,
|
||||||
esPorPagar,
|
esPorPagar,
|
||||||
formatFechaCorta,
|
formatFechaBreve,
|
||||||
|
formatMonto,
|
||||||
formatTotales,
|
formatTotales,
|
||||||
|
hoyCalendario,
|
||||||
|
proximaFecha,
|
||||||
totalesPorMoneda,
|
totalesPorMoneda,
|
||||||
} from "@/lib/cobros";
|
} from "@/lib/cobros";
|
||||||
import { SubirComprobante } from "./SubirComprobante";
|
import { SubirComprobante } from "./SubirComprobante";
|
||||||
|
import { CopiarDato } from "./CopiarDato";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -25,56 +30,70 @@ const DIAS_SEMANA = [
|
|||||||
"sábado",
|
"sábado",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// Pagos ya registrados que se ven sin desplegar el historial de cada programa.
|
||||||
|
const HISTORIAL_VISIBLE = 4;
|
||||||
|
|
||||||
function frecuenciaLegible(p: {
|
function frecuenciaLegible(p: {
|
||||||
frecuencia: string;
|
frecuencia: string;
|
||||||
diaSemana?: number | null;
|
diaSemana?: number | null;
|
||||||
diaMes?: number | null;
|
diaMes?: number | null;
|
||||||
}): string {
|
}): string {
|
||||||
if (p.frecuencia === "semanal") {
|
if (p.frecuencia === "semanal") return `cada ${DIAS_SEMANA[p.diaSemana ?? 0]}`;
|
||||||
return `Semanal (${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`;
|
||||||
if (p.frecuencia === "quincenal") {
|
|
||||||
return "Quincenal (días 1 y 15)";
|
|
||||||
}
|
|
||||||
if (p.frecuencia === "mensual") {
|
|
||||||
return `Mensual (día ${p.diaMes ?? 1})`;
|
|
||||||
}
|
|
||||||
return p.frecuencia;
|
return p.frecuencia;
|
||||||
}
|
}
|
||||||
|
|
||||||
function EstadoPagoBadge({
|
function EstadoHistorial({ estado }: { estado: string }) {
|
||||||
estado,
|
if (estado === ESTADOS_PAGO.VERIFICADO) {
|
||||||
rechazoMotivo,
|
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">
|
||||||
estado: string;
|
<Check className="w-3 h-3" />
|
||||||
rechazoMotivo?: string | null;
|
Verificado
|
||||||
}) {
|
</span>
|
||||||
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";
|
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<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">
|
||||||
<span className={`inline-block px-2.5 py-0.5 rounded-full text-xs font-medium ${cls}`}>
|
<Clock3 className="w-3 h-3" />
|
||||||
{label}
|
En revisión
|
||||||
</span>
|
</span>
|
||||||
{estado === ESTADOS_PAGO.RECHAZADO && rechazoMotivo && (
|
|
||||||
<p className="text-xs text-muted mt-1">Motivo: {rechazoMotivo}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guia de pagos recurrentes: un bloque por programa y su tabla de cobros,
|
type FilaHistorial = {
|
||||||
// con subida de comprobante para los pendientes/rechazados.
|
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() {
|
export default async function ClientePagosPage() {
|
||||||
const session = await requireRole("cliente");
|
const session = await requireRole("cliente");
|
||||||
if (!session) redirect("/login?panel=cliente");
|
if (!session) redirect("/login?panel=cliente");
|
||||||
@@ -87,143 +106,208 @@ export default async function ClientePagosPage() {
|
|||||||
include: {
|
include: {
|
||||||
pagos: {
|
pagos: {
|
||||||
orderBy: { fecha: "desc" },
|
orderBy: { fecha: "desc" },
|
||||||
include: { comprobante: { select: { archivoNombre: true, subidoAt: true } } },
|
include: { comprobante: { select: { archivoNombre: true } } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
getConfigBancaria(),
|
getConfigBancaria(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Lo que el cliente debe hoy: pendientes + comprobantes rechazados.
|
const hoy = hoyCalendario();
|
||||||
const porPagar = programas.flatMap((prog) =>
|
|
||||||
prog.pagos
|
// Lo que el cliente debe: pendientes + comprobantes rechazados.
|
||||||
.filter((pago) => esPorPagar(pago.estado))
|
const porPagar = programas
|
||||||
.map((pago) => ({ monto: pago.monto, programa: { moneda: prog.moneda } }))
|
.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 = [
|
const datosPago = [
|
||||||
["Titular", banco.razon_social],
|
["Titular", banco.razon_social],
|
||||||
["CLABE", banco.clabe_interbancaria],
|
["CLABE", banco.clabe_interbancaria],
|
||||||
["Cuenta", banco.cuenta_nacional],
|
["Cuenta", banco.cuenta_nacional],
|
||||||
].filter((par): par is [string, string] => Boolean(par[1]));
|
].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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div className="mb-8">
|
<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">
|
<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>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{porPagar.length > 0 && (
|
<div className="grid gap-6 lg:grid-cols-[minmax(0,1fr)_18rem]">
|
||||||
<div className="mb-4 rounded-xl border border-amber-200 bg-amber-50 p-4">
|
<section aria-labelledby="titulo-por-pagar" className="min-w-0 lg:col-start-1 lg:row-start-1">
|
||||||
<p className="font-semibold text-amber-800">
|
{porPagar.length > 0 ? (
|
||||||
Tienes {porPagar.length}{" "}
|
<div className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||||
{porPagar.length === 1 ? "pago pendiente" : "pagos pendientes"} por{" "}
|
<div className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 px-5 py-4 border-b border-border">
|
||||||
{formatTotales(totalesPorMoneda(porPagar))}
|
<h2 id="titulo-por-pagar" className="text-lg font-semibold">
|
||||||
</p>
|
Por pagar
|
||||||
<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}
|
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-sm text-muted mt-0.5">
|
<p className="text-sm text-muted">
|
||||||
{formatCurrency(prog.monto)} · {frecuenciaLegible(prog)} · {prog.moneda}
|
{porPagar.length} {porPagar.length === 1 ? "cobro" : "cobros"} ·{" "}
|
||||||
|
<span className="font-semibold text-foreground tabular-nums">
|
||||||
|
{formatTotales(totalesPorMoneda(porPagar))}
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{!prog.activo && (
|
<ul className="divide-y divide-border">
|
||||||
<span className="inline-block px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-600">
|
{porPagar.map((pago) => {
|
||||||
Programa inactivo
|
const vencido = diasHasta(pago.fecha, hoy) < 0;
|
||||||
</span>
|
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>
|
||||||
|
) : (
|
||||||
|
<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 ? (
|
<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">
|
||||||
<div className="bg-card-bg rounded-xl border border-border p-8 text-center text-sm text-muted">
|
{datosPago.length > 0 && (
|
||||||
Aún no se han generado cobros de este programa.
|
<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>
|
||||||
) : (
|
</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 px-5 py-4 text-sm">
|
||||||
<thead>
|
<h2 className="font-semibold mb-2">Cómo se registra tu pago</h2>
|
||||||
<tr className="border-b border-border bg-gray-50">
|
<ol className="list-decimal space-y-1.5 pl-4 text-muted marker:text-muted">
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Fecha</th>
|
<li>Haz la transferencia por el monto del cobro.</li>
|
||||||
<th className="text-right px-5 py-3 font-medium text-muted">Monto</th>
|
<li>Sube el comprobante (imagen o PDF, hasta 10 MB) en ese cobro.</li>
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Estado</th>
|
<li>Lo revisamos y te avisamos cuando quede verificado.</li>
|
||||||
<th className="text-left px-5 py-3 font-medium text-muted">Acción</th>
|
</ol>
|
||||||
</tr>
|
</div>
|
||||||
</thead>
|
</aside>
|
||||||
<tbody>
|
|
||||||
{prog.pagos.map((pago) => (
|
<section aria-labelledby="titulo-historial" className="min-w-0 lg:col-start-1 lg:row-start-2">
|
||||||
<tr key={pago.id} className="border-b border-border hover:bg-gray-50 transition-colors">
|
<h2 id="titulo-historial" className="text-lg font-semibold mb-3 mt-2">
|
||||||
<td className="px-5 py-3">{formatFechaCorta(pago.fecha)}</td>
|
Historial
|
||||||
<td className="px-5 py-3 text-right font-medium">
|
</h2>
|
||||||
{formatCurrency(pago.monto)}
|
<div className="space-y-4">
|
||||||
</td>
|
{programas.map((prog) => {
|
||||||
<td className="px-5 py-3">
|
const registrados = prog.pagos.filter((p) => !esPorPagar(p.estado));
|
||||||
<EstadoPagoBadge
|
const visibles = registrados.slice(0, HISTORIAL_VISIBLE);
|
||||||
estado={pago.estado}
|
const anteriores = registrados.slice(HISTORIAL_VISIBLE);
|
||||||
rechazoMotivo={pago.rechazoMotivo}
|
const proximo = prog.activo ? proximaFecha(prog, hoy) : null;
|
||||||
/>
|
return (
|
||||||
</td>
|
<div key={prog.id} className="bg-card-bg rounded-xl border border-border overflow-hidden">
|
||||||
<td className="px-5 py-3">
|
<div className="flex flex-wrap items-start justify-between gap-2 px-5 py-4 border-b border-border">
|
||||||
{pago.estado === ESTADOS_PAGO.PENDIENTE ||
|
<div className="min-w-0">
|
||||||
pago.estado === ESTADOS_PAGO.RECHAZADO ? (
|
<h3 className="font-semibold">{prog.concepto}</h3>
|
||||||
<SubirComprobante pagoId={pago.id} />
|
<p className="text-sm text-muted mt-0.5">
|
||||||
) : (
|
<span className="tabular-nums">{formatMonto(prog.monto, prog.moneda)}</span>{" "}
|
||||||
<a
|
{frecuenciaLegible(prog)}
|
||||||
href={`/api/comprobantes/${pago.id}`}
|
{proximo && ` · próximo: ${formatFechaBreve(proximo, hoy)}`}
|
||||||
target="_blank"
|
</p>
|
||||||
rel="noopener noreferrer"
|
</div>
|
||||||
className="text-primary text-sm hover:underline"
|
{!prog.activo && (
|
||||||
>
|
<span className="rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-600">
|
||||||
Ver comprobante
|
Programa inactivo
|
||||||
</a>
|
</span>
|
||||||
)}
|
)}
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
{registrados.length === 0 ? (
|
||||||
))}
|
<p className="px-5 py-4 text-sm text-muted">Aún no hay pagos registrados.</p>
|
||||||
</tbody>
|
) : (
|
||||||
</table>
|
<>
|
||||||
</div>
|
<ul className="divide-y divide-border">
|
||||||
)}
|
{visibles.map((pago) => (
|
||||||
</section>
|
<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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export interface ResumenCotizacion {
|
|||||||
fecha: Date;
|
fecha: Date;
|
||||||
estado: string;
|
estado: string;
|
||||||
esDoble: boolean;
|
esDoble: boolean;
|
||||||
|
incluirIva: boolean;
|
||||||
totales: ReturnType<typeof calcularTotalesCotizacion>;
|
totales: ReturnType<typeof calcularTotalesCotizacion>;
|
||||||
totalesOpciones?: {
|
totalesOpciones?: {
|
||||||
"1": ReturnType<typeof calcularTotalesOpcion>;
|
"1": ReturnType<typeof calcularTotalesOpcion>;
|
||||||
@@ -34,9 +35,11 @@ export interface ResumenCliente {
|
|||||||
// por moneda.
|
// por moneda.
|
||||||
pendientes: number;
|
pendientes: number;
|
||||||
saldoPendiente: Record<string, number>;
|
saldoPendiente: Record<string, number>;
|
||||||
|
// Fecha del cobro por pagar mas antiguo (null si no debe nada).
|
||||||
|
masAntiguo: Date | null;
|
||||||
enRevision: number;
|
enRevision: number;
|
||||||
verificadosMes: 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({
|
prisma.pagoRecurrente.findMany({
|
||||||
where: { estado: { in: ESTADOS_POR_PAGAR }, programa: { clienteId } },
|
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({
|
prisma.pagoRecurrente.count({
|
||||||
where: { estado: ESTADOS_PAGO.EN_REVISION, programa: { clienteId } },
|
where: { estado: ESTADOS_PAGO.EN_REVISION, programa: { clienteId } },
|
||||||
@@ -98,6 +102,7 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
|||||||
fecha: c.fecha,
|
fecha: c.fecha,
|
||||||
estado: c.estado,
|
estado: c.estado,
|
||||||
esDoble: c.esDoble,
|
esDoble: c.esDoble,
|
||||||
|
incluirIva: c.incluirIva,
|
||||||
totales,
|
totales,
|
||||||
...(c.esDoble
|
...(c.esDoble
|
||||||
? {
|
? {
|
||||||
@@ -113,9 +118,9 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
|||||||
const proximos = programas
|
const proximos = programas
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
const fecha = proximaFecha(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())
|
.sort((a, b) => a.fecha.getTime() - b.fecha.getTime())
|
||||||
.slice(0, 3);
|
.slice(0, 3);
|
||||||
|
|
||||||
@@ -126,6 +131,7 @@ export async function obtenerResumenCliente(clienteId: string): Promise<ResumenC
|
|||||||
pagos: {
|
pagos: {
|
||||||
pendientes: porPagar.length,
|
pendientes: porPagar.length,
|
||||||
saldoPendiente: totalesPorMoneda(porPagar),
|
saldoPendiente: totalesPorMoneda(porPagar),
|
||||||
|
masAntiguo: porPagar[0]?.fecha ?? null,
|
||||||
enRevision,
|
enRevision,
|
||||||
verificadosMes,
|
verificadosMes,
|
||||||
proximos,
|
proximos,
|
||||||
|
|||||||
+18
-1
@@ -16,7 +16,9 @@
|
|||||||
--sidebar-active: #2563eb;
|
--sidebar-active: #2563eb;
|
||||||
--card-bg: #ffffff;
|
--card-bg: #ffffff;
|
||||||
--border: #e2e8f0;
|
--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 {
|
@theme inline {
|
||||||
@@ -49,3 +51,18 @@ body {
|
|||||||
scrollbar-width: thin;
|
scrollbar-width: thin;
|
||||||
scrollbar-color: #cbd5e1 transparent;
|
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";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { Suspense, useState } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
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() {
|
export default function LoginPage() {
|
||||||
|
return (
|
||||||
|
<Suspense>
|
||||||
|
<LoginForm />
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function LoginForm() {
|
||||||
const router = useRouter();
|
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 [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
@@ -30,37 +43,43 @@ export default function LoginPage() {
|
|||||||
router.refresh();
|
router.refresh();
|
||||||
} else {
|
} else {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setError(data.error || "Error al iniciar sesion");
|
setError(data.error || "No se pudo iniciar sesión");
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
setError("Error de conexion");
|
setError("Sin conexión con el servidor. Intenta de nuevo.");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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="w-full max-w-sm">
|
||||||
<div className="bg-white rounded-xl shadow-lg border border-border p-8">
|
<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 text-center mb-2">Cotizador</h1>
|
<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">
|
<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>
|
</p>
|
||||||
|
|
||||||
{error && (
|
{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}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
<form onSubmit={handleSubmit} className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-muted mb-1">
|
<label htmlFor="login-email" className="block text-sm font-medium mb-1">
|
||||||
Email
|
Correo
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
|
id="login-email"
|
||||||
type="email"
|
type="email"
|
||||||
|
autoComplete="email"
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
required
|
required
|
||||||
@@ -70,15 +89,17 @@ export default function LoginPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-muted mb-1">
|
<label htmlFor="login-password" className="block text-sm font-medium mb-1">
|
||||||
Password
|
Contraseña
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
|
id="login-password"
|
||||||
type="password"
|
type="password"
|
||||||
|
autoComplete="current-password"
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
required
|
required
|
||||||
placeholder="Tu contrasena"
|
placeholder="Tu contraseña"
|
||||||
suppressHydrationWarning
|
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"
|
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);
|
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 {
|
export function formatTotales(totales: Record<string, number>): string {
|
||||||
const partes = Object.entries(totales).map(([moneda, total]) =>
|
const partes = Object.entries(totales).map(([moneda, total]) => formatMonto(total, moneda));
|
||||||
new Intl.NumberFormat("es-MX", {
|
|
||||||
style: "currency",
|
|
||||||
currency: moneda || "MXN",
|
|
||||||
maximumFractionDigits: 2,
|
|
||||||
}).format(total)
|
|
||||||
);
|
|
||||||
return partes.length ? partes.join(" + ") : "$0";
|
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".
|
// Version corta: "04/07/2026".
|
||||||
export function formatFechaCorta(date: Date): string {
|
export function formatFechaCorta(date: Date): string {
|
||||||
const { y, m, d } = aCalendario(date);
|
const { y, m, d } = aCalendario(date);
|
||||||
|
|||||||
Reference in New Issue
Block a user