Skip to content

Commit

Permalink
Pagos (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelmarain authored Nov 10, 2024
2 parents f1edeac + ccf6dd6 commit 05f1659
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 12 deletions.
4 changes: 2 additions & 2 deletions FrontAdmin/src/API/Pagos.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Cookies from 'js-cookie';

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

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

const response = await fetch(url, {
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function Deuda() {
<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 && (
data && Object.keys(data.alumnos).length > 0 ? (
<>
<Box flexDirection={"row"} display={"flex"} justifyContent={"space-around"} w={"100%"} >
<Tag bg="secundaryBg" flexDirection={"column"} w={"60%"} p={2} fontWeight="bold" fontFamily={"serif"} >
Expand Down Expand Up @@ -121,7 +121,12 @@ function Deuda() {
</Box>
)}
</>
)}
): null}
{data && Object.keys(data.alumnos).length === 0 ? (
<Flex justifyContent={"center"} w={"100%"} mt={6}>
<Text fontSize={24}>No hay deudas</Text>
</Flex>
) : null}
</Box>
</Flex>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Pago = {

export default function Pagos() {

const { fecha } = useParams<{ fecha: string }>();
const { fecha_inicio, fecha_fin } = useParams<{ fecha_inicio: string, fecha_fin: string }>();
const [data, setData] = useState<Data | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [selectedDni, setSelectedDni] = useState<string | null>(null);
Expand All @@ -54,11 +54,9 @@ export default function Pagos() {
};

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);
const datos = await GetPagos(fecha_inicio, fecha_fin);
setData(datos);
console.log(data);
} catch (error) {
Expand All @@ -68,7 +66,7 @@ export default function Pagos() {
}
};
fetchPagos();
}, [fecha]);
}, [fecha_inicio, fecha_fin]);

return (
<Flex w={"100%"} justifyContent={"center"} alignItems={"center"} flex={1}>
Expand All @@ -79,7 +77,7 @@ export default function Pagos() {
<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>
<Text fontSize={30}>{`${fecha_inicio} / ${fecha_fin}`}</Text>
</Tag>
<Tag bg="secundaryBg" flexDirection={"column"} w={"40%"} p={2} fontWeight="bold" fontFamily={"serif"} >
<Text fontSize={18}>Total Recaudado:</Text>
Expand Down
113 changes: 113 additions & 0 deletions FrontAdmin/src/components/Pages/Estadisticas/SubPages/Pagos/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import React, { useState } from 'react';
import { Heading, Input, Flex,Button , Text } from '@chakra-ui/react';
import {formatoFechaISOaAAAAMMDD} from '../../../../../utils/general';
import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';

function SelectPagos () {
const [selectedStartMonth, setSelectedStartMonth] = useState('');
const [selectedEndMonth, setSelectedEndMonth] = useState('');
const [mesInicio, setmesInicio] = useState('');
const [mesFin, setmesFin] = useState('');
const [today, setToday] = useState(new Date());
const navigate = useNavigate();

useEffect(() => {
if (selectedStartMonth && selectedEndMonth) {
navigate(`/admin/estadisticas/pagos/${selectedStartMonth}/${selectedEndMonth}`);
}
}, [selectedStartMonth, selectedEndMonth]);

const handleMonthStartChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const [year, month, day] = event.target.value.split('-');
const formattedDate = `${day}-${month}-${year}`;
setSelectedStartMonth(formattedDate);
setmesInicio(event.target.value);
};

const handleMonthEndChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const [year, month, day] = event.target.value.split('-');
const formattedDate = `${day}-${month}-${year}`;
setSelectedEndMonth(formattedDate);
setmesFin(event.target.value);
};

const handleButtonClick = () => {
const formattedStartMonth = selectedStartMonth.split('-').reverse().join('-');
const formattedEndMonth = selectedEndMonth.split('-').reverse().join('-');
setSelectedStartMonth(formattedStartMonth);
setSelectedEndMonth(formattedEndMonth);
};

const handleMesActual = () => {
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const startMonth = `01-${month}-${year}`;
const endMonth = `${day}-${month}-${year}`;
setSelectedStartMonth(startMonth);
setSelectedEndMonth(endMonth);
};

const handleCuatrimestreActual = () => {
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const startMonth = `01-08-${year}`;
const endMonth = `${day}-${month}-${year}`;
setSelectedStartMonth(startMonth);
setSelectedEndMonth(endMonth);
};

const handleAnioActual = () => {
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0');
const day = String(today.getDate()).padStart(2, '0');
const startMonth = `01-03-${year}`;
const endMonth = `${day}-${month}-${year}`;
setSelectedStartMonth(startMonth);
setSelectedEndMonth(endMonth);
};


return (
<Flex gap={2} direction={"column"}>
<Heading fontSize={22} mt={6}>Seleccione un periodo</Heading>
<Flex direction={'row'} w={'100%'} gap={4} mt={2}>
<Button w={'100%'} variant={'light'}
onClick={handleMesActual}>
Mes Actual
</Button >
<Button variant={'light'} w={'100%'}
onClick={handleCuatrimestreActual}>
Cuatrimestre Actual
</Button>
<Button variant={'light'} w={'100%'}
onClick={handleAnioActual}>
Año Actual
</Button>
</Flex>
<Flex mt={4} gap={4}>
<Input
type="date"
value={mesInicio}
onChange={handleMonthStartChange}
/>
<Text> - </Text>
<Input
type="date"
value={mesFin}
onChange={handleMonthEndChange}
/>
</Flex>
<Flex justifyContent={"flex-end"} mt={1}>
<Button colorScheme='blue' variant={"solid"}
onClick={handleButtonClick}
isDisabled={!selectedStartMonth || !selectedEndMonth}
>Solicitar</Button>
</Flex>
</Flex>
);
};

export default SelectPagos;
5 changes: 3 additions & 2 deletions FrontAdmin/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import FichaAlumno from './components/Pages/Alumnos/SubPages/FichaAlumno'; impor
import ListadoAlumnosQueCursanMateria from './components/Pages/Estadisticas/SubPages/PaginasMaterias/ListadoAlumnosQueCursanMateria';
import AlumnosCompromisoPago from './components/Pages/Estadisticas/SubPages/Alumnos-que-fimaron-compromiso-de-pago';
import Select from './components/Pages/Estadisticas/SubPages/Cuotas/Select';
import SelectPagos from './components/Pages/Estadisticas/SubPages/Pagos/Select';
import Listado from './components/Pages/Estadisticas/SubPages/Cuotas/Listado';
import path from 'path';
import EstadoCuenta from './components/Pages-Alumnos/EstadoCuenta/EstadoCuenta';
Expand Down Expand Up @@ -94,11 +95,11 @@ const routes = [
},
{
path: 'pagos',
element: <Select page={'pagos'} />,
element: <SelectPagos />,
rol: 'admin',
},
{
path: 'pagos/:fecha',
path: 'pagos/:fecha_inicio/:fecha_fin',
element: <Pagos />,
rol: 'admin',
},
Expand Down

0 comments on commit 05f1659

Please sign in to comment.