Files
front-AT/app/Components/Receipt/Receipt.tsx
T

147 lines
3.5 KiB
TypeScript
Raw Normal View History

2025-09-19 17:20:05 -06:00
"use client";
2025-09-22 11:57:52 -06:00
2025-10-01 15:29:23 -06:00
import toast from "react-hot-toast";
2025-09-19 17:20:05 -06:00
import { useState } from "react";
import { PostReceipt } from "@/app/lib/postReceipt";
2025-10-06 17:26:14 -06:00
import { useRouter } from "next/navigation";
2025-09-19 17:20:05 -06:00
import "./Receipt.css";
interface ReceiptsProps {
2025-09-22 12:15:32 -04:00
numAcount: number | null;
2025-09-19 17:20:05 -06:00
}
2025-09-29 15:37:56 -06:00
function Receipt({ numAcount }: ReceiptsProps) {
2025-09-22 11:57:52 -06:00
const router = useRouter();
2025-09-19 17:20:05 -06:00
const [folio, setFolio] = useState("");
const [amount, setAmount] = useState("");
const [date, setDate] = useState("");
//restrict this month//
const day = new Date();
const year = day.getFullYear();
const month = day.getMonth();
const today = day.getDate();
const minFecha = new Date(year, month, 1).toISOString().split("T")[0];
const maxFecha = new Date(year, month, today).toISOString().split("T")[0];
//restrict this month//
2025-09-22 11:57:52 -06:00
const handleSaveReceipt = async () => {
2025-09-22 12:15:32 -04:00
if (!numAcount) {
2025-10-01 15:29:23 -06:00
toast.error("busca de nuevo al estudiante");
return;
2025-09-17 16:47:19 -06:00
}
2025-09-19 17:20:05 -06:00
if (!folio) {
2025-10-01 15:29:23 -06:00
toast.error("Ingresa el folio del ticket");
return;
2025-09-19 17:20:05 -06:00
}
if (!amount) {
2025-10-01 15:29:23 -06:00
toast.error("Coloca el monto a depositar");
return;
2025-09-19 17:20:05 -06:00
}
if (!date) {
2025-10-01 15:29:23 -06:00
toast.error("Coloca la fecha");
return;
2025-09-19 17:20:05 -06:00
}
2025-09-22 11:57:52 -06:00
try {
await PostReceipt({
id_cuenta: numAcount,
folio_recibo: folio,
monto: Number(amount),
fecha_recibo: date,
});
setFolio("");
setAmount("");
setDate("");
2025-10-01 15:29:23 -06:00
toast.success("Recibo guardado");
2025-10-03 17:29:53 -06:00
router.refresh();
2025-09-22 11:57:52 -06:00
} catch (err: any) {
2025-10-01 15:29:23 -06:00
toast.error(String(err));
2025-09-22 11:57:52 -06:00
}
2025-09-19 17:20:05 -06:00
};
return (
<form
onSubmit={(e) => {
e.preventDefault();
handleSaveReceipt();
}}
>
<div className="gap">
<div className="groupInput">
<label className="label">Ticket:</label>
2025-10-06 17:26:14 -06:00
<div className="groupInformation">
<input
type="text"
value={folio}
onChange={(error) => {
const value = error.target.value;
if (/^\d*$/.test(value) && value.length <= 7) {
setFolio(value);
}
}}
placeholder="Numero de tiket..."
inputMode="numeric"
pattern="[0-9]*"
/>
<select className="informationButton">
<option>7</option>
<option>8</option>
</select>
</div>
2025-09-19 17:20:05 -06:00
</div>
<div className="groupInput">
<label className="label">Monto:</label>
<input
type="text"
value={amount}
onChange={(e) => {
const value = e.target.value;
if (/^\d*\.?\d*$/.test(value)) {
const numericValue = parseFloat(value);
if (value === "" || numericValue <= 1000) {
setAmount(value);
} else {
2025-10-01 15:29:23 -06:00
toast.error("El monto no puede superar $1000.00");
2025-09-19 17:20:05 -06:00
}
}
2025-09-02 19:50:17 -04:00
}}
2025-09-19 17:20:05 -06:00
placeholder="Monto recibido..."
inputMode="numeric"
pattern="^\d*\.?\d+$"
/>
</div>
<div className="groupInput">
<label className="label">Fecha de Pago:</label>
<input
type="date"
value={date}
onChange={(e) => setDate(e.target.value)}
min={minFecha}
max={maxFecha}
/>
</div>
<div className="containerButton">
<button className="button buttonSearch">Guardar</button>
</div>
</div>
</form>
);
2025-09-02 19:50:17 -04:00
}
2025-09-19 17:20:05 -06:00
export default Receipt;
//IO