Skip to content

Commit

Permalink
Tup 90 pesta a pagos (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelmarain authored Oct 16, 2024
2 parents 39599f2 + 49ea488 commit 4e194fb
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 12 deletions.
2 changes: 1 addition & 1 deletion FrontAdmin/src/API-Alumnos/Pagos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const FetchPostPago = async (
const token = Cookies.get('tokennn');
const dni = Cookies.get('dni');

const response = await fetch(`http://localhost:8000/api/pagos/alumno/${dni}`, {
const response = await fetch(`http://localhost:8000/api/pagos/alumno/${dni}/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
27 changes: 27 additions & 0 deletions FrontAdmin/src/API/Pagos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Cookies from 'js-cookie';

export const GetPagos = async (year?: string, month?: string) => {

const token = Cookies.get('tokennn');
const url = `http://localhost:8000/api/estadisticas/pagos_mes/${year}/${month}/`;

const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
}
});

if (response.ok) {
const data = await response.json();
return data;
} else {
const errorData = await response.json();
throw new Error(
`Error en la respuesta del servidor: ${errorData.message}`
);
}
};

export default GetPagos;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Listado() {
full_name: string;
estado_financiero: string;
};
const { fecha } = useParams<{ fecha: string }>();
const {fecha} = useParams<{ fecha: string }>();
const [abonaron, setAbonaron] = useState<Alumno[]>([]);
const [totalabonaron, setTotalAbonaron] = useState<number>(0);
const [noAbonaron, setNoAbonaron] = useState<Alumno[]>([]);
Expand Down Expand Up @@ -82,6 +82,7 @@ export default function Listado() {
fetchAbonaron(fecha);
}, [limit2, offset2, fecha, filter]);


const handleFilterChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setFilter(event.target.value);
};
Expand Down Expand Up @@ -127,10 +128,10 @@ export default function Listado() {
{loading2 ? <Flex justifyContent={"center"} w={"100%"}> <Spinner size="xl" /> </Flex>:
abonaron.length > 0 ? <Flex direction={"column"} w={"100%"}>
<Flex direction={"row"} w={"100%"} justifyContent={"center"} gap={4} mb={3} >
<Tag bg="secundaryBg" w={"100%"} size="lg" fontSize={18} display="flex" justifyContent="center" fontWeight={"bold"} fontFamily={"serif"}> Periodo: {fecha} </Tag>
<Tag bg="secundaryBg" w={"100%"} size="lg" fontSize={18} display="flex" justifyContent="center" fontWeight={"bold"} fontFamily={"serif"}> Total: {totalNoAbonaron}</Tag>
<Tag bg="secundaryBg" w={"100%"} size="lg" p={"10px"} fontSize={18} display="flex" justifyContent="center" fontWeight={"bold"} fontFamily={"serif"}> Periodo: {fecha} </Tag>
<Tag bg="secundaryBg" w={"100%"} size="lg" fontSize={18} display="flex" justifyContent="center" fontWeight={"bold"} fontFamily={"serif"}> Total: {totalabonaron}</Tag>
</Flex>
<Input type="text" placeholder="Buscar..." w={"50%"} mb={4} />
<Input type="text" value={filter} onChange={handleFilterChange} placeholder="Buscar por Apellido y Nombre, Legajo o DNI..." w={"100%"} mb={4} />
<Tabla headers={headers} data={abonaron} />
<Box bottom="0" width="100%" bg="white" p="10px" mt={4} boxShadow="md" >
<Flex justifyContent="space-between" alignItems={"center"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,34 @@ import React, { useState } from 'react';
import { Heading, Input, Flex, Button } from '@chakra-ui/react';
import {formatoFechaAAAAMMaMMAAAA} from '../../../../../utils/general';
import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';

export default function Select() {
type SelectProps = {
page: string;
}

const Select: React.FC<SelectProps> = ({ page }) => {
const [selectedMonth, setSelectedMonth] = useState('');
const [fecha, setFecha] = useState('');
const navigate = useNavigate();

useEffect(() => {
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
setSelectedMonth(`${year}-${month}`);
}, []);

const handleMonthChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedMonth(event.target.value);
setFecha(formatoFechaAAAAMMaMMAAAA(event.target.value));
};

const handleButtonClick = () => {
const [year, month] = selectedMonth.split('-');
if (page === 'cuotas') {
navigate(`/admin/estadisticas/cuotas/${month}-${year}`);
} else if (page === 'pagos') {
navigate(`/admin/estadisticas/pagos/${year}-${month}`);
}
};

return (
Expand All @@ -26,9 +44,11 @@ export default function Select() {
/>
<Flex justifyContent={"flex-end"} mt={1}>
<Button colorScheme='blue' variant={"solid"}
onClick={() => navigate(`/admin/estadisticas/cuotas/${fecha}`)}
onClick={handleButtonClick}
>Solicitar</Button>
</Flex>
</Flex>
);
};

export default Select;
137 changes: 137 additions & 0 deletions FrontAdmin/src/components/Pages/Estadisticas/SubPages/Pagos/Pagos.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { useEffect } from "react";
import { useParams } from "react-router-dom"
import GetPagos from "../../../../../API/Pagos";
import { useState } from "react";
import {
Button,
IconButton,
Box,
Flex,
Text,
Table,
Thead,
Tbody,
Tr,
Th,
Td,
Tag,
Spinner,
} from '@chakra-ui/react'
import { ViewIcon } from '@chakra-ui/icons'
import { IoEyeOutline } from "react-icons/io5";

type Pago = {
fecha: string;
monto: number;
};

type Alumno = {
nombre: string;
total: number;
pagos: Pago[];
};

type Data = {
total_mes: number;
alumnos: {
[dni: string]: Alumno;
};
};

export default function Pagos() {

const { fecha } = useParams<{ fecha: string }>();
const [data, setData] = useState<Data | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [selectedDni, setSelectedDni] = useState<string | null>(null);

const handleDetailsClick = (dni: string) => {
if (selectedDni === dni) {
setSelectedDni(null);
return;
}
setSelectedDni(dni);
};

useEffect (() => {
const [year, month] = fecha ? fecha.split('-') : [undefined, undefined];
const fetchPagos = async () => {
try {
console.log('Buscando pagos de: ', year, month);
const datos = await GetPagos(year, month);
setData(datos);
console.log(data);
} catch (error) {
console.log(error);
} finally {
setLoading(false);
}
};
fetchPagos();
}, [fecha]);

return (
<Flex w={"100%"} justifyContent={"center"} alignItems={"center"} flex={1}>
<Box w={"100%"} p={4}>
{loading === true ? <Flex justifyContent={"center"} w={"100%"}> <Spinner size="xl" /> </Flex> :
data && (
<>
<Box flexDirection={"row"} display={"flex"} justifyContent={"space-around"} w={"100%"} >
<Tag bg="secundaryBg" flexDirection={"column"} w={"40%"} p={2} fontWeight="bold" fontFamily={"serif"} >
<Text fontSize={18}>Periodo:</Text>
<Text fontSize={30}>{fecha}</Text>
</Tag>
<Tag bg="secundaryBg" flexDirection={"column"} w={"40%"} p={2} fontWeight="bold" fontFamily={"serif"} >
<Text fontSize={18}>Total Recaudado:</Text>
<Text fontSize={30}>{ "$ " + new Intl.NumberFormat('es-ES', { notation: "compact", compactDisplay: "short" }).format(data.total_mes)}</Text>
</Tag>
</Box>
<Table variant="simple" mt={6} borderWidth={1} borderColor={'grey.700'}>
<Thead>
<Tr>
<Th textAlign="center" fontFamily="Helvetica" fontWeight="900">Apellido y Nombre</Th>
<Th textAlign="center" fontFamily="Helvetica" fontWeight="900">DNI</Th>
<Th textAlign="center" fontFamily="Helvetica" fontWeight="900">Total</Th>
<Th textAlign="center" fontFamily="Helvetica" fontWeight="900" w={"20%"}>Ver Detalles</Th>
</Tr>
</Thead>
<Tbody>
{Object.keys(data.alumnos).map((dni) => (
<Tr key={dni}>
<Td textAlign="center" > {data.alumnos[dni].nombre}</Td>
<Td textAlign="center" >{new Intl.NumberFormat('es-ES').format(parseInt(dni))}</Td>
<Td textAlign="center" >{ "$ " + new Intl.NumberFormat('es-ES').format(data.alumnos[dni].total)}</Td>
<Td textAlign="center" >
<Button bg='transparent' _hover='transparent' m="0px" p="0px" onClick={() => handleDetailsClick(dni)}><IoEyeOutline size="22px"> </IoEyeOutline> </Button>
</Td>
</Tr>
))}
</Tbody>
</Table>
{selectedDni && (
<Box mt={6} >
<Table variant="simple" borderWidth={0.5} borderColor={'grey.700'}>
<Thead>
<Tr>
<Th textAlign="center">Fecha Pago</Th>
<Th textAlign="center">Monto Confirmado</Th>
</Tr>
</Thead>
<Tbody>
{data.alumnos[selectedDni].pagos.map((pago, index) => (
<Tr key={index}>
<Td textAlign="center">{pago.fecha}</Td>
<Td textAlign="center">{ "$ " + new Intl.NumberFormat('es-ES').format(pago.monto)}</Td>
</Tr>
))}
</Tbody>
</Table>
</Box>
)}
</>
)}
</Box>
</Flex>
);

}
2 changes: 1 addition & 1 deletion FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const ITEMS_SUBMENU = [
{ url: 'cuotas', title: 'Cuotas' , tooltip: 'Alumnos que abonaron/no abonaron una respectiva cuota' },
{ url: 'matricula', title: 'Matricula' },
{ url: 'alumnos-que-firmaron-compromiso-de-pago', title: 'Compromiso de Pago'},
{ url: '#', title: 'Pagos' },
{ url: 'pagos', title: 'Pagos' },
{
url: 'alumnos-que-cursan-materia',
title: 'Alumnos que cursan una materia',
Expand Down
14 changes: 12 additions & 2 deletions FrontAdmin/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import path from 'path';
import EstadoCuenta from './components/Pages-Alumnos/EstadoCuenta/EstadoCuenta';
import Sysadmin from './components/Pages/SysAdmin/SysAdmin';
import Matricula from './components/Pages/Estadisticas/SubPages/Matricula';
import Pagos from './components/Pages/Estadisticas/SubPages/Pagos/Pagos';
import Inhabilitados from './components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones';
import AlumnosBaja from './components/Pages/Estadisticas/AlumnosBaja';


const routes = [
{
path: 'alumnos',
Expand Down Expand Up @@ -82,14 +82,24 @@ const routes = [
},
{
path: 'cuotas',
element: <Select />,
element: <Select page={'cuotas'} />,
rol: 'admin',
},
{
path : 'cuotas/:fecha',
element: <Listado />,
rol: 'admin',
},
{
path: 'pagos',
element: <Select page={'pagos'} />,
rol: 'admin',
},
{
path: 'pagos/:fecha',
element: <Pagos />,
rol: 'admin',
},
{
path: 'inhabilitaciones',
element: <Inhabilitados />,
Expand Down

0 comments on commit 4e194fb

Please sign in to comment.