diff --git a/api/audit.js b/api/audit.js index 623b533..83f98da 100644 --- a/api/audit.js +++ b/api/audit.js @@ -8,10 +8,9 @@ router.get("/", async function(req, res) { let conn; try { conn = await util.getDBConnection(); // get connection from db - const query = ` //語法有問題 - SELECT - item_form.application_id, - item_form.item_info_id, + const query = + ` + SELECT item_form.application_id, item_form.item_info_id, item_info.item_content, item_form.application_unit, item_form.subsidy, scholarship_application.application_date, @@ -20,12 +19,15 @@ router.get("/", async function(req, res) { 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 }); + scholarship_application ON item_form.application_id = scholarship_application.application_id + LEFT JOIN + student ON scholarship_application.student_id = student.student_id + LEFT JOIN + item_info ON item_form.item_info_id = item_info.item_info_id + ; + `; + const result = await conn.query(query); + res.json({ success: true, data: result }); } catch(e) { console.error(e); diff --git a/api/main.js b/api/main.js index 28cad07..89f05ef 100644 --- a/api/main.js +++ b/api/main.js @@ -31,6 +31,12 @@ router.post("/", async function(req, res) { console.log(req.body); // data const apply_infos = req.body.apply_infos; // get data from request + const application_units = req.body.application_units; + const subsidy_amounts = req.body.subsidy_amounts; + const student_id = req.body.student_id; + const student_name = req.body.student_name; + const department_and_grade = req.body.department_and_grade; + const advisor_id = req.body.advisor_name; const time = moment(new Date()).format("YYYY-MM-DD"); if (!student_id) { @@ -40,8 +46,13 @@ router.post("/", async function(req, res) { conn = await util.getDBConnection(); // get connection from db await conn.beginTransaction(); + // insert into student, if not existed + const stu_existed = await conn.query("SELECT COUNT(*) FROM student WHERE student_id=?", student_id); + if (!stu_existed[0]["COUNT(*)"]) { + await conn.batch("INSERT INTO student VALUES(?, ?, ?, ?);", [student_id, department_and_grade, student_name, advisor_id]); + } // insert data into table : scholarship_application - const scholarship_application_info = await conn.batch("INSERT INTO scholarship_application(`application_date`, `student_id`) VALUES(?, ?);", [time, req.body.student_id]); + const scholarship_application_info = await conn.batch("INSERT INTO scholarship_application(`application_date`, `student_id`) VALUES(?, ?);", [time, student_id]); const scholarship_application_id = scholarship_application_info.insertId; // get the application_id of previous record // 這邊你們要再改 @@ -53,7 +64,7 @@ router.post("/", async function(req, res) { // 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.batch("INSERT INTO item_form(`application_id`, `item_info_id`, `application_unit`, `subsidy`) VALUES(?, ?, ?, ?);", [scholarship_application_id, apply_infos[i], application_units[i], subsidy_amounts[i]]); } await conn.commit(); diff --git a/js/audit.js b/js/audit.js index 463ef44..a57ef14 100644 --- a/js/audit.js +++ b/js/audit.js @@ -1,4 +1,8 @@ + let item_info_len = 0; +let all_audit_data = null; +let current_review_apllication_id; +const application_detail_init_table_content = document.getElementById("application_detail").innerHTML; async function getItemInfo() { // get the data from table : item_info @@ -13,21 +17,106 @@ async function getItemInfo() { } } +function combineSameAppData(data) { + // combine the same application id data in a same record + let n_data = {}; + let next_record = true; + for (let i = 0; i < data.length; i++) { + if (i > 0 && data[i].application_id != data[i-1].application_id) { + // this record is different from the last + next_record = true; + } + if (next_record) { + // this is new record + next_record = false; + // init this record + n_data[data[i].application_id] = {}; + n_data[data[i].application_id].application_id = data[i].application_id; + n_data[data[i].application_id].application_date = data[i].application_date; + n_data[data[i].application_id].student_id = data[i].student_id; + n_data[data[i].application_id].student_name = data[i].student_name; + n_data[data[i].application_id].application_units = [data[i].application_unit]; + n_data[data[i].application_id].item_contents = [data[i].item_content]; + n_data[data[i].application_id].subsidys = [data[i].subsidy]; + } + else { + n_data[data[i].application_id].application_units.push(data[i].application_unit); + n_data[data[i].application_id].item_contents.push(data[i].item_content); + n_data[data[i].application_id].subsidys.push(data[i].subsidy); + } + } + all_audit_data = n_data; + return n_data; +} + +function auditCase(application_id) { + current_review_apllication_id = application_id; + + // add item content + const table_id = "application_detail"; + document.getElementById(table_id).innerHTML = application_detail_init_table_content; + let table_content = document.getElementById(table_id).innerHTML; + const data = all_audit_data[application_id]; + console.log(data); + table_content += ""; + for (let i = 0;i < data.item_contents.length;i++) { + if (data.item_contents[i].includes("已向")) { + table_content += + ` + ${data.item_contents[i]} ,申請單位: ${data.application_units[i]} 獲得補助金額:NT$${data.subsidys[i]} + ` + } + else { + table_content += + ` + + + ${data.item_contents[i]} + ` + } + } + document.getElementById(table_id).innerHTML = table_content; + + // add simple info + document.getElementById("application_info").innerHTML = + ` + 申請編號:${data.application_id}
+ 申請日期:${data.application_date}
+ 申請人姓名:${data.student_name}
+ 申請人學號:${data.student_id}
+ 申請內容: + `; + + console.log(); +} + async function putDataInTable(table_id) { // get data - const data = await getItemInfo(); - if (data != null && table_id != null) { + const result = await getItemInfo(); + const data = combineSameAppData(result.data); + const suc = result.success; + if (suc && 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 += ` + const keys = (Object.keys(data)); + let next_record = false; + let this_application_info = {}; + console.log(data); + for (let i = 0; i < keys.length; i++) { + table_content += + ` - ${data[i].item_content} -
- `; + ${data[keys[i]].application_id} + ${data[keys[i]].application_date} + ${data[keys[i]].student_id} + ${data[keys[i]].student_name} + + + ` + ; } + /* `

證明文件是否備齊



` + */ // write back data into table document.getElementById(table_id).innerHTML = table_content; // set info length @@ -83,7 +173,11 @@ async function putDataInTable(table_id) { async function setAssistantName() { // get student name, and show on page - document.getElementById("assistant_name").innerHTML = "test"; + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const s_num = urlParams.get("s_num"); + const name = urlParams.get("name"); + document.getElementById("assistant_name").innerHTML = name; } async function sendApplyData() { @@ -118,4 +212,11 @@ async function sendApplyData() { console.log(result); } -putDataInTable("info_item"); \ No newline at end of file +async function sendReviewResult() { + // send current review result of the application + console.log(`send current review result of the application ${current_review_apllication_id}`); + // 你們這邊要將編號為 current_review_apllication_id 的審核表的資料送去後端處理 +} + +setAssistantName(); +putDataInTable("application_table"); \ No newline at end of file diff --git a/js/login.js b/js/login.js index 8f35f82..d95933b 100644 --- a/js/login.js +++ b/js/login.js @@ -1,13 +1,19 @@ async function submit() { const account = document.getElementById("account").value; const password = document.getElementById("password").value; - console.log(account, password); let data = {account : account, password : password}; - let suc_login = await axios.post('/api/login', data); + let suc_login = await axios.post('http://163.22.17.184:5000/api/login', data); suc_login = suc_login.data; console.log(suc_login); if (suc_login.suc) { - location.href = '/main'; + if (account.length >= 9) { + // student + location.href = `/main?name=${suc_login.authen_result}&s_num=${account}`; + } + else { + // assistant + location.href = `/audit?name=${suc_login.authen_result}&s_num=${account}`; + } } else { alert("帳號或密碼錯誤"); diff --git a/js/main.js b/js/main.js index dc3f99a..5a2021f 100644 --- a/js/main.js +++ b/js/main.js @@ -74,8 +74,8 @@ async function setStudentName() { async function sendApplyData() { // get student name - const student_name = document.getElementById("student_name").value; - const student_id = document.getElementById("student_id").value; + 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").value; const advisor_name = document.getElementById("advisor_name").value; // get checked infos @@ -101,9 +101,20 @@ async function sendApplyData() { application_units, subsidy_amounts }; + console.log(data); // send data let result = await axios.post('/api/main', data); console.log(result); } +function setUserInfo() { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const s_num = urlParams.get("s_num"); + const name = urlParams.get("name"); + document.getElementById("student_id").innerHTML = s_num; + document.getElementById("student_name").innerHTML = name; +} + +setUserInfo(); putDataInTable("info_item"); \ No newline at end of file diff --git a/scholarship.sql b/scholarship.sql index 3e13961..68b39be 100644 --- a/scholarship.sql +++ b/scholarship.sql @@ -97,8 +97,8 @@ CREATE TABLE `item_form` ( `item_id` int(4) NOT NULL, `application_id` int(4) NOT NULL, `item_info_id` int(4) NOT NULL, - `application_unit` varchar(50) NOT NULL, - `subsidy` int(4) NOT NULL + `application_unit` varchar(50) NULL, + `subsidy` int(4) NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- @@ -159,7 +159,7 @@ CREATE TABLE `student` ( `student_id` varchar(9) NOT NULL COMMENT '學號', `departmant_and_grade` varchar(10) NOT NULL COMMENT '系級', `student_name` varchar(20) NOT NULL COMMENT '學生姓名', - `advisor_id` int(4) NOT NULL + `advisor_id` int(4) NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- diff --git a/templates/audit.html b/templates/audit.html index a7ef5b8..4bd13d1 100644 --- a/templates/audit.html +++ b/templates/audit.html @@ -10,12 +10,7 @@
- - +

@@ -26,11 +21,80 @@

-

申請資料

+ + + + + + +
+

申請資料

+ + + + + + + +
申請編號申請日期申請人學號申請人姓名
+
+

申請詳細資訊

+
+ + +
+
+

申請審核

+

證明文件是否備齊

+
+ + + ,尚須補繳: +
+ +

學生事務委員會審核結果

+
+ + + + 會議名稱("學期-次數"):,核發獎學金 + 元 +
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ + + +
+

+ +

審核區

+ +
diff --git a/templates/main.html b/templates/main.html index 739c474..e1805e7 100644 --- a/templates/main.html +++ b/templates/main.html @@ -10,12 +10,10 @@
- - +
- - +
@@ -35,19 +33,19 @@
diff --git a/utilities/utilities.js b/utilities/utilities.js index f628599..f2ff5d1 100644 --- a/utilities/utilities.js +++ b/utilities/utilities.js @@ -4,10 +4,10 @@ const db = require("mariadb"); // create pool const pool = db.createPool({ - connectionLimit : 500, + connectionLimit : 50, host : 'localhost', - user : 'root', - password : '', + user : 'test', + password : '123', database : 'scholarship' }); diff --git a/utilities/utilities_main.js b/utilities/utilities_main.js index 7af5930..f2ff5d1 100644 --- a/utilities/utilities_main.js +++ b/utilities/utilities_main.js @@ -4,10 +4,10 @@ const db = require("mariadb"); // create pool const pool = db.createPool({ - connectionLimit : 500, + connectionLimit : 50, host : 'localhost', - user : 'user', - password : '', + user : 'test', + password : '123', database : 'scholarship' });