แก้ข้อความ/ตัดข้อมูลรายงาน ทปอ.สามัญ #2274

This commit is contained in:
harid 2026-03-20 11:02:53 +07:00
parent 66d8ba089d
commit bc83a2bc40
3 changed files with 517 additions and 141 deletions

View file

@ -941,6 +941,7 @@ export class ProfileEmployeeController extends Controller {
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
const profiles = await this.profileRepo.findOne({
relations: [
"posLevel",
"currentSubDistrict",
"currentDistrict",
"currentProvince",
@ -1021,6 +1022,13 @@ export class ProfileEmployeeController extends Controller {
order: { lastUpdatedAt: "DESC" },
});
const posMasterId =
profiles.current_holders == null ||
profiles.current_holders.length == 0 ||
profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id) == null
? null
: profiles.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.id;
const root =
profiles.current_holders == null ||
profiles.current_holders.length == 0 ||
@ -1081,12 +1089,7 @@ export class ProfileEmployeeController extends Controller {
certificateType: item.certificateType ?? null,
issuer: item.issuer ?? null,
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
issueDate: item.issueDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate))
: "",
expireDate: item.expireDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate))
: "",
detail: Extension.ToThaiNumber(`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim()),
issueToExpireDate: item.issueDate
? item.expireDate
? Extension.ToThaiNumber(
@ -1102,13 +1105,12 @@ export class ProfileEmployeeController extends Controller {
certificateType: "-",
issuer: "-",
certificateNo: "-",
issueDate: "-",
expireDate: "-",
detail: "-",
issueToExpireDate: "-",
},
];
const training_raw = await this.trainingRepository.find({
select: ["place", "department", "name", "duration", "isDeleted"],
select: ["place", "department", "name", "duration", "isDeleted", "startDate", "endDate"],
where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" },
});
@ -1119,6 +1121,7 @@ export class ProfileEmployeeController extends Controller {
degree: item.name ? Extension.ToThaiNumber(item.name) : "",
place: item.place ? Extension.ToThaiNumber(item.place) : "",
duration: item.duration ? Extension.ToThaiNumber(item.duration) : "",
date: Extension.ToThaiNumber(`${Extension.ToThaiFullDate2(item.startDate)} - ${Extension.ToThaiFullDate2(item.endDate)}`)
}))
: [
{
@ -1126,6 +1129,7 @@ export class ProfileEmployeeController extends Controller {
degree: "-",
place: "-",
duration: "-",
date: "-"
},
];
@ -1167,13 +1171,15 @@ export class ProfileEmployeeController extends Controller {
date: item.isDate
? `${item.startDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)) : ""} - ${item.endDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)) : ""}`
: `${item.startDate ? Extension.ToThaiNumber(Extension.ToThaiShortYear(new Date(item.startDate))) : ""} - ${item.endDate ? Extension.ToThaiNumber(Extension.ToThaiShortYear(new Date(item.endDate))) : ""}`,
degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "",
degree: `${item.degree ?? ""} ${item.field ?? ""}`.trim(),
level: item.educationLevel
}))
: [
{
institute: "-",
date: "-",
degree: "-",
level: "-"
},
];
const salary_raw = await this.salaryRepo.find({
@ -1513,6 +1519,7 @@ export class ProfileEmployeeController extends Controller {
positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString())
: "",
refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb} ที่ ${item.commandNo}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
}))
: [
{
@ -1525,9 +1532,10 @@ export class ProfileEmployeeController extends Controller {
posLevel: "-",
amount: "-",
positionSalaryAmount: "-",
refDoc: "-"
},
];
// ลูกจ้างยังไม่มีรักษาการและช่วยราชการ
const actposition_raw = await this.profileActpositionRepo.find({
select: ["dateStart", "dateEnd", "position", "isDeleted"],
where: { profileEmployeeId: id, isDeleted: false },
@ -1599,30 +1607,36 @@ export class ProfileEmployeeController extends Controller {
order: { createdAt: "ASC" },
});
const duty =
duty_raw.length > 0
? duty_raw.map((item) => ({
date:
item.dateStart && item.dateEnd
? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
)
: item.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
: item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "",
refCommandDate: item.refCommandDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
: "",
refCommandNo: item.refCommandNo ? Extension.ToThaiNumber(item.refCommandNo) : "",
}))
: [
{
date: "-",
refCommandDate: "-",
refCommandNo: "-",
},
];
duty_raw.length > 0
? duty_raw.map((item) => ({
date:
item.dateStart && item.dateEnd
? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
)
: item.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
: item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "",
type: "-",
detail: Extension.ToThaiNumber(item.detail),
agency: "-",
refCommandNo: item.refCommandNo
? item.refCommandDate
? Extension.ToThaiNumber(`${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`)
: Extension.ToThaiNumber(item.refCommandNo)
: "-",
}))
: [
{
date: "-",
type: "-",
detail: "-",
agency: "-",
refCommandNo: "-",
},
];
const assessments_raw = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" },
@ -1631,7 +1645,9 @@ export class ProfileEmployeeController extends Controller {
assessments_raw.length > 0
? assessments_raw.map((item) => ({
year: item.year ? Extension.ToThaiNumber((parseInt(item.year) + 543).toString()) : "",
period: item.period && item.period == "APR" ? "เมษายน" : "ตุลาคม",
period: item.period && item.period == "APR"
? Extension.ToThaiNumber(`1 เม.ย. ${(parseInt(item.year) + 543 - 1).toString()} - 31 มี.ค. ${(parseInt(item.year) + 543).toString()}`)
: Extension.ToThaiNumber(`1 ต.ค. ${(parseInt(item.year) + 543 - 1).toString()} - 30 ก.ย. ${(parseInt(item.year) + 543).toString()}`),
point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "",
point1Total: item.point1Total
? Extension.ToThaiNumber(item.point1Total.toString())
@ -1640,18 +1656,20 @@ export class ProfileEmployeeController extends Controller {
point2Total: item.point2Total
? Extension.ToThaiNumber(item.point2Total.toString())
: "",
pointSum: item.pointSum ? Extension.ToThaiNumber(item.pointSum.toString()) : "",
pointSum: item.pointSum
? Extension.ToThaiNumber(`ร้อยละ ${item.pointSum.toString()}`)
: "",
pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "",
level:
item.pointSum < 60.0
? "ต้องปรับปรุง (คะแนนต่ำกว่าร้อยละ ๖๐.)"
? "ต้องปรับปรุง"
: item.pointSum <= 69.99 && item.pointSum >= 60.0
? "พอใช้ (คะแนนร้อยละ ๖๐. - ๖๙.๙๙)"
? "พอใช้"
: item.pointSum <= 79.99 && item.pointSum >= 70.0
? "ดี (คะแนนร้อยละ ๗๐. - ๗๙.๙๙)"
? "ดี"
: item.pointSum <= 89.99 && item.pointSum >= 80.0
? "ดีมาก (คะแนนร้อยละ ๘๐. - ๘๙.๙๙)"
: "ดีเด่น (คะแนนร้อยละ ๙๐. ขึ้นไป)",
? "ดีมาก"
: "ดีเด่น",
}))
: [
{
@ -1706,6 +1724,7 @@ export class ProfileEmployeeController extends Controller {
? Extension.ToThaiNumber(item.positionCee)
: null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "",
refDoc: Extension.ToThaiNumber(`คำสั่ง ${item.posNumCodeSitAbb} ที่ ${item.commandNo}/${item.commandYear>2500?item.commandYear:item.commandYear+543} ลว. ${(Extension.ToThaiFullDate2(item.commandDateAffect))}`)
}))
: [
{
@ -1716,9 +1735,83 @@ export class ProfileEmployeeController extends Controller {
position: "-",
posLevel: "-",
amount: "-",
refDoc: "-"
},
];
// ประวัติพ้นจากราชการ
const retireCodes = ['C-PM-12','C-PM-13','C-PM-17','C-PM-18','C-PM-19','C-PM-20','C-PM-23','C-PM-43'];
let retires = [];
let inRetirePeriod = false;
let currentRetire = null;
for (let i = 0; i < position_raw.length; i++) {
const item = position_raw[i];
if (retireCodes.includes(item.commandCode)) {
// เริ่มพ้นจากราชการ
currentRetire = {
commandName: item.commandName ?? "-",
startDate: item.commandDateAffect
};
inRetirePeriod = true;
}
else if (inRetirePeriod && currentRetire) {
// เจอคำสั่งถัดไปที่ไม่ใช่การพ้นจากราชการ = วันกลับเข้า
const endDate = item.commandDateAffect;
let daysCount = 0;
if (currentRetire.startDate && endDate) {
const start = new Date(currentRetire.startDate);
const end = new Date(endDate);
daysCount = Math.ceil((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
}
const startDateStr = currentRetire.startDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(currentRetire.startDate))
: "-";
const endDateStr = endDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(endDate))
: "-";
retires.push({
date: `${startDateStr} - ${endDateStr}`,
detail: currentRetire.commandName,
day: daysCount > 0 ? Extension.ToThaiNumber(daysCount.toLocaleString()) : "-"
});
inRetirePeriod = false;
currentRetire = null;
}
}
// กรณีไม่มีข้อมูล
if (retires.length === 0) {
retires.push({ date: "-", detail: "-", day: "-" });
}
const org =
(_child4 == null ? "" : _child4 + " ") +
(_child3 == null ? "" : _child3 + " ") +
(_child2 == null ? "" : _child2 + " ") +
(_child1 == null ? "" : _child1 + " ") +
(_root == null ? "" : _root).trim()
const _position = profiles?.position != null ?
profiles?.posLevel != null
? `${profiles.position}${profiles.posLevel.posLevelName}`
: profiles.position
: ""
const ocAssistance = await this.profileAssistanceRepository.findOne({
select: ["agency", "profileEmployeeId", "commandName", "status", "isDeleted"],
where: {
profileEmployeeId: id,
commandName: "ให้ช่วยราชการ",
status: "PENDING",
isDeleted: false, },
order: { createdAt: "ASC" },
});
const sum = profiles
? Extension.ToThaiNumber(
(
@ -1766,7 +1859,8 @@ export class ProfileEmployeeController extends Controller {
prefix: profiles?.prefix != null ? profiles.prefix : "",
firstName: profiles?.firstName != null ? profiles.firstName : "",
lastName: profiles?.lastName != null ? profiles.lastName : "",
position: profiles?.position != null ? profiles.position : "",
position: _position,
posAssistance: ocAssistance ? "-" : _position, // ปัจจุบันช่วยราชการยังไม่มีเก็บฟิลด์ตำแหน่ง
amount:
profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "",
positionSalaryAmount:
@ -1782,12 +1876,13 @@ export class ProfileEmployeeController extends Controller {
? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString())
: "",
salarySum: sum,
ocFullPath:
(_child4 == null ? "" : _child4 + "\n") +
(_child3 == null ? "" : _child3 + "\n") +
(_child2 == null ? "" : _child2 + "\n") +
(_child1 == null ? "" : _child1 + "\n") +
(_root == null ? "" : _root),
ocFullPath: org,
ocAssistance: ocAssistance?.agency ?? org,
root: _root == null ? "" : _root,
agency: (_child4 == null ? "" : _child4 + " ") +
(_child3 == null ? "" : _child3 + " ") +
(_child2 == null ? "" : _child2 + " ") +
(_child1 == null ? "" : _child1).trim(),
birthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "",
@ -1916,6 +2011,7 @@ export class ProfileEmployeeController extends Controller {
assessments,
profileAbility,
otherIncome,
retires
};
return new HttpSuccess({