แก้ข้อความ/ตัดข้อมูลรายงาน ทปอ.สามัญ #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

@ -90,6 +90,7 @@ import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService"; import { CreatePosMasterHistoryOfficer, getTopDegrees } from "../services/PositionService";
import { ProfileLeaveService } from "../services/ProfileLeaveService"; import { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController"; import { PostRetireToExprofile } from "./ExRetirementController";
import { getPosNumCodeSit } from "../services/CommandService";
@Route("api/v1/org/profile") @Route("api/v1/org/profile")
@Tags("Profile") @Tags("Profile")
@Security("bearerAuth") @Security("bearerAuth")
@ -945,6 +946,7 @@ export class ProfileController extends Controller {
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) { public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
const profiles = await this.profileRepo.findOne({ const profiles = await this.profileRepo.findOne({
relations: [ relations: [
"posLevel",
"currentSubDistrict", "currentSubDistrict",
"currentDistrict", "currentDistrict",
"currentProvince", "currentProvince",
@ -1025,6 +1027,13 @@ export class ProfileController extends Controller {
order: { lastUpdatedAt: "DESC" }, 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 = const root =
profiles.current_holders == null || profiles.current_holders == null ||
profiles.current_holders.length == 0 || profiles.current_holders.length == 0 ||
@ -1085,12 +1094,7 @@ export class ProfileController extends Controller {
certificateType: item.certificateType ?? null, certificateType: item.certificateType ?? null,
issuer: item.issuer ?? null, issuer: item.issuer ?? null,
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null, certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
issueDate: item.issueDate detail: Extension.ToThaiNumber(`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim()),
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate))
: "",
expireDate: item.expireDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate))
: "",
issueToExpireDate: item.issueDate issueToExpireDate: item.issueDate
? item.expireDate ? item.expireDate
? Extension.ToThaiNumber( ? Extension.ToThaiNumber(
@ -1106,13 +1110,12 @@ export class ProfileController extends Controller {
certificateType: "-", certificateType: "-",
issuer: "-", issuer: "-",
certificateNo: "-", certificateNo: "-",
issueDate: "-", detail: "-",
expireDate: "-",
issueToExpireDate: "-", issueToExpireDate: "-",
}, },
]; ];
const training_raw = await this.trainingRepository.find({ const training_raw = await this.trainingRepository.find({
select: ["place", "department", "name", "duration", "isDeleted"], select: ["place", "department", "name", "duration", "isDeleted", "startDate", "endDate"],
where: { profileId: id, isDeleted: false }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -1123,6 +1126,7 @@ export class ProfileController extends Controller {
degree: item.name ? Extension.ToThaiNumber(item.name) : "", degree: item.name ? Extension.ToThaiNumber(item.name) : "",
place: item.place ? Extension.ToThaiNumber(item.place) : "", place: item.place ? Extension.ToThaiNumber(item.place) : "",
duration: item.duration ? Extension.ToThaiNumber(item.duration) : "", duration: item.duration ? Extension.ToThaiNumber(item.duration) : "",
date: Extension.ToThaiNumber(`${Extension.ToThaiFullDate2(item.startDate)} - ${Extension.ToThaiFullDate2(item.endDate)}`)
})) }))
: [ : [
{ {
@ -1130,6 +1134,7 @@ export class ProfileController extends Controller {
degree: "-", degree: "-",
place: "-", place: "-",
duration: "-", duration: "-",
date: "-"
}, },
]; ];
@ -1171,13 +1176,15 @@ export class ProfileController extends Controller {
date: item.isDate date: item.isDate
? `${item.startDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)) : ""} - ${item.endDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)) : ""}` ? `${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))) : ""}`, : `${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: "-", institute: "-",
date: "-", date: "-",
degree: "-", degree: "-",
level: "-"
}, },
]; ];
const salary_raw = await this.salaryRepo.find({ const salary_raw = await this.salaryRepo.find({
@ -1297,8 +1304,8 @@ export class ProfileController extends Controller {
section: item.section ? Extension.ToThaiNumber(item.section) : "", section: item.section ? Extension.ToThaiNumber(item.section) : "",
page: item.page ? Extension.ToThaiNumber(item.page) : "", page: item.page ? Extension.ToThaiNumber(item.page) : "",
refCommandDate: item.refCommandDate refCommandDate: item.refCommandDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) ? Extension.ToThaiNumber(`ราชกิจจานุเบกษา เล่มที่ ${item.volume ?? "-"} ตอนที่ ${item.section ?? "-"} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`)
: "", : "-",
note: item.note ? Extension.ToThaiNumber(item.note) : "", note: item.note ? Extension.ToThaiNumber(item.note) : "",
})) }))
: [ : [
@ -1314,6 +1321,7 @@ export class ProfileController extends Controller {
section: "-", section: "-",
page: "-", page: "-",
refCommandDate: "-", refCommandDate: "-",
note: "-"
}, },
]; ];
@ -1517,6 +1525,7 @@ export class ProfileController extends Controller {
positionSalaryAmount: item.positionSalaryAmount positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString()) ? 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))}`)
})) }))
: [ : [
{ {
@ -1529,75 +1538,211 @@ export class ProfileController extends Controller {
posLevel: "-", posLevel: "-",
amount: "-", amount: "-",
positionSalaryAmount: "-", positionSalaryAmount: "-",
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 actposition_raw = await this.profileActpositionRepo.find({ const actposition_raw = await this.profileActpositionRepo.find({
select: ["dateStart", "dateEnd", "position", "isDeleted"], select: ["dateStart", "profileId", "dateEnd", "position", "commandId", "isDeleted"],
where: { profileId: id, isDeleted: false }, where: { profileId: id, status: true, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
let _actpositions = [];
if (actposition_raw.length > 0){
for (const item of actposition_raw) {
let _commandTypename: string = "รักษาการในตำแหน่ง";
let _document: string = "-";
let _org: string = "-";
if (item.commandId) {
const {
posNumCodeSitAbb,
commandTypeName,
commandNo,
commandYear,
commandExcecuteDate,
} = await getPosNumCodeSit(item.commandId, "REPORTED");
_document = Extension.ToThaiNumber(
`คำสั่ง ${posNumCodeSitAbb}
${commandNo}/${commandYear>2500?commandYear:commandYear+543}
. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}`
)
_commandTypename = commandTypeName;
}
// ค้นหาหน่วยงานที่รักษาการ
const _posmasterAct = await this.posMasterActRepository.findOne({
where: {
posMasterChildId: posMasterId ?? "",
statusReport: "DONE"
}
});
if (_posmasterAct) {
const _posMater = await this.posMasterRepo.findOne({
where: {
id: _posmasterAct.posMasterId
},
relations:{
orgRoot: true,
orgChild1: true,
orgChild2: true,
orgChild3: true,
orgChild4: true,
}
});
let child4 = _posMater?.orgChild4?.orgChild4Name ?? ""
let child3 = _posMater?.orgChild3?.orgChild3Name ?? ""
let child2 = _posMater?.orgChild2?.orgChild2Name ?? ""
let child1 = _posMater?.orgChild1?.orgChild1Name ?? ""
let root = _posMater?.orgRoot?.orgRootName ?? ""
_org = `${child4} ${child3} ${child2} ${child1} ${root}`.trim();
}
_actpositions.push({
data:
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))
: "",
position: item.position ? Extension.ToThaiNumber(item.position) : "",
commandName: _commandTypename,
agency: _org,
note: _posmasterAct && _posmasterAct?.posMasterOrder
? Extension.ToThaiNumber(_posmasterAct?.posMasterOrder.toString())
: "-",
document: _document,
});
}
}
else {
_actpositions.push({
date: "-",
position: "-",
commandName: "-",
agency: "-",
note: "-",
document: "-",
});
}
// ช่วยราชการ
const assistance_raw = await this.profileAssistanceRepository.find({ const assistance_raw = await this.profileAssistanceRepository.find({
select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"], select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"],
where: { profileId: id, isDeleted: false }, where: { profileId: id, status: "PENDING", isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
let _assistances = []
if (assistance_raw.length > 0) {
for (const item of assistance_raw) {
let _commandTypename: string = item.commandName ?? "ให้ช่วยราชการ";
let _document: string = "-";
let _org: string = item.agency ? Extension.ToThaiNumber(item.agency) : "-";
if (item.commandId) {
const {
posNumCodeSitAbb,
commandTypeName,
commandNo,
commandYear,
commandExcecuteDate,
} = await getPosNumCodeSit(item.commandId);
_document = Extension.ToThaiNumber(`
${posNumCodeSitAbb}
${commandNo}/${commandYear>2500?commandYear:commandYear+543}
. ${(Extension.ToThaiFullDate2(commandExcecuteDate))}
`)
_commandTypename = commandTypeName;
}
_assistances.push({
data:
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))
: "",
position: "-", // รักษาการปัจจุบันไม่มีฟิลด์ตำแหน่ง
commandName: _commandTypename,
agency: _org,
note: "-",
document: _document,
});
}
}
else {
_assistances.push({
date: "-",
position: "-",
commandName: "-",
agency: "-",
note: "-",
document: "-",
});
}
// Merge รักษาการ และ ช่วยราชาร
const actposition = [..._actpositions, ..._assistances];
const _actposition =
actposition_raw.length > 0
? actposition_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))
: "",
position: item.position ? Extension.ToThaiNumber(item.position) : "",
commandName: "รักษาการในตำแหน่ง",
agency: "",
document: "",
}))
: [
{
date: "-",
position: "-",
commandName: "-",
agency: "-",
document: "-",
},
];
const _assistance =
assistance_raw.length > 0
? assistance_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))
: "",
position: "",
commandName: item.commandName ? Extension.ToThaiNumber(item.commandName) : "",
agency: item.agency ? Extension.ToThaiNumber(item.agency) : "",
document: item.document ? Extension.ToThaiNumber(item.document) : "",
}))
: [
{
date: "-",
position: "-",
commandName: "-",
agency: "-",
document: "-",
},
];
const actposition = [..._actposition, ..._assistance];
const duty_raw = await this.dutyRepository.find({ const duty_raw = await this.dutyRepository.find({
where: { profileId: id, isDeleted: false }, where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
@ -1615,15 +1760,21 @@ export class ProfileController extends Controller {
: item.dateEnd : item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "", : "",
refCommandDate: item.refCommandDate type: "-",
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) detail: Extension.ToThaiNumber(item.detail),
: "", agency: "-",
refCommandNo: item.refCommandNo ? Extension.ToThaiNumber(item.refCommandNo) : "", refCommandNo: item.refCommandNo
? item.refCommandDate
? Extension.ToThaiNumber(`${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`)
: Extension.ToThaiNumber(item.refCommandNo)
: "-",
})) }))
: [ : [
{ {
date: "-", date: "-",
refCommandDate: "-", type: "-",
detail: "-",
agency: "-",
refCommandNo: "-", refCommandNo: "-",
}, },
]; ];
@ -1635,7 +1786,9 @@ export class ProfileController extends Controller {
assessments_raw.length > 0 assessments_raw.length > 0
? assessments_raw.map((item) => ({ ? assessments_raw.map((item) => ({
year: item.year ? Extension.ToThaiNumber((parseInt(item.year) + 543).toString()) : "", 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()) : "", point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "",
point1Total: item.point1Total point1Total: item.point1Total
? Extension.ToThaiNumber(item.point1Total.toString()) ? Extension.ToThaiNumber(item.point1Total.toString())
@ -1644,18 +1797,20 @@ export class ProfileController extends Controller {
point2Total: item.point2Total point2Total: item.point2Total
? Extension.ToThaiNumber(item.point2Total.toString()) ? 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) : "", pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "",
level: level:
item.pointSum < 60.0 item.pointSum < 60.0
? "ต้องปรับปรุง (คะแนนต่ำกว่าร้อยละ ๖๐.)" ? "ต้องปรับปรุง"
: item.pointSum <= 69.99 && item.pointSum >= 60.0 : item.pointSum <= 69.99 && item.pointSum >= 60.0
? "พอใช้ (คะแนนร้อยละ ๖๐. - ๖๙.๙๙)" ? "พอใช้"
: item.pointSum <= 79.99 && item.pointSum >= 70.0 : item.pointSum <= 79.99 && item.pointSum >= 70.0
? "ดี (คะแนนร้อยละ ๗๐. - ๗๙.๙๙)" ? "ดี"
: item.pointSum <= 89.99 && item.pointSum >= 80.0 : item.pointSum <= 89.99 && item.pointSum >= 80.0
? "ดีมาก (คะแนนร้อยละ ๘๐. - ๘๙.๙๙)" ? "ดีมาก"
: "ดีเด่น (คะแนนร้อยละ ๙๐. ขึ้นไป)", : "ดีเด่น",
})) }))
: [ : [
{ {
@ -1711,6 +1866,7 @@ export class ProfileController extends Controller {
? Extension.ToThaiNumber(item.positionCee) ? Extension.ToThaiNumber(item.positionCee)
: null, : null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "", 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))}`)
})) }))
: [ : [
{ {
@ -1721,6 +1877,7 @@ export class ProfileController extends Controller {
position: "-", position: "-",
posLevel: "-", posLevel: "-",
amount: "-", amount: "-",
refDoc: "-"
}, },
]; ];
@ -1775,20 +1932,41 @@ export class ProfileController extends Controller {
}) })
.catch(() => {}); .catch(() => {});
if (!portfolios) { if (!portfolios) {
portfolios = [{ name: "-", year: "-" }]; portfolios = [{ name: "-", year: "-", position: "-" }];
} else { } else {
portfolios = portfolios.map((x: any) => ({ portfolios = portfolios.map((x: any) => ({
name: x.name ? Extension.ToThaiNumber(x.name) : "-", name: x.name ? Extension.ToThaiNumber(x.name) : "-",
year: x.year ? Extension.ToThaiNumber(x.year.toString()) : "-", year: x.year ? Extension.ToThaiNumber(x.year.toString()) : "-",
position: `${x.position ?? "-"}`
})); }));
} }
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", "profileId", "commandName", "status", "isDeleted"],
where: {
profileId: id,
commandName: "ให้ช่วยราชการ",
status: "PENDING",
isDeleted: false, },
order: { createdAt: "ASC" },
});
const data = { const data = {
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`, fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
prefix: profiles?.prefix != null ? profiles.prefix : "", prefix: profiles?.prefix != null ? profiles.prefix : "",
firstName: profiles?.firstName != null ? profiles.firstName : "", firstName: profiles?.firstName != null ? profiles.firstName : "",
lastName: profiles?.lastName != null ? profiles.lastName : "", lastName: profiles?.lastName != null ? profiles.lastName : "",
position: profiles?.position != null ? profiles.position : "", position: _position,
posAssistance: ocAssistance ? "-" : _position, // ปัจจุบันช่วยราชการยังไม่มีเก็บฟิลด์ตำแหน่ง
amount: amount:
profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "", profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "",
positionSalaryAmount: positionSalaryAmount:
@ -1804,12 +1982,13 @@ export class ProfileController extends Controller {
? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString()) ? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString())
: "", : "",
salarySum: sum, salarySum: sum,
ocFullPath: ocFullPath: org,
(_child4 == null ? "" : _child4 + "\n") + ocAssistance: ocAssistance?.agency ?? org,
(_child3 == null ? "" : _child3 + "\n") + root: _root == null ? "" : _root,
(_child2 == null ? "" : _child2 + "\n") + agency: (_child4 == null ? "" : _child4 + " ") +
(_child1 == null ? "" : _child1 + "\n") + (_child3 == null ? "" : _child3 + " ") +
(_root == null ? "" : _root), (_child2 == null ? "" : _child2 + " ") +
(_child1 == null ? "" : _child1).trim(),
birthDate: profiles?.birthDate birthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "", : "",
@ -1939,6 +2118,7 @@ export class ProfileController extends Controller {
profileAbility, profileAbility,
otherIncome, otherIncome,
portfolios, portfolios,
retires
}; };
return new HttpSuccess({ return new HttpSuccess({

View file

@ -941,6 +941,7 @@ export class ProfileEmployeeController extends Controller {
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) { public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
const profiles = await this.profileRepo.findOne({ const profiles = await this.profileRepo.findOne({
relations: [ relations: [
"posLevel",
"currentSubDistrict", "currentSubDistrict",
"currentDistrict", "currentDistrict",
"currentProvince", "currentProvince",
@ -1021,6 +1022,13 @@ export class ProfileEmployeeController extends Controller {
order: { lastUpdatedAt: "DESC" }, 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 = const root =
profiles.current_holders == null || profiles.current_holders == null ||
profiles.current_holders.length == 0 || profiles.current_holders.length == 0 ||
@ -1081,12 +1089,7 @@ export class ProfileEmployeeController extends Controller {
certificateType: item.certificateType ?? null, certificateType: item.certificateType ?? null,
issuer: item.issuer ?? null, issuer: item.issuer ?? null,
certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null, certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null,
issueDate: item.issueDate detail: Extension.ToThaiNumber(`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim()),
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate))
: "",
expireDate: item.expireDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate))
: "",
issueToExpireDate: item.issueDate issueToExpireDate: item.issueDate
? item.expireDate ? item.expireDate
? Extension.ToThaiNumber( ? Extension.ToThaiNumber(
@ -1102,13 +1105,12 @@ export class ProfileEmployeeController extends Controller {
certificateType: "-", certificateType: "-",
issuer: "-", issuer: "-",
certificateNo: "-", certificateNo: "-",
issueDate: "-", detail: "-",
expireDate: "-",
issueToExpireDate: "-", issueToExpireDate: "-",
}, },
]; ];
const training_raw = await this.trainingRepository.find({ 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 }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -1119,6 +1121,7 @@ export class ProfileEmployeeController extends Controller {
degree: item.name ? Extension.ToThaiNumber(item.name) : "", degree: item.name ? Extension.ToThaiNumber(item.name) : "",
place: item.place ? Extension.ToThaiNumber(item.place) : "", place: item.place ? Extension.ToThaiNumber(item.place) : "",
duration: item.duration ? Extension.ToThaiNumber(item.duration) : "", 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: "-", degree: "-",
place: "-", place: "-",
duration: "-", duration: "-",
date: "-"
}, },
]; ];
@ -1167,13 +1171,15 @@ export class ProfileEmployeeController extends Controller {
date: item.isDate date: item.isDate
? `${item.startDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.startDate)) : ""} - ${item.endDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.endDate)) : ""}` ? `${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))) : ""}`, : `${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: "-", institute: "-",
date: "-", date: "-",
degree: "-", degree: "-",
level: "-"
}, },
]; ];
const salary_raw = await this.salaryRepo.find({ const salary_raw = await this.salaryRepo.find({
@ -1513,6 +1519,7 @@ export class ProfileEmployeeController extends Controller {
positionSalaryAmount: item.positionSalaryAmount positionSalaryAmount: item.positionSalaryAmount
? Extension.ToThaiNumber(Number(item.positionSalaryAmount).toLocaleString()) ? 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: "-", posLevel: "-",
amount: "-", amount: "-",
positionSalaryAmount: "-", positionSalaryAmount: "-",
refDoc: "-"
}, },
]; ];
// ลูกจ้างยังไม่มีรักษาการและช่วยราชการ
const actposition_raw = await this.profileActpositionRepo.find({ const actposition_raw = await this.profileActpositionRepo.find({
select: ["dateStart", "dateEnd", "position", "isDeleted"], select: ["dateStart", "dateEnd", "position", "isDeleted"],
where: { profileEmployeeId: id, isDeleted: false }, where: { profileEmployeeId: id, isDeleted: false },
@ -1599,30 +1607,36 @@ export class ProfileEmployeeController extends Controller {
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
const duty = const duty =
duty_raw.length > 0 duty_raw.length > 0
? duty_raw.map((item) => ({ ? duty_raw.map((item) => ({
date: date:
item.dateStart && item.dateEnd item.dateStart && item.dateEnd
? Extension.ToThaiNumber( ? Extension.ToThaiNumber(
`${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`, `${Extension.ToThaiFullDate2(item.dateStart)} - ${Extension.ToThaiFullDate2(item.dateEnd)}`,
) )
: item.dateStart : item.dateStart
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateStart))
: item.dateEnd : item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "", : "",
refCommandDate: item.refCommandDate type: "-",
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) detail: Extension.ToThaiNumber(item.detail),
: "", agency: "-",
refCommandNo: item.refCommandNo ? Extension.ToThaiNumber(item.refCommandNo) : "", refCommandNo: item.refCommandNo
})) ? item.refCommandDate
: [ ? Extension.ToThaiNumber(`${item.refCommandNo} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`)
{ : Extension.ToThaiNumber(item.refCommandNo)
date: "-", : "-",
refCommandDate: "-", }))
refCommandNo: "-", : [
}, {
]; date: "-",
type: "-",
detail: "-",
agency: "-",
refCommandNo: "-",
},
];
const assessments_raw = await this.profileAssessmentsRepository.find({ const assessments_raw = await this.profileAssessmentsRepository.find({
where: { profileEmployeeId: id, isDeleted: false }, where: { profileEmployeeId: id, isDeleted: false },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
@ -1631,7 +1645,9 @@ export class ProfileEmployeeController extends Controller {
assessments_raw.length > 0 assessments_raw.length > 0
? assessments_raw.map((item) => ({ ? assessments_raw.map((item) => ({
year: item.year ? Extension.ToThaiNumber((parseInt(item.year) + 543).toString()) : "", 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()) : "", point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "",
point1Total: item.point1Total point1Total: item.point1Total
? Extension.ToThaiNumber(item.point1Total.toString()) ? Extension.ToThaiNumber(item.point1Total.toString())
@ -1640,18 +1656,20 @@ export class ProfileEmployeeController extends Controller {
point2Total: item.point2Total point2Total: item.point2Total
? Extension.ToThaiNumber(item.point2Total.toString()) ? 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) : "", pointSumTh: item.pointSum ? Extension.textPoint(item.pointSum) : "",
level: level:
item.pointSum < 60.0 item.pointSum < 60.0
? "ต้องปรับปรุง (คะแนนต่ำกว่าร้อยละ ๖๐.)" ? "ต้องปรับปรุง"
: item.pointSum <= 69.99 && item.pointSum >= 60.0 : item.pointSum <= 69.99 && item.pointSum >= 60.0
? "พอใช้ (คะแนนร้อยละ ๖๐. - ๖๙.๙๙)" ? "พอใช้"
: item.pointSum <= 79.99 && item.pointSum >= 70.0 : item.pointSum <= 79.99 && item.pointSum >= 70.0
? "ดี (คะแนนร้อยละ ๗๐. - ๗๙.๙๙)" ? "ดี"
: item.pointSum <= 89.99 && item.pointSum >= 80.0 : item.pointSum <= 89.99 && item.pointSum >= 80.0
? "ดีมาก (คะแนนร้อยละ ๘๐. - ๘๙.๙๙)" ? "ดีมาก"
: "ดีเด่น (คะแนนร้อยละ ๙๐. ขึ้นไป)", : "ดีเด่น",
})) }))
: [ : [
{ {
@ -1706,6 +1724,7 @@ export class ProfileEmployeeController extends Controller {
? Extension.ToThaiNumber(item.positionCee) ? Extension.ToThaiNumber(item.positionCee)
: null, : null,
amount: item.amount ? Extension.ToThaiNumber(Number(item.amount).toLocaleString()) : "", 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: "-", position: "-",
posLevel: "-", posLevel: "-",
amount: "-", 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 const sum = profiles
? Extension.ToThaiNumber( ? Extension.ToThaiNumber(
( (
@ -1766,7 +1859,8 @@ export class ProfileEmployeeController extends Controller {
prefix: profiles?.prefix != null ? profiles.prefix : "", prefix: profiles?.prefix != null ? profiles.prefix : "",
firstName: profiles?.firstName != null ? profiles.firstName : "", firstName: profiles?.firstName != null ? profiles.firstName : "",
lastName: profiles?.lastName != null ? profiles.lastName : "", lastName: profiles?.lastName != null ? profiles.lastName : "",
position: profiles?.position != null ? profiles.position : "", position: _position,
posAssistance: ocAssistance ? "-" : _position, // ปัจจุบันช่วยราชการยังไม่มีเก็บฟิลด์ตำแหน่ง
amount: amount:
profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "", profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "",
positionSalaryAmount: positionSalaryAmount:
@ -1782,12 +1876,13 @@ export class ProfileEmployeeController extends Controller {
? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString()) ? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString())
: "", : "",
salarySum: sum, salarySum: sum,
ocFullPath: ocFullPath: org,
(_child4 == null ? "" : _child4 + "\n") + ocAssistance: ocAssistance?.agency ?? org,
(_child3 == null ? "" : _child3 + "\n") + root: _root == null ? "" : _root,
(_child2 == null ? "" : _child2 + "\n") + agency: (_child4 == null ? "" : _child4 + " ") +
(_child1 == null ? "" : _child1 + "\n") + (_child3 == null ? "" : _child3 + " ") +
(_root == null ? "" : _root), (_child2 == null ? "" : _child2 + " ") +
(_child1 == null ? "" : _child1).trim(),
birthDate: profiles?.birthDate birthDate: profiles?.birthDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate))
: "", : "",
@ -1916,6 +2011,7 @@ export class ProfileEmployeeController extends Controller {
assessments, assessments,
profileAbility, profileAbility,
otherIncome, otherIncome,
retires
}; };
return new HttpSuccess({ return new HttpSuccess({

View file

@ -1,6 +1,17 @@
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { CommandRecive } from "../entities/CommandRecive"; import { CommandRecive } from "../entities/CommandRecive";
import { Command } from "../entities/Command"; import { Command } from "../entities/Command";
import { OrgRoot } from "../entities/OrgRoot";
import { Profile } from "../entities/Profile";
export interface PosNumCodeSitResult {
posNumCodeSit: string;
posNumCodeSitAbb: string;
commandTypeName: string;
commandNo: string;
commandYear: number;
commandExcecuteDate: Date;
}
/** /**
* *
@ -44,3 +55,92 @@ export async function reOrderCommandRecivesAndDelete(
} }
} }
/**
* posNumCodeSit posNumCodeSitAbb commandId
* @param commandId ID
* @param status ()
* @returns Promise<PosNumCodeSitResult>
*/
export async function getPosNumCodeSit(
commandId: string,
status?: string
): Promise<PosNumCodeSitResult> {
const commandRepo = AppDataSource.getRepository(Command);
const orgRootRepo = AppDataSource.getRepository(OrgRoot);
const profileRepo = AppDataSource.getRepository(Profile);
let posNumCodeSit:string = "";
let posNumCodeSitAbb:string = "";
let commandTypeName:string = "";
let commandNo:string = "";
let commandYear:number = 0;
let commandExcecuteDate:Date = new Date;
let _command: Command | null;
if (!status) {
_command = await commandRepo.findOne({
where: { id: commandId },
relations: { commandType: true }
});
}
else {
_command = await commandRepo.findOne({
where: { id: commandId, status: status },
relations: { commandType: true }
});
}
if (_command) {
if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") {
const orgRootDeputy = await orgRootRepo.findOne({
where: {
isDeputy: true,
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
},
relations: ["orgRevision"],
});
posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร";
posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป.";
} else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") {
posNumCodeSit = "กรุงเทพมหานคร";
posNumCodeSitAbb = "กทม.";
} else {
let _profileAdmin = await profileRepo.findOne({
where: {
keycloak: _command?.createdUserId.toString(),
current_holders: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
},
},
relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"],
});
posNumCodeSit =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ??
"";
posNumCodeSitAbb =
_profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot
.orgRootShortName ?? "";
}
commandTypeName = _command?.commandType?.name ?? "";
commandNo = _command?.commandNo ?? "";
commandYear = _command?.commandYear;
commandExcecuteDate = _command?.commandExcecuteDate;
}
return {
posNumCodeSit,
posNumCodeSitAbb,
commandTypeName,
commandNo,
commandYear,
commandExcecuteDate,
};
}