diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index e4685a53..896717c8 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -90,7 +90,6 @@ 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") @@ -946,7 +945,6 @@ 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", @@ -1027,13 +1025,6 @@ 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 || @@ -1094,7 +1085,12 @@ export class ProfileController extends Controller { certificateType: item.certificateType ?? null, issuer: item.issuer ?? null, certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null, - detail: Extension.ToThaiNumber(`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim()), + issueDate: item.issueDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) + : "", + expireDate: item.expireDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)) + : "", issueToExpireDate: item.issueDate ? item.expireDate ? Extension.ToThaiNumber( @@ -1110,12 +1106,13 @@ export class ProfileController extends Controller { certificateType: "-", issuer: "-", certificateNo: "-", - detail: "-", + issueDate: "-", + expireDate: "-", issueToExpireDate: "-", }, ]; const training_raw = await this.trainingRepository.find({ - select: ["place", "department", "name", "duration", "isDeleted", "startDate", "endDate"], + select: ["place", "department", "name", "duration", "isDeleted"], where: { profileId: id, isDeleted: false }, order: { createdAt: "ASC" }, }); @@ -1126,7 +1123,6 @@ 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)}`) })) : [ { @@ -1134,7 +1130,6 @@ export class ProfileController extends Controller { degree: "-", place: "-", duration: "-", - date: "-" }, ]; @@ -1176,15 +1171,13 @@ 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.field ?? ""}`.trim(), - level: item.educationLevel + degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", })) : [ { institute: "-", date: "-", degree: "-", - level: "-" }, ]; const salary_raw = await this.salaryRepo.find({ @@ -1304,8 +1297,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(`ราชกิจจานุเบกษา เล่มที่ ${item.volume ?? "-"} ตอนที่ ${item.section ?? "-"} ลว. ${Extension.ToThaiFullDate2(item.refCommandDate)}`) - : "-", + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) + : "", note: item.note ? Extension.ToThaiNumber(item.note) : "", })) : [ @@ -1321,7 +1314,6 @@ export class ProfileController extends Controller { section: "-", page: "-", refCommandDate: "-", - note: "-" }, ]; @@ -1525,7 +1517,6 @@ 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))}`) })) : [ { @@ -1538,211 +1529,75 @@ 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", "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, status: "PENDING", isDeleted: false }, + select: ["dateStart", "dateEnd", "position", "isDeleted"], + where: { profileId: id, isDeleted: false }, + order: { createdAt: "ASC" }, + }); + const assistance_raw = await this.profileAssistanceRepository.find({ + select: ["dateStart", "dateEnd", "commandName", "agency", "document", "isDeleted"], + where: { profileId: id, 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" }, @@ -1760,21 +1615,15 @@ export class ProfileController extends Controller { : 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) - : "-", + refCommandDate: item.refCommandDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.refCommandDate)) + : "", + refCommandNo: item.refCommandNo ? Extension.ToThaiNumber(item.refCommandNo) : "", })) : [ { date: "-", - type: "-", - detail: "-", - agency: "-", + refCommandDate: "-", refCommandNo: "-", }, ]; @@ -1786,9 +1635,7 @@ 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" - ? 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()}`), + period: item.period && item.period == "APR" ? "เมษายน" : "ตุลาคม", point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "", point1Total: item.point1Total ? Extension.ToThaiNumber(item.point1Total.toString()) @@ -1797,20 +1644,18 @@ 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 - ? "ดีมาก" - : "ดีเด่น", + ? "ดีมาก (คะแนนร้อยละ ๘๐.๐๐ - ๘๙.๙๙)" + : "ดีเด่น (คะแนนร้อยละ ๙๐.๐๐ ขึ้นไป)", })) : [ { @@ -1866,7 +1711,6 @@ 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))}`) })) : [ { @@ -1877,7 +1721,6 @@ export class ProfileController extends Controller { position: "-", posLevel: "-", amount: "-", - refDoc: "-" }, ]; @@ -1932,41 +1775,20 @@ export class ProfileController extends Controller { }) .catch(() => {}); if (!portfolios) { - portfolios = [{ name: "-", year: "-", position: "-" }]; + portfolios = [{ name: "-", year: "-" }]; } 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: _position, - posAssistance: ocAssistance ? "-" : _position, // ปัจจุบันช่วยราชการยังไม่มีเก็บฟิลด์ตำแหน่ง + position: profiles?.position != null ? profiles.position : "", amount: profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "", positionSalaryAmount: @@ -1982,13 +1804,12 @@ export class ProfileController extends Controller { ? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString()) : "", salarySum: sum, - ocFullPath: org, - ocAssistance: ocAssistance?.agency ?? org, - root: _root == null ? "" : _root, - agency: (_child4 == null ? "" : _child4 + " ") + - (_child3 == null ? "" : _child3 + " ") + - (_child2 == null ? "" : _child2 + " ") + - (_child1 == null ? "" : _child1).trim(), + ocFullPath: + (_child4 == null ? "" : _child4 + "\n") + + (_child3 == null ? "" : _child3 + "\n") + + (_child2 == null ? "" : _child2 + "\n") + + (_child1 == null ? "" : _child1 + "\n") + + (_root == null ? "" : _root), birthDate: profiles?.birthDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) : "", @@ -2118,7 +1939,6 @@ export class ProfileController extends Controller { profileAbility, otherIncome, portfolios, - retires }; return new HttpSuccess({ diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index c87f61f9..43dbd8f3 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -941,7 +941,6 @@ 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", @@ -1022,13 +1021,6 @@ 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 || @@ -1089,7 +1081,12 @@ export class ProfileEmployeeController extends Controller { certificateType: item.certificateType ?? null, issuer: item.issuer ?? null, certificateNo: item.certificateNo ? Extension.ToThaiNumber(item.certificateNo) : null, - detail: Extension.ToThaiNumber(`${item.issuer ?? ""} ${item.certificateNo ?? ""}`.trim()), + issueDate: item.issueDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.issueDate)) + : "", + expireDate: item.expireDate + ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(item.expireDate)) + : "", issueToExpireDate: item.issueDate ? item.expireDate ? Extension.ToThaiNumber( @@ -1105,12 +1102,13 @@ export class ProfileEmployeeController extends Controller { certificateType: "-", issuer: "-", certificateNo: "-", - detail: "-", + issueDate: "-", + expireDate: "-", issueToExpireDate: "-", }, ]; const training_raw = await this.trainingRepository.find({ - select: ["place", "department", "name", "duration", "isDeleted", "startDate", "endDate"], + select: ["place", "department", "name", "duration", "isDeleted"], where: { profileEmployeeId: id, isDeleted: false }, order: { createdAt: "ASC" }, }); @@ -1121,7 +1119,6 @@ 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)}`) })) : [ { @@ -1129,7 +1126,6 @@ export class ProfileEmployeeController extends Controller { degree: "-", place: "-", duration: "-", - date: "-" }, ]; @@ -1171,15 +1167,13 @@ 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.field ?? ""}`.trim(), - level: item.educationLevel + degree: item.degree ? `${item.degree} ${item.field ? item.field : ""}` : "", })) : [ { institute: "-", date: "-", degree: "-", - level: "-" }, ]; const salary_raw = await this.salaryRepo.find({ @@ -1519,7 +1513,6 @@ 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))}`) })) : [ { @@ -1532,10 +1525,9 @@ 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 }, @@ -1607,36 +1599,30 @@ 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)) - : "", - 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: "-", - }, - ]; + 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: "-", + }, + ]; const assessments_raw = await this.profileAssessmentsRepository.find({ where: { profileEmployeeId: id, isDeleted: false }, order: { createdAt: "ASC" }, @@ -1645,9 +1631,7 @@ 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" - ? 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()}`), + period: item.period && item.period == "APR" ? "เมษายน" : "ตุลาคม", point1: item.point1 ? Extension.ToThaiNumber(item.point1.toString()) : "", point1Total: item.point1Total ? Extension.ToThaiNumber(item.point1Total.toString()) @@ -1656,20 +1640,18 @@ 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 - ? "ดีมาก" - : "ดีเด่น", + ? "ดีมาก (คะแนนร้อยละ ๘๐.๐๐ - ๘๙.๙๙)" + : "ดีเด่น (คะแนนร้อยละ ๙๐.๐๐ ขึ้นไป)", })) : [ { @@ -1724,7 +1706,6 @@ 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))}`) })) : [ { @@ -1735,83 +1716,9 @@ 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( ( @@ -1859,8 +1766,7 @@ export class ProfileEmployeeController extends Controller { prefix: profiles?.prefix != null ? profiles.prefix : "", firstName: profiles?.firstName != null ? profiles.firstName : "", lastName: profiles?.lastName != null ? profiles.lastName : "", - position: _position, - posAssistance: ocAssistance ? "-" : _position, // ปัจจุบันช่วยราชการยังไม่มีเก็บฟิลด์ตำแหน่ง + position: profiles?.position != null ? profiles.position : "", amount: profiles?.amount != null ? Extension.ToThaiNumber(profiles.amount.toLocaleString()) : "", positionSalaryAmount: @@ -1876,13 +1782,12 @@ export class ProfileEmployeeController extends Controller { ? Extension.ToThaiNumber(profiles.amountSpecial.toLocaleString()) : "", salarySum: sum, - ocFullPath: org, - ocAssistance: ocAssistance?.agency ?? org, - root: _root == null ? "" : _root, - agency: (_child4 == null ? "" : _child4 + " ") + - (_child3 == null ? "" : _child3 + " ") + - (_child2 == null ? "" : _child2 + " ") + - (_child1 == null ? "" : _child1).trim(), + ocFullPath: + (_child4 == null ? "" : _child4 + "\n") + + (_child3 == null ? "" : _child3 + "\n") + + (_child2 == null ? "" : _child2 + "\n") + + (_child1 == null ? "" : _child1 + "\n") + + (_root == null ? "" : _root), birthDate: profiles?.birthDate ? Extension.ToThaiNumber(Extension.ToThaiFullDate2(profiles.birthDate)) : "", @@ -2011,7 +1916,6 @@ export class ProfileEmployeeController extends Controller { assessments, profileAbility, otherIncome, - retires }; return new HttpSuccess({ diff --git a/src/services/CommandService.ts b/src/services/CommandService.ts index b002462c..295d9ce8 100644 --- a/src/services/CommandService.ts +++ b/src/services/CommandService.ts @@ -1,17 +1,6 @@ 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; -} /** * เรียงลำดับผู้ได้รับคำสั่งใหม่หลังจากลบรายการ และอัพเดทสถานะคำสั่งถ้าไม่มีผู้ได้รับคำสั่งเหลือ @@ -55,92 +44,3 @@ export async function reOrderCommandRecivesAndDelete( } } - -/** - * ดึงข้อมูล posNumCodeSit และ posNumCodeSitAbb จาก commandId - * @param commandId ID ของคำสั่ง - * @param status สถานะของคำสั่ง (ไม่บังคับส่ง) - * @returns Promise ข้อมูลชื่อหน่วยงานและชื่อย่อ - */ -export async function getPosNumCodeSit( - commandId: string, - status?: string -): Promise { - 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, - }; -}