modified creadores
This commit is contained in:
@@ -1,43 +1,74 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import styles from "./style.module.css";
|
|
||||||
import Cookies from "js-cookie";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import { saveAs } from "file-saver";
|
||||||
|
import ExcelJS from "exceljs";
|
||||||
|
|
||||||
export default function DownloadReporteXLSX() {
|
import styles from "./style.module.css";
|
||||||
|
|
||||||
|
interface Recibo {
|
||||||
|
id_recibo: number;
|
||||||
|
folio_recibo: string;
|
||||||
|
fecha_recibo: string;
|
||||||
|
fecha_registro: string;
|
||||||
|
monto: string;
|
||||||
|
user: {
|
||||||
|
usuario: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Columns{
|
||||||
|
header:string;
|
||||||
|
key:string;
|
||||||
|
width:number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
data: Recibo[];
|
||||||
|
columns:Columns[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DownloadReporteXLSX({ data,columns }: Props) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const formatearFechaMX = (fechaISO: string) => {
|
||||||
|
return new Date(fechaISO).toLocaleString("es-MX", {
|
||||||
|
timeZone: "America/Mexico_City",
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleDownload = async () => {
|
const handleDownload = async () => {
|
||||||
|
if (!data || data.length === 0) return;
|
||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const token = Cookies.get("token");
|
|
||||||
const headers = { Authorization: `Bearer ${token}` };
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const workbook = new ExcelJS.Workbook();
|
||||||
`${process.env.NEXT_PUBLIC_API_URL}/equipos/reporteXLSX`,//Modificar
|
const worksheet = workbook.addWorksheet("Recibos");
|
||||||
{ headers }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
worksheet.columns = columns;
|
||||||
toast.error("Error al descargar el archivo");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const blob = await response.blob();
|
data.forEach((recibo) => {
|
||||||
const url = window.URL.createObjectURL(blob);
|
worksheet.addRow({
|
||||||
|
folio: recibo.folio_recibo,
|
||||||
|
monto: Number(recibo.monto),
|
||||||
|
fechaRecibo: recibo.fecha_recibo,
|
||||||
|
fechaRegistro: formatearFechaMX(recibo.fecha_registro),
|
||||||
|
usuario: recibo.user.usuario,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const a = document.createElement("a");
|
worksheet.getColumn("monto").numFmt = '"$"#,##0.00';
|
||||||
a.href = url;
|
|
||||||
a.download = "Reporte Recibos.xlsx";
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
a.remove();
|
|
||||||
|
|
||||||
window.URL.revokeObjectURL(url);
|
const buffer = await workbook.xlsx.writeBuffer();
|
||||||
|
const blob = new Blob([buffer], {
|
||||||
|
type:
|
||||||
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
|
});
|
||||||
|
|
||||||
|
saveAs(blob, "Reporte_Recibos.xlsx");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error("Error generando Excel", error);
|
||||||
toast.error("Hubo un problema al descargar el archivo.");
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -52,7 +83,13 @@ export default function DownloadReporteXLSX() {
|
|||||||
{loading ? (
|
{loading ? (
|
||||||
<div className={styles.loader}></div>
|
<div className={styles.loader}></div>
|
||||||
) : (
|
) : (
|
||||||
<img src="/excel.svg" alt="Excel" className={styles.iconExcel} width={30} height={30}/>
|
<img
|
||||||
|
src="/excel.svg"
|
||||||
|
alt="Excel"
|
||||||
|
className={styles.iconExcel}
|
||||||
|
width={30}
|
||||||
|
height={30}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,6 +24,14 @@ function PorRecibos({ desde, hasta }: Props) {
|
|||||||
const [recibos, setRecibos] = useState<Recibo[]>([]);
|
const [recibos, setRecibos] = useState<Recibo[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{ header: "Folio", key: "folio", width: 15 },
|
||||||
|
{ header: "Monto", key: "monto", width: 15 },
|
||||||
|
{ header: "Fecha Recibo", key: "fechaRecibo", width: 18 },
|
||||||
|
{ header: "Fecha Registro", key: "fechaRegistro", width: 22 },
|
||||||
|
{ header: "Usuario", key: "usuario", width: 20 },
|
||||||
|
];
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!desde || !hasta) return;
|
if (!desde || !hasta) return;
|
||||||
|
|
||||||
@@ -61,7 +69,8 @@ function PorRecibos({ desde, hasta }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ position: "relative" }}>
|
<div style={{ position: "relative" }}>
|
||||||
{recibos.length > 0 && <DownloadReporteXLSX />}
|
{recibos.length > 0 && <DownloadReporteXLSX data={recibos} columns={columns} />}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
overflow: "auto",
|
overflow: "auto",
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ function PorServicio({ desde, hasta }: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ position: "relative" }}>
|
<div style={{ position: "relative" }}>
|
||||||
{servicios.length > 0 && <DownloadReporteXLSX />}
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ export default function BarNavigation() {
|
|||||||
>
|
>
|
||||||
<li>Activos y en Mantenimiento</li>
|
<li>Activos y en Mantenimiento</li>
|
||||||
</Link>
|
</Link>
|
||||||
<Link
|
{/* <Link
|
||||||
href="/Mensajes"
|
href="/Mensajes"
|
||||||
className="links"
|
className="links"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
@@ -132,7 +132,7 @@ export default function BarNavigation() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<li>Mensajes</li>
|
<li>Mensajes</li>
|
||||||
</Link>
|
</Link> */}
|
||||||
<Link
|
<Link
|
||||||
href="/Programas"
|
href="/Programas"
|
||||||
className="links"
|
className="links"
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export default function BarNavigationServicio() {
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li className="subMenu" onClick={toggleMenu}>
|
{/* <li className="subMenu" onClick={toggleMenu}>
|
||||||
<Link
|
<Link
|
||||||
href="/Mensajes"
|
href="/Mensajes"
|
||||||
className="links"
|
className="links"
|
||||||
@@ -111,7 +111,7 @@ export default function BarNavigationServicio() {
|
|||||||
>
|
>
|
||||||
<span>Mensajes</span>
|
<span>Mensajes</span>
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li> */}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import Image from "next/image";
|
||||||
|
import "./creadores.css";
|
||||||
|
|
||||||
|
interface props{
|
||||||
|
title:string;
|
||||||
|
img:string;
|
||||||
|
width:number;
|
||||||
|
height:number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CreatorCard({title,img,width,height}:props) {
|
||||||
|
return (
|
||||||
|
<div className="card">
|
||||||
|
<div className="imageWrapper">
|
||||||
|
<Image
|
||||||
|
src={img}
|
||||||
|
alt="IO"
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
className="creators"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<h1 className="title">{title}</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
+3
-25
@@ -1,5 +1,5 @@
|
|||||||
import Image from "next/image";
|
|
||||||
import "./creadores.css";
|
import "./creadores.css";
|
||||||
|
import CreatorCard from "./CreatorCard";
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
return (
|
return (
|
||||||
@@ -7,31 +7,9 @@ export default function Page() {
|
|||||||
<div className="container" style={{ display: "flex", justifyContent: "center", gap: "4rem" }}>
|
<div className="container" style={{ display: "flex", justifyContent: "center", gap: "4rem" }}>
|
||||||
<div className="img"></div>
|
<div className="img"></div>
|
||||||
|
|
||||||
<div className="card">
|
<CreatorCard title="IO" img="/IO.png" width={150} height={200} />
|
||||||
<div className="imageWrapper">
|
<CreatorCard title="CarloSpak" img="/SPAK.png" width={160} height={100} />
|
||||||
<Image
|
|
||||||
src="/IO.png"
|
|
||||||
alt="IO"
|
|
||||||
width={160}
|
|
||||||
height={200}
|
|
||||||
className="creators"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<h1 className="title">IO</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="card">
|
|
||||||
<div className="imageWrapper">
|
|
||||||
<Image
|
|
||||||
src="/SPAK.png"
|
|
||||||
alt="Carlos Pak"
|
|
||||||
width={160}
|
|
||||||
height={100}
|
|
||||||
className="creators"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<h1 className="title">Carlos Pak</h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Generated
+1010
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.11.0",
|
"axios": "^1.11.0",
|
||||||
|
"exceljs": "^4.4.0",
|
||||||
|
"file-saver": "^2.0.5",
|
||||||
"js-cookie": "^3.0.5",
|
"js-cookie": "^3.0.5",
|
||||||
"next": "^16.0.7",
|
"next": "^16.0.7",
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
@@ -21,6 +23,7 @@
|
|||||||
"sweetalert2-react-content": "^5.1.1"
|
"sweetalert2-react-content": "^5.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/file-saver": "^2.0.7",
|
||||||
"@types/js-cookie": "^3.0.6",
|
"@types/js-cookie": "^3.0.6",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
|
|||||||
Reference in New Issue
Block a user