From 6c80ecf3db2863704119853fef3974f6eedebbf8 Mon Sep 17 00:00:00 2001 From: Tyrannusss Date: Tue, 3 Mar 2026 17:26:16 -0600 Subject: [PATCH] se agrego la vista para el monto total por periodo y tipo de servicio --- app/(private)/Periodo-Graficas/page.tsx | 150 ++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 app/(private)/Periodo-Graficas/page.tsx diff --git a/app/(private)/Periodo-Graficas/page.tsx b/app/(private)/Periodo-Graficas/page.tsx new file mode 100644 index 0000000..54c6e41 --- /dev/null +++ b/app/(private)/Periodo-Graficas/page.tsx @@ -0,0 +1,150 @@ +"use client"; + +import { useState, useEffect } from "react"; +import { envConfig } from "@/app/lib/config"; +import axios from "axios"; +import Cookies from "js-cookie"; + +interface TotalServicioPeriodo { + nombre_servicio: string; + periodo: string; + monto_total: number; +} + +interface Servicio { + id_servicio: number; + servicio: string; +} + +interface Periodo { + id_periodo: number; + semestre: string; +} + +export default function ReporteTotalesPage() { + const [totales, setTotales] = useState([]); + const [servicios, setServicios] = useState([]); + const [periodos, setPeriodos] = useState([]); + const [cargando, setCargando] = useState(true); + + // Estados para los filtros + const [periodoInicio, setPeriodoInicio] = useState(""); + const [periodoFin, setPeriodoFin] = useState(""); + const [servicioId, setServicioId] = useState(""); + + const token = Cookies.get("token"); + const headers = { Authorization: `Bearer ${token}` }; + + // Obtener lista de servicios y periodos para los selects + useEffect(() => { + const fetchData = async () => { + try { + const [serviciosRes, periodosRes] = await Promise.all([ + axios.get(`${envConfig.apiUrl}/servicio`, { headers }), + axios.get(`${envConfig.apiUrl}/periodo`, { headers }), + ]); + setServicios(serviciosRes.data); + setPeriodos(periodosRes.data); + } catch (error) { + console.error("Error al cargar servicios o periodos", error); + } + }; + fetchData(); + }, []); + + const obtenerTotales = async () => { + setCargando(true); + try { + // Construir query params + const params = new URLSearchParams(); + if (periodoInicio) params.append("periodoInicio", periodoInicio); + if (periodoFin) params.append("periodoFin", periodoFin); + if (servicioId) params.append("servicioId", servicioId); + + const url = `${envConfig.apiUrl}/detalle-servicio/totales-por-periodo?${params.toString()}`; + const res = await axios.get(url, { headers }); + setTotales(res.data); + } catch (error) { + console.error("Error al obtener totales", error); + } finally { + setCargando(false); + } + }; + + // Llamar cuando cambien los filtros (podría ser con un botón o automático con debounce) + const aplicarFiltros = () => { + obtenerTotales(); + }; + + return ( +
+

REPORTE DE TOTALES POR SERVICIO Y PERIODO

+ + {/* Filtros */} +
+ + + + + + + +
+ + {cargando ? ( +

Cargando...

+ ) : ( +
+ + + + + + + + + + {totales.map((item, index) => ( + + + + + + ))} + +
ServicioPeriodoMonto Total
{item.nombre_servicio}{item.periodo}${item.monto_total.toFixed(2)}
+
+ )} +
+ ); +} \ No newline at end of file