From 43c873ce467cba373ca6834da49027a4e1272f3a Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 3 Feb 2025 15:47:29 +0700 Subject: [PATCH] #1001, #1007, #1033, #1037, #1039, #1045, #1043 --- src/controllers/ReportController.ts | 785 +++++++++++++++------------- 1 file changed, 423 insertions(+), 362 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 10aab7f..7e92e33 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1078,7 +1078,7 @@ export class ReportController extends Controller { group: convertGroup, }, }); - + if (salaryPeriod.period === "APR") { let salaryProfileGroup1: any; let salaryProfileGroup2: any; @@ -1090,7 +1090,12 @@ export class ReportController extends Controller { }, }); } - + const rootName = await this.salaryOrgRepository.findOne({ + where: { + rootId: rootId, + }, + select: ["root"], + }); //รอบปีก่อนๆ const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ where: { @@ -1108,33 +1113,35 @@ export class ReportController extends Controller { }); let salaryOrg1_APR = null; - if(salaryPeriodIncrease1_APR) { - salaryOrg1_APR = await this.salaryOrgRepository.findOne({ + if (salaryPeriodIncrease1_APR) { + salaryOrg1_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_APR?.id, // rootId: rootId, + root: rootName?.root, snapshot: "SNAP1", group: convertGroup, }, }); } - + let salaryOrg1_OCT = null; - if(salaryPeriodIncrease1_OCT) { - salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ - where: { - salaryPeriodId: salaryPeriodIncrease1_OCT?.id, - // rootId: rootId, - snapshot: "SNAP1", - group: convertGroup, - }, - }); + if (salaryPeriodIncrease1_OCT) { + salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease1_OCT?.id, + // rootId: rootId, + root: rootName?.root, + snapshot: "SNAP1", + group: convertGroup, + }, + }); } const salaryProfile1 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), - // type: "FULL", + type: Not(In(["NONE", "PENDING"])), }, }); //รอบปีก่อนหน้า @@ -1152,13 +1159,14 @@ export class ReportController extends Controller { isActive: true, }, }); - + let salaryOrg2_APR = null; - if(salaryPeriodIncrease2_APR){ - salaryOrg2_APR = await this.salaryOrgRepository.findOne({ + if (salaryPeriodIncrease2_APR) { + salaryOrg2_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, // rootId: rootId, + root: rootName?.root, snapshot: "SNAP1", group: convertGroup, }, @@ -1166,26 +1174,25 @@ export class ReportController extends Controller { } let salaryOrg2_OCT = null; - if(salaryPeriodIncrease2_OCT){ + if (salaryPeriodIncrease2_OCT) { salaryOrg2_OCT = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, // rootId: rootId, + root: rootName?.root, snapshot: "SNAP1", group: convertGroup, }, }); } - // console.log("d2",salaryOrg2_APR); - // console.log("d3",salaryOrg2_OCT); + const salaryProfile2 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]), - // type: "FULL", + type: Not(In(["NONE", "PENDING"])), }, }); - // console.log("d4",salaryProfile2); - + const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); const yearIncrease1 = Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 2)), @@ -1346,24 +1353,23 @@ export class ReportController extends Controller { const salaryProfile_APR = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg_APR?.id, - // type: In(["HAFT", "FULL"]), + type: Not(In(["NONE", "PENDING"])), }, }); - //end period APR - const salaryProfileGroup1 = await this.salaryProfileRepository.find({ - where: { - salaryOrgId: salaryOrg?.id, - type: In(["FULLHAFT", "FULL"]), - }, - }); - const salaryProfileGroup2 = await this.salaryProfileRepository.find({ + const salaryProfile_current = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg?.id, type: In(["FULLHAFT", "FULL"]), }, }); + // const salaryProfileGroup2 = await this.salaryProfileRepository.find({ + // where: { + // salaryOrgId: salaryOrg?.id, + // type: In(["FULLHAFT", "FULL"]), + // }, + // }); //รอบปีก่อนๆ const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ @@ -1381,33 +1387,35 @@ export class ReportController extends Controller { }, }); let salaryOrg1_APR = null; - if(salaryPeriodIncrease1_APR) { - salaryOrg1_APR = await this.salaryOrgRepository.findOne({ + if (salaryPeriodIncrease1_APR) { + salaryOrg1_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_APR?.id, // rootId: rootId, + root: salaryOrg.root, snapshot: "SNAP1", group: convertGroup, }, }); } - + let salaryOrg1_OCT = null; - if(salaryPeriodIncrease1_OCT) { - salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ - where: { - salaryPeriodId: salaryPeriodIncrease1_OCT?.id, - // rootId: rootId, - snapshot: "SNAP1", - group: convertGroup, - }, - }); + if (salaryPeriodIncrease1_OCT) { + salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodIncrease1_OCT?.id, + // rootId: rootId, + root: salaryOrg.root, + snapshot: "SNAP1", + group: convertGroup, + }, + }); } const salaryProfile1 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), - // type: "FULL", + type: Not(In(["NONE", "PENDING"])), }, }); @@ -1428,11 +1436,12 @@ export class ReportController extends Controller { }); let salaryOrg2_APR = null; - if(salaryPeriodIncrease2_APR){ - salaryOrg2_APR = await this.salaryOrgRepository.findOne({ + if (salaryPeriodIncrease2_APR) { + salaryOrg2_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, // rootId: rootId, + root: salaryOrg.root, snapshot: "SNAP1", group: convertGroup, }, @@ -1440,20 +1449,23 @@ export class ReportController extends Controller { } let salaryOrg2_OCT = null; - if(salaryPeriodIncrease2_OCT){ + if (salaryPeriodIncrease2_OCT) { salaryOrg2_OCT = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, // rootId: rootId, + root: salaryOrg.root, snapshot: "SNAP1", group: convertGroup, }, }); } + const salaryProfile2 = await this.salaryProfileRepository.find({ + //เอามาหาว่าทั้งปีได้เลื่อนขั้นไหม where: { salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]), - // type: "FULL", + type: Not(In(["NONE", "PENDING"])), }, }); @@ -1492,157 +1504,165 @@ export class ReportController extends Controller { point: fifteenPercent + fifteenPoint, pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, root: salaryOrg?.root, - profile: salaryProfileGroup1 - ? salaryProfileGroup1.map((item: any, index: any) => ({ - no: Extension.ToThaiNumber(String(index + 1)), - affiliation: - (item.child4 == undefined && item.child4 == null ? "" : item.child4 + " ") + - (item.child3 == undefined && item.child3 == null ? "" : item.child3 + " ") + - (item.child2 == undefined && item.child2 == null ? "" : item.child2 + " ") + - (item.child1 == undefined && item.child1 == null ? "" : item.child1 + " ") + - (item.root == undefined && item.root == null ? "" : item.root), - fullName: item.prefix + item.firstName + " " + item.lastName, - posLevel: item.posLevel, - posMasterNo: - Extension.ToThaiNumber(item.orgShortName) + - Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())), - amount: - item.amount == undefined || item.amount == null - ? "๐" - : Extension.ToThaiNumber(String(item.amount.toLocaleString())), - salaryIncrease1: - salaryProfile1.length > 0 - ? (() => { - const filteredType = salaryProfile1 - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" - ? "ครึ่งขั้น" - : Type === "FULL" - ? "หนึ่งขั้น" - : Type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : "ไม่ได้เลื่อนขั้น"; - })() - : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า - salaryIncrease2: - salaryProfile2.length > 0 - ? (() => { - const filteredType = salaryProfile2 - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" - ? "ครึ่งขั้น" - : Type === "FULL" - ? "หนึ่งขั้น" - : Type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : "ไม่ได้เลื่อนขั้น"; - })() - : null, //การเลื่อนเงินเดือนปีก่อนหน้า - salaryIncreaseAPR: - salaryProfile_APR.length > 0 - ? (() => { - const filteredType = salaryProfile_APR - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" - ? "ครึ่งขั้น" - : Type === "FULL" - ? "หนึ่งขั้น" - : Type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : "ไม่ได้เลื่อนขั้น"; - })() - : null, //การเลื่อนเงินเดือนรอบเมษา - Type: - item.type === "FULL" - ? "หนึ่งขั้น" - : item.type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : null, - score1: item.result, //ผลการประเมินฯ ครั้งที่ 1 - score2: null, //ผลการประเมินฯ ครั้งที่ 2 - })) + profile: salaryProfile_current + ? salaryProfile_current + .filter( + (item: any) => salaryProfile_APR.some((x: any) => x.citizenId === item.citizenId), // ตรวจสอบว่า citizenId ของ item มีอยู่ใน salaryProfile_APR หรือไม่ + ) + .map((item: any, index: any) => ({ + no: Extension.ToThaiNumber(String(index + 1)), + affiliation: + (item.child4 == undefined && item.child4 == null ? "" : item.child4 + " ") + + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + " ") + + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + " ") + + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + " ") + + (item.root == undefined && item.root == null ? "" : item.root), + fullName: item.prefix + item.firstName + " " + item.lastName, + posLevel: item.posLevel, + posMasterNo: + Extension.ToThaiNumber(item.orgShortName) + + Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())), + amount: + item.amount == undefined || item.amount == null + ? "๐" + : Extension.ToThaiNumber(String(item.amount.toLocaleString())), + salaryIncrease1: + salaryProfile1.length > 0 + ? (() => { + const filteredType = salaryProfile1 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า + salaryIncrease2: + salaryProfile2.length > 0 + ? (() => { + const filteredType = salaryProfile2 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนปีก่อนหน้า + salaryIncreaseAPR: + salaryProfile_APR.length > 0 + ? (() => { + const filteredType = salaryProfile_APR + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนรอบเมษา + Type: + item.type === "FULL" + ? "หนึ่งขั้น" + : item.type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : null, + score1: item.result, //ผลการประเมินฯ ครั้งที่ 1 + score2: null, //ผลการประเมินฯ ครั้งที่ 2 + })) : null, - profileGroup2: salaryProfileGroup2 - ? salaryProfileGroup2.map((item, index) => ({ - no: Extension.ToThaiNumber(String(index + 1)), - affiliation: - (item.child4 == undefined && item.child4 == null ? "" : item.child4 + " ") + - (item.child3 == undefined && item.child3 == null ? "" : item.child3 + " ") + - (item.child2 == undefined && item.child2 == null ? "" : item.child2 + " ") + - (item.child1 == undefined && item.child1 == null ? "" : item.child1 + " ") + - (item.root == undefined && item.root == null ? "" : item.root), - fullName: item.prefix + item.firstName + " " + item.lastName, - posLevel: item.posLevel, - posMasterNo: - Extension.ToThaiNumber(item.orgShortName) + - Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())), - amount: - item.amount == undefined || item.amount == null - ? "๐" - : Extension.ToThaiNumber(String(item.amount.toLocaleString())), - salaryIncrease1: - salaryProfile1.length > 0 - ? (() => { - const filteredType = salaryProfile1 - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" - ? "ครึ่งขั้น" - : Type === "FULL" - ? "หนึ่งขั้น" - : Type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : "ไม่ได้เลื่อนขั้น"; - })() - : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า - salaryIncrease2: - salaryProfile2.length > 0 - ? (() => { - const filteredType = salaryProfile2 - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" - ? "ครึ่งขั้น" - : Type === "FULL" - ? "หนึ่งขั้น" - : Type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : "ไม่ได้เลื่อนขั้น"; - })() - : null, //การเลื่อนเงินเดือนปีก่อนหน้า - salaryIncreaseAPR: - salaryProfile_APR.length > 0 - ? (() => { - const filteredType = salaryProfile_APR - .filter((profile) => profile.citizenId === item.citizenId) - .map((profile) => profile.type); - const Type = filteredType[0]; - return Type === "HAFT" - ? "ครึ่งขั้น" - : Type === "FULL" - ? "หนึ่งขั้น" - : Type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : "ไม่ได้เลื่อนขั้น"; - })() - : null, //การเลื่อนเงินเดือนรอบเมษา - Type: - item.type === "FULL" - ? "หนึ่งขั้น" - : item.type === "FULLHAFT" - ? "หนึ่งขั้นครึ่ง" - : null, - score1: item.result, //ผลการประเมินฯ ครั้งที่ 1 - score2: null, //ผลการประเมินฯ ครั้งที่ 2 - })) + profileGroup2: salaryProfile_current + ? salaryProfile_current + .filter((item: any) => + salaryProfile_APR.some((x: any) => x.citizenId === item.citizenId), + ) + .map((item: any, index: any) => ({ + no: Extension.ToThaiNumber(String(index + 1)), + affiliation: + (item.child4 == undefined && item.child4 == null ? "" : item.child4 + " ") + + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + " ") + + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + " ") + + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + " ") + + (item.root == undefined && item.root == null ? "" : item.root), + fullName: item.prefix + item.firstName + " " + item.lastName, + posLevel: item.posLevel, + posMasterNo: + Extension.ToThaiNumber(item.orgShortName) + + Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())), + amount: + item.amount == undefined || item.amount == null + ? "๐" + : Extension.ToThaiNumber(String(item.amount.toLocaleString())), + salaryIncrease1: + salaryProfile1.length > 0 + ? (() => { + const filteredType = salaryProfile1 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนปีก่อนๆหน้า + salaryIncrease2: + salaryProfile2.length > 0 + ? (() => { + const filteredType = salaryProfile2 + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนปีก่อนหน้า + salaryIncreaseAPR: + salaryProfile_APR.length > 0 + ? (() => { + const filteredType = salaryProfile_APR + .filter((profile) => profile.citizenId === item.citizenId) + .map((profile) => profile.type); + const Type = filteredType[0]; + return Type === "HAFT" + ? "ครึ่งขั้น" + : Type === "FULL" + ? "หนึ่งขั้น" + : Type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : "ไม่ได้เลื่อนขั้น"; + })() + : null, //การเลื่อนเงินเดือนรอบเมษา + Type: + item.type === "FULL" + ? "หนึ่งขั้น" + : item.type === "FULLHAFT" + ? "หนึ่งขั้นครึ่ง" + : null, + score1: item.result, //ผลการประเมินฯ ครั้งที่ 1 + score2: null, //ผลการประเมินฯ ครั้งที่ 2 + })) : null, }, }); @@ -2037,12 +2057,14 @@ export class ReportController extends Controller { return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullname: profile.prefix + profile.firstName + " " + profile.lastName, - position: profile.position??"-", + position: profile.position ?? "-", affiliation: affiliation, posLevel: profile.posLevel, - posNumber: profile.orgShortName || profile.posMasterNo ? - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) : "-", + posNumber: + profile.orgShortName || profile.posMasterNo + ? Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) + : "-", amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", reason: null, //เหตุผล score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน @@ -2101,8 +2123,8 @@ export class ReportController extends Controller { const convertGroup = group.toUpperCase(); const salaryProfile = await this.salaryProfileRepository.find({ where: { - type: Not(In(["NONE","PENDING"])), - isReserve : Not(true), + type: Not(In(["NONE", "PENDING"])), + isReserve: Not(true), salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -2132,7 +2154,7 @@ export class ReportController extends Controller { const formattedData = salaryProfile.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: item.prefix + item.firstName + " " + item.lastName, - position: item.position??"-", + position: item.position ?? "-", affiliation: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + " ") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + " ") + @@ -2160,11 +2182,13 @@ export class ReportController extends Controller { ? `(${Extension.ToThaiNumber(String(item.positionSalaryAmount))})` : ""), remark: [ - item.type === "FULL" ? "หนึ่งขั้น" : "", - item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "", - item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ" : "", - item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : "" - ].filter(Boolean).join("\n") + item.type === "FULL" ? "หนึ่งขั้น" : "", + item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "", + item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ" : "", + item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : "", + ] + .filter(Boolean) + .join("\n"), })); return new HttpSuccess({ @@ -2679,9 +2703,11 @@ export class ReportController extends Controller { posLevel: profile.posLevel ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", - posNumber: profile.orgShortName || profile.posMasterNo ? - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) : "-", + posNumber: + profile.orgShortName || profile.posMasterNo + ? Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) + : "-", amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", reason: profile.remark, @@ -2845,13 +2871,15 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posLevel: profile.posLevel ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", - posNumber: profile.orgShortName || profile.posMasterNo ? - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) : "-", + posNumber: + profile.orgShortName || profile.posMasterNo + ? Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) + : "-", amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) @@ -2933,13 +2961,15 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posLevel: profile.posLevel ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", - posNumber:profile.orgShortName || profile.posMasterNo ? - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()): "-", + posNumber: + profile.orgShortName || profile.posMasterNo + ? Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) + : "-", amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) @@ -3015,7 +3045,7 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posLevel: profile.posLevel ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", @@ -3156,7 +3186,7 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), @@ -3536,7 +3566,7 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posLevel: profile.posLevel ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", @@ -4190,15 +4220,13 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", yearOld2: - octPreviousYear2 == null - ? "-" - : Extension.ToThaiNumber(octPreviousYear2.year.toString()), + octPreviousYear2 == null ? "-" : Extension.ToThaiNumber(octPreviousYear2.year.toString()), typeOld2: octPreviousYear2 && octPreviousYearProfile2.length > 0 ? (() => { @@ -4324,7 +4352,7 @@ export class ReportController extends Controller { const _salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: Not("NONE"), + type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -4334,6 +4362,7 @@ export class ReportController extends Controller { order: { orgShortName: "ASC", posMasterNo: "ASC", + result: "DESC", }, }); @@ -4369,7 +4398,7 @@ export class ReportController extends Controller { aprPreviousYearProfileCurrent = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: Not("NONE"), + type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -4384,7 +4413,7 @@ export class ReportController extends Controller { octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: Not("NONE"), + type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", rootId: rootId, @@ -4399,7 +4428,7 @@ export class ReportController extends Controller { aprPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { - type: Not("NONE"), + type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", salaryPeriodId: aprPreviousYear2?.id, @@ -4409,101 +4438,121 @@ export class ReportController extends Controller { }); } - // const agency = _salaryProfileEmployee[0] == null ? "" : _salaryProfileEmployee[0].root; + // ฟังก์ชันที่ใช้ตรวจสอบการตรงตามเงื่อนไข + const checkTypeMatch = (type1: any, type2: any) => { + if (type1 === "FULL" && type2 === "FULL") return true; + if (type1 === "HAFT" && type2 === "FULLHAFT") return true; + if (type1 === "FULLHAFT" && type2 === "HAFT") return true; + return false; + }; - const formattedData = _salaryProfileEmployee.map((profile, index) => { - const fullNameParts = [ - profile.child4, - profile.child3, - profile.child2, - profile.child1, - profile.root, - ]; + const formattedData = _salaryProfileEmployee + .filter((profile) => { + const matchingProfile = aprPreviousYearProfileCurrent.find( + (profileAPR) => profileAPR.citizenId === profile.citizenId, + ); + if (!matchingProfile) return false; + const typeMatch = checkTypeMatch(matchingProfile.type, profile.type); + return typeMatch; + }) + .map((profile, index) => { + const fullNameParts = [ + profile.child4, + profile.child3, + profile.child2, + profile.child1, + profile.root, + ]; - const affiliation = fullNameParts - .filter((part) => part !== undefined && part !== null) - .join(" "); - const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; + const affiliation = fullNameParts + .filter((part) => part !== undefined && part !== null) + .join(" "); + const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; - return { - no: Extension.ToThaiNumber((index + 1).toLocaleString()), - fullName: fullName, - affiliation: affiliation, - position: profile.position??"-", - posLevel: profile.posLevel?Extension.ToThaiNumber(profile.posLevel.toLocaleString()):"-", - posNumber: profile.orgShortName || profile.posMasterNo ? - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) : "-", - amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", - //เมษา ปีก่อนหน้า - typeOld2: - aprPreviousYear2 && aprPreviousYearProfile2.length > 0 - ? (() => { - const _profile = aprPreviousYearProfile2.filter( - (profileAPR2) => profileAPR2.citizenId === profile.citizenId, - ); - if (_profile.length > 0) { - return _profile[0]?.type === "HAFT" + return { + no: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + affiliation: affiliation, + position: profile.position ?? "-", + posLevel: profile.posLevel + ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) + : "-", + posNumber: + profile.orgShortName || profile.posMasterNo + ? Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(String(profile.posMasterNo.toLocaleString())) + : "-", + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", + // เมษา ปีก่อนหน้า + typeOld2: + aprPreviousYear2 && aprPreviousYearProfile2.length > 0 + ? (() => { + const _profile = aprPreviousYearProfile2.filter( + (profileAPR2) => profileAPR2.citizenId === profile.citizenId, + ); + if (_profile.length > 0) { + return _profile[0]?.type === "HAFT" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + } + return null; + })() + : "-", + yearOld: + octPreviousYear == null + ? null + : Extension.ToThaiNumber(octPreviousYear.year.toString()), + // ตุลา ปีก่อนหน้า + typeOld1: + octPreviousYear && octPreviousYearProfile.length > 0 + ? (() => { + const _profile = octPreviousYearProfile.filter( + (profileOCT) => profileOCT.citizenId === profile.citizenId, + ); + if (_profile.length > 0) { + return _profile[0]?.type === "HAFT" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + } + return null; + })() + : "-", + typeOld: + aprPreviousYearProfileCurrent.length > 0 + ? (() => { + const _profile = aprPreviousYearProfileCurrent.filter( + (profileAPR) => profileAPR.citizenId === profile.citizenId, + ); + const _type = _profile[0]?.type; + return _type === "HAFT" ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" + : _type === "FULL" ? "๑ ขั้น" - : profile?.type === "FULLHAFT" + : _type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; - } - return null; - })() - : "-", - yearOld: - octPreviousYear == null ? null : Extension.ToThaiNumber(octPreviousYear.year.toString()), - //ตุลา ปีก่อนหน้า - typeOld1: - octPreviousYear && octPreviousYearProfile.length > 0 - ? (() => { - const _profile = octPreviousYearProfile.filter( - (profileOCT) => profileOCT.citizenId === profile.citizenId, - ); - if (_profile.length > 0) { - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; - } - return null; - })() - : "-", - typeOld: - aprPreviousYearProfileCurrent.length > 0 - ? (() => { - const _profile = aprPreviousYearProfileCurrent - .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) - .map((profile) => ({ - type: profile.type, - })); - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; - })() - : "-", //เมษา - type: - profile.type === "HAFT" - ? "๐.๕ ขั้น" - : profile.type === "FULL" - ? "๑ ขั้น" - : profile.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ", - score1: profile.result?? "-", - score2: "-", - }; - }); + })() + : "-", // เมษา + type: + profile.type === "HAFT" + ? "๐.๕ ขั้น" + : profile.type === "FULL" + ? "๑ ขั้น" + : profile.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ", + score1: profile.result ?? "-", + score2: "-", + }; + }); return new HttpSuccess({ template: "emp2-03", @@ -4587,15 +4636,15 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", //pos\n - // profile.position + - // "\n" + - // (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + " ") + - // (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + " ") + - // (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + " ") + - // (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + " ") + - // (profile.root == undefined && profile.root == null ? "" : profile.root), + // profile.position + + // "\n" + + // (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + " ") + + // (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + " ") + + // (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + " ") + + // (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + " ") + + // (profile.root == undefined && profile.root == null ? "" : profile.root), posLevel: profile.posLevel ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", @@ -5236,23 +5285,25 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", //pos\n - // profile.position + - // "\n" + - // (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + " ") + - // (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + " ") + - // (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + " ") + - // (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + " ") + - // (profile.root == undefined && profile.root == null ? "" : profile.root), - posLevel: profile.posLevel, + // profile.position + + // "\n" + + // (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + " ") + + // (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + " ") + + // (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + " ") + + // (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + " ") + + // (profile.root == undefined && profile.root == null ? "" : profile.root), + posLevel: profile.posLevel + ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` + : "-", posNumber: Extension.ToThaiNumber(profile.orgShortName) + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), - amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) - : null, + : "-", reason1: null, //เหตุผลที่ไม่ได้เลื่อนขั้น reason2: null, //เหตุผลที่ไม่ได้เลื่อนขั้น reason3: null, //เหตุผลที่ไม่ได้เลื่อนขั้น @@ -5334,8 +5385,8 @@ export class ReportController extends Controller { affiliation: affiliation, position: profile.position, posLevel: profile.posLevel - ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` - : "-", + ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` + : "-", }; }); @@ -5526,15 +5577,15 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", //pos\n - // profile.position + - // "\n" + - // (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + " ") + - // (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + " ") + - // (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + " ") + - // (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + " ") + - // (profile.root == undefined && profile.root == null ? "" : profile.root), + // profile.position + + // "\n" + + // (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + " ") + + // (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + " ") + + // (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + " ") + + // (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + " ") + + // (profile.root == undefined && profile.root == null ? "" : profile.root), posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + @@ -5702,6 +5753,7 @@ export class ReportController extends Controller { order: { orgShortName: "ASC", posMasterNo: "ASC", + type: "DESC", }, }); @@ -5729,18 +5781,27 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position??"-", + position: profile.position ?? "-", posLevel: profile.posLevel ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) : "-", - posNumber: profile.orgShortName || profile.posMasterNo ? - Extension.ToThaiNumber(profile.orgShortName) + - Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()):"-", + posNumber: + profile.orgShortName || profile.posMasterNo + ? Extension.ToThaiNumber(profile.orgShortName) + + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) + : "-", amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", - reason: null, + reason: + profile.type === "HAFT" + ? "๐.๕ ขั้น" + : profile.type === "FULL" + ? "๑ ขั้น" + : profile.type === "FULLHAFT" + ? "๑.๕ ขั้น" + : null, }; }); @@ -5781,7 +5842,7 @@ export class ReportController extends Controller { rootId: rootId, salaryPeriodId: salaryPeriodId, }, - type: In(["NONE","PENDING"]), + type: In(["NONE", "PENDING"]), isRetired: false, }, order: { @@ -5816,7 +5877,7 @@ export class ReportController extends Controller { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, - position: profile.position?profile.position:"-", + position: profile.position ? profile.position : "-", posLevel: profile.posLevel ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) : "-", @@ -5863,7 +5924,7 @@ export class ReportController extends Controller { const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { - type: Not(In(["NONE","PENDING"])), + type: Not(In(["NONE", "PENDING"])), amountSpecial: MoreThan(0), salaryOrg: { snapshot: "SNAP2", @@ -5973,7 +6034,7 @@ export class ReportController extends Controller { const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { - type: Not(In(["NONE","PENDING"])), + type: Not(In(["NONE", "PENDING"])), amountSpecial: 0, salaryOrg: { snapshot: "SNAP2", @@ -6013,8 +6074,8 @@ export class ReportController extends Controller { affiliation: affiliation, position: profile.position ?? "-", posLevel: profile.posLevel - ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` - : "-", + ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` + : "-", posNumber: profile.orgShortName || profile.posMasterNo ? Extension.ToThaiNumber(profile.orgShortName) +