Skip to content

Commit

Permalink
Merge branch 'dev' into TUP-90-Pesta-a-Pagos
Browse files Browse the repository at this point in the history
Signed-off-by: Yoel Marain <[email protected]>
  • Loading branch information
yoelmarain authored Oct 16, 2024
2 parents 082783b + 39599f2 commit 49ea488
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 58 deletions.
75 changes: 75 additions & 0 deletions FrontAdmin/src/API/Inhabilitaciones.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Cookies from 'js-cookie';

export const getInhabilitaciones = async (limit: number, offset: number) => {
try {
const token = Cookies.get('tokennn');
const response = await fetch(`http://localhost:8000/api/alumnos/inhabilitados?limit=${limit}&offset=${offset}` , {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
});

if (response.ok) {
const data = await response.json();
return data;
} else {
throw new Error('Error en la respuesta del servidor');
}
} catch (error) {
throw new Error('Network error: ' + error);
}
};


export const getAlumnosaInhabilitar = async () => {
try {
const token = Cookies.get('tokennn');
const response = await fetch(`http://localhost:8000/api/alumnos/alumnos-a-inhabilitar` , {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
});

if (response.ok) {
const data = await response.json();
return data;
} else {
throw new Error('Error en la respuesta del servidor');
}
} catch (error) {
throw new Error('Network error: ' + error);
}

};

export const inhabilitarAlumno = async (legajo: number) => {
try {
const token = Cookies.get('tokennn');
const response = await fetch(`http://localhost:8000/api/alumnos/alumno-a-inhabilitar/${legajo}/` , {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
});
if (response.ok) {
if (response.status === 204) {
// No hay contenido en la respuesta
return {};
} else {
const data = await response.json();
return data;
}
} else {
throw new Error('Error en la respuesta del servidor');
}
} catch (error) {
throw new Error('Network error: ' + error);
}

};

25 changes: 25 additions & 0 deletions FrontAdmin/src/API/Montos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,28 @@ export const loadPDF = async (id :string,file: File) => {
throw new Error('Network error: ' + JSON.stringify(error));
}
};

export const deleteCompromiso = async (id: number) => {
try {
const token = Cookies.get('tokennn');

const response = await fetch(`http://localhost:8000/api/compromisos/${id}/`, {
method: 'DELETE',
headers: {
Authorization: `Bearer ${token}`,
},
});

if (response.ok) {
const data = await response.json();
return data;
} else {
const errorResponse = await response.json();
throw new Error(
'Error en la respuesta del servidor: ' + JSON.stringify(errorResponse)
);
}
} catch (error) {
throw new Error('Network error: ' + error);
}
}
20 changes: 14 additions & 6 deletions FrontAdmin/src/components/Pages/Configuracion/Configuracion.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grid, GridItem, Flex, Button, Text, Box } from '@chakra-ui/react';
import { Grid, GridItem, Flex, Button, Text, Box, Spinner } from '@chakra-ui/react';
import Montos from './Montos/Montos';
import { FetchMontos } from '../../../API/Montos';
import { useEffect, useState } from 'react';
Expand All @@ -13,8 +13,10 @@ function Configuracion() {
const [totalCount, setTotalCount] = useState(0);

const fetchMontos = async (offset: number, limit: number) => {
setLoading(true);
try {
const data = await FetchMontos(offset, limit);

setMontos(data.results);
setTotalCount(data.count);
} catch (error) {
Expand Down Expand Up @@ -46,11 +48,17 @@ function Configuracion() {

return (
<Grid templateColumns={{ base: '1fr', md: 'repeat(2, 1fr)' }} pb="80px">
<GridItem colSpan={2} mt="20px">
<Montos compromisos={montos} fetchMontos={() => fetchMontos(offset, limit)} />
</GridItem>
<GridItem colSpan={{ base: 1, md: 2 }}>
<NewInterfaz compromisos={montos} />
<GridItem colSpan={2} mt="20px">
{loading ? (
<Flex justifyContent="center" alignItems="center" height="100%">
<Spinner size="xl" />
</Flex>
) : (
<>
<Montos compromisos={montos} fetchMontos={() => fetchMontos(offset, limit)} />
<NewInterfaz compromisos={montos} fetchMontos={() => fetchMontos(offset, limit)} />
</>
)}
</GridItem>
<Box position="fixed" bottom="0" width="90%" bg="white" p="10px" boxShadow="md">
<Flex justifyContent="space-between">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ import {
ModalBody,
ModalCloseButton,
useDisclosure,
Spinner,
} from '@chakra-ui/react';
import Cookies from 'js-cookie';
import { useEffect, useState } from 'react';

import { deleteCompromiso } from '../../../../API/Montos';
import ModalComponent from '../../../Modal/ModalConfirmarCambios';
interface Compromiso {
anio: string | number | Date;
fecha_carga_comp_pdf: string;
Expand All @@ -38,24 +40,27 @@ interface Compromiso {
fecha_vencimiento_1: number;
fecha_vencimiento_2: number;
fecha_vencimiento_3: number;

}

interface CardCargaProps {
compromisos: Compromiso[];
fetchMontos: () => void;
}

const NewInterfaz = ({ compromisos }: CardCargaProps) => {
const NewInterfaz = ({ compromisos, fetchMontos }: CardCargaProps) => {
const [montos, setMontos] = useState<Compromiso[]>([]);
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
const { isOpen, onOpen, onClose } = useDisclosure();
const { isOpen: isConfirmOpen, onOpen: onConfirmOpen, onClose: onConfirmClose } = useDisclosure(); // Estado para el modal de confirmación
const [isDeleting, setIsDeleting] = useState(false); // Estado de carga para la eliminación

useEffect(() => {
const sortedMontos = [...compromisos].sort((a, b) => {
const dateA = new Date(a.fecha_carga_comp_pdf);
const dateB = new Date(b.fecha_carga_comp_pdf);
return dateB.getTime() - dateA.getTime();
});
console.log('Montos ordenados:', sortedMontos);
setMontos(sortedMontos);
}, [compromisos]);

Expand All @@ -82,6 +87,24 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => {
onClose();
};

const handleDeleteLastCompromiso = async () => {
if (montos.length === 0) return;

const lastCompromiso = montos[0];
try {
setIsDeleting(true);
await deleteCompromiso(lastCompromiso.id_comp_pago);
fetchMontos();
onConfirmClose();
} catch (error) {
console.error('Error al eliminar el compromiso:', error);
} finally {
fetchMontos();
onConfirmClose();
setIsDeleting(false);
}
};

return (
<Box
borderWidth="1px"
Expand All @@ -101,7 +124,7 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => {
<Tr>
<Th p={1}>Año/ Cuatrimestre</Th>
<Th p={2}>Matrícula</Th>
<Th p={2}>Montos</Th>
<Th p={2}>Montos</Th>
<Th p={1}>Dia de vencimiento</Th>
<Th p={1}>Fecha Ult Modif.</Th>
<Th p={1}>Acciones</Th>
Expand All @@ -116,8 +139,6 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => {
monto.cuatrimestre}
</Td>
<Td p={2}>{' $ ' + monto.matricula}</Td>


<Td p={2}>
<Box>
<Text fontWeight="bold">Monto Completo: {' $ ' + monto.monto_completo}</Text>
Expand All @@ -129,31 +150,36 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => {
</Box>
</Td>
<Td p={1}>
<Text >
<Text>
1er Vencimiento: <Box as="span" fontWeight="bold" color="black">{monto.fecha_vencimiento_1}</Box>
</Text>
<Text >
<Text>
2do Vencimiento: <Box as="span" fontWeight="bold" color="black">{monto.fecha_vencimiento_2}</Box>
</Text>
<Text >
<Text>
3er Vencimiento: <Box as="span" fontWeight="bold" color="black">{monto.fecha_vencimiento_3}</Box>
</Text>
</Td>

<Td p={1}>
{new Date(monto.fecha_carga_comp_pdf).toLocaleString(
'es-ES',
{ dateStyle: 'short', timeStyle: 'short' }
)}
</Td>

<Td p={1}>
<Button
colorScheme="blue"
onClick={() => handleViewPdf(monto.archivo_pdf_url)}
>
Ver pdf
</Button>
<Flex direction="column" gap={2}>
<Button
colorScheme="blue"
onClick={() => handleViewPdf(monto.archivo_pdf_url)}
>
Ver pdf
</Button>
{index === 0 && (
<Button colorScheme="red" onClick={onConfirmOpen} isLoading={isDeleting}>
Eliminar
</Button>
)}
</Flex>
</Td>
</Tr>
))}
Expand All @@ -178,9 +204,14 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => {
</ModalFooter>
</ModalContent>
</Modal>
<ModalComponent
isOpen={isConfirmOpen}
onClose={onConfirmClose}
texto="¿Está seguro de que desea eliminar el último compromiso cargado?"
confirmar={handleDeleteLastCompromiso}
/>
</Box>
);
};

export default NewInterfaz;

11 changes: 11 additions & 0 deletions FrontAdmin/src/components/Pages/Estadisticas/AlumnosBaja.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import TablaAlumnos from './SubPages/TablaAlumnos';
import { FetchFirmantes } from '../../../API/AlumnosCompromisoPago';

const AlumnosBaja = () => {
return (
<TablaAlumnos fetchFunction={FetchFirmantes} title="Alumnos que se dieron de baja" />
);
};

export default AlumnosBaja;
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Tabs, TabList, Tab, TabPanels, TabPanel } from '@chakra-ui/react';
import TablaAlumnos from './TablaAlumnos';
import { FetchFirmantes } from '../../../../API/AlumnosCompromisoPago';
import { FetchNoFirmantes } from '../../../../API/AlumnosCompromisoPago';
import Pestaña from './Pestaña';

const AlumnosCompromisoPago: React.FC = () => {
const [index, setIndex] = useState(0); // Estado para manejar la pestaña seleccionada
Expand All @@ -11,32 +12,8 @@ const AlumnosCompromisoPago: React.FC = () => {
<div>
<Tabs variant="enclosed" index={index} onChange={setIndex} isLazy>
<TabList display="flex" justifyContent="center" alignItems="center" borderBottom="2px solid" borderColor="gray.200">
<Tab
_selected={{
borderBottom: "2px solid",
borderColor: "blue.500",
color: "blue.500",
borderTop: "none",
borderLeft: "none",
borderRight: "none"
}}
_focus={{ boxShadow: "none" }}
>
Firmaron
</Tab>
<Tab
_selected={{
borderBottom: "2px solid",
borderColor: "blue.500",
color: "blue.500",
borderTop: "none",
borderLeft: "none",
borderRight: "none"
}}
_focus={{ boxShadow: "none" }}
>
No firmaron
</Tab>
<Pestaña title="Firmaron" />
<Pestaña title="No Firmaron" />
</TabList>

<TabPanels>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export default function Listado() {

const handleNextPage2 = () => {
if (offset2 + limit2 < totalabonaron) {
setOffset1(offset2 + limit2);
setOffset2(offset2 + limit2);
}
};

const handlePreviousPage2 = () => {
if (offset2 > 0) {
setOffset1(offset2 - limit2);
setOffset2(offset2 - limit2);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Tabla: React.FC<TablaProps> = ({ headers, data }) => {
'DNI': 'user',
'Estado financiero': 'estado_financiero',
'Legajo': 'legajo',
'Desde': 'fecha_inhabilitacion'
};
const navigate = useNavigate();

Expand Down
Loading

0 comments on commit 49ea488

Please sign in to comment.