diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 866fa3d..c41df8c 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: { @@ -3044,11 +3222,11 @@ export class ReportController extends Controller { ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : null, precentTwo: - profile.positionSalaryAmountPer == 0.2 + profile.positionSalaryAmountPer == 0.02 ? profile.positionSalaryAmount * profile.positionSalaryAmountPer : null, //ร้อยละ 2 precentFour: - profile.positionSalaryAmountPer == 0.4 + profile.positionSalaryAmountPer == 0.04 ? profile.positionSalaryAmount * profile.positionSalaryAmountPer : null, //ร้อยละ 4 reason: null, // หมายเหตุ diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index 141507a..cdd89fe 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -230,31 +230,6 @@ export class SalaryEmployeeController extends Controller { }, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), }); - // if (keyword != undefined && keyword !== "") { - // const filteredSalary = salary.filter( - // (x) => - // x.name?.toString().includes(keyword) || - // x.group?.toString().includes(keyword) || - // x.isActive?.toString().includes(keyword) || - // x.date?.toString().includes(keyword) || - // x.startDate?.toString().includes(keyword) || - // x.endDate?.toString().includes(keyword) || - // x.details?.toString().includes(keyword), - // ); - - // const formattedData = filteredSalary.map((item) => ({ - // id: item.id, - // name: item.name, - // group: item.group, - // isActive: item.isActive, - // date: item.date, - // startDate: item.startDate, - // endDate: item.endDate, - // details: item.details, - // })); - // const slicedData = formattedData.slice((page - 1) * pageSize, page * pageSize); - // return new HttpSuccess({ data: slicedData, total: formattedData.length }); - // } const formattedData = salary.map((item) => ({ id: item.id, diff --git a/src/controllers/SalaryFormulaEmployeeController.ts b/src/controllers/SalaryFormulaEmployeeController.ts index c5545cf..b5b0136 100644 --- a/src/controllers/SalaryFormulaEmployeeController.ts +++ b/src/controllers/SalaryFormulaEmployeeController.ts @@ -226,26 +226,28 @@ export class SalaryFormulaEmployeeController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, + @Query("posTypeId") posTypeId?: string, ) { - let whereClause: any = {}; - if (keyword != undefined && keyword !== "") { - whereClause = { - where: [ - { details: Like(`%${keyword}%`) }, - { position: Like(`%${keyword}%`) }, - { posType: { posTypeName: Like(`%${keyword}%`)} }, - { posLevel: { posLevelName: Like(`%${keyword}%`)} }, - ], - }; - } - const [getFormula, total] = await this.salaryFormulaEmployeeRepository.findAndCount({ - relations: ["salaryEmployee", "posType", "posLevel", "salaryEmployeeMins"], - ...whereClause, - order: { - lastUpdatedAt: "DESC", - }, - ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), - }); + const [getFormula, total] = await AppDataSource.getRepository(SalaryFormulaEmployee) + .createQueryBuilder("salaryFormulaEmployee") + .leftJoinAndSelect("salaryFormulaEmployee.salaryEmployee", "salaryEmployee") + .leftJoinAndSelect("salaryFormulaEmployee.posType", "posType") + .leftJoinAndSelect("salaryFormulaEmployee.posLevel", "posLevel") + .leftJoinAndSelect("salaryFormulaEmployee.salaryEmployeeMins", "salaryEmployeeMins") + .andWhere( + keyword == undefined + ? "1=1" + : [ + { details: Like(`%${keyword}%`) }, + { position: Like(`%${keyword}%`) }, + { posLevel: { posLevelName: Like(`%${keyword}%`) } }, + ], + ) + .andWhere(posTypeId == undefined ? "1=1" : { posTypeId: Like(`%${posTypeId}%`) }) + .orderBy("salaryFormulaEmployee.lastUpdatedAt", "DESC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); const mapFormula = getFormula.map((item) => ({ id: item.id, diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index 28fbd4c..933651f 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -349,23 +349,23 @@ export class SalaryPeriodEmployeeController extends Controller { salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; if (salaryRankAmountMax != null) { if (step - salaryRankAmountMax.step <= 0.5) { - salaryProfile.positionSalaryAmountPer = 0.2; + salaryProfile.positionSalaryAmountPer = 0.02; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.2; + : salaryRankAmountMax.salaryMonth * 0.02; } else if (step - salaryRankAmountMax.step <= 1) { - salaryProfile.positionSalaryAmountPer = 0.4; + salaryProfile.positionSalaryAmountPer = 0.04; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.4; + : salaryRankAmountMax.salaryMonth * 0.04; } else { - salaryProfile.positionSalaryAmountPer = 0.6; + salaryProfile.positionSalaryAmountPer = 0.06; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.6; + : salaryRankAmountMax.salaryMonth * 0.06; } } else { salaryProfile.positionSalaryAmountPer = 0; @@ -678,23 +678,23 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; if (salaryRankAmountMax != null) { if (step - salaryRankAmountMax.step <= 0.5) { - salaryProfile.positionSalaryAmountPer = 0.2; + salaryProfile.positionSalaryAmountPer = 0.02; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.2; + : salaryRankAmountMax.salaryMonth * 0.02; } else if (step - salaryRankAmountMax.step <= 1) { - salaryProfile.positionSalaryAmountPer = 0.4; + salaryProfile.positionSalaryAmountPer = 0.04; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.4; + : salaryRankAmountMax.salaryMonth * 0.04; } else { - salaryProfile.positionSalaryAmountPer = 0.6; + salaryProfile.positionSalaryAmountPer = 0.06; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.6; + : salaryRankAmountMax.salaryMonth * 0.06; } } else { salaryProfile.positionSalaryAmountPer = 0; @@ -1065,23 +1065,23 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; if (salaryRankAmountMax != null) { if (step - salaryRankAmountMax.step <= 0.5) { - salaryProfile.positionSalaryAmountPer = 0.2; + salaryProfile.positionSalaryAmountPer = 0.02; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.2; + : salaryRankAmountMax.salaryMonth * 0.02; } else if (step - salaryRankAmountMax.step <= 1) { - salaryProfile.positionSalaryAmountPer = 0.4; + salaryProfile.positionSalaryAmountPer = 0.04; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.4; + : salaryRankAmountMax.salaryMonth * 0.04; } else { - salaryProfile.positionSalaryAmountPer = 0.6; + salaryProfile.positionSalaryAmountPer = 0.06; salaryProfile.amountSpecial = salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null ? 0 - : salaryRankAmountMax.salaryMonth * 0.6; + : salaryRankAmountMax.salaryMonth * 0.06; } } else { salaryProfile.positionSalaryAmountPer = 0;