2025-09-19 17:20:05 -06:00
|
|
|
"use client";
|
|
|
|
|
import AlertBox from "../AlertBox/AlertBox";
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { PostReceipt } from "@/app/lib/postReceipt";
|
|
|
|
|
import Cookies from "js-cookie";
|
|
|
|
|
|
|
|
|
|
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-22 12:15:32 -04:00
|
|
|
function Receipt({ numAcount }: ReceiptsProps) {
|
2025-09-19 17:20:05 -06:00
|
|
|
const [folio, setFolio] = useState("");
|
|
|
|
|
const [amount, setAmount] = useState("");
|
|
|
|
|
const [date, setDate] = useState("");
|
|
|
|
|
|
|
|
|
|
const [error, setError] = useState("");
|
|
|
|
|
const [alert, setAlert] = 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//
|
|
|
|
|
|
|
|
|
|
const handleSaveReceipt = () => {
|
2025-09-22 12:15:32 -04:00
|
|
|
if (!numAcount) {
|
2025-09-19 17:20:05 -06:00
|
|
|
setError("Error busca denuevo al estudiante");
|
|
|
|
|
return;
|
2025-09-17 16:47:19 -06:00
|
|
|
}
|
|
|
|
|
|
2025-09-19 17:20:05 -06:00
|
|
|
if (!folio) {
|
|
|
|
|
setError("Ingresa el folio del tiket");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!amount) {
|
|
|
|
|
setError("coloca el monto a depositar");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!date) {
|
|
|
|
|
setError("coloca la fecha");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PostReceipt({
|
2025-09-22 12:15:32 -04:00
|
|
|
id_cuenta: numAcount,
|
2025-09-19 17:20:05 -06:00
|
|
|
folio_recibo: folio,
|
|
|
|
|
monto: Number(amount),
|
|
|
|
|
fecha_recibo: date,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handleSaveReceipt();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="gap">
|
|
|
|
|
<div className="groupInput">
|
|
|
|
|
<label className="label">Ticket:</label>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={folio}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const value = e.target.value;
|
|
|
|
|
if (/^\d*$/.test(value)) {
|
|
|
|
|
setFolio(value);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Numero de folio..."
|
|
|
|
|
inputMode="numeric"
|
|
|
|
|
pattern="[0-9]*"
|
|
|
|
|
/>
|
|
|
|
|
</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 {
|
|
|
|
|
setAlert("");
|
|
|
|
|
setError("El monto no puede superar $1000.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>
|
|
|
|
|
|
|
|
|
|
{error && <AlertBox message={error} type="error" />}
|
|
|
|
|
{alert && <AlertBox message={alert} type="success" />}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
2025-09-02 19:50:17 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-19 17:20:05 -06:00
|
|
|
export default Receipt;
|
|
|
|
|
//IO
|