api import profileSalaryTemp #1570
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m4s

& Fix Report KK1 #2439
This commit is contained in:
harid 2026-04-23 16:31:22 +07:00
parent 7e3982a96d
commit 8912e83227
3 changed files with 636 additions and 51 deletions

View file

@ -1950,35 +1950,78 @@ export class ProfileEmployeeController extends Controller {
// ประวัติพ้นจากราชการ
let retires = [];
const currentDate = new Date();
// todo: รอข้อสรุป
// const retire_raw = await this.salaryRepo.findOne({
// where: {
// profileEmployeeId: id,
// commandCode: In(["12", "15", "16"]),
// },
// order: { order: "desc" },
// });
// if (retire_raw) {
// const startDate = retire_raw.commandDateAffect;
// commandCode ที่ถือว่าออกจากราชการ
const retireCommandCodes = ["12", "15", "16"];
// // คำนวณจำนวนวันจากวันพ้นสภาพถึงปัจจุบัน
// let daysCount = 0;
// if (startDate) {
// const start = new Date(startDate);
// daysCount = Math.ceil((currentDate.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
// }
// ดึงข้อมูล profileSalary ทั้งหมดเพื่อหาประวัติพ้นจากราชการ
const salaries = await this.salaryRepo.find({
where: { profileEmployeeId: id },
order: { order: "ASC" },
});
// const startDateStr = startDate
// ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
// : "-";
// มีคำสั่งพ้นราชการหรือไม่
if (salaries.length > 0 && salaries.some((s) => s.commandCode &&
retireCommandCodes.includes(s.commandCode))) {
// กรองข้อมูลซ้ำตาม commandDateAffect
const uniqueSalaries = salaries.filter((item, index, self) =>
index === self.findIndex((t) => t.commandDateAffect?.getTime() === item.commandDateAffect?.getTime())
);
// retires.push({
// date: `${startDateStr} - ปัจจุบัน`,
// detail: retire_raw.commandName ?? "-",
// day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
// });
// }
// วนลูปหาคู่ของ "ออกราชการ" และ "กลับเข้าราชการ"
for (let i = 0; i < uniqueSalaries.length; i++) {
const current = uniqueSalaries[i];
// เป็นคำสั่งออกจากราชการหรือไม่
if (current.commandCode && retireCommandCodes.includes(current.commandCode)) {
const startDate = current.commandDateAffect;
let endDate: Date | null = null;
let endRecord = null;
// หาคำสั่งถัดไปที่ไม่ใช่การออกจากราชการ (ถือว่ากลับเข้าราชการ)
for (let j = i + 1; j < uniqueSalaries.length; j++) {
const next = uniqueSalaries[j];
if (next.commandCode && !retireCommandCodes.includes(next.commandCode)) {
endDate = next.commandDateAffect;
endRecord = next;
break;
}
}
// ถ้าไม่เจอคำสั่งกลับเข้า ให้ใช้วันปัจจุบัน
if (!endDate) {
endDate = currentDate;
}
// คำนวณจำนวนวัน
let daysCount = 0;
if (startDate && endDate) {
const start = new Date(startDate);
const end = new Date(endDate);
daysCount = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
}
// สร้าง detail จาก commandName + remark
const commandName = current.commandName || "";
const remark = current.remark || "";
const detail = `${commandName} ${remark}`.trim();
// แปลงวันที่เป็น format ไทย
const startDateStr = startDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(startDate))
: "-";
const endDateStr = endDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(endDate))
: "-";
retires.push({
date: `${startDateStr} - ${endDateStr}`,
detail: detail || "-",
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
});
}
}
}
// กรณีไม่มีข้อมูล
if (retires.length === 0) {