You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
9.1 KiB
277 lines
9.1 KiB
import React, { useEffect, useState } from 'react'
|
|
import { useParams, Link } from 'react-router-dom'
|
|
import classe from '../assets/AllStyleComponents.module.css'
|
|
import classeHome from '../assets/Home.module.css'
|
|
import Paper from '@mui/material/Paper'
|
|
import { Button, Modal, Box } from '@mui/material'
|
|
import { IoMdReturnRight } from 'react-icons/io'
|
|
import jsPDF from 'jspdf'
|
|
import autoTable from 'jspdf-autotable'
|
|
import { FaDownload } from 'react-icons/fa'
|
|
import logoRelerev1 from '../assets/logorelever.png'
|
|
import logoRelerev2 from '../assets/logorelever2.png'
|
|
|
|
const Resultat = () => {
|
|
const { niveau, scolaire } = useParams()
|
|
const formData = {
|
|
niveau,
|
|
scolaire
|
|
}
|
|
const [etudiants, setEtudiants] = useState([])
|
|
const [mention, setMention] = useState([])
|
|
const [session, setSession] = useState([])
|
|
|
|
useEffect(() => {
|
|
window.notes.getMoyenne(formData).then((response) => {
|
|
setEtudiants(response)
|
|
})
|
|
window.noteRepech.getMoyenneRepech(formData).then((response) => {
|
|
setSession(response)
|
|
})
|
|
window.mention.getMention().then((response) => {
|
|
setMention(response)
|
|
})
|
|
}, [])
|
|
|
|
let dataToMap = []
|
|
|
|
function returnmention(id) {
|
|
let mentions
|
|
for (let index = 0; index < mention.length; index++) {
|
|
if (mention[index].id == id) {
|
|
mentions = mention[index].nom
|
|
}
|
|
}
|
|
return mentions
|
|
}
|
|
|
|
function checkNull(params) {
|
|
if (params == null || params == undefined) {
|
|
return null
|
|
}
|
|
return params
|
|
}
|
|
|
|
const print = () => {
|
|
const generatePDF = () => {
|
|
try {
|
|
const pdf = new jsPDF({
|
|
orientation: 'portrait',
|
|
unit: 'mm',
|
|
format: 'a4'
|
|
})
|
|
|
|
pdf.addImage(logoRelerev1, 'PNG', 10, 5, 40, 20)
|
|
pdf.addImage(logoRelerev2, 'PNG', 175, 5, 30, 30)
|
|
|
|
// Ajouter le texte entre les logos
|
|
pdf.setFontSize(10)
|
|
pdf.text('REPOBLIKAN\'I MADAGASIKARA', 105, 10, { align: 'center' })
|
|
pdf.text('Fitiavana-Tanindrazana-Fandrosoana', 105, 14, { align: 'center' })
|
|
pdf.text('********************', 105, 18, { align: 'center' })
|
|
pdf.text('MINISTÈRE DE L\'ENSEIGNEMENT SUPÉRIEUR', 105, 22, { align: 'center' })
|
|
pdf.text('ET DE LA RECHERCHE SCIENTIFIQUE', 105, 26, { align: 'center' })
|
|
pdf.text('********************', 105, 30, { align: 'center' })
|
|
pdf.text('UNIVERSITÉ DE TOAMASINA', 105, 34, { align: 'center' })
|
|
pdf.text('ÉCOLE SUPÉRIEURE POLYTECHNIQUE', 105, 38, { align: 'center' })
|
|
|
|
// Select the table
|
|
autoTable(pdf, {
|
|
html: '#myTable2',
|
|
startY: 50, // décalé vers le bas pour laisser la place aux logos et texte
|
|
theme: 'grid',
|
|
headStyles: {
|
|
fillColor: 'gray',
|
|
halign: 'center',
|
|
fontStyle: 'bold',
|
|
textColor: 'black'
|
|
},
|
|
styles: { fontSize: 8, cellPadding: 2, halign: 'center' }
|
|
})
|
|
|
|
pdf.save(`Resultat-${niveau}-${scolaire}.pdf`)
|
|
} catch (error) {
|
|
console.error('Error generating PDF:', error)
|
|
}
|
|
}
|
|
generatePDF()
|
|
}
|
|
|
|
function compareSessionNotes(session1, session2) {
|
|
let notes
|
|
if (session2) {
|
|
if (session1 < session2.note) {
|
|
notes = session2.note
|
|
} else {
|
|
notes = session1
|
|
}
|
|
} else {
|
|
notes = session1
|
|
}
|
|
return notes
|
|
}
|
|
|
|
for (let index = 0; index < etudiants.length; index++) {
|
|
let total = 0
|
|
let note = 0
|
|
let totalCredit = 0
|
|
|
|
// Create a new object for each student
|
|
let modelJson = {
|
|
id: '',
|
|
nom: '',
|
|
prenom: '',
|
|
photos: '',
|
|
moyenne: '',
|
|
mention: '',
|
|
anneescolaire: ''
|
|
}
|
|
|
|
for (let j = 0; j < etudiants[index].length; j++) {
|
|
modelJson.id = etudiants[index][j].etudiant_id
|
|
modelJson.nom = etudiants[index][j].nom
|
|
modelJson.prenom = etudiants[index][j].prenom
|
|
modelJson.photos = etudiants[index][j].photos
|
|
modelJson.mention = etudiants[index][j].mention_id
|
|
modelJson.anneescolaire = etudiants[index][j].annee_scolaire
|
|
|
|
// console.log(checkNull(session[index][j]));
|
|
if (session[index]) {
|
|
note +=
|
|
compareSessionNotes(etudiants[index][j].note, checkNull(session[index][j])) *
|
|
etudiants[index][j].credit
|
|
} else {
|
|
note += etudiants[index][j].note * etudiants[index][j].credit
|
|
}
|
|
totalCredit += etudiants[index][j].credit
|
|
}
|
|
|
|
total = note / totalCredit
|
|
modelJson.moyenne = total.toFixed(2)
|
|
|
|
// Add the new object to the array
|
|
dataToMap.push(modelJson)
|
|
}
|
|
|
|
const sortedStudents = dataToMap
|
|
.filter((student) => parseFloat(student.moyenne) >= 10)
|
|
.sort((a, b) => parseFloat(b.moyenne) - parseFloat(a.moyenne))
|
|
|
|
console.log(sortedStudents)
|
|
|
|
return (
|
|
<div className={classe.mainHome}>
|
|
<div className={classeHome.header}>
|
|
<div className={classe.h1style}>
|
|
<div className={classeHome.blockTitle}>
|
|
<h1>
|
|
Resultat des {niveau} en {scolaire}
|
|
</h1>
|
|
<div style={{ display: 'flex', gap: '10px' }}>
|
|
<Link to={'#'} onClick={print}>
|
|
<Button color="warning" variant="contained">
|
|
<FaDownload style={{ fontSize: '20px' }} />
|
|
Télécharger
|
|
</Button>
|
|
</Link>
|
|
<Link to={'#'} onClick={() => window.history.back()}>
|
|
<Button color="warning" variant="contained">
|
|
<IoMdReturnRight style={{ fontSize: '20px' }} />
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className={classeHome.boxEtudiantsCard}>
|
|
<Paper
|
|
sx={{
|
|
height: 'auto',
|
|
width: '100%',
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
padding: '2%'
|
|
}}
|
|
>
|
|
{/* En-tête avec logos et texte */}
|
|
<div
|
|
style={{
|
|
display: 'flex',
|
|
alignItems: 'flex-start',
|
|
justifyContent: 'space-between',
|
|
marginBottom: '20px',
|
|
position: 'relative'
|
|
}}
|
|
>
|
|
<img src={logoRelerev1} alt="Logo gauche" width={70} />
|
|
|
|
{/* Texte centré entre les logos */}
|
|
<div
|
|
style={{
|
|
position: 'absolute',
|
|
left: '50%',
|
|
transform: 'translateX(-50%)',
|
|
textAlign: 'center',
|
|
fontSize: '10px',
|
|
lineHeight: '1.2'
|
|
}}
|
|
>
|
|
<div style={{ fontWeight: 'bold' }}>REPOBLIKAN'I MADAGASIKARA</div>
|
|
<div style={{ fontStyle: 'italic' }}>Fitiavana-Tanindrazana-Fandrosoana</div>
|
|
<div>********************</div>
|
|
<div style={{ fontWeight: 'bold' }}>MINISTÈRE DE L'ENSEIGNEMENT SUPÉRIEUR</div>
|
|
<div style={{ fontWeight: 'bold' }}>ET DE LA RECHERCHE SCIENTIFIQUE</div>
|
|
<div>********************</div>
|
|
<div style={{ fontWeight: 'bold' }}>UNIVERSITÉ DE TOAMASINA</div>
|
|
<div style={{ fontWeight: 'bold' }}>ÉCOLE SUPÉRIEURE POLYTECHNIQUE</div>
|
|
</div>
|
|
|
|
<img src={logoRelerev2} alt="Logo droite" width={90} height={90} />
|
|
</div>
|
|
|
|
{/* Informations du parcours */}
|
|
<div style={{ marginBottom: '15px', fontSize: '12px' }}>
|
|
<div><strong>Parcours :</strong> GC</div>
|
|
<div><strong>Niveau :</strong> {niveau}</div>
|
|
<div><strong>Année Universitaire :</strong> {scolaire}</div>
|
|
</div>
|
|
|
|
<table
|
|
className="table table-bordered table-striped text-center shadow-sm"
|
|
id="myTable2"
|
|
style={{ fontSize: '12px' }}
|
|
>
|
|
<thead className="table-secondary">
|
|
<tr>
|
|
<td colSpan={4} className="py-3" style={{ backgroundColor: '#f8f9fa' }}>
|
|
<h6 style={{ margin: 0, fontWeight: 'bold' }}>
|
|
Résultat de la Deuxième Session : {niveau} admis en L3 par ordre de mérite
|
|
</h6>
|
|
</td>
|
|
</tr>
|
|
<tr style={{ backgroundColor: '#e9ecef' }}>
|
|
<th style={{ width: '10%', fontWeight: 'bold' }}>RANG</th>
|
|
<th style={{ width: '30%', fontWeight: 'bold' }}>NOMS</th>
|
|
<th style={{ width: '40%', fontWeight: 'bold' }}>PRÉNOMS</th>
|
|
<th style={{ width: '20%', fontWeight: 'bold' }}>Moyenne</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{sortedStudents.map((sorted, index) => (
|
|
<tr key={sorted.id}>
|
|
<td style={{ fontWeight: 'bold' }}>{index + 1}.</td>
|
|
<td style={{ textAlign: 'left', paddingLeft: '10px', fontWeight: 'bold' }}>{sorted.nom}</td>
|
|
<td style={{ textAlign: 'left', paddingLeft: '10px' }}>{sorted.prenom}</td>
|
|
<td style={{ fontWeight: 'bold' }}>{sorted.moyenne}</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</Paper>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Resultat
|