2025-09-19 17:20:05 -06:00
|
|
|
"use client";
|
2025-09-22 11:57:52 -06:00
|
|
|
|
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
|
|
|
|
2026-02-11 15:09:45 -05:00
|
|
|
import Swal from "sweetalert2";
|
2026-02-18 19:14:37 -06:00
|
|
|
import "./Receipt.css";
|
2025-09-19 17:20:05 -06:00
|
|
|
|
|
|
|
|
interface ReceiptsProps {
|
2025-09-22 12:15:32 -04:00
|
|
|
numAcount: number | null;
|
2025-09-19 17:20:05 -06:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 13:46:09 -06:00
|
|
|
export default 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("");
|
2026-02-09 12:23:03 -06:00
|
|
|
const [lock, setLock] = useState<boolean>(true);
|
2026-02-16 19:04:18 -06:00
|
|
|
const todayISO = new Date().toLocaleDateString("en-CA");
|
2026-01-23 14:57:17 -06:00
|
|
|
const [date, setDate] = useState(todayISO);
|
2025-09-19 17:20:05 -06:00
|
|
|
|
|
|
|
|
//restrict this month//
|
|
|
|
|
const day = new Date();
|
|
|
|
|
const year = day.getFullYear();
|
|
|
|
|
const month = day.getMonth();
|
|
|
|
|
const today = day.getDate();
|
|
|
|
|
|
2026-03-02 14:17:43 -06:00
|
|
|
let minMount = month
|
|
|
|
|
if(!lock){
|
|
|
|
|
minMount = month-1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const minFecha = new Date(year, minMount, 1).toISOString().split("T")[0];
|
2025-09-19 17:20:05 -06:00
|
|
|
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 () => {
|
2026-02-24 17:24:48 -06:00
|
|
|
if (numAcount == null) {
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-20 14:33:08 -05:00
|
|
|
Swal.fire({
|
2026-02-23 09:41:40 -06:00
|
|
|
title: "busca de nuevo al estudiante!",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
2025-10-01 15:29:23 -06:00
|
|
|
return;
|
2025-09-17 16:47:19 -06:00
|
|
|
}
|
|
|
|
|
|
2025-09-19 17:20:05 -06:00
|
|
|
if (!folio) {
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-20 14:33:08 -05:00
|
|
|
Swal.fire({
|
2026-02-23 09:41:40 -06:00
|
|
|
title: "Ingresa el folio del ticket!",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
2025-10-01 15:29:23 -06:00
|
|
|
return;
|
2025-09-19 17:20:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!amount) {
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-20 14:33:08 -05:00
|
|
|
Swal.fire({
|
2026-02-23 09:41:40 -06:00
|
|
|
title: "Coloca el monto a depositar!",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
2025-10-01 15:29:23 -06:00
|
|
|
return;
|
2025-09-19 17:20:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!date) {
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-20 14:33:08 -05:00
|
|
|
Swal.fire({
|
2026-02-23 09:41:40 -06:00
|
|
|
title: "Coloca la fecha!",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
2025-10-01 15:29:23 -06:00
|
|
|
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("");
|
2026-02-11 16:30:02 -06:00
|
|
|
setDate(todayISO);
|
2025-09-22 11:57:52 -06:00
|
|
|
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-11 15:09:45 -05:00
|
|
|
Swal.fire({
|
2026-02-20 14:33:08 -05:00
|
|
|
title: "Recibo Guardado Correctamente!",
|
2026-02-11 15:09:45 -05:00
|
|
|
icon: "success",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
|
|
|
|
|
2025-10-03 17:29:53 -06:00
|
|
|
router.refresh();
|
2025-09-22 11:57:52 -06:00
|
|
|
} catch (err: any) {
|
2026-02-18 19:01:31 -06:00
|
|
|
Swal.fire({
|
2026-02-23 09:41:40 -06:00
|
|
|
title: err,
|
2026-02-18 19:01:31 -06:00
|
|
|
icon: "error",
|
|
|
|
|
draggable: false
|
|
|
|
|
});
|
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-08 12:01:52 -06:00
|
|
|
<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]*"
|
|
|
|
|
/>
|
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);
|
|
|
|
|
|
2026-02-09 12:23:03 -06:00
|
|
|
if (lock && numericValue > 1000) {
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-19 08:04:54 -06:00
|
|
|
Swal.fire({
|
|
|
|
|
title:
|
|
|
|
|
"El monto no puede superar $1000.00 Desbloquea el candado !",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true,
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (numericValue > 10000) {
|
2026-02-23 09:41:40 -06:00
|
|
|
|
2026-02-19 08:04:54 -06:00
|
|
|
Swal.fire({
|
|
|
|
|
title:
|
|
|
|
|
"El monto no puede superar $10000.00 pesos",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true,
|
|
|
|
|
});
|
2026-02-09 12:23:03 -06:00
|
|
|
return;
|
2025-09-19 17:20:05 -06:00
|
|
|
}
|
2026-02-09 12:23:03 -06:00
|
|
|
|
|
|
|
|
setAmount(value);
|
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>
|
|
|
|
|
|
2026-02-09 12:23:03 -06:00
|
|
|
<div className="containerButton" style={{ position: 'relative' }}>
|
2026-01-13 18:51:56 -06:00
|
|
|
<button className="button buttonSearch" type="submit">Guardar</button>
|
2026-02-09 12:23:03 -06:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
className={`button buttonCancel ${lock ? "buttonLock" : "buttonOpenLock"
|
|
|
|
|
}`}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setLock((prev) => !prev)
|
|
|
|
|
setAmount('');
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-09-19 17:20:05 -06:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
2025-09-02 19:50:17 -04:00
|
|
|
}
|
2025-09-19 17:20:05 -06:00
|
|
|
//IO
|