Files
front-AT/app/Components/Reportes/porRecibo.tsx
T

119 lines
2.8 KiB
TypeScript
Raw Normal View History

2026-01-15 14:24:02 -06:00
"use client";
2026-01-15 14:24:02 -06:00
import { useEffect, useState } from "react";
import axios from "axios";
import DownloadReporteXLSX from "../Dowload/Reporte";
2026-01-14 14:53:36 -06:00
interface Recibo {
id_recibo: number;
folio_recibo: string;
fecha_recibo: string;
fecha_registro: string;
monto: string;
2026-01-15 14:24:02 -06:00
user: {
2026-01-16 15:47:16 -06:00
usuario: string;
2026-01-15 14:24:02 -06:00
};
2026-01-14 14:53:36 -06:00
}
interface Props {
desde: string | null;
hasta: string | null;
}
2026-01-14 14:53:36 -06:00
function PorRecibos({ desde, hasta }: Props) {
const [recibos, setRecibos] = useState<Recibo[]>([]);
const [loading, setLoading] = useState(false);
2026-02-13 16:10:05 -06:00
const columns = [
{ header: "Folio", key: "folio", width: 15 },
{ header: "Monto", key: "monto", width: 15 },
{ header: "Fecha Recibo", key: "fechaRecibo", width: 18 },
{ header: "Fecha Registro", key: "fechaRegistro", width: 22 },
{ header: "Usuario", key: "usuario", width: 20 },
];
2026-01-14 14:53:36 -06:00
useEffect(() => {
if (!desde || !hasta) return;
const fetchRecibos = async () => {
setLoading(true);
try {
const res = await axios.post(
`${process.env.NEXT_PUBLIC_API_URL}/recibo/rango`,
{ desde, hasta }
);
setRecibos(res.data);
} catch (error) {
2026-01-15 14:24:02 -06:00
console.error("Error al obtener recibos", error);
2026-01-14 14:53:36 -06:00
} finally {
setLoading(false);
}
};
fetchRecibos();
}, [desde, hasta]);
const formatearFechaMX = (fechaISO: string) => {
return new Date(fechaISO).toLocaleString("es-MX", {
timeZone: "America/Mexico_City",
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
};
return (
2026-01-15 14:24:02 -06:00
<div style={{ position: "relative" }}>
2026-02-13 16:10:05 -06:00
{recibos.length > 0 && <DownloadReporteXLSX data={recibos} columns={columns} />}
2026-01-15 14:24:02 -06:00
<div
style={{
overflow: "auto",
height: "270px",
scrollbarColor: "#2563eb white",
}}
>
{loading && <p>Cargando...</p>}
2026-01-14 14:53:36 -06:00
2026-01-15 14:24:02 -06:00
<table>
<thead>
2026-01-14 14:53:36 -06:00
<tr>
2026-01-15 14:24:02 -06:00
<th>Folio</th>
<th>Monto</th>
<th>fecha recibo</th>
<th>fecha registro</th>
<th>Usuario</th>
2026-01-14 14:53:36 -06:00
</tr>
2026-01-15 14:24:02 -06:00
</thead>
2026-01-14 14:53:36 -06:00
2026-01-15 14:24:02 -06:00
<tbody>
{!loading && recibos.length === 0 && (
<tr>
2026-01-16 15:47:16 -06:00
<td colSpan={5}>No hay recibos en este rango</td>
2026-01-15 14:24:02 -06:00
</tr>
)}
{recibos.map((recibo) => (
<tr key={recibo.id_recibo}>
<td>{recibo.folio_recibo}</td>
<td>${Number(recibo.monto).toFixed(2)}</td>
<td>{recibo.fecha_recibo}</td>
<td>{formatearFechaMX(recibo.fecha_registro)}</td>
2026-01-16 15:47:16 -06:00
<td>{recibo.user.usuario}</td>
2026-01-15 14:24:02 -06:00
</tr>
))}
</tbody>
</table>
</div>
</div>
);
}
export default PorRecibos;