add audit form(not yet)、modify main form

This commit is contained in:
Chen,Hui Chen 2024-06-16 18:33:14 +08:00
parent bd5833acfe
commit 4ca4ef1d62
10 changed files with 321 additions and 86 deletions

89
api/audit.js Normal file
View File

@ -0,0 +1,89 @@
// Required modules
const router = require('express').Router();
const util = require("./../utilities/utilities_main.js");
const moment = require("moment");
router.get("/", async function(req, res) {
try {
let conn;
try {
conn = await util.getDBConnection(); // get connection from db
const query = ` //語法有問題
SELECT
item_form.application_id,
item_form.item_info_id,
item_form.application_unit,
item_form.subsidy,
scholarship_application.application_date,
scholarship_application.student_id,
student.student_name
FROM
item_form
RIGHT JOIN
scholarship_application ON item_form.application_id = scholarship_application.application_id;
RIGHT JOIN
student ON scholarship_application.student_id = student.student_id;
`;
const result = await conn.query(query);
res.json({ success: true, data: result });
}
catch(e) {
console.error(e);
res.json({suc : false});
}
finally {
util.closeDBConnection(conn); // close db connection
}
}
catch(e) {
console.log(e);
}
})
router.post("/", async function(req, res) {
try {
let conn;
try {
console.log(req.body);
// data
const apply_infos = req.body.apply_infos; // get data from request
const time = moment(new Date()).format("YYYY-MM-DD");
if (!assistant_id) {
throw new Error("Assistant ID is missing in the request body.");
}
conn = await util.getDBConnection(); // get connection from db
await conn.beginTransaction();
// insert data into table : scholarship_application
const scholarship_audit_info = await conn.batch("INSERT INTO audit_form(``, ``) VALUES(?, ?);", [time, req.body.student_id]);
const scholarship_audit_id = scholarship_audit_info.insertId; // get the application_id of previous record
console.log(scholarship_audit_info.insertId);
console.log(apply_infos);
// insert each apply item into item_form
for (let i = 0;i < apply_infos.length;i++) {
await conn.batch("INSERT INTO item_form(`application_id`, `item_info_id`, `application_unit`, `subsidy`) VALUES(?, ?, ?, ?);", [scholarship_application_id, apply_infos[i], application_unit, subsidy]);
}
await conn.commit();
res.json({suc : true});
}
catch(e) {
console.error(e);
await conn.rollback();
res.json({suc : false});
}
finally {
util.closeDBConnection(conn); // close db connection
}
}
catch(e) {
console.log(e);
}
})
module.exports = router;

View File

@ -1,6 +1,6 @@
// Required modules
const router = require('express').Router();
const util = require("./../utilities/utilities.js");
const util = require("./../utilities/utilities_main.js");
const jwt = require('jsonwebtoken');
router.post("/", async function(req, res) {

View File

@ -33,6 +33,10 @@ router.post("/", async function(req, res) {
const apply_infos = req.body.apply_infos; // get data from request
const time = moment(new Date()).format("YYYY-MM-DD");
if (!student_id) {
throw new Error("Student ID is missing in the request body.");
}
conn = await util.getDBConnection(); // get connection from db
await conn.beginTransaction();

2
db.js
View File

@ -27,7 +27,7 @@ const db = require("mariadb");
// create pool
const pool = db.createPool({
connectionLimit : 500,
connectionLimit : 10,
host : 'localhost',
user : 'user',
password : '',

View File

@ -16,13 +16,15 @@ app.use(cookieParser()); //解析 HTTP 請求的 cookie
// // pages
+app.use("/example", require("./pages/example.js"));
+app.use("/main", require("./pages/main.js"));
// app.use("/login", require("./pages/login.js"));
// app.use("/apply", require("./pages/apply.js"));
+app.use("/login", require("./pages/login.js"));
+app.use("/apply", require("./pages/apply.js"));
+app.use("/audit", require("./pages/audit.js"));
// // api
// app.use("/api/login", require("./api/login.js"));
app.use("/api/login", require("./api/login.js"));
app.use("/api/example", require("./api/example.js"));
app.use("/api/main", require("./api/main.js"));
app.use("/api/audit", require("./api/audit.js"));
// // static files
app.use('/js', express.static('./js'));
app.use('/css', express.static('./css'));
@ -48,70 +50,9 @@ app.get('/', (req, res) => {
console.log(`Example app listening at http://localhost:${port}`)
})
// // 設定 view engine
// app.set('view engine', 'ejs')
// // 建立 todos data
// const todos = [
// 'first todo', 'second todo', 'third todo'
// ]
// app.get('/todos', (req, res) => {
// // 第二個參數可傳入資料
// res.render('todos', {
// todos // todos: todos 一樣的話可省略寫法
// })
// })
// // 加上 :id 代表不確定的參數
// app.get('/todos/:id', (req, res) => {
// // params: 可拿到網址列上指定的參數
// const id = req.params.id
// const todo = todos[id]
// res.render('todo', {
// todo
// })
// })
// app.get('/', (req, res) => {
// //res.send('index')
// })
// app.get('/main.ejs', (req, res) => {
// // 叫 express 去 render views 底下叫做 hello 的檔案,副檔名可省略
// //res.render('hello')
// })
// app.listen(port, () => {
// console.log(`listening at http://localhost:${port}`)
// })
// // 引入 controller
// const todoController = require('./controllers/todo')
// app.set('view engine', 'ejs')
// const todos = [
// 'first todo', 'second todo', 'third todo'
// ]
// // 可直接使用 controller 的方法拿取資料和進行 render
// app.get('/todos', todoController.getAll)
// app.get('/todos/:id',)
// const todoController = require('./controllers/todo')
// app.set('view engine', 'ejs')
// app.get('/todos',)
// app.get('/todos/:id', todoController.get)
// app.listen(port, () => {
// // 連線資料庫
// db.connect()
// console.log(`Example app listening at http://localhost:${port}`)
// })

121
js/audit.js Normal file
View File

@ -0,0 +1,121 @@
let item_info_len = 0;
async function getItemInfo() {
// get the data from table : item_info
try {
let result = await axios.get('/api/audit');
result = result.data;
return result;
}
catch (e) {
console.error(e);
return null;
}
}
async function putDataInTable(table_id) {
// get data
const data = await getItemInfo();
if (data != null && table_id != null) {
// insert data into table
let table_content = document.getElementById(table_id).innerHTML;
for (let i = 0; i < data.length; i++) {
table_content += `
<tr>
<td>${data[i].item_content}</td>
<br>
</tr>`;
}
`<h2>證明文件是否備齊</h2>
<div>
<label>
<input type="radio" id="checkbox_yes_${i}" value="yes"/>
</label>
<label>
<input type="radio" id="checkbox_no_${i}" value="no"/>
</label>
尚須補繳<input type="text" id="unit_${i}"/>
</div>
<h2>學生事務委員會審核結果</h2>
<div>
<input type="radio" id="passed" value="passed">
<label ></label>
會議名稱("學期-次數"):<input type="text" id="passedTimes" style="width: 50px;">核發獎學金
<input type="number" id="scholarshipAmount" style="width: 100px;">
<br>
<blockquote>
<div >
<label>通過日期</label>
<input type="date" id="passed_date">
</div>
</blockquote>
</div>
<div>
<input type="radio" id="notPassed" value="notPassed">
<label>未通過</label>
</div>
<br>
<div>
<label for="noSupportProof"> 未獲補助證明檔案繳交處</label>
<input type="file" id="noSupportProof" accept=".pdf, .doc, .docx, .jpg, .jpeg, .png">
</div>
<br></br>
`
// write back data into table
document.getElementById(table_id).innerHTML = table_content;
// set info length
item_info_len = data.length;
}
else {
console.error("data and table id can not be null");
}
}
async function setAssistantName() {
// get student name, and show on page
document.getElementById("assistant_name").innerHTML = "test";
}
async function sendApplyData() {
// get student name
const student_name = document.getElementById("assistant_name").value;
// get checked infos
let apply_infos = [];
let application_units = [];
let subsidy_amounts = [];
for (let i = 0; i < item_info_len; i++) {
if (document.getElementById(`checkbox_${i}`).checked) {
apply_infos.push(i + 1);
// get unit、subsidy
if (document.getElementById(`unit_${i}`) && document.getElementById(`subsidy_${i}`)) {
application_units.push(document.getElementById(`unit_${i}`).value);
subsidy_amounts.push(document.getElementById(`subsidy_${i}`).value);
} else {
application_units.push(null);
subsidy_amounts.push(null);
}
}
}
const data = {student_id,student_name,department_and_grade, advisor_name,
apply_infos,
application_units,
subsidy_amounts
};
// send data
let result = await axios.post('/api/main', data);
console.log(result);
}
putDataInTable("info_item");

View File

@ -23,24 +23,36 @@ async function putDataInTable(table_id) {
for (let i = 0; i < data.length; i++) {
if (i === 2 || i === 3 || i === 10 || i === 11) {
table_content += `
<tr>
<blockquote>
<td><input type='checkbox' id='checkbox_${i}'/></td>
<td>${data[i].item_content}</td>
<td><div>申請單位:</div><input type='text' id='unit_${i}'/></td>
<td><div>獲得補助金額:</div><input type='number' id='subsidy_${i}'/></td>
</tr>`;
申請單位:</div><input type='text' id='unit_${i}'/>
<td>獲得補助金額NT$</div><input type='number' id='subsidy_${i}'/></td>
</blockquote>`;
} else if (i === 4 || i === 5 || i === 12 || i === 13) {
table_content += `
<tr>
<td><input type='checkbox' id='checkbox_${i}'/></td>
<td>${data[i].item_content}</td>
<td><div>申請單位:</div><input type='text' id='unit_${i}'/></td>
<td>申請單位:</div><input type='text' id='unit_${i}'/></td>
<br>
</tr>`;
} else {
} else if(i===data.length-1){
table_content += `
<tr>
<td><input type='checkbox' id='checkbox_${i}'/></td>
<td>${data[i].item_content}</td>
<td></div><input type='text' id='else_${i}'/></td>
<br>
<br>
</tr>`;
}
else {
table_content += `
<tr>
<td><input type='checkbox' id='checkbox_${i}'/></td>
<td>${data[i].item_content}</td>
<br>
</tr>`;
}
}
@ -55,17 +67,17 @@ async function putDataInTable(table_id) {
}
}
// async function setStudentName() {
// // get student name, and show on page
// document.getElementById("student_name").innerHTML = "test";
// }
async function setStudentName() {
// get student name, and show on page
document.getElementById("student_name").innerHTML = "test";
}
async function sendApplyData() {
// get student name
const student_name = document.getElementById("student_name").innerHTML;
const student_id = document.getElementById("student_id").innerHTML;
const department_and_grade = document.getElementById("department_and_grade").innerHTML;
const advisor_name = document.getElementById("advisor_name").innerHTML;
const student_name = document.getElementById("student_name").value;
const student_id = document.getElementById("student_id").value;
const department_and_grade = document.getElementById("department_and_grade").value;
const advisor_name = document.getElementById("advisor_name").value;
// get checked infos
let apply_infos = [];
let application_units = [];

17
pages/audit.js Normal file
View File

@ -0,0 +1,17 @@
const router = require('express').Router();
const { error } = require('console');
const util = require("./../utilities/utilities_main.js");
// processing request
router.get('/', async function(req, res) {
try {
res.sendFile(util.getParentPath(__dirname) + '/templates/audit.html');
}
catch(e) {
console.log(e);
res.json({error_msg : "failed to access the file"});
}
return;
});
module.exports = router;

41
templates/audit.html Normal file
View File

@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<link href="/css/audit.css" rel="stylesheet">
<head>
<title>國立暨南國際大學資管系獎學金審核表</title>
</head>
<body>
<h1 align="center">國立暨南國際大學資管系獎學金審核表</h1>
<div id="assistant">
<div>
<label>系所助理:</label>
<select id="assistant_name" name="assistant_name" required>
<option value="">請選系所助理</option>
<option value="王慈君">王慈君</option>
<option value="賴玫旋">賴玫旋</option>
</select>
</div>
<br>
<div>
<label>選擇要審核的學號</label>
<select id="student_id_select">
<option value="">請選擇</option>
</select>
</div>
<br>
<fieldset>
<h2 align="center">申請資料</h2>
</fieldset>
<br>
<fieldset>
<h2 align="center">審核區</h2>
<form id="audit_item" border="1">
</form></fieldset>
</body>
<script src="https://cdn.jsdelivr.net/npm/axios@1.6.7/dist/axios.min.js"></script>
<script src = "/js/audit.js"></script>
</html>

View File

@ -54,12 +54,22 @@
<br>
<hr>
<h2>申請項目及說明</h2>
<table id="info_item" border="1">
<tr>
<td>是否申請</td>
<td>項目內容</td>
</tr>
</table>
<form id="info_item" border="1">
<div>
</div>
</form>
</fieldset>
<p>
說明:<br>
一、依據「國立暨南國際大學資訊管理學系獎助學金作業要點」辦理。<br>
二、申辦流程:由學生詳填本申請書並檢附相關證明文件,逕送系辦審查資料是否齊全,提交學生事務委員會審核後,由系辦通知申請學生核定結果(獎學金將逕行撥入申請學生帳戶)。<br>
三、獲得本系獎助學金補助者須提供申請事項之詳細資訊,供系上公告與相關宣傳使用。若後續有召開分享會等相關需要,獲補助者需配合辦理。
</p>
<button onclick="sendApplyData()">送出申請</button>
</body>
<script src="https://cdn.jsdelivr.net/npm/axios@1.6.7/dist/axios.min.js"></script>