diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index d688f75..b00d03a 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -1025,7 +1025,7 @@ export class ReportController extends Controller { }); } - /** + /** * API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน * * @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน @@ -1033,90 +1033,84 @@ export class ReportController extends Controller { * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ - @Get("gov1-04/{rootId}/{salaryPeriodId}") - async SalaryReport4(@Path() rootId: string, @Path() salaryPeriodId: string) { - const salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { - id: salaryPeriodId, - period: "APR", - isActive: true, - }, - }); - - if (!salaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); - } - - const salaryOrg = await this.salaryOrgRepository.findOne({ - where: { - salaryPeriodId: salaryPeriodId, - rootId: rootId, - snapshot: "SNAP2", - }, - order: { - group: "ASC", - }, - relations: ["salaryProfiles"], - }); - - const salaryProfile = await this.salaryProfileRepository.find({ - where: { - salaryOrgId: salaryOrg?.id, - type: Not("NONE"), //ทุก Type ยกเว้นไม่ได้เลื่อน - }, - select: [ - "id", - "prefix", - "firstName", - "lastName", - "root", - "position", - "posType", - "posLevel", - "orgShortName", - "posMasterNo", - "amount", - "amountSpecial", - ], - order: { - posMasterNo: "ASC", - }, - }); - - return new HttpSuccess({ - template: "gov1-04", - reportName: "gov1-04", - data: { - year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod?.year))), - effectiveDate: salaryPeriod?.effectiveDate, - root: salaryProfile[0]?.root, - profile: salaryProfile.map((item, index) => ({ - no: Extension.ToThaiNumber(String(index + 1)), - fullname: item.prefix + item.firstName + " " + item.lastName, - position: - item.position + - "/" + - (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), - posLevel: item.posLevel, - orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)), - amount: - item.amount == undefined || item.amount == null - ? "๐" - : Extension.ToThaiNumber(String(item.amount)), + @Get("gov1-04/{rootId}/{salaryPeriodId}") + async SalaryReport4(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + // period: "APR", + isActive: true, + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodId, + rootId: rootId, + snapshot: "SNAP2", + }, + order: { + group: "ASC", + }, + relations: ["salaryProfiles"], + }); + + const salaryProfile = await this.salaryProfileRepository.find({ + relations: ["salaryOrg"], + where: { + salaryOrgId: salaryOrg?.id, + }, + order: { + salaryOrg: { + group: "ASC", + }, + type: "DESC", + posMasterNo: "ASC", + }, + }); + + 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: salaryProfile[0]?.root, + profile: salaryProfile.map((item, index) => ({ + no: Extension.ToThaiNumber(String(index + 1)), + fullname: item.prefix + item.firstName + " " + item.lastName, + log_group: item.salaryOrg.group, + log_type: item.type, + position: + item.position + + "/" + + (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), + posLevel: item.posLevel, + orgShortName: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)), + amount: + item.amount == undefined || item.amount == null + ? "๐" + : Extension.ToThaiNumber(String(item.amount)), amountSpecial: - item.amountSpecial == undefined || item.amountSpecial == null - ? "๐" - : Extension.ToThaiNumber(String(item.amountSpecial)), - score: null, //สรุปผลการประเมินฯ ระดับและคะแนน - remark: null, //หมายเหตุ - })), - }, - }); - } + (item.positionSalaryAmount == undefined || item.positionSalaryAmount == null ? "๐" : Extension.ToThaiNumber(String(item.positionSalaryAmount))) + + (item.amountSpecial == undefined || item.amountSpecial == null ? "๐" : `(${Extension.ToThaiNumber(String(item.amountSpecial))})`), + score: null, //สรุปผลการประเมินฯ ระดับและคะแนน + remark: + `${item.type == "FULL" ? "" : "หนึ่งขั้น"}\n` + + `${item.amountSpecial != 0 ? "" : "ได้รับค่าตอบแทนพิเศษ"}\n` + + `${item.isNext == true ? "" : "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)"}`, // หมายเหตุ + })), + }, + }); + } /** * API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน