2025-09-17 16:47:19 -06:00
|
|
|
"use client";
|
2025-09-03 20:41:25 -04:00
|
|
|
|
2025-09-22 11:57:52 -06:00
|
|
|
import Cookies from "js-cookie";
|
2025-09-02 19:50:17 -04:00
|
|
|
import { useState } from "react";
|
2025-09-29 22:48:06 -06:00
|
|
|
import { useRouter } from "next/navigation";
|
2025-09-19 17:20:05 -06:00
|
|
|
import { PostImpressions } from "@/app/lib/postImpressions";
|
2026-02-11 15:09:45 -05:00
|
|
|
import Swal from "sweetalert2";
|
2025-09-19 17:20:05 -06:00
|
|
|
|
2025-09-04 18:04:41 -04:00
|
|
|
interface CostOption {
|
|
|
|
|
value: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ImpressionsProps {
|
|
|
|
|
costs: CostOption[];
|
2025-09-22 12:15:32 -04:00
|
|
|
numAcount: number | null;
|
2026-01-23 12:35:35 -06:00
|
|
|
id_servicio: number;
|
2025-09-04 18:04:41 -04:00
|
|
|
}
|
2025-09-19 17:20:05 -06:00
|
|
|
|
2026-01-23 12:35:35 -06:00
|
|
|
function Impressions({ costs, numAcount, id_servicio }: ImpressionsProps) {
|
2025-09-17 16:47:19 -06:00
|
|
|
const [pages, setPages] = useState("");
|
2026-02-24 16:57:23 -06:00
|
|
|
const [cost, setCost] = useState(String(costs[0].value));
|
2026-02-26 09:22:39 -06:00
|
|
|
|
2026-02-25 19:27:04 -06:00
|
|
|
const total = Number(cost) * Number(pages);
|
2025-09-17 16:47:19 -06:00
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const handleLogout = () => {
|
|
|
|
|
Cookies.remove("token");
|
|
|
|
|
Cookies.remove("session");
|
|
|
|
|
router.push("/Login");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handlePayment = async () => {
|
2026-02-24 17:24:48 -06:00
|
|
|
if (numAcount == null) {
|
2026-02-20 14:33:08 -05:00
|
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!pages) {
|
2026-02-20 14:33:08 -05:00
|
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: "Ingresa el numero de hojas a imprimir!",
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
2025-10-01 15:29:23 -06:00
|
|
|
return;
|
2025-09-17 16:47:19 -06:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 19:42:13 -06:00
|
|
|
if (!cost) {
|
2026-02-20 14:33:08 -05:00
|
|
|
|
|
|
|
|
Swal.fire({
|
|
|
|
|
title: "Selecciona un costo!",
|
|
|
|
|
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
|
|
|
const result = await PostImpressions({
|
2025-09-22 11:57:52 -06:00
|
|
|
id_cuenta: numAcount,
|
|
|
|
|
numero_hojas: parseInt(pages),
|
2026-02-25 19:27:04 -06:00
|
|
|
monto: total,
|
2026-01-23 12:35:35 -06:00
|
|
|
id_servicio,
|
2025-09-19 17:20:05 -06:00
|
|
|
});
|
|
|
|
|
|
2026-01-28 17:04:29 -06:00
|
|
|
if (result?.error) {
|
|
|
|
|
if (result.message === "Token inválido") {
|
|
|
|
|
handleLogout();
|
|
|
|
|
} else {
|
2026-02-23 09:41:40 -06:00
|
|
|
Swal.fire({
|
|
|
|
|
title: result.message,
|
|
|
|
|
icon: "error",
|
|
|
|
|
draggable: true
|
|
|
|
|
});
|
2025-09-22 11:57:52 -06:00
|
|
|
}
|
2025-09-17 16:47:19 -06:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 17:20:05 -06:00
|
|
|
setPages("");
|
2026-02-26 09:22:39 -06:00
|
|
|
setCost(String(costs[0].value));
|
2026-02-20 14:33:08 -05:00
|
|
|
|
2026-02-11 15:09:45 -05:00
|
|
|
Swal.fire({
|
2026-02-20 14:33:08 -05:00
|
|
|
title: "Impresion cobrada 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-17 16:47:19 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
handlePayment();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div className="gap">
|
|
|
|
|
<div className="groupInput">
|
|
|
|
|
<label className="label">Costo:</label>
|
|
|
|
|
<select value={cost} onChange={(e) => setCost(e.target.value)}>
|
2025-09-24 17:51:54 -06:00
|
|
|
<option value="">Selecciona el costo</option>
|
2025-09-17 16:47:19 -06:00
|
|
|
{costs.map((c) => (
|
|
|
|
|
<option key={c.value} value={c.value}>
|
|
|
|
|
${c.value}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="groupInput">
|
|
|
|
|
<label className="label">Hojas:</label>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={pages}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
const value = e.target.value;
|
|
|
|
|
if (/^\d*$/.test(value)) {
|
|
|
|
|
setPages(value);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Numero de hojas a imprimir..."
|
|
|
|
|
inputMode="numeric"
|
|
|
|
|
pattern="[0-9]*"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-01-23 12:35:35 -06:00
|
|
|
<div
|
2026-02-27 19:52:23 -06:00
|
|
|
className="groupInput total"
|
2026-01-23 12:35:35 -06:00
|
|
|
>
|
2025-09-29 15:37:56 -06:00
|
|
|
<label className="label">Total:</label>
|
|
|
|
|
<label
|
|
|
|
|
style={{ width: "100%", minWidth: "200px", maxWidth: "500px" }}
|
|
|
|
|
>
|
2026-02-25 19:27:04 -06:00
|
|
|
{pages && cost && `$${total}.00`}
|
2025-09-22 11:57:52 -06:00
|
|
|
</label>
|
2025-09-17 16:47:19 -06:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="containerButton">
|
|
|
|
|
<button className="button buttonCharge" type="submit">
|
|
|
|
|
Cobrar
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
2025-09-02 19:50:17 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 16:47:19 -06:00
|
|
|
export default Impressions;
|
|
|
|
|
//IO
|