แก้ข้อความ/ตัดข้อมูลรายงาน ทปอ.สามัญ #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 { ProfileLeaveService } from "../services/ProfileLeaveService";
import { PostRetireToExprofile } from "./ExRetirementController";
import { getPosNumCodeSit } from "../services/CommandService";
@Route("api/v1/org/profile")
@Tags("Profile")
@Security("bearerAuth")
@ -945,6 +946,7 @@ export class ProfileController extends Controller {
public async getKk1new(@Path() id: string, @Request() req: RequestWithUser) {
const profiles = await this.profileRepo.findOne({
relations: [
"posLevel",
"currentSubDistrict",
"currentDistrict",
"currentProvince",
@ -1025,6 +1027,13 @@ export class ProfileController 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 ||
@ -1085,12 +1094,7 @@ export class ProfileController 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(
@ -1106,13 +1110,12 @@ export class ProfileController 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: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" },
});
@ -1123,6 +1126,7 @@ export class ProfileController 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)}`)
}))
: [
{
@ -1130,6 +1134,7 @@ export class ProfileController extends Controller {
degree: "-",
place: "-",
duration: "-",
date: "-"
},
];
@ -1171,13 +1176,15 @@ export class ProfileController 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({
@ -1297,8 +1304,8 @@ export class ProfileController extends Controller {
section: item.section ? Extension.ToThaiNumber(item.section) : "",
page: item.page ? Extension.ToThaiNumber(item.page) : "",
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) : "",
}))
: [
@ -1314,6 +1321,7 @@ export class ProfileController extends Controller {
section: "-",
page: "-",
refCommandDate: "-",
note: "-"
},
];
@ -1517,6 +1525,7 @@ export class ProfileController 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))}`)
}))
: [
{
@ -1529,75 +1538,211 @@ export class ProfileController extends Controller {
posLevel: "-",
amount: "-",
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({
select: ["dateStart", "dateEnd", "position", "isDeleted"],
where: { profileId: id, isDeleted: false },
select: ["dateStart", "profileId", "dateEnd", "position", "commandId", "isDeleted"],
where: { profileId: id, status: true, isDeleted: false },
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({
select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"],
where: { profileId: id, isDeleted: false },
where: { profileId: id, status: "PENDING", isDeleted: false },
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({
where: { profileId: id, isDeleted: false },
order: { createdAt: "ASC" },
@ -1615,15 +1760,21 @@ export class ProfileController extends Controller {
: item.dateEnd
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.dateEnd))
: "",
refCommandDate: item.refCommandDate
? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate))
: "",
refCommandNo: item.refCommandNo ? Extension.ToThaiNumber(item.refCommandNo) : "",
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: "-",
refCommandDate: "-",
type: "-",
detail: "-",
agency: "-",
refCommandNo: "-",
},
];
@ -1635,7 +1786,9 @@ export class ProfileController 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())
@ -1644,18 +1797,20 @@ export class ProfileController 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
? "ดีมาก (คะแนนร้อยละ ๘๐. - ๘๙.๙๙)"
: "ดีเด่น (คะแนนร้อยละ ๙๐. ขึ้นไป)",
? "ดีมาก"
: "ดีเด่น",
}))
: [
{
@ -1711,6 +1866,7 @@ export class ProfileController 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))}`)
}))
: [
{
@ -1721,6 +1877,7 @@ export class ProfileController extends Controller {
position: "-",
posLevel: "-",
amount: "-",
refDoc: "-"
},
];
@ -1775,20 +1932,41 @@ export class ProfileController extends Controller {
})
.catch(() => {});
if (!portfolios) {
portfolios = [{ name: "-", year: "-" }];
portfolios = [{ name: "-", year: "-", position: "-" }];
} else {
portfolios = portfolios.map((x: any) => ({
name: x.name ? Extension.ToThaiNumber(x.name) : "-",
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 = {
fullName: `${profiles?.prefix}${profiles?.firstName} ${profiles?.lastName}`,
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:
@ -1804,12 +1982,13 @@ export class ProfileController 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))
: "",
@ -1939,6 +2118,7 @@ export class ProfileController extends Controller {
profileAbility,
otherIncome,
portfolios,
retires
};
return new HttpSuccess({

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({

View file

@ -1,6 +1,17 @@
import { AppDataSource } from "../database/data-source";
import { CommandRecive } from "../entities/CommandRecive";
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,
};
}