From 478cd7f083ad1d983a12fa12f528527882a57166 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 27 Mar 2024 15:30:41 +0700 Subject: [PATCH 1/2] =?UTF-8?q?gov-(04-05)=20=E0=B8=81=E0=B8=A3=E0=B8=AD?= =?UTF-8?q?=E0=B8=87=E0=B9=80=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= =?UTF-8?q?=E0=B9=81=E0=B8=A5=E0=B8=B0=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B9=80?= =?UTF-8?q?=E0=B8=81=E0=B8=A9=E0=B8=B5=E0=B8=A2=E0=B8=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReportController.ts | 186 +++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 4 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 6954e00..5b3b310 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1529,9 +1529,9 @@ export class ReportController extends Controller { } /** - * API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน + * API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * - * @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน + * @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period @@ -1557,6 +1557,7 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน + isReserve: false //กรองเฉพาะคนที่ไม่เกษียณ }, order: { salaryOrg: { @@ -1624,9 +1625,105 @@ export class ReportController extends Controller { } /** - * API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน + * API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) * - * @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน + * @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) + * + * @param {string} rootId Guid, *Id Root + * @param {string} salaryPeriodId Guid, *Id Period + */ + @Get("gov-04-01/{rootId}/{salaryPeriodId}") + async SalaryReport4Retire(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + type: "NONE", //ไม่ได้เลื่อน + isReserve: true //กรองเฉพาะคนที่เกษียณ + }, + order: { + salaryOrg: { + group: "ASC", + }, + type: "DESC", + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.map((profile, index) => { + return { + no: Extension.ToThaiNumber(String(index + 1)), + fullname: profile.prefix + profile.firstName + " " + profile.lastName, + log_group: profile.salaryOrg.group, + log_type: profile.type, + log_isNext: profile.isNext, + position: + profile.position + + "/" + + (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, + orgShortName: profile.orgShortName + Extension.ToThaiNumber(String(profile.posMasterNo)), + amount: + profile.amount == undefined || profile.amount == null || profile.amount == 0 + ? "" + : Extension.ToThaiNumber(String(profile.amount)), + amountSpecial: + (profile.positionSalaryAmount == undefined || + profile.positionSalaryAmount == null || + profile.positionSalaryAmount == 0 + ? "" + : Extension.ToThaiNumber(String(profile.positionSalaryAmount))) + + (profile.amountSpecial == undefined || + profile.amountSpecial == null || + profile.amountSpecial == 0 + ? "" + : `(${Extension.ToThaiNumber(String(profile.amountSpecial))})`), + score: null, //สรุปผลการประเมินฯ ระดับและคะแนน + remark: + `${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + + `${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` + + `${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + + `${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04", + reportName: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + effectiveDate: salaryPeriod.effectiveDate, + root: agency, + profile: formattedData, + }, + }); + } + + /** + * API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม + * + * @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period @@ -1652,6 +1749,87 @@ export class ReportController extends Controller { salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน + isReserve: false //กรองเฉพาะคนที่ไม่เกษียณ + }, + order: { + salaryOrg: { + group: "ASC", + }, + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.map((profile, index) => { + const fullNameParts = [ + profile.position, + profile.child4, + profile.child3, + profile.child2, + profile.child1, + profile.root, + ]; + + const position = fullNameParts + .filter((part) => part !== undefined && part !== null) + .join("/"); + + return { + no: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullname: profile.prefix + profile.firstName + " " + profile.lastName, + position: position, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + score: null, //สรุปผลการประเมินฯ ระดับและคะแนน + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05", + reportName: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + + /** + * API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) + * + * @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) + * + * @param {string} rootId Guid, *Id Root + * @param {string} salaryPeriodId Guid, *Id Period + */ + @Get("gov-05-01/{rootId}/{salaryPeriodId}") + async SalaryReport5retire(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + type: "NONE", //ไม่ได้เลื่อน + isReserve: true //กรองเฉพาะคนที่เกษียณ }, order: { salaryOrg: { From 7a6f594580cc70639d6bd1cd50d2895811696dee Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 27 Mar 2024 16:00:02 +0700 Subject: [PATCH 2/2] emp2-02 --- src/controllers/ReportController.ts | 334 +++++++++++++++++++++------- 1 file changed, 256 insertions(+), 78 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 37baaa9..866fa3d 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -2488,7 +2488,7 @@ export class ReportController extends Controller { where: { id: salaryPeriodId, period: "APR", - isActive: true + isActive: true, }, }); if (!salaryPeriod) { @@ -2500,7 +2500,7 @@ export class ReportController extends Controller { id: salaryPeriodId, year: salaryPeriod.year - 1, period: "APR", - isActive: true + isActive: true, }, }); const salaryPeriodOCT = await this.salaryPeriodRepository.findOne({ @@ -2508,19 +2508,19 @@ export class ReportController extends Controller { id: salaryPeriodId, year: salaryPeriod.year - 1, period: "OCT", - isActive: true + isActive: true, }, }); const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg",], + relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, - type: "NONE" + type: "NONE", }, order: { orgShortName: "ASC", @@ -2530,26 +2530,26 @@ export class ReportController extends Controller { if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - + const _salaryProfileEmpAPR = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg",], + relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodAPR?.id, - } - } + }, + }, }); const _salaryProfileEmpOCT = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg",], + relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodOCT?.id, - } - } + }, + }, }); const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; @@ -2574,31 +2574,66 @@ export class ReportController extends Controller { posNumber: profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "๐", - type1: _salaryProfileEmpAPR.length > 0 - ? (() => { - const _profile = _salaryProfileEmpAPR - .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) - .map((profile) => ({ type: profile.type, isNext: profile.isNext, positionSalaryAmountPer: profile.positionSalaryAmountPer })); - if(_profile[0].isNext){ - return _profile[0].positionSalaryAmountPer === 0.02 ? "๒%" : _profile[0].positionSalaryAmountPer === 0.04 ? "๔%": "๖%" - } - return _profile[0].type === "HALF" ? "๐.๕ ขั้น" : _profile[0].type === "FULL" ? "๑ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; - })() - : null, //เมษา ปีก่อนหน้า - type2: _salaryProfileEmpOCT.length > 0 - ? (() => { - const _profile = _salaryProfileEmpOCT - .filter((profileOCT) => profileOCT.citizenId === profile.citizenId) - .map((profile) => ({ type: profile.type, isNext: profile.isNext, positionSalaryAmountPer: profile.positionSalaryAmountPer })); - if(_profile[0].isNext){ - return _profile[0].positionSalaryAmountPer === 0.02 ? "๒%" : _profile[0].positionSalaryAmountPer === 0.04 ? "๔%": "๖%" - } - return _profile[0].type === "HALF" ? "๐.๕ ขั้น" : _profile[0].type === "FULL" ? "๑ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; - })() - : null, //ตุลา ปีก่อนหน้า - type: profile.isNext === true - ? profile.positionSalaryAmountPer === 0.02 ? "๒%" : profile.positionSalaryAmountPer === 0.04 ? "๔%" : "๖%" - : profile.type === "HALF" ? "๐.๕ ขั้น" : profile.type === "FULL" ? "๑ ขั้น" : "ไม่ได้เลื่อนขั้นฯ", + type1: + _salaryProfileEmpAPR.length > 0 + ? (() => { + const _profile = _salaryProfileEmpAPR + .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) + .map((profile) => ({ + type: profile.type, + isNext: profile.isNext, + positionSalaryAmountPer: profile.positionSalaryAmountPer, + })); + if (_profile[0].isNext) { + return _profile[0].positionSalaryAmountPer === 0.02 + ? "๒%" + : _profile[0].positionSalaryAmountPer === 0.04 + ? "๔%" + : "๖%"; + } + return _profile[0].type === "HALF" + ? "๐.๕ ขั้น" + : _profile[0].type === "FULL" + ? "๑ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + })() + : null, //เมษา ปีก่อนหน้า + type2: + _salaryProfileEmpOCT.length > 0 + ? (() => { + const _profile = _salaryProfileEmpOCT + .filter((profileOCT) => profileOCT.citizenId === profile.citizenId) + .map((profile) => ({ + type: profile.type, + isNext: profile.isNext, + positionSalaryAmountPer: profile.positionSalaryAmountPer, + })); + if (_profile[0].isNext) { + return _profile[0].positionSalaryAmountPer === 0.02 + ? "๒%" + : _profile[0].positionSalaryAmountPer === 0.04 + ? "๔%" + : "๖%"; + } + return _profile[0].type === "HALF" + ? "๐.๕ ขั้น" + : _profile[0].type === "FULL" + ? "๑ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + })() + : null, //ตุลา ปีก่อนหน้า + type: + profile.isNext === true + ? profile.positionSalaryAmountPer === 0.02 + ? "๒%" + : profile.positionSalaryAmountPer === 0.04 + ? "๔%" + : "๖%" + : profile.type === "HALF" + ? "๐.๕ ขั้น" + : profile.type === "FULL" + ? "๑ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ", score: null, //ผลการประเมิน remark: null, //หมายเหตุ }; @@ -2609,8 +2644,12 @@ export class ReportController extends Controller { reportName: "emp1-09", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - yearBeforeSlice: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1)).slice(-2)), - yearSlice: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2)), + yearBeforeSlice: Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year - 1)).slice(-2), + ), + yearSlice: Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2), + ), agency: agency, data: formattedData, }, @@ -3310,16 +3349,16 @@ export class ReportController extends Controller { if (!octSnap2) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - let fullHaftTotalAmount = 0; - let fullHaftCount = 0; - let fullTotalAmount = 0; - let fullCount = 0; - let haftTotalAmount = 0; - let haftCount = 0; - let noneCount = 0; + let fullHaftTotalAmount: any = 0; + let fullHaftCount: any = 0; + let fullTotalAmount: any = 0; + let fullCount: any = 0; + let haftTotalAmount: any = 0; + let haftCount: any = 0; + let noneCount: any = 0; if (octSnap2 && octSnap2.salaryProfiles) { - octSnap2.salaryProfiles.forEach((profile) => { + octSnap2.salaryProfiles.forEach((profile: any) => { switch (profile.type) { case "FULLHAFT": fullHaftTotalAmount += profile.amount ?? 0; @@ -3344,18 +3383,20 @@ export class ReportController extends Controller { const emp2step = new Set(); if (octSnap2 && aprSnap2) { - octSnap2.salaryProfiles.forEach(octProfile => { - aprSnap2.salaryProfiles.forEach(aprProfile => { - if (octProfile.citizenId === aprProfile.citizenId && - ((octProfile.type === 'FULL' && aprProfile.type === 'FULL') || - (octProfile.type === 'HAFT' && aprProfile.type === 'FULLHAFT') || - (octProfile.type === 'FULLHAFT' && aprProfile.type === 'HAFT'))) { - emp2step.add(octProfile.citizenId); - } - }); + octSnap2.salaryProfiles.forEach((octProfile) => { + aprSnap2.salaryProfiles.forEach((aprProfile) => { + if ( + octProfile.citizenId === aprProfile.citizenId && + ((octProfile.type === "FULL" && aprProfile.type === "FULL") || + (octProfile.type === "HAFT" && aprProfile.type === "FULLHAFT") || + (octProfile.type === "FULLHAFT" && aprProfile.type === "HAFT")) + ) { + emp2step.add(octProfile.citizenId); + } }); + }); } - const totalEmp2step = emp2step.size??0; + const totalEmp2step = emp2step.size ?? 0; const agency = octSnap1.salaryProfiles[0] == null ? "" : octSnap1.salaryProfiles[0].root; return new HttpSuccess({ @@ -3363,26 +3404,38 @@ export class ReportController extends Controller { reportName: "emp2-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice(-2), + yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice( + -2, + ), agency: agency, totalUser: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.total.toString()), - totalSalary: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toString()), - sixPercent: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toString()), - remainingAmountApr: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย. - remainingAmountOct: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค. + totalSalary: + octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toString()), + sixPercent: + octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toString()), + remainingAmountApr: + aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย. + remainingAmountOct: + octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค. totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง) - fifteenPercentOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.fifteenPercent.toString()), - totalUseOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง) - full2: Extension.ToThaiNumber(totalEmp2step.toString()), //เลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้นจำนวน(คน) - fullHaft: Extension.ToThaiNumber(fullHaftCount.toString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง) - fullHaftSalary: Extension.ToThaiNumber(fullHaftTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้นครึ่ง) - full: Extension.ToThaiNumber(fullCount.toString()), //จำนวน(คน)(หนึ่งขั้น) - fullSalary: Extension.ToThaiNumber(fullTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้น) - haft: Extension.ToThaiNumber(haftCount.toString()), //จำนวน(คน)(ครึ่งขั้น) - haftSalary: Extension.ToThaiNumber(haftTotalAmount.toString()), //ใช้เงิน(ครึ่งขั้น) - notPromoted: Extension.ToThaiNumber(noneCount.toString()), //ไม่ได้เลื่อนขั้นค่าจ้างจำนวน(คน) + fifteenPercentOld: + aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.fifteenPercent.toString()), + totalUseOld: + aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง) + full2: totalEmp2step == null ? "" : Extension.ToThaiNumber(totalEmp2step.toString()), //เลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้นจำนวน(คน) + fullHaft: fullHaftCount == null ? "" : Extension.ToThaiNumber(fullHaftCount.toString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง) + fullHaftSalary: + fullHaftTotalAmount == null ? "" : Extension.ToThaiNumber(fullHaftTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้นครึ่ง) + full: fullCount == null ? "" : Extension.ToThaiNumber(fullCount.toString()), //จำนวน(คน)(หนึ่งขั้น) + fullSalary: + fullTotalAmount == null ? "" : Extension.ToThaiNumber(fullTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้น) + haft: haftCount == null ? "" : Extension.ToThaiNumber(haftCount.toString()), //จำนวน(คน)(ครึ่งขั้น) + haftSalary: + haftTotalAmount == null ? "" : Extension.ToThaiNumber(haftTotalAmount.toString()), //ใช้เงิน(ครึ่งขั้น) + notPromoted: noneCount == null ? "" : Extension.ToThaiNumber(noneCount.toString()), //ไม่ได้เลื่อนขั้นค่าจ้างจำนวน(คน) total: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.useAmount.toString()), //รวมใช้เงิน - summary: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.remainingAmount.toString()), //เหลือเงิน + summary: + octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.remainingAmount.toString()), //เหลือเงิน }, }); } @@ -3397,11 +3450,78 @@ export class ReportController extends Controller { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, + period: "OCT", }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } + + const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ + where: { + period: "APR", + year: salaryPeriod?.year, + }, + }); + if (!salaryPeriodAPR) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + + const salaryPeriodAPRProfile = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg"], + where: { + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodAPR?.id, + }, + }, + }); + + const octPreviousYear = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + period: "OCT", + year: salaryPeriod?.year - 1, + }, + }); + + const octPreviousYear2 = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + period: "OCT", + year: salaryPeriod?.year - 2, + }, + }); + + let octPreviousYearProfile: SalaryProfileEmployee[] = []; + if (octPreviousYear) { + octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg"], + where: { + salaryOrg: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: octPreviousYear?.id, + }, + }, + }); + } + + let octPreviousYearProfile2: SalaryProfileEmployee[] = []; + if (octPreviousYear2) { + octPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg"], + where: { + salaryOrg: { + snapshot: "SNAP2", + salaryPeriodId: octPreviousYear2?.id, + rootId: rootId, + }, + }, + }); + } + const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { @@ -3423,7 +3543,10 @@ export class ReportController extends Controller { const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - const formattedData = _salaryPeriod.map((profile, index) => { + const formattedData = _salaryPeriod.map((profile: any, index: number) => { + if (!profile) { + return null; + } const fullNameParts = [ profile.child4, profile.child3, @@ -3444,10 +3567,65 @@ export class ReportController extends Controller { posNumber: profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, - // typeOld2:, //ปีงบประมาณพ.ศ...(จำนวนขั้น)การเลื่อนขั้นค่าจ้าง - // typeOld1:, //ปีงบประมาณพ.ศ...(จำนวนขั้น)การเลื่อนขั้นค่าจ้าง - // typeOld:, //1 เมษายน(จำนวนขั้น)การเลื่อนขั้นค่าจ้าง - // type:, //หน่วยงานพิจารณาเลื่อนขั้นค่าจ้าง 1 ต.ค. (จำนวนขั้น) + yearOld2: octPreviousYear2 == null ? null : Extension.ToThaiNumber(octPreviousYear2.year.toString()), + typeOld2: + octPreviousYear2 && octPreviousYearProfile2.length > 0 ? (() => { + const _profile = octPreviousYearProfile2 + .filter((profileOCT2) => profileOCT2.citizenId === profile.citizenId); + if (_profile.length > 0) { + return _profile[0]?.type === "HALF" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHALF" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + } + return null; + })() + : 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 === "HALF" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHALF" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + } + return null; + })() + : null, + typeOld: + salaryPeriodAPRProfile.length > 0 + ? (() => { + const _profile = salaryPeriodAPRProfile + .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) + .map((profile) => ({ + type: profile.type, + })); + return _profile[0]?.type === "HALF" + ? "๐.๕ ขั้น" + : _profile[0]?.type === "FULL" + ? "๑ ขั้น" + : profile?.type === "FULLHALF" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ"; + })() + : null, //เมษา ปีเดียวกัน + type: + profile.type === "HALF" + ? "๐.๕ ขั้น" + : profile.type === "FULL" + ? "๑ ขั้น" + : profile.type === "FULLHALF" + ? "๑.๕ ขั้น" + : "ไม่ได้เลื่อนขั้นฯ", //หน่วยงานพิจารณาเลื่อนขั้นค่าจ้าง 1 ต.ค. (จำนวนขั้น) }; });