forked from CSI-KJSCE/appointment_to_examiner
appointment report generation
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import axios from "axios";
|
||||
import * as XLSX from "xlsx-js-style";
|
||||
import { jsPDF } from "jspdf";
|
||||
import autoTable from "jspdf-autotable";
|
||||
|
||||
|
||||
const CourseConsolidated = () => {
|
||||
const [data, setData] = useState([]);
|
||||
@@ -51,12 +54,87 @@ const CourseConsolidated = () => {
|
||||
if (currentPage > 1) setCurrentPage((prevPage) => prevPage - 1);
|
||||
};
|
||||
|
||||
const createExcelFile = (courseData, courseName) => {
|
||||
const workbook = XLSX.utils.book_new();
|
||||
const worksheet = XLSX.utils.json_to_sheet(courseData);
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, courseName);
|
||||
XLSX.writeFile(workbook, `${courseName.replace(/\s+/g, "_")}_Table.xlsx`);
|
||||
};
|
||||
const generateAppointmentPDF = (courseData, courseName) => {
|
||||
console.log(courseData);
|
||||
const doc = new jsPDF();
|
||||
|
||||
// Add Title
|
||||
doc.setFontSize(16);
|
||||
doc.text(`${courseName} - Appointment Order`, 105, 10, { align: "center" });
|
||||
|
||||
// Add the table for names and roles (Using courseData for this)
|
||||
const table1Data = [
|
||||
...(courseData.oralPracticalTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya Institute of Technology",
|
||||
"Assessment Role",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.reassessmentTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya Institute of Technology",
|
||||
"Reassessment Role",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.paperSettingTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya Institute of Technology",
|
||||
"Paper Setter",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.moderationTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya Institute of Technology",
|
||||
"Moderator",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
...(courseData.pwdPaperSettingTeachers?.map((teacher) => [
|
||||
teacher,
|
||||
"K. J. Somaiya Institute of Technology",
|
||||
"PwD Paper Setter",
|
||||
"Contact Number",
|
||||
]) || []),
|
||||
];
|
||||
|
||||
|
||||
autoTable(doc, {
|
||||
head: [["Name", "Affiliation", "Appointment Role", "Contact No."]],
|
||||
body: table1Data,
|
||||
startY: 20,
|
||||
theme: "grid",
|
||||
});
|
||||
|
||||
// Add the descriptive paragraph
|
||||
const text = `Dear all,\n\nYou have been appointed to jointly act as Paper Setters as mentioned against your name for the following Examination to be held at K. J. Somaiya Institute of Technology, Sion, Mumbai:`;
|
||||
doc.setFontSize(12);
|
||||
doc.text(text, 10, doc.previousAutoTable.finalY + 10);
|
||||
|
||||
// Add the exam details table using `courseData`
|
||||
const table2Data = [
|
||||
["Programme:", courseData.courseName],
|
||||
["Exam Category:", "Regular Examination"],
|
||||
["Exam Type:", courseData.examType],
|
||||
["Exam Season:", "Second Half - Winter Examination 2023"],
|
||||
["Number of Sets Required:", courseData.paperSettingTeachers.length],
|
||||
["Year:", courseData.year],
|
||||
["Semester:", courseData.semester],
|
||||
["Course Name:", courseName],
|
||||
["Course Code:", courseData.courseCode],
|
||||
];
|
||||
|
||||
|
||||
|
||||
autoTable(doc, {
|
||||
body: table2Data,
|
||||
startY: doc.previousAutoTable.finalY + 30,
|
||||
theme: "plain",
|
||||
styles: { lineColor: [0, 0, 0], lineWidth: 0.1 },
|
||||
});
|
||||
|
||||
// Save the PDF
|
||||
doc.save(`${courseName} - AppointmentOrder.pdf`);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -100,7 +178,7 @@ const CourseConsolidated = () => {
|
||||
>
|
||||
<h2 style={{ margin: 0 }}>{courseName}'s Table</h2>
|
||||
<button
|
||||
onClick={() => createExcelFile(courseData, courseName)}
|
||||
onClick={() => generateAppointmentPDF(courseData[0], courseName)}
|
||||
className="btn btn-primary"
|
||||
style={{
|
||||
padding: "10px 15px",
|
||||
@@ -109,8 +187,8 @@ const CourseConsolidated = () => {
|
||||
textDecoration: "none",
|
||||
borderRadius: "5px",
|
||||
}}
|
||||
>
|
||||
Download {courseName}'s Table
|
||||
>
|
||||
Download {courseName}'s Appointment Order
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -148,7 +226,7 @@ const CourseConsolidated = () => {
|
||||
<td>{row.year}</td>
|
||||
<td>
|
||||
{row.oralPracticalTeachers &&
|
||||
row.oralPracticalTeachers.length > 0 ? (
|
||||
row.oralPracticalTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.oralPracticalTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
@@ -160,7 +238,7 @@ const CourseConsolidated = () => {
|
||||
</td>
|
||||
<td>
|
||||
{row.assesmentTeachers &&
|
||||
row.assesmentTeachers.length > 0 ? (
|
||||
row.assesmentTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.assesmentTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
@@ -172,7 +250,7 @@ const CourseConsolidated = () => {
|
||||
</td>
|
||||
<td>
|
||||
{row.reassessmentTeachers &&
|
||||
row.reassessmentTeachers.length > 0 ? (
|
||||
row.reassessmentTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.reassessmentTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
@@ -184,7 +262,7 @@ const CourseConsolidated = () => {
|
||||
</td>
|
||||
<td>
|
||||
{row.paperSettingTeachers &&
|
||||
row.paperSettingTeachers.length > 0 ? (
|
||||
row.paperSettingTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.paperSettingTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
@@ -196,7 +274,7 @@ const CourseConsolidated = () => {
|
||||
</td>
|
||||
<td>
|
||||
{row.moderationTeachers &&
|
||||
row.moderationTeachers.length > 0 ? (
|
||||
row.moderationTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.moderationTeachers.map((teacher, idx) => (
|
||||
<li key={idx}>{teacher}</li>
|
||||
@@ -208,7 +286,7 @@ const CourseConsolidated = () => {
|
||||
</td>
|
||||
<td>
|
||||
{row.pwdPaperSettingTeachers &&
|
||||
row.pwdPaperSettingTeachers.length > 0 ? (
|
||||
row.pwdPaperSettingTeachers.length > 0 ? (
|
||||
<ul style={{ margin: 0, paddingLeft: "20px" }}>
|
||||
{row.pwdPaperSettingTeachers.map(
|
||||
(teacher, idx) => (
|
||||
|
||||
Reference in New Issue
Block a user