/**
* Student
* =======
* 主要功能:儲存「平均分數、名次」
*/
class Student {
// init
constructor(classNo, seatNo, name, avg, rank){
this.classNo = classNo;
this.seatNo = seatNo;
this.name = name;
this.average = +avg; // 平均分數
this.rank = +rank; // 名次
}
// 高二、三:每班 1 名,學業成績 >= 80。
get isAwarded() {
// 第一學期
if (+app.semester === 1) {
return this.rank === 1 && this.average >= 80;
}
// 第二學期
else {
if (+this.classNo < 200) return this.rank <= 2; // 高一 :2 名/班
return this.rank === 1 && this.average >= 80; // 高二三:1 名/班、學業成績 >= 80
}
}
// toString
toString() {
return `${this.classNo}-${this.seatNo} ${this.name}:平均分數 = ${this.average}, 名次 = ${this.rank}`;
}
// row for table (with index: i)
rowForAwardTable(i) {
return [i, this.classNo, this.name, '表現優秀', this.average, app.award, ''];
}
}
// 🔸 all students
Student.all = [];
// Student award list data
Student.dataForAwardTable = function(){
const students = Student.all.filter(stu => stu.isAwarded);
const header = ['編號', '班級', '姓名', '日常生活表現', '學業總平均', '金額', '蓋章或簽名'];
const cols = header.length;
const title = [`臺北市 ${app.year} 學年度第 ${app.semester} 學期高級中等學校學生獎學金印領清冊`].padEndSpaces(cols - 1);
const subtitle = [`校名:臺北市立陽明高級中學`].padEndSpaces(cols - 1);
const line = [].padEndSpaces(cols);
/* ------------------------ 寫入表尾 --------------------------- */
const n = students.length; // 總人數
const total = n * +app.award; // 合計總金額
const junior = (+app.semester === 2) ? `;一年級上學期名額併入本學期,爰每班分配 2 名` : '';
const footer = [
[`合計總人數:${n}`, '', '', `合計總金額:${total}`, '', '', ''],
[`學校總人數:`, '', '', `學校總班級數:`, '', '', ''],
['', '', '', '', '', '', ''],
['承辦人:', '', '', '註冊組長:', '教務主任:', '', '校長:'],
['', '', '', '', '', '', ''],
['', '', '', '', '', '', ''],
['出納:', '', '', '主計人員:', '會計主任:', '', '',],
['', '', '', '', '', '', ''],
['', '', '', '', '', '', ''],
['⭐️ 本表填妥後,請核章。', '', '', '', '', '', ''],
[`⭐️ 二、三年級每班分配 1 名${junior}。`, '', '', '', '', '', ''],
];
return [
title, subtitle, line,
header,
...students.map((stu, i) => stu.rowForAwardTable(i+1)),
line,
...footer,
];
};