diff --git a/app/(private)/AgregarTiempo/Addtime.tsx b/app/(private)/AgregarTiempo/Addtime.tsx index 95d96c7..7f4b6f7 100644 --- a/app/(private)/AgregarTiempo/Addtime.tsx +++ b/app/(private)/AgregarTiempo/Addtime.tsx @@ -43,11 +43,16 @@ export default function AddTime({ const month = day.getMonth(); const today = day.getDate(); - const minFecha = new Date(year, month, 1).toISOString().split("T")[0]; + let minMount = month + if (!lock) { + minMount = month - 1 + } + + const minFecha = new Date(year, minMount, 1).toISOString().split("T")[0]; const maxFecha = new Date(year, month, today).toISOString().split("T")[0]; const handleSaveReceipt = async () => { - if (numAcount == null) { + if (numAcount == null) { Swal.fire({ title: "Busca de nuevo al estudiante!", diff --git a/app/(private)/AgregarTiempo/addTime.css b/app/(private)/AgregarTiempo/addTime.css index 9e09a4e..150592a 100644 --- a/app/(private)/AgregarTiempo/addTime.css +++ b/app/(private)/AgregarTiempo/addTime.css @@ -33,7 +33,7 @@ .buttonOpenLock { padding: 0.8rem; position: absolute; - right: 0; + right: 100px; background-color: #8cd32f; } diff --git a/app/(private)/Impresiones/page.tsx b/app/(private)/Impresiones/page.tsx index e7c50ec..1ae3f3f 100644 --- a/app/(private)/Impresiones/page.tsx +++ b/app/(private)/Impresiones/page.tsx @@ -67,7 +67,6 @@ export default async function Page(props: { console.error("Error obteniendo costos:", error); } - const getCostsByService = (id_servicio: number) => { return costos .filter((c) => c.id_servicio === id_servicio) diff --git a/app/(private)/Periodo/page.tsx b/app/(private)/Periodo/page.tsx index 1605a02..52439a8 100644 --- a/app/(private)/Periodo/page.tsx +++ b/app/(private)/Periodo/page.tsx @@ -1,6 +1,7 @@ "use client"; import { useState, useEffect } from "react"; +import { envConfig } from "@/app/lib/config"; import axios from "axios"; import Cookies from "js-cookie"; @@ -9,9 +10,11 @@ interface Periodo { semestre: string; fecha_inicio_servicio: string; fecha_fin_servicio: string; - activo: boolean; + activo: { + type: string; + data: number[]; + }; } - export default function PeriodoPage() { const [periodos, setPeriodos] = useState([]); @@ -21,7 +24,7 @@ export default function PeriodoPage() { const [modoEdicion, setModoEdicion] = useState(false); const [idEditar, setIdEditar] = useState(null); - const API = "http://localhost:5000/periodo"; + const API = `${envConfig.apiUrl}/periodo`; const token = Cookies.get("token"); const headers = { Authorization: `Bearer ${token}` }; @@ -39,10 +42,8 @@ export default function PeriodoPage() { obtenerPeriodos(); }, []); - // VALIDAR SEMESTRE const handleSemestreChange = (e: React.ChangeEvent) => { const valor = e.target.value; - if (/^\d{0,6}$/.test(valor)) { setSemestre(valor); @@ -74,16 +75,6 @@ export default function PeriodoPage() { } }; - - const eliminarPeriodo = async (id_periodo: number) => { - try { - await axios.delete(`${API}/${id_periodo}`, { headers }); - obtenerPeriodos(); - } catch (error) { - console.error("Error al eliminar periodo", error); - } - }; - const cargarPeriodo = (p: Periodo) => { setModoEdicion(true); setIdEditar(p.id_periodo); @@ -129,7 +120,6 @@ export default function PeriodoPage() {

PERIODO ESCOLAR

- {/* ================= FORMULARIO ================= */}
- {/* ================= TABLA ================= */}
@@ -203,7 +192,7 @@ export default function PeriodoPage() { - + ))} diff --git a/app/Components/CheckBoxEquipo.tsx b/app/Components/CheckBoxEquipo.tsx index ebadfb5..896ad89 100644 --- a/app/Components/CheckBoxEquipo.tsx +++ b/app/Components/CheckBoxEquipo.tsx @@ -3,7 +3,6 @@ import { useEffect, useState } from "react"; import { envConfig } from "../lib/config"; import { getEquipoByCount } from "../lib/getEquipoByCount"; - import SearchUser from "./Global/SearchUser/searchUser"; import SearchEquipo from "./SearchEquipo"; import axios from "axios"; @@ -18,8 +17,9 @@ async function getEquipoId(idEquipo: number) { const res = await axios.get( `${envConfig.apiUrl}/bitacora/equipo/${idEquipo}`, - { headers }, + { headers } ); + return res.data; } catch (error: any) { if (axios.isAxiosError(error)) { @@ -27,7 +27,6 @@ async function getEquipoId(idEquipo: number) { error: error.response?.data?.message || "Error al consultar equipo", }; } - return { error: "Error desconocido" }; } } @@ -38,25 +37,31 @@ interface Props { } export default function CheckBoxEquipo({ numAcount, machine }: Props) { - const [modo, setModo] = useState<"Equipo" | "Cuenta" | null>("Cuenta"); - const [bitacora, setBitacora] = useState(null); - const [tiempoRestante, setTiempoRestante] = useState(""); - const [minutos, setMinutos] = useState(); - const [error, setError] = useState() - const [loading, setLoading] = useState(false) + const [modo, setModo] = useState<"Equipo" | "Cuenta">("Cuenta"); - const token = Cookies.get("token"); - const headers = { Authorization: `Bearer ${token}` }; + const [bitacoraCuenta, setBitacoraCuenta] = useState(null); + const [bitacoraEquipo, setBitacoraEquipo] = useState(null); + const [tiempoRestante, setTiempoRestante] = useState(""); + const [minutos, setMinutos] = useState(0); + + const [errorCuenta, setErrorCuenta] = useState(null); + const [errorEquipo, setErrorEquipo] = useState(null); + + const [loading, setLoading] = useState(false); + + const bitacora = + modo === "Cuenta" ? bitacoraCuenta : bitacoraEquipo; const fetchByCuenta = async (idCuenta: number) => { const result = await getEquipoByCount(idCuenta); if (result?.error) { - setError(result.error); - setBitacora(null); + setErrorCuenta(result.error); + setBitacoraCuenta(null); } else { - setBitacora(result); + setErrorCuenta(null); + setBitacoraCuenta(result); } }; @@ -64,28 +69,27 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) { const result = await getEquipoId(idEquipo); if (result?.error) { - setError(result.error); - setBitacora(null); + setErrorEquipo(result.error); + setBitacoraEquipo(null); } else { - setBitacora(result); + setErrorEquipo(null); + setBitacoraEquipo(result); } }; useEffect(() => { - if (!numAcount) return; - const idCuenta = parseInt(numAcount); - if (isNaN(idCuenta)) return; + if (modo !== "Cuenta" || !numAcount) return; - fetchByCuenta(idCuenta); - }, [numAcount]); + const idCuenta = parseInt(numAcount); + if (!isNaN(idCuenta)) fetchByCuenta(idCuenta); + }, [numAcount, modo]); useEffect(() => { - if (!machine) return; - const idEquipo = parseInt(machine); - if (isNaN(idEquipo)) return; + if (modo !== "Equipo" || !machine) return; - fetchByEquipo(idEquipo); - }, [machine]); + const idEquipo = parseInt(machine); + if (!isNaN(idEquipo)) fetchByEquipo(idEquipo); + }, [machine, modo]); useEffect(() => { if (!bitacora) return; @@ -93,19 +97,32 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) { const entrada = new Date(bitacora.tiempo_entrada).getTime(); const asignadoMs = bitacora.tiempo_asignado * 60 * 1000; - const interval = setInterval(() => { + const updateTimer = () => { const ahora = Date.now(); const restante = entrada + asignadoMs - ahora; if (restante <= 0) { setTiempoRestante("agotado"); - clearInterval(interval); - } else { - const minutos = Math.floor(restante / 60000); - setMinutos(minutos + 1); - const segundos = Math.floor((restante % 60000) / 1000); - setTiempoRestante(`${minutos} minutos con ${segundos} segundos`); + setMinutos(0); + return false; } + + const minutosRestantes = Math.floor(restante / 60000); + const segundos = Math.floor((restante % 60000) / 1000); + + setMinutos(minutosRestantes+1); + setTiempoRestante( + `${minutosRestantes} minuto(s) con ${segundos} segundo(s)` + ); + + return true; + }; + + updateTimer(); + + const interval = setInterval(() => { + const sigue = updateTimer(); + if (!sigue) clearInterval(interval); }, 1000); return () => clearInterval(interval); @@ -113,29 +130,40 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) { const handleButton = async (e: React.MouseEvent) => { e.preventDefault(); - setLoading(false) + if (!bitacora) return; - await axios.patch( - `${envConfig.apiUrl}/bitacora/cancelar/${bitacora.id_bitacora}`, - { tiempo_asignado: minutos }, - { headers } - ); + setLoading(true); + try { + const token = Cookies.get("token"); + const headers = { Authorization: `Bearer ${token}` }; - Swal.fire({ - title: "Tiempo cancelado Correctamente!", - icon: "success", - draggable: true, - }); + await axios.patch( + `${envConfig.apiUrl}/bitacora/cancelar/${bitacora.id_bitacora}`, + { tiempo_asignado: minutos }, + { headers } + ); - if (modo === "Cuenta" && numAcount) { - fetchByCuenta(parseInt(numAcount)); + Swal.fire({ + title: "Tiempo cancelado correctamente!", + icon: "success", + }); + + if (modo === "Cuenta" && numAcount) { + fetchByCuenta(parseInt(numAcount)); + } + + if (modo === "Equipo" && machine) { + fetchByEquipo(parseInt(machine)); + } + } catch (error) { + Swal.fire({ + title: "Error al cancelar tiempo", + icon: "error", + }); + } finally { + setLoading(false); } - - if (modo === "Equipo" && machine) { - fetchByEquipo(parseInt(machine)); - } - setLoading(true) }; return ( @@ -144,7 +172,6 @@ export default function CheckBoxEquipo({ numAcount, machine }: Props) {
{p.semestre} {p.fecha_inicio_servicio} {p.fecha_fin_servicio}{p.activo === true ? "Sí" : "No"}{p.activo.data[0] === 1 ? "Sí" : "No"} - -