diff --git a/src/app/api/portal/pagos-validados/route.ts b/src/app/api/portal/pagos-validados/route.ts index 0fe5b6e..934a57e 100644 --- a/src/app/api/portal/pagos-validados/route.ts +++ b/src/app/api/portal/pagos-validados/route.ts @@ -18,11 +18,15 @@ export async function GET(req: Request): Promise { const year = url.searchParams.get("year") ?? String(now.getFullYear()); const m = Number(mes); const y = Number(year); + const l = Number(url.searchParams.get("limite") ?? "200"); if (!Number.isInteger(m) || m < 1 || m > 12 || !Number.isInteger(y) || y < 2000 || y > 2100) { return NextResponse.json({ error: "mes (1-12) y year válidos requeridos" }, { status: 400 }); } + if (!Number.isInteger(l) || l < 1 || l > 1000) { + return NextResponse.json({ error: "limite (1-1000) requerido" }, { status: 400 }); + } const res = await fetch( - `${SAM_API_URL}/api/Boletas/payments?mes=${m}&year=${y}`, + `${SAM_API_URL}/api/Boletas/payments?mes=${m}&year=${y}&limite=${l}`, { cache: "no-store" } ); const text = await res.text(); diff --git a/src/app/m/[name]/page.tsx b/src/app/m/[name]/page.tsx index f467928..2c0d22c 100644 --- a/src/app/m/[name]/page.tsx +++ b/src/app/m/[name]/page.tsx @@ -67,6 +67,18 @@ interface Boleta { monto: number; tipo?: string; estado?: string; + esValido?: boolean; + errorMotivo?: string | null; +} + +// Fecha real = distinta de nula/vacía y del MinValue de .NET +// (0001-01-01: la función PG no informó fecha de caja). +function fechaReal(f: string | null | undefined): boolean { + return !!f && !f.startsWith("0001-01-01"); +} + +function fechaCorta(f: string | null | undefined): string { + return fechaReal(f) ? String(f).slice(0, 10) : "—"; } function HelpdeskUsage() { @@ -229,7 +241,7 @@ function PagosUsage() { setLoading(true); setError(null); try { - const res = await fetch(`/api/portal/pagos-validados?mes=${m}&year=${y}`, { + const res = await fetch(`/api/portal/pagos-validados?mes=${m}&year=${y}&limite=200`, { cache: "no-store", }); const data = await res.json().catch(() => null); @@ -254,7 +266,13 @@ function PagosUsage() { // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - const total = (rows ?? []).reduce((acc, r) => acc + (Number(r.monto) || 0), 0); + const valid = (rows ?? []).filter( + (r) => r.esValido !== false && fechaReal(r.fecha) + ); + const errors = (rows ?? []).filter( + (r) => r.esValido === false || !fechaReal(r.fecha) + ); + const total = valid.reduce((acc, r) => acc + (Number(r.monto) || 0), 0); return ( <> @@ -300,7 +318,9 @@ function PagosUsage() { {rows && ( - {rows.length} pagos · Total ${total.toLocaleString("es-CL")} + {valid.length} válidos + {errors.length > 0 && ` · ${errors.length} observados`} · Total + ${total.toLocaleString("es-CL")} )} @@ -318,11 +338,11 @@ function PagosUsage() { )} - {!error && !loading && rows && rows.length === 0 && ( -

Sin pagos validados para {mes}/{year}.

+ {!error && !loading && rows && valid.length === 0 && ( +

Sin pagos válidos para {mes}/{year}.

)} - {!error && !loading && rows && rows.length > 0 && ( + {!error && !loading && rows && valid.length > 0 && (
@@ -335,7 +355,7 @@ function PagosUsage() { - {rows.slice(0, 100).map((r, i) => ( + {valid.slice(0, 100).map((r, i) => ( - + ))}
{r.folio} @@ -344,20 +364,60 @@ function PagosUsage() { {r.alumnoRut} ) : null} - {r.fecha ? String(r.fecha).slice(0, 10) : "—"} - {fechaCorta(r.fecha)} ${Number(r.monto || 0).toLocaleString("es-CL")} {r.estado || r.tipo || "—"}
- {rows.length > 100 && ( - Mostrando 100 de {rows.length}. + {valid.length > 100 && ( + Mostrando 100 de {valid.length}. )}
)} + {!error && !loading && rows && errors.length > 0 && ( +
+ + + {errors.length} registro{errors.length !== 1 ? "s" : ""} observado{ + errors.length !== 1 ? "s" : "" + } (no son ventas válidas) + +
+ + + + + + + + + + + + {errors.slice(0, 100).map((r, i) => ( + + + + + + + + ))} + +
FolioAlumnoFechaMontoMotivo
{r.folio || "—"} + {r.alumnoNombre ?? "—"} + {r.alumnoRut ? ( + {r.alumnoRut} + ) : null} + {fechaCorta(r.fecha)}${Number(r.monto || 0).toLocaleString("es-CL")}{r.errorMotivo || "Sin fecha válida"}
+ {errors.length > 100 && ( + Mostrando 100 de {errors.length}. + )} +
+
+ )} Fuente: GET /api/Boletas/payments?mes=&year= (SAM.API).