import { Controller, Get, Post, Route, Security, Tags, Body, Path, Request, SuccessResponse, Response, } from "tsoa"; import { AppDataSource } from "../database/data-source"; import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { In, Not, IsNull, MoreThan, Double, Brackets } from "typeorm"; import { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { SalaryPeriod } from "../entities/SalaryPeriod"; import { SalaryOrg } from "../entities/SalaryOrg"; import { SalaryProfile } from "../entities/SalaryProfile"; import Extension from "../interfaces/extension"; import { SalaryEmployee } from "../entities/SalaryEmployee"; import { SalaryRankEmployee } from "../entities/SalaryRankEmployee"; import { EmployeePosType } from "../entities/EmployeePosType"; import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee"; import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee"; import { setLogDataDiff } from "../interfaces/utils"; import { RequestWithUser } from "../middlewares/user"; import permission from "../interfaces/permission"; import CallAPI from "../interfaces/call-api"; import { isNotEmittedStatement } from "typescript"; import { SalaryFormulaEmployee } from "../entities/SalaryFormulaEmployee"; @Route("api/v1/salary/report") @Tags("Report") @Security("bearerAuth") @Response( HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class ReportController extends Controller { private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); private salaryRepository = AppDataSource.getRepository(Salarys); private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee); private salaryRankRepository = AppDataSource.getRepository(SalaryRanks); private salaryEmployeeRankRepository = AppDataSource.getRepository(SalaryRankEmployee); private poTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg); private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee); private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile); private salaryProfileEmployeeRepository = AppDataSource.getRepository(SalaryProfileEmployee); private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee); /** * API รายงานอัตราเงินเดือน * * @summary รายงานอัตราเงินเดือน * * @param {string} id Guid, *Id ผังเงินเดือน */ @Get("{id}") async SalaryReport(@Path() id: string) { const salarys = await this.salaryRepository.findOne({ where: { id: id }, }); if (!salarys) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } const posType = await this.poTypeRepository.findOne({ where: { id: salarys.posTypeId }, }); const posLevel = await this.posLevelRepository.findOne({ where: { id: salarys.posLevelId }, }); const salaryRank = await this.salaryRankRepository.find({ where: { salaryId: salarys.id, }, select: [ "id", "salary", "salaryHalf", "salaryHalfSpecial", "salaryFull", "salaryFullSpecial", "salaryFullHalf", "salaryFullHalfSpecial", ], order: { salary: "DESC", salaryHalf: "DESC", }, }); const mapSalaryRank = salaryRank.map((item) => ({ // no: index + 1, // id: item.id, salary: item.salary == null || item.salary == 0 ? "" : item.salary.toLocaleString(), salaryHalf: item.salaryHalf == null || item.salaryHalf == 0 ? "" : item.salaryHalf.toLocaleString() + (item.salaryHalfSpecial == null || item.salaryHalfSpecial == 0 ? "" : " (" + item.salaryHalfSpecial.toLocaleString() + "*)"), salaryFull: item.salaryFull == null || item.salaryFull == 0 ? "" : item.salaryFull.toLocaleString() + (item.salaryFullSpecial == null || item.salaryFullSpecial == 0 ? "" : " (" + item.salaryFullSpecial.toLocaleString() + "*)"), salaryFullHalf: item.salaryFullHalf == null || item.salaryFullHalf == 0 ? "" : item.salaryFullHalf.toLocaleString() + (item.salaryFullHalfSpecial == null || item.salaryFullHalfSpecial == 0 ? "" : " (" + item.salaryFullHalfSpecial.toLocaleString() + "*)"), })); return new HttpSuccess({ template: "SalaryRank", reportName: "SalaryRank", data: { nameType: "ผังข้าราชการกรุงเทพมหานครสามัญ", level: posLevel?.posLevelName == null ? "" : posLevel?.posLevelName, type: posType?.posTypeName == null ? "" : posType?.posTypeName, date: salarys.date == null ? "" : salarys.date.getDate() + " " + Extension.ToThaiMonth(salarys.date.getMonth() + 1) + " " + Extension.ToThaiYear(salarys.date.getFullYear()), startDate: salarys.startDate == null ? "" : salarys.startDate.getDate() + " " + Extension.ToThaiMonth(salarys.startDate.getMonth() + 1) + " " + Extension.ToThaiYear(salarys.startDate.getFullYear()), endDate: salarys.endDate == null ? "" : salarys.endDate.getDate() + " " + Extension.ToThaiMonth(salarys.endDate.getMonth() + 1) + " " + Extension.ToThaiYear(salarys.endDate.getFullYear()), details: salarys.details == null ? "" : salarys.details, salaryRanks: mapSalaryRank, }, }); } /** * API รายงานอัตราเงินเดือนลูกจ้าง * * @summary รายงานอัตราเงินเดือนลูกจ้าง * * @param {string} id Guid, *Id ผังเงินเดือนลูกจ้าง */ @Get("employee/{id}") async SalaryEmployeeReport(@Path() id: string) { const salarys = await this.salaryEmployeeRepository.findOne({ where: { id: id }, }); if (!salarys) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } const salaryRank = await this.salaryEmployeeRankRepository.find({ where: { salaryEmployeeId: salarys.id, }, select: ["id", "step", "salaryMonth", "salaryDay"], order: { step: "ASC", salaryMonth: "ASC", }, }); const mapSalaryRank = salaryRank.map((item) => ({ step: item.step == null || item.step == 0 ? "" : item.step.toLocaleString(), salaryMonth: item.salaryMonth == null || item.salaryMonth == 0 ? "" : item.salaryMonth.toLocaleString(), salaryDay: item.salaryDay == null || item.salaryDay == 0 ? "" : item.salaryDay.toLocaleString(), })); return new HttpSuccess({ template: "SalaryRankEmployee", reportName: "SalaryRankEmployee", data: { date: Extension.ToThaiFullDate(new Date()), group: salarys.group == null || salarys.group == 0 ? "" : salarys.group.toLocaleString(), salaryRanks: mapSalaryRank, }, }); } /** * API รายชื่อข้าราชการผู้ที่ครองตำแหน่ง ณ วันที่ 1 มีนาคม(รอบเมษายน) และ ณ วันที่ 1 กันยายน(รอบตุลาคม) * * @summary รายชื่อข้าราชการผู้ที่ครองตำแหน่ง ณ วันที่ 1 มีนาคม(รอบเมษายน) และ ณ วันที่ 1 กันยายน(รอบตุลาคม) * */ @Get("gov-01/{rootId}/{salaryPeriodId}/{group}") async SalaryReport1( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const _salaryPeriod = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP1", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); // const _salaryPeriod1 = await this.salaryProfileRepository.find({ // relations: ["salaryOrg", "salaryOrg.salaryPeriod"], // where: { // salaryOrg: { // snapshot: "SNAP1", // rootId: rootId, // salaryPeriodId: salaryPeriodId, // group: "GROUP1", // }, // type: "HAFT", // }, // order: { // citizenId: "ASC", // isReserve: "ASC", // }, // }); // const _salaryPeriod2 = await this.salaryProfileRepository.find({ // relations: ["salaryOrg", "salaryOrg.salaryPeriod"], // where: { // salaryOrg: { // snapshot: "SNAP1", // rootId: rootId, // salaryPeriodId: salaryPeriodId, // group: "GROUP1", // }, // type: "FULL", // }, // order: { // citizenId: "ASC", // isReserve: "ASC", // }, // }); // const _salaryPeriod3 = await this.salaryProfileRepository.find({ // relations: ["salaryOrg", "salaryOrg.salaryPeriod"], // where: { // salaryOrg: { // snapshot: "SNAP1", // rootId: rootId, // salaryPeriodId: salaryPeriodId, // group: "GROUP1", // }, // type: "NONE", // }, // order: { // citizenId: "ASC", // isReserve: "ASC", // }, // }); // const _salaryPeriod4 = await this.salaryProfileRepository.find({ // relations: ["salaryOrg", "salaryOrg.salaryPeriod"], // where: { // salaryOrg: { // snapshot: "SNAP1", // rootId: rootId, // salaryPeriodId: salaryPeriodId, // group: "GROUP2", // }, // type: "HAFT", // }, // order: { // citizenId: "ASC", // isReserve: "ASC", // }, // }); // const _salaryPeriod5 = await this.salaryProfileRepository.find({ // relations: ["salaryOrg", "salaryOrg.salaryPeriod"], // where: { // salaryOrg: { // snapshot: "SNAP1", // rootId: rootId, // salaryPeriodId: salaryPeriodId, // group: "GROUP2", // }, // type: "FULL", // }, // order: { // citizenId: "ASC", // isReserve: "ASC", // }, // }); // const _salaryPeriod6 = await this.salaryProfileRepository.find({ // relations: ["salaryOrg", "salaryOrg.salaryPeriod"], // where: { // salaryOrg: { // snapshot: "SNAP1", // rootId: rootId, // salaryPeriodId: salaryPeriodId, // group: "GROUP2", // }, // type: "NONE", // }, // order: { // citizenId: "ASC", // isReserve: "ASC", // }, // }); // const _salaryPeriod = _salaryPeriod1.concat( // _salaryPeriod2, // _salaryPeriod3, // _salaryPeriod4, // _salaryPeriod5, // _salaryPeriod6, // ); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: root, data: formattedData, }, }); } /** * API บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน และตุลาคม * * @summary บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน และตุลาคม * */ @Get("gov-02/{rootId}/{salaryPeriodId}") async SalaryReport2(@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.salaryOrgRepository.find({ relations: ["salaryPeriod", "salaryProfiles"], where: { snapshot: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); const agency = _salaryPeriod[0] == null || _salaryPeriod[0].salaryProfiles[0] == null ? "" : _salaryPeriod[0].salaryProfiles[0].root; if (salaryPeriod.period == "APR") { let data1 = _salaryPeriod.find((x) => x.group == "GROUP2"); let formattedData1; if (data1 != null) { formattedData1 = { total: Extension.ToThaiNumber(data1.total.toLocaleString()), fifteenPercent: Extension.ToThaiNumber( `${data1.fifteenPercent.toLocaleString()}.${data1.fifteenPoint.toLocaleString()}`, ), full: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "FULL").length.toLocaleString(), ), haft: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "NONE").length.toLocaleString(), ), reason: null, }; } let data2 = _salaryPeriod.find((x) => x.group == "GROUP1"); let formattedData2; if (data2 != null) { formattedData2 = { total: Extension.ToThaiNumber(data2.total.toLocaleString()), fifteenPercent: Extension.ToThaiNumber( `${data2.fifteenPercent.toLocaleString()}.${data2.fifteenPoint.toLocaleString()}`, ), full: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "FULL") .length.toLocaleString(), ), haft: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "HAFT") .length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "NONE") .length.toLocaleString(), ), reason: null, }; } let data3 = _salaryPeriod.find((x) => x.group == "GROUP1"); let formattedData3; if (data3 != null) { formattedData3 = { total: Extension.ToThaiNumber(data3.total.toLocaleString()), fifteenPercent: Extension.ToThaiNumber( `${data3.fifteenPercent.toLocaleString()}.${data3.fifteenPoint.toLocaleString()}`, ), full: Extension.ToThaiNumber( data3.salaryProfiles .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .filter((x) => x.type == "FULL") .length.toLocaleString(), ), haft: Extension.ToThaiNumber( data3.salaryProfiles .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .filter((x) => x.type == "HAFT") .length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data3.salaryProfiles .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .filter((x) => x.type == "NONE") .length.toLocaleString(), ), reason: null, }; } let data4 = _salaryPeriod.find((x) => x.group == "GROUP1"); let formattedData4; if (data4 != null) { formattedData4 = { total: Extension.ToThaiNumber(data4.total.toLocaleString()), fifteenPercent: Extension.ToThaiNumber( `${data4.fifteenPercent.toLocaleString()}.${data4.fifteenPoint.toLocaleString()}`, ), full: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "FULL").length.toLocaleString(), ), haft: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "NONE").length.toLocaleString(), ), reason: null, }; } return new HttpSuccess({ template: "gov1-02", reportName: "gov1-02", data: { // date: Extension.ToThaiNumber( // Extension.ToThaiFullDate2(new Date(`${salaryPeriod.year}-03-01`)), // ), year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearSlice: Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2), ), // dateNow: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), agency: agency, data1: formattedData1, data2: formattedData2, data3: formattedData3, data4: formattedData4, }, }); } else { let data1 = _salaryPeriod.find((x) => x.group == "GROUP2"); const _salaryPeriodAPR1 = await this.salaryOrgRepository.findOne({ where: { snapshot: "SNAP1", group: "GROUP1", rootId: rootId, salaryPeriod: { period: "APR", year: salaryPeriod.year, }, }, relations: { salaryProfiles: true }, }); const _salaryPeriodAPR2 = await this.salaryOrgRepository.findOne({ where: { snapshot: "SNAP1", group: "GROUP2", rootId: rootId, salaryPeriod: { period: "APR", year: salaryPeriod.year, }, }, relations: { salaryProfiles: true }, }); let formattedData1; if (data1 != null) { const haftSalary = data1.salaryProfiles .filter((x) => x.type == "HAFT") .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullSalary = data1.salaryProfiles .filter((x) => x.type == "FULL") .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullHaftSalary = data1.salaryProfiles .filter((x) => x.type == "FULLHAFT") .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); formattedData1 = { totalSalary: Extension.ToThaiNumber(data1.currentAmount.toLocaleString()), totalUser: Extension.ToThaiNumber(data1.total.toLocaleString()), sixPercentAmount: Extension.ToThaiNumber(data1.sixPercentAmount.toLocaleString()), spentAmount: Extension.ToThaiNumber(data1.spentAmount.toLocaleString()), remainingAmount: Extension.ToThaiNumber(data1.remainingAmount.toLocaleString()), fifteenPercentOld: Extension.ToThaiNumber( `${_salaryPeriodAPR2 == null ? 0 : _salaryPeriodAPR2.fifteenPercent.toLocaleString()}.${_salaryPeriodAPR2 == null ? 0 : _salaryPeriodAPR2.fifteenPoint.toLocaleString()}`, ), totalOld: Extension.ToThaiNumber( (_salaryPeriodAPR2 == null || _salaryPeriodAPR2.salaryProfiles.length == 0 ? 0 : _salaryPeriodAPR2.salaryProfiles.filter((x) => x.type == "FULL").length ).toLocaleString(), ), haft: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toLocaleString(), ), full: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "FULL").length.toLocaleString(), ), fullHaft: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "FULLHAFT").length.toString(), ), notPromoted: Extension.ToThaiNumber( data1.salaryProfiles.filter((x) => x.type == "NONE").length.toLocaleString(), ), haftSalary: Extension.ToThaiNumber(haftSalary.toLocaleString()), fullSalary: Extension.ToThaiNumber(fullSalary.toLocaleString()), fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toLocaleString()), total: Extension.ToThaiNumber( (haftSalary + fullSalary + fullHaftSalary).toLocaleString(), ), summary: Extension.ToThaiNumber( ( data1.sixPercentAmount - data1.spentAmount - haftSalary - fullSalary - fullHaftSalary ).toLocaleString(), ), reason: null, }; } let data2 = _salaryPeriod.find((x) => x.group == "GROUP1"); let formattedData2; if (data2 != null) { const haftSalary = data2.salaryProfiles .filter((x) => x.type == "HAFT") .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullSalary = data2.salaryProfiles .filter((x) => x.type == "FULL") .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullHaftSalary = data2.salaryProfiles .filter((x) => x.type == "FULLHAFT") .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); formattedData2 = { totalSalary: Extension.ToThaiNumber(data2.currentAmount.toLocaleString()), totalUser: Extension.ToThaiNumber(data2.total.toLocaleString()), sixPercentAmount: Extension.ToThaiNumber(data2.sixPercentAmount.toLocaleString()), spentAmount: Extension.ToThaiNumber(data2.spentAmount.toLocaleString()), remainingAmount: Extension.ToThaiNumber(data2.remainingAmount.toLocaleString()), fifteenPercentOld: Extension.ToThaiNumber( `${_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent.toLocaleString()}.${_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPoint.toLocaleString()}`, ), totalOld: Extension.ToThaiNumber( (_salaryPeriodAPR1 == null || _salaryPeriodAPR1.salaryProfiles.length == 0 ? 0 : _salaryPeriodAPR1.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "FULL").length ).toLocaleString(), ), haft: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "HAFT") .length.toLocaleString(), ), full: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "FULL") .length.toLocaleString(), ), fullHaft: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "FULLHAFT") .length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data2.salaryProfiles .filter( (x) => x.posLevel == "อาวุโส" || x.posLevel == "ชำนาญการพิเศษ" || (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), ) .filter((x) => x.type == "NONE") .length.toLocaleString(), ), haftSalary: Extension.ToThaiNumber(haftSalary.toLocaleString()), fullSalary: Extension.ToThaiNumber(fullSalary.toLocaleString()), fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toLocaleString()), total: Extension.ToThaiNumber( (haftSalary + fullSalary + fullHaftSalary).toLocaleString(), ), summary: Extension.ToThaiNumber( ( data2.sixPercentAmount - data2.spentAmount - haftSalary - fullSalary - fullHaftSalary ).toLocaleString(), ), reason: null, }; } let data3 = _salaryPeriod.find((x) => x.group == "GROUP1"); let formattedData3; if (data3 != null) { const haftSalary = data3.salaryProfiles .filter((x) => x.type == "HAFT") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullSalary = data3.salaryProfiles .filter((x) => x.type == "FULL") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullHaftSalary = data3.salaryProfiles .filter((x) => x.type == "FULLHAFT") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); formattedData3 = { totalSalary: Extension.ToThaiNumber(data3.currentAmount.toLocaleString()), totalUser: Extension.ToThaiNumber(data3.total.toLocaleString()), sixPercentAmount: Extension.ToThaiNumber(data3.sixPercentAmount.toLocaleString()), spentAmount: Extension.ToThaiNumber(data3.spentAmount.toLocaleString()), remainingAmount: Extension.ToThaiNumber(data3.remainingAmount.toLocaleString()), fifteenPercentOld: Extension.ToThaiNumber( `${_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent.toLocaleString()}.${_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPoint.toLocaleString()}`, ), totalOld: Extension.ToThaiNumber( (_salaryPeriodAPR1 == null || _salaryPeriodAPR1.salaryProfiles.length == 0 ? 0 : _salaryPeriodAPR1.salaryProfiles .filter((x) => x.type == "FULL") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ).length ).toLocaleString(), ), haft: Extension.ToThaiNumber( data3.salaryProfiles .filter((x) => x.type == "HAFT") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .length.toLocaleString(), ), full: Extension.ToThaiNumber( data3.salaryProfiles .filter((x) => x.type == "FULL") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .length.toLocaleString(), ), fullHaft: Extension.ToThaiNumber( data3.salaryProfiles .filter((x) => x.type == "FULLHAFT") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data3.salaryProfiles .filter((x) => x.type == "NONE") .filter( (x) => x.posLevel == "ปฏิบัติงาน" || x.posLevel == "ชำนาญงาน" || x.posLevel == "ปฏิบัติการ" || x.posLevel == "ชำนาญการ", ) .length.toLocaleString(), ), haftSalary: Extension.ToThaiNumber(haftSalary.toLocaleString()), fullSalary: Extension.ToThaiNumber(fullSalary.toLocaleString()), fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toLocaleString()), total: Extension.ToThaiNumber( (haftSalary + fullSalary + fullHaftSalary).toLocaleString(), ), summary: Extension.ToThaiNumber( ( data3.sixPercentAmount - data3.spentAmount - haftSalary - fullSalary - fullHaftSalary ).toLocaleString(), ), reason: null, }; } let data4 = _salaryPeriod.find((x) => x.group == "GROUP1"); let formattedData4; if (data4 != null) { const haftSalary = data4.salaryProfiles .filter((x) => x.type == "HAFT") .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullSalary = data4.salaryProfiles .filter((x) => x.type == "FULL") .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); const fullHaftSalary = data4.salaryProfiles .filter((x) => x.type == "FULLHAFT") .reduce((accumulator, object: any) => { return ( accumulator + (object.amountUse == null ? 0 : object.amountUse) + (object.amountSpecial == null ? 0 : object.amountSpecial) ); }, 0); formattedData4 = { totalSalary: Extension.ToThaiNumber(data4.currentAmount.toLocaleString()), totalUser: Extension.ToThaiNumber(data4.total.toLocaleString()), sixPercentAmount: Extension.ToThaiNumber(data4.sixPercentAmount.toLocaleString()), spentAmount: Extension.ToThaiNumber(data4.spentAmount.toLocaleString()), remainingAmount: Extension.ToThaiNumber(data4.remainingAmount.toLocaleString()), fifteenPercentOld: Extension.ToThaiNumber( `${_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent.toLocaleString()}.${_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPoint.toLocaleString()}`, ), totalOld: Extension.ToThaiNumber( (_salaryPeriodAPR1 == null || _salaryPeriodAPR1.salaryProfiles.length == 0 ? 0 : _salaryPeriodAPR1.salaryProfiles.filter((x) => x.type == "FULL").length ).toLocaleString(), ), haft: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toLocaleString(), ), full: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "FULL").length.toLocaleString(), ), fullHaft: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "FULLHAFT").length.toLocaleString(), ), notPromoted: Extension.ToThaiNumber( data4.salaryProfiles.filter((x) => x.type == "NONE").length.toLocaleString(), ), haftSalary: Extension.ToThaiNumber(haftSalary.toLocaleString()), fullSalary: Extension.ToThaiNumber(fullSalary.toLocaleString()), fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toLocaleString()), total: Extension.ToThaiNumber( (haftSalary + fullSalary + fullHaftSalary).toLocaleString(), ), summary: Extension.ToThaiNumber( ( data4.sixPercentAmount - data4.spentAmount - haftSalary - fullSalary - fullHaftSalary ).toLocaleString(), ), reason: null, }; } return new HttpSuccess({ template: "gov2-02", reportName: "gov2-02", data: { // date: Extension.ToThaiNumber( // Extension.ToThaiFullDate2(new Date(`${salaryPeriod.year}-03-01`)), // ), year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearSlice: Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year)).slice(-2), ), // dateNow: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), agency: agency, data1: formattedData1, data2: formattedData2, data3: formattedData3, data4: formattedData4, }, }); } } /** * API รายชื่อข้าราชการที่ได้รับการเสนอขอเลื่อนหนึ่งขั้น รอบเมษายน และทั้งปีสองขั้น รอบตุลาคม * * @summary รายชื่อข้าราชการที่ได้รับการเสนอขอเลื่อนหนึ่งขั้น รอบเมษายน และทั้งปีสองขั้น รอบตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-03/{rootId}/{salaryPeriodId}/{group}") async SalaryReport3( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const salaryOrg = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodId, rootId: rootId, snapshot: "SNAP1", group: convertGroup, }, }); //รอบเมษา if (salaryPeriod.period === "APR") { let salaryProfileGroup1: any; let salaryProfileGroup2: any; if (salaryOrg) { salaryProfileGroup1 = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg?.id, type: "FULL", //หนึ่งขั้น }, }); } // const rootName = await this.salaryOrgRepository.findOne({ // where: { // rootId: rootId, // }, // select: ["root"], // }); //รอบปีก่อนหน้า const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriod.year - 1, isActive: true, }, }); const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod.year - 1, isActive: true, }, }); let salaryOrg2_APR = null; if (salaryPeriodIncrease2_APR) { salaryOrg2_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, // rootId: rootId, // root: rootName?.root, rootId: salaryOrg?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, }); } let salaryOrg2_OCT = null; if (salaryPeriodIncrease2_OCT) { salaryOrg2_OCT = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_OCT?.id, // rootId: rootId, // root: rootName?.root, rootId: salaryOrg?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, }); } const salaryProfile2 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]), type: Not(In(["NONE", "PENDING"])), }, }); //รอบปีก่อนๆ const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriod.year - 2, isActive: true, }, }); const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod.year - 2, isActive: true, }, }); let salaryOrg1_APR = null; if (salaryPeriodIncrease1_APR) { salaryOrg1_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_APR?.id, // rootId: rootId, // root: rootName?.root, rootId: salaryOrg2_APR?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, }); } let salaryOrg1_OCT = null; if (salaryPeriodIncrease1_OCT) { salaryOrg1_OCT = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease1_OCT?.id, // rootId: rootId, // root: rootName?.root, rootId: salaryOrg2_APR?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, }); } const salaryProfile1 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), type: Not(In(["NONE", "PENDING"])), }, }); const year = salaryPeriod.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))):""; const yearIncrease1 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 2)), ):""; const yearIncrease2 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), ):""; const fifteenPercent_Group1 = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? "๐" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); const fifteenPoint_Group1 = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); const fifteenPercent_Group2 = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? "๐" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); const fifteenPoint_Group2 = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); return new HttpSuccess({ template: "gov1-03", reportName: "gov1-03", data: { year: year, yearIncrease1: yearIncrease1, yearIncrease2: yearIncrease2, yearIncreaseSlice: yearIncrease2?yearIncrease2.slice(-2):"", yearSlice: year?year.slice(-2):"", point: fifteenPercent_Group1 + fifteenPoint_Group1, 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 + "\n") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + (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" ? "หนึ่งขั้น" : "ไม่ได้เลื่อนขั้น"; })() : "-", //การเลื่อนเงินเดือนปีก่อนๆหน้า 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" ? "หนึ่งขั้น" : "ไม่ได้เลื่อนขั้น"; })() : "-", //การเลื่อนเงินเดือนปีก่อนหน้า score: item.result, //ผลการประเมินฯ remark: item.remark, //หมายเหตุ })) : null, // profileGroup2: salaryProfileGroup2 // ? salaryProfileGroup2.map((item: any, index: any) => ({ // no: Extension.ToThaiNumber(String(index + 1)), // affiliation: // (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "\n") + // (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + // (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + // (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + // (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" // ? "หนึ่งขั้น" // : "ไม่ได้เลื่อนขั้น"; // })() // : "-", //การเลื่อนเงินเดือนปีก่อนๆหน้า // 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" // ? "หนึ่งขั้น" // : "ไม่ได้เลื่อนขั้น"; // })() // : "-", //การเลื่อนเงินเดือนปีก่อนหน้า // score: item.result, //ผลการประเมินฯ // remark: item.remark, //หมายเหตุ // })) // : null, }, }); //รอบตุลา } else if (salaryPeriod.period === "OCT") { // find period APR const salaryPeriod_APR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriod?.year, isActive: true, }, }); const salaryOrg_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriod_APR?.id, rootId: rootId, snapshot: "SNAP1", group: convertGroup, }, }); const salaryProfile_APR = await this.salaryProfileRepository.find({ where: { salaryOrgId: salaryOrg_APR?.id, type: Not(In(["NONE", "PENDING"])), }, }); //end period APR 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({ where: { period: "APR", year: salaryPeriod.year - 2, isActive: true, }, }); const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod.year - 2, isActive: true, }, }); let salaryOrg1_APR = null; 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, root: salaryOrg?.root, snapshot: "SNAP1", group: convertGroup, }, }); } const salaryProfile1 = await this.salaryProfileRepository.find({ where: { salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]), type: Not(In(["NONE", "PENDING"])), }, }); //รอบปีก่อนหน้า const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriod.year - 1, isActive: true, }, }); const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod.year - 1, isActive: true, }, }); let salaryOrg2_APR = null; if (salaryPeriodIncrease2_APR) { salaryOrg2_APR = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodIncrease2_APR?.id, // rootId: rootId, root: salaryOrg?.root, snapshot: "SNAP1", group: convertGroup, }, }); } let salaryOrg2_OCT = null; 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: Not(In(["NONE", "PENDING"])), }, }); const year = salaryPeriod.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))):""; const yearIncrease1 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 2)), ):""; const yearIncrease2 = salaryPeriod.year?Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), ):""; const fifteenPercent = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? "๐" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); const fifteenPoint = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); const fifteenPercent_Group2 = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ? "๐" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent)); const fifteenPoint_Group2 = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint)); return new HttpSuccess({ template: "gov2-03", reportName: "gov2-03", data: { year: year, yearIncrease1: yearIncrease1, yearIncrease2: yearIncrease2, yearIncreaseSlice: yearIncrease2?yearIncrease2.slice(-2):"", yearSlice: year?year.slice(-2):"", point: fifteenPercent + fifteenPoint, pointGroup2: fifteenPercent_Group2 + fifteenPoint_Group2, root: salaryOrg?.root, profile: salaryProfile_current ? salaryProfile_current .filter((item: any) => salaryProfile_APR.some((x: any) => x.citizenId === item.citizenId && ( x.type === "HAFT" && ["FULLHAFT"].includes(item.type) || x.type === "FULL" && ["FULL", "FULLHAFT"].includes(item.type) ) ) ) .map((item: any, index: any) => ({ no: Extension.ToThaiNumber(String(index + 1)), affiliation: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "\n") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + (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" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น"; })() : "-", //การเลื่อนเงินเดือนปีก่อนๆหน้า 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" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น"; })() : "-", //การเลื่อนเงินเดือนปีก่อนหน้า 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" ? "หนึ่งขั้นครึ่ง" : "ไม่ได้เลื่อนขั้น"; })() : "-", //การเลื่อนเงินเดือนรอบเมษา Type: item.type === "FULL" ? "หนึ่งขั้น" : item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "-", score1: item.result ?? "-", //ผลการประเมินฯ ครั้งที่ 1 score2: "-", //ผลการประเมินฯ ครั้งที่ 2 })) : null, // 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 + "\n") + // (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + // (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + // (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + // (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" // ? "หนึ่งขั้นครึ่ง" // : "ไม่ได้เลื่อนขั้น"; // })() // : "-", //การเลื่อนเงินเดือนปีก่อนๆหน้า // 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" // ? "หนึ่งขั้นครึ่ง" // : "ไม่ได้เลื่อนขั้น"; // })() // : "-", //การเลื่อนเงินเดือนปีก่อนหน้า // 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" // ? "หนึ่งขั้นครึ่ง" // : "ไม่ได้เลื่อนขั้น"; // })() // : "-", //การเลื่อนเงินเดือนรอบเมษา // Type: // item.type === "FULL" // ? "หนึ่งขั้น" // : item.type === "FULLHAFT" // ? "หนึ่งขั้นครึ่ง" // : "-", // score1: item.result ?? "-", //ผลการประเมินฯ ครั้งที่ 1 // score2: "-", //ผลการประเมินฯ ครั้งที่ 2 // })) // : null, }, }); } } /** * API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * * @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-04/{rootId}/{salaryPeriodId}/{group}/{type}") async SalaryReport4( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, @Path() type: string = 'ALL' ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); let condition: any = { salaryOrg: { snapshot: "SNAP2", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }; // condition.type = In(["HAFT", "FULL", "FULLHAFT"]); condition.isRetired = salaryPeriod.period === "APR" ? In([true, false]) : false; //กรองเฉพาะคนที่ไม่เกษียณเฉพาะรอบตุลา if(salaryPeriod.period == "APR"){ if(type == "HAFT"){ condition.type = "HAFT"; }else if(type == "FULL"){ condition.type = "FULL"; } }else{ if(type == "HAFT"){ condition.type = "HAFT"; }else if(type == "FULL"){ condition.type = "FULL"; }else if(type == "FULLHAFT"){ condition.type = "FULLHAFT"; } } const _salaryPeriod = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: condition, order: { salaryOrg: { group: "ASC", }, type: "DESC", orgShortName: "ASC", posMasterNo: "ASC", }, }); const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; // 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), position: (profile.position ? profile.position : "-") + (profile.posExecutive ? `\n${profile.positionExecutiveField ? `${profile.posExecutive}(${profile.positionExecutiveField})` : profile.posExecutive}` : ""), affiliation: (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + "\n") + (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + "\n") + (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + "\n") + (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + "\n") + (profile.root == undefined && profile.root == null ? "" : profile.root), posLevel: profile.posLevel, orgShortName: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(String(profile.posMasterNo.toLocaleString())), amount: profile.amount == undefined || profile.amount == null || profile.amount == 0 ? "" : Extension.ToThaiNumber(String(profile.amount.toLocaleString())), amountSpecial: (profile.positionSalaryAmount == undefined || profile.positionSalaryAmount == null || profile.positionSalaryAmount == 0 ? "" : Extension.ToThaiNumber(String(profile.positionSalaryAmount.toLocaleString()))) + (profile.amountSpecial == undefined || profile.amountSpecial == null || profile.amountSpecial == 0 ? "" : `(${Extension.ToThaiNumber(String(profile.amountSpecial.toLocaleString()))})`), score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน 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: root, profile: formattedData, }, }); } /** * API แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) * * @summary แบบ 1 กท บัญชีรายชื่อผู้สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-04-01/{rootId}/{salaryPeriodId}/{group}") async SalaryReport4Retire( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const _salaryPeriod = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, type: In(["HAFT", "FULL", "FULLHAFT"]), isRetired: true, //กรองเฉพาะคนที่เกษียณ }, order: { salaryOrg: { group: "ASC", }, type: "DESC", orgShortName: "ASC", posMasterNo: "ASC", }, }); const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; // 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.position : "-") + (profile.posExecutive ? `\n${profile.positionExecutiveField ? `${profile.posExecutive}(${profile.positionExecutiveField})` : profile.posExecutive}` : ""), affiliation: (profile.child4 == undefined && profile.child4 == null ? "" : profile.child4 + "\n") + (profile.child3 == undefined && profile.child3 == null ? "" : profile.child3 + "\n") + (profile.child2 == undefined && profile.child2 == null ? "" : profile.child2 + "\n") + (profile.child1 == undefined && profile.child1 == null ? "" : profile.child1 + "\n") + (profile.root == undefined && profile.root == null ? "" : profile.root), posLevel: profile.posLevel, orgShortName: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(String(profile.posMasterNo.toLocaleString())), amount: profile.amount == undefined || profile.amount == null || profile.amount == 0 ? "" : Extension.ToThaiNumber(String(profile.amount.toLocaleString())), amountSpecial: (profile.positionSalaryAmount == undefined || profile.positionSalaryAmount == null || profile.positionSalaryAmount == 0 ? "" : Extension.ToThaiNumber(String(profile.positionSalaryAmount.toLocaleString()))) + (profile.amountSpecial == undefined || profile.amountSpecial == null || profile.amountSpecial == 0 ? "" : `(${Extension.ToThaiNumber(String(profile.amountSpecial.toLocaleString()))})`), score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน 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-01", reportName: salaryPeriod.period == "APR" ? "gov1-04" : "gov2-04-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), effectiveDate: salaryPeriod.effectiveDate, root: root, profile: formattedData, }, }); } /** * API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * * @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-05/{rootId}/{salaryPeriodId}/{group}") async SalaryReport5( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const _salaryPeriod = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน isRetired: salaryPeriod.period === "APR" ? In([true, false]) : false, //กรองเฉพาะคนที่ไม่เกษียณเฉพาะรอบตุลา }, order: { salaryOrg: { group: "ASC", }, orgShortName: "ASC", posMasterNo: "ASC", }, }); const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullname: profile.prefix + profile.firstName + " " + profile.lastName, position: (profile.position ? profile.position : "-") + (profile.posExecutive ? `\n${profile.positionExecutiveField ? `${profile.posExecutive}(${profile.positionExecutiveField})` : profile.posExecutive}` : ""), affiliation: affiliation, posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: profile.remark, //เหตุผล score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน remark: 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: root, data: formattedData, }, }); } /** * API แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) * * @summary แบบ 2 กท บัญชีรายชื่อผู้ไม่สมควรได้เลื่อนเงินเดือน รอบเมษายน และ ตุลาคม (เกษียณอายุราชการ) * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-05-01/{rootId}/{salaryPeriodId}/{group}") async SalaryReport5retire( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const _salaryPeriod = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, type: "NONE", //ไม่ได้เลื่อน isRetired: true, //กรองเฉพาะคนที่เกษียณ }, order: { salaryOrg: { group: "ASC", }, orgShortName: "ASC", posMasterNo: "ASC", }, }); const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullname: profile.prefix + profile.firstName + " " + profile.lastName, position: (profile.position ? profile.position : "-") + (profile.posExecutive ? `\n${profile.positionExecutiveField ? `${profile.posExecutive}(${profile.positionExecutiveField})` : profile.posExecutive}` : ""), affiliation: affiliation, posLevel: profile.posLevel, 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) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน remark: profile.remark, //หมายเหตุ }; }); return new HttpSuccess({ template: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05-01", reportName: salaryPeriod.period == "APR" ? "gov1-05" : "gov2-05-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: root, data: formattedData, }, }); } // /* API แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก // * // * @summary แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก // * // * @param {string} rootId Guid, *Id Root // * @param {string} salaryPeriodId Guid, *Id Period // */ // @Get("gov-06/{rootId}/{salaryPeriodId}") // async SalaryReport6(){ // } /** * API คำสั่งเลื่อนเงินเดือน รอบเมษายน และรอบตุลาคม * * @summary คำสั่งเลื่อนเงินเดือน รอบเมษายน และรอบตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-07/{rootId}/{salaryPeriodId}/{group}") async SalaryReport7( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const salaryProfile = await this.salaryProfileRepository.find({ where: { type: Not(In(["NONE", "PENDING"])), isReserve: Not(true), salaryOrg: { snapshot: "SNAP2", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, salaryPeriod: { period: salaryPeriod.period === "APR" ? "APR" : "OCT", }, }, }, order: { type: "DESC", orgShortName: "ASC", posMasterNo: "ASC", }, }); const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; // const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root; const formattedData = salaryProfile.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: item.prefix + item.firstName + " " + item.lastName, position: (item.position ? item.position : "-") + (item.posExecutive ? `\n${item.positionExecutiveField ? `${item.posExecutive}(${item.positionExecutiveField})` : item.posExecutive}` : ""), affiliation: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "\n") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + (item.root == undefined && item.root == null ? "" : item.root), posType: item.posType, posLevel: item.posLevel, posExecutive: item.posExecutive ? item.posExecutive : "-", fullPositionName: item.posExecutive ? item.position + " (" + item.posExecutive + ")" : item.position || "-", posMasterNo: Extension.ToThaiNumber(item.orgShortName) + " " + Extension.ToThaiNumber(String(item.posMasterNo.toLocaleString())), amount: item.amount == undefined || item.amount == null ? "๐" : Extension.ToThaiNumber(String(item.amount.toLocaleString())), positionSalaryAmount: item.positionSalaryAmount == undefined || item.positionSalaryAmount == null ? "๐" : Extension.ToThaiNumber(String(item.positionSalaryAmount.toLocaleString())) + (item.amountSpecial > 0 ? `(${Extension.ToThaiNumber(String(item.amountSpecial))})` : ""), remark: [ item.type === "FULL" ? "หนึ่งขั้น" : "", item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : "", item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ" : "", item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : "", ] .filter(Boolean) .join("\n"), })); return new HttpSuccess({ template: salaryPeriod.period === "APR" ? "gov1-07" : "gov2-08", reportName: salaryPeriod.period === "APR" ? "gov1-07" : "gov2-08", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearOld: Extension.ToThaiNumber((salaryPeriod.year + 542).toString()), date: salaryPeriod.period === "APR" ? Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), ) : Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), ), agency: root, data: formattedData, }, }); } /** * API คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ รอบตุลาคม * * @summary คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ รอบตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-07-01/{rootId}/{salaryPeriodId}/{group}") async SalaryReport7retire( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const salaryProfile = await this.salaryProfileRepository.find({ where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, salaryPeriod: { period: salaryPeriod.period, }, }, isRetired: true, // เฉพาะคนที่เกษียณ type: Not(In(["NONE", "PENDING"])), }, order: { type: "DESC", orgShortName: "ASC", posMasterNo: "ASC", }, }); const _root = await this.salaryOrgRepository.findOne({ where: { rootId: rootId, group: convertGroup, salaryPeriodId: salaryPeriodId, }, }); const root = _root?.root == null ? "" : _root.root; const formattedData = salaryProfile.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: item.prefix + item.firstName + " " + item.lastName, position: (item.position ? item.position : "-") + (item.posExecutive ? `\n${item.positionExecutiveField ? `${item.posExecutive}(${item.positionExecutiveField})` : item.posExecutive}` : ""), affiliation: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "\n") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + (item.root == undefined && item.root == null ? "" : item.root), posType: item.posType, 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())), positionSalaryAmount: item.positionSalaryAmount == undefined || item.positionSalaryAmount == null ? "๐" : Extension.ToThaiNumber(String(item.positionSalaryAmount.toLocaleString())) + (item.amountSpecial > 0 ? `(${Extension.ToThaiNumber(String(item.positionSalaryAmount))})` : ""), remark: `${item.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + `${item.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` + `${item.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + `${item.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, })); return new HttpSuccess({ template: "gov2-07", reportName: "gov2-07", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearOld: Extension.ToThaiNumber((salaryPeriod.year + 542).toString()), date: Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), ), agency: root, data: formattedData, }, }); } /** * APIคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน และรอบตุลาคม * * @summary คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน และรอบตุลาคม * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-08/{rootId}/{salaryPeriodId}/{group}") async SalaryReport8( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, // period: "APR", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } const convertGroup = group.toUpperCase(); const salaryOrg = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodId, rootId: rootId, snapshot: "SNAP2", group: convertGroup, }, relations: ["salaryProfiles"], }); const salaryProfileSpecial = await this.salaryProfileRepository.find({ relations: ["salaryOrg"], where: { salaryOrgId: In([salaryOrg?.id]), amountSpecial: MoreThan(0), }, select: [ "id", "prefix", "firstName", "lastName", "root", "child1", "child2", "child3", "child4", "position", "posType", "posLevel", "orgShortName", "posMasterNo", "amount", "amountSpecial", "remark", ], order: { salaryOrg: { group: "ASC", }, posMasterNo: "ASC", }, }); const salaryProfileNoAmount = await this.salaryProfileRepository.find({ relations: ["salaryOrg"], where: { salaryOrgId: In([salaryOrg?.id]), // amountUse: IsNull() || 0, // positionSalaryAmount: IsNull() || 0, type: "NONE", }, select: [ "id", "prefix", "firstName", "lastName", "root", "child1", "child2", "child3", "child4", "position", "posType", "posLevel", "orgShortName", "posMasterNo", "amount", "remark", ], order: { salaryOrg: { group: "ASC", }, posMasterNo: "ASC", }, }); const profileSpecial = salaryProfileSpecial.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: item.prefix + item.firstName + " " + item.lastName, position: (item.position ? item.position : "-") + (item.posExecutive ? `\n${item.positionExecutiveField ? `${item.posExecutive}(${item.positionExecutiveField})` : item.posExecutive}` : ""), affiliation: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "\n") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + (item.root == undefined && item.root == null ? "" : item.root), posType: item.posType, 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())), amountSpecial: item.amountSpecial == undefined || item.amountSpecial == null ? "๐" : Extension.ToThaiNumber(String(item.amountSpecial.toLocaleString())), remark: item.remark ?? "", })); const profileNoAmount = salaryProfileNoAmount.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: item.prefix + item.firstName + " " + item.lastName, position: (item.position ? item.position : "-") + (item.posExecutive ? `\n${item.positionExecutiveField ? `${item.posExecutive}(${item.positionExecutiveField})` : item.posExecutive}` : ""), affiliation: (item.child4 == undefined && item.child4 == null ? "" : item.child4 + "\n") + (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "\n") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "\n") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "\n") + (item.root == undefined && item.root == null ? "" : item.root), posType: item.posType, 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())), remark: item.remark ?? "", })); return new HttpSuccess({ template: salaryPeriod.period === "APR" ? "gov1-08" : "gov2-09", reportName: salaryPeriod.period === "APR" ? "gov1-08" : "gov2-09", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), date: salaryPeriod.period === "APR" ? Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-04-01`)), ) : Extension.ToThaiNumber( Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-10-01`)), ), agency: salaryOrg?.root, profileSpecial: profileSpecial, profileNoAmount: profileNoAmount, }, }); } /** * API เงินเดือน แบบบัญชีถือจ่าย (จ.๑๘) ของข้าราชการกรุงเทพมหานครสามัญ * * @summary เงินเดือน แบบบัญชีถือจ่าย (จ.๑๘) ของข้าราชการกรุงเทพมหานครสามัญ * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov-10/{rootId}/{salaryPeriodId}/{group}") async SalaryReport10( @Path() rootId: string, @Path() salaryPeriodId: string, @Path() group: string, ) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, // period: "OCT",?? isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } //ปีก่อนหน้า const salaryOldPeriod = await this.salaryPeriodRepository.findOne({ where: { year: salaryPeriod?.year - 1, period: "OCT", }, }); const convertGroup = group.toUpperCase(); const salaryOrg = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodId, rootId: rootId, snapshot: "SNAP2", group: convertGroup, }, relations: ["salaryProfiles"], }); //ปีก่อนหน้า let salaryOrgPrevious = null; if (salaryOldPeriod) { salaryOrgPrevious = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryOldPeriod?.id, rootDnaId: salaryOrg?.rootDnaId, snapshot: "SNAP1", group: convertGroup, }, }); } const salaryProfile = await this.salaryProfileRepository.find({ relations: ["salaryOrg"], where: { salaryOrgId: In([salaryOrg?.id]), // amountSpecial: MoreThan(0), }, order: { salaryOrg: { group: "ASC", }, posMasterNo: "ASC", }, }); const salaryProfilePrevious = await this.salaryProfileRepository.find({ relations: ["salaryOrg"], where: { salaryOrgId: In([salaryOrgPrevious?.id]), }, order: { salaryOrg: { group: "ASC", }, posMasterNo: "ASC", }, }); const formattedData = salaryProfile.map((item, index) => ({ no: Extension.ToThaiNumber(String(index + 1)), fullname: item.prefix + item.firstName + " " + item.lastName, root: item.root ?? "-", position: (item.position ? item.position : "-") + (item.posExecutive ? `\n${item.positionExecutiveField ? `${item.posExecutive} (${item.positionExecutiveField})` : item.posExecutive}` : ""), posMasterNo: Extension.ToThaiNumber(item.orgShortName) + " " + Extension.ToThaiNumber(String(item.posMasterNo)), posTypeCurrent: item.posType ?? "-", posLevelCurrent: item.posLevel ?? "-", amountCurrent: item.amount ? Extension.ToThaiNumber(item.amount.toLocaleString()) : "-", posTypePrevious: salaryProfilePrevious.length > 0 ? (() => { const filteredType = salaryProfilePrevious .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.posType); const posType = filteredType[0]; return posType ? posType : "-"; })() : "-", posLevelPrevious: salaryProfilePrevious.length > 0 ? (() => { const filteredLevel = salaryProfilePrevious .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.posLevel); const posLevel = filteredLevel[0]; return posLevel ? posLevel : "-"; })() : "-", amountPrevious: salaryProfilePrevious.length > 0 ? (() => { const filteredAmount = salaryProfilePrevious .filter((profile) => profile.citizenId === item.citizenId) .map((profile) => profile.amount); const amount = filteredAmount[0]; return amount ? Extension.ToThaiNumber(amount.toLocaleString()) : "-"; })() : "-", deduction: "-", //เงินปรับลด promote: item.amountUse ? Extension.ToThaiNumber(item.amountUse.toLocaleString()) : "-", //เงินเลื่อนขั้น qualification: "-", //เงินปรับวุฒิ adjustRate: "-", //เงินปรับอัตรา newRate: "-", //อัตราตั้งใหม่ specialPromote: "-", //ลำดับการเลื่อนกรณีพิเศษ remark: item.remark ?? "-", temporaryPayment: "-", //ถือจ่ายชั่วคราวขั้น })); return new HttpSuccess({ template: "gov2-10", reportName: "gov2-10", data: { data: formattedData, }, }); } /** * API 01-บัญชีคำนวณโควตา * * @summary 01-บัญชีคำนวณโควตา * */ @Get("emp-01/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_1(@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.salaryOrgEmployeeRepository.findOne({ relations: ["salaryPeriod", "salaryProfiles"], where: { snapshot: "SNAP2", group: "GROUP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); const agency = _salaryPeriod == null || _salaryPeriod.salaryProfiles[0] == null ? "" : _salaryPeriod.salaryProfiles[0].root; return new HttpSuccess({ template: "emp1-01", reportName: "emp1-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, total: _salaryPeriod == null ? "" : Extension.ToThaiNumber(_salaryPeriod.total.toString()), fifteenPercent: _salaryPeriod == null ? "" : Extension.ToThaiNumber( `${_salaryPeriod.fifteenPercent.toLocaleString()}.${_salaryPeriod.fifteenPoint.toLocaleString()}`, ), full: _salaryPeriod == null ? "" : Extension.ToThaiNumber( _salaryPeriod.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), ), haft: _salaryPeriod == null ? "" : Extension.ToThaiNumber( _salaryPeriod.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), ), notPromoted: _salaryPeriod == null ? "" : Extension.ToThaiNumber( _salaryPeriod.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), ), reason: null, }, }); } /** * API 02-รายชื่อลูกจ้างประจำผู้ครองตำแหน่ง ณ วันที่ 1 มีนาคม * * @summary 02-รายชื่อลูกจ้างประจำผู้ครองตำแหน่ง ณ วันที่ 1 มีนาคม * */ @Get("emp-02/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_2(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { amount: "ASC", rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: "emp1-02", reportName: "emp1-02", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 03-รายชื่อลูกจ้างประจำที่ได้รับการเสนอขอเลื่อนขั้นค่าจ้างหนึ่งขั้น * * @summary 03-รายชื่อลูกจ้างประจำที่ได้รับการเสนอขอเลื่อนขั้นค่าจ้างหนึ่งขั้น * */ @Get("emp-03/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_3(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: "FULL", salaryOrg: { snapshot: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { result: "DESC", rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const fifteenPercent = (_salaryPeriod[0]?.salaryOrg == null || _salaryPeriod[0]?.salaryOrg?.fifteenPercent == null ? "" : _salaryPeriod[0]?.salaryOrg?.fifteenPercent.toString()) + "." + (_salaryPeriod[0]?.salaryOrg == null || _salaryPeriod[0]?.salaryOrg?.fifteenPoint == null ? "๐๐" : _salaryPeriod[0]?.salaryOrg?.fifteenPoint.toString()); const formattedData = _salaryPeriod.map((profile, index) => { const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, fullName, ]; const affiliationParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, ]; const affiliation = affiliationParts .filter((part) => part !== undefined && part !== null) .join("\n"); const fullName_aff = fullNameParts .filter((part) => part !== undefined && part !== null && part !== "") .join("\n"); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName_aff, affiliation: affiliation, 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()) : "-", amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", reason: profile.remark, }; }); return new HttpSuccess({ template: "emp1-03", reportName: "emp1-03", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), fifteenPercent: Extension.ToThaiNumber(fifteenPercent), yearShort: Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year)).substr(-2), ), yearShortOld: Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)).substr(-2), ), agency: agency, data: formattedData, }, }); } /** * API 04-แบบ ลจ.กทม.1-รายชื่อลูกจ้างผู้สมควรได้เลื่อนขั้นค่าจ้าง * * @summary 04-แบบ ลจ.กทม.1-รายชื่อลูกจ้างผู้สมควรได้เลื่อนขั้นค่าจ้าง * */ @Get("emp-04/{rootId}/{salaryPeriodId}/{type}") async SalaryReportEmp1_4(@Path() rootId: string, @Path() salaryPeriodId: string, @Path() type: string = 'ALL') { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } let condition: any = { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }; condition.type = In(["HAFT", "FULL", "FULLHAFT"]); if(salaryPeriod.period == "APR"){ if(type == "HAFT"){ condition.type = "HAFT"; }else if(type == "FULL"){ condition.type = "FULL"; } }else{ if(type == "HAFT"){ condition.type = "HAFT"; }else if(type == "FULL"){ condition.type = "FULL"; }else if(type == "FULLHAFT"){ condition.type = "FULLHAFT"; } } const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: condition, order: { amount: "ASC", rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน reason: profile.remark, }; }); return new HttpSuccess({ template: "emp1-04", reportName: "emp1-04", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 05-แบบ ลจ.กทม.1-1-รายชื่อลูกจ้างผู้สมควรได้รับค่าตอบแทนพิเศษ * * @summary 05-แบบ ลจ.กทม.1-1-รายชื่อลูกจ้างผู้สมควรได้รับค่าตอบแทนพิเศษ * */ @Get("emp-05/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_5(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["HAFT", "FULL", "FULLHAFT"]), amountSpecial: MoreThan(0), isNext: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { amount: "ASC", rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", amountSpecialFormated: profile.amountSpecial > 0 ? "(" + Extension.ToThaiNumber(profile.amountSpecial.toString()) + ")" : "-", amountSpecial: profile.amountSpecial > 0 ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน reason: profile.remark, }; }); return new HttpSuccess({ template: "emp1-05", reportName: "emp1-05", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 06-แบบ ลจ.กทม.2-รายชื่อลูกจ้างผู้ไม่สมควรเลื่อนขั้นค่าจ้าง * * @summary 06-แบบ ลจ.กทม.2-รายชื่อลูกจ้างผู้ไม่สมควรเลื่อนขั้นค่าจ้าง * */ @Get("emp-06/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_6(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["NONE"]), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { amount: "ASC", rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", reasonSign: "", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน reason: profile.remark, //เหตุผลที่ไม่สมควรหรือไม่อาจเลื่อนขั้นค่าจ้าง }; }); return new HttpSuccess({ template: "emp1-06", reportName: "emp1-06", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 07-แบบ ลจ.กทม.2-1-รายชื่อลูกจ้างผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ * * @summary 07-แบบ ลจ.กทม.2-1-รายชื่อลูกจ้างผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ * */ @Get("emp-07/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_7(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["NONE"]), // amountSpecial: MoreThan(0),xx salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { amount: "ASC", rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม const filteredProfiles = await Promise.all( _salaryPeriod.map(async (profile) => { const salaryRankMax = await this.salaryEmployeeRankRepository .createQueryBuilder("rank") .leftJoin("rank.salaryEmployee_", "emp") .where("emp.isActive = :isActive", { isActive: true }) .andWhere("emp.group = :group", { group: profile.group }) .orderBy("rank.step", "DESC") .getOne(); const match = salaryRankMax != null && profile.salaryLevel != null && profile.salaryLevel === salaryRankMax.step && profile.amount === salaryRankMax.salaryMonth; if (!match) return null; return { profile, salaryRankMax }; }) ); const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); const formattedData = validProfiles.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", reasonSign: "", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", reason: profile.remark, }; }); return new HttpSuccess({ template: "emp1-07", reportName: "emp1-07", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } // /** // * API 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง // * // * @summary 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง // * // */ // @Get("emp-08/{rootId}/{salaryPeriodId}") // async SalaryReportEmp1_8(@Path() rootId: string, @Path() salaryPeriodId: string) { // const salaryPeriod = await this.salaryPeriodRepository.findOne({ // where: { // id: salaryPeriodId, // }, // }); // if (!salaryPeriod) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); // } // } /** * API 09-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับเลื่อนขั้นค่าจ้างในวันที่ 1 เมษา ย้อนหลัง 3 ครั้ง * * @summary 09-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับเลื่อนขั้นค่าจ้างในวันที่ 1 เมษา ย้อนหลัง 3 ครั้ง * */ @Get("emp-09/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_9(@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 salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, year: salaryPeriod.year - 1, period: "APR", isActive: true, }, }); const salaryPeriodOCT = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, year: salaryPeriod.year - 1, period: "OCT", isActive: true, }, }); const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, type: "NONE", }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _salaryProfileEmpAPR = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodAPR?.id, }, }, }); const _salaryProfileEmpOCT = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodOCT?.id, }, }, }); const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, position: profile.position ?? "-", posNumber: Extension.ToThaiNumber(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" ? "๑ ขั้น" : "ไม่ได้เลื่อนขั้นฯ", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //ผลการประเมิน remark: profile.remark, //หมายเหตุ }; }); return new HttpSuccess({ template: "emp1-09", 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), ), agency: agency, data: formattedData, }, }); } /** * API 10-รายชื่อลูกจ้างประจำผู้มีผลการประเมินดีเด่น * * @summary 10-รายชื่อลูกจ้างประจำผู้มีผลการประเมินดีเด่น * */ @Get("emp-10/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_10(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, isGood: true, type: Not("NONE"), }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = salaryProfileEmp[0] == null ? "" : salaryProfileEmp[0].root; const formattedData = salaryProfileEmp.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("\n"); 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 ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", }; }); return new HttpSuccess({ template: "emp1-10", reportName: "emp1-10", data: { yearOld: salaryPeriod.year ? Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))) : "", year: salaryPeriod.year ? Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))) : "", agency: agency, data: formattedData, }, }); } /** * API 11-คำสั่ง * * @summary 11-คำสั่ง * */ @Get("emp-11/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_11(@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: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, `${profile.prefix}${profile.firstName} ${profile.lastName}`, ]; const fullName = fullNameParts .filter((part) => part !== undefined && part !== null) .join(" "); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: "emp1-11", reportName: "emp1-11", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 12-บัญชีรายละเอียดผู้ได้รับอัตราค่าจ้างสูงกว่าขั้นสูง (แนบท้ายคำสั่ง) * * @summary 12-บัญชีรายละเอียดผู้ได้รับอัตราค่าจ้างสูงกว่าขั้นสูง (แนบท้ายคำสั่ง) * */ @Get("emp-12/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_12(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["HAFT", "FULL", "FULLHAFT"]), isNext: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", positionSalaryAmount: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน remark: `${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + `${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` + `${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + `${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ }; }); return new HttpSuccess({ template: "emp1-12", reportName: "emp1-12", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 13-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง * * @summary 13-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง * */ @Get("emp-13/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_13(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["NONE"]), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", positionSalaryAmount: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", //สรุปผลการประเมินฯ ระดับและคะแนน reason: profile.remark, // หมายเหตุ }; }); return new HttpSuccess({ template: "emp1-13", reportName: "emp1-13", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 14-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ * * @summary 14-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ * */ @Get("emp-14/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_14(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { isNext: false, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", positionSalaryAmount: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", reason: null, // หมายเหตุ }; }); return new HttpSuccess({ template: "emp1-14", reportName: "emp1-14", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง) * * @summary 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง) * */ @Get("emp-15/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_15(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { // isNext: true, amountSpecial: MoreThan(0), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", posMasterNo: "ASC", positionSalaryAmount: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", posNumber: profile.orgShortName || profile.posMasterNo ? Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()) : "-", amount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", precentTwo: profile.positionSalaryAmountPer == 0.02 ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", //ร้อยละ 2 precentFour: profile.positionSalaryAmountPer == 0.04 ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", //ร้อยละ 4 reason: null, // หมายเหตุ }; }); return new HttpSuccess({ template: "emp1-15", reportName: "emp1-15", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 17-คำสั่ง * * @summary 17-คำสั่ง * */ @Get("emp-17/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_17(@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: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, `${profile.prefix}${profile.firstName} ${profile.lastName}`, ]; const fullName = fullNameParts .filter((part) => part !== undefined && part !== null) .join(" "); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: "emp1-17", reportName: "emp1-17", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 18-คำสั่ง * * @summary 18-คำสั่ง * */ @Get("emp-18/{rootId}/{salaryPeriodId}") async SalaryReportEmp1_18(@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: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, `${profile.prefix}${profile.firstName} ${profile.lastName}`, ]; const fullName = fullNameParts .filter((part) => part !== undefined && part !== null) .join(" "); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: "emp1-18", reportName: "emp1-18", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 01-บัญชีการคำนวณวงเงินเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร * * @summary 01-บัญชีการคำนวณวงเงินเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร * */ @Get("emp2-01/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_1(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); //*****ปิด Throw ทั้งหมดเพราะ FE อยากได้ preview report เปล่าแทน***** // if (!salaryPeriod) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); // } const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ where: { year: salaryPeriod?.year, period: "APR", }, }); // if (!salaryPeriodAPR) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนรอบเดือนเมษายน"); // } const aprSnap2 = await this.salaryOrgEmployeeRepository.findOne({ relations: ["salaryPeriod", "salaryProfiles"], where: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodAPR?.id, }, }); // if (!aprSnap2) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // } const octSnap1 = await this.salaryOrgEmployeeRepository.findOne({ relations: ["salaryPeriod", "salaryProfiles"], where: { snapshot: "SNAP1", group: "GROUP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // if (!octSnap1) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // } const octSnap2 = await this.salaryOrgEmployeeRepository.findOne({ relations: ["salaryPeriod", "salaryProfiles"], where: { snapshot: "SNAP2", group: "GROUP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // if (!octSnap2) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // } 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: any) => { switch (profile.type) { case "FULLHAFT": // fullHaftTotalAmount += profile.amount ?? 0; fullHaftTotalAmount += profile.amountUse > 0 ? profile.amountUse : 0; fullHaftCount++; break; case "FULL": // fullTotalAmount += profile.amount ?? 0; fullTotalAmount += profile.amountUse > 0 ? profile.amountUse : 0; fullCount++; break; case "HAFT": // haftTotalAmount += profile.amount ?? 0; haftTotalAmount += profile.amountUse > 0 ? profile.amountUse : 0; haftCount++; break; case "NONE": noneCount++; break; default: break; } }); } 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); } }); }); } const totalEmp2step = emp2step.size ?? 0; // const agency = octSnap1.salaryProfiles[0] == null ? "" : octSnap1.salaryProfiles[0].root; return new HttpSuccess({ template: "emp2-01", reportName: "emp2-01", data: { year: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))): "", yearShort: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice( -2, ):"", agency: octSnap1?.root == null ? "" : octSnap1.root, totalUser: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.total.toLocaleString()), totalSalary: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toLocaleString()), sixPercent: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toLocaleString()), remainingAmountApr: // aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toLocaleString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย. aprSnap2 != null && octSnap2 ? Extension.ToThaiNumber(octSnap2?.spentAmount.toLocaleString()): "", remainingAmountOct: //octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toLocaleString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค. octSnap2 == null ? "" : Extension.ToThaiNumber( (octSnap2.sixPercentAmount - octSnap2.spentAmount).toLocaleString(), ), totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toLocaleString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง) fifteenPercentOld: Extension.ToThaiNumber( `${aprSnap2?.fifteenPercent.toLocaleString()}.${aprSnap2?.fifteenPoint.toLocaleString()}`, ), totalUseOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toLocaleString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง) full2: totalEmp2step == null ? "" : Extension.ToThaiNumber(totalEmp2step.toLocaleString()), //เลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้นจำนวน(คน) fullHaft: fullHaftCount == null ? "" : Extension.ToThaiNumber(fullHaftCount.toLocaleString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง) fullHaftSalary: fullHaftTotalAmount == null ? "" : Extension.ToThaiNumber(fullHaftTotalAmount.toLocaleString()), //ใช้เงิน(หนึ่งขั้นครึ่ง) full: fullCount == null ? "" : Extension.ToThaiNumber(fullCount.toLocaleString()), //จำนวน(คน)(หนึ่งขั้น) fullSalary: fullTotalAmount == null ? "" : Extension.ToThaiNumber(fullTotalAmount.toLocaleString()), //ใช้เงิน(หนึ่งขั้น) haft: haftCount == null ? "" : Extension.ToThaiNumber(haftCount.toLocaleString()), //จำนวน(คน)(ครึ่งขั้น) haftSalary: haftTotalAmount == null ? "" : Extension.ToThaiNumber(haftTotalAmount.toLocaleString()), //ใช้เงิน(ครึ่งขั้น) notPromoted: noneCount == null ? "" : Extension.ToThaiNumber(noneCount.toLocaleString()), //ไม่ได้เลื่อนขั้นค่าจ้างจำนวน(คน) total: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.useAmount.toLocaleString()), //รวมใช้เงิน summary: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.remainingAmount.toLocaleString()), //เหลือเงิน }, }); } /** * API 02-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ครองตำแหน่ง * * @summary 02-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ครองตำแหน่ง * */ @Get("emp2-02/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_2(@Path() rootId: string, @Path() salaryPeriodId: string) { 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 salaryPeriodOCTProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriod?.id, }, }, }); // let octPreviousYear:any = null; // let octPreviousYear2:any = null; // if (salaryPeriod?.year) { // const yearMi1 = salaryPeriod.year - 1; // const yearMi2 = salaryPeriod.year - 2; // octPreviousYear = await this.salaryPeriodRepository.findOne({ // where: { // period: "OCT", // year: yearMi1, // }, // }); // octPreviousYear2 = await this.salaryPeriodRepository.findOne({ // where: { // period: "OCT", // year: yearMi2, // }, // }); // } const octPreviousYear = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod?.year - 1, }, }); const octPreviousYear2 = await this.salaryPeriodRepository.findOne({ where: { 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: { salaryOrg: { snapshot: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile: any, index: number) => { if (!profile) { return null; } const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, ]; const affiliation = fullNameParts .filter((part) => part !== undefined && part !== null) .join("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, 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()), typeOld2: octPreviousYear2 && octPreviousYearProfile2.length > 0 ? (() => { const _profile = octPreviousYearProfile2.filter( (profileOCT2) => profileOCT2.citizenId === profile.citizenId, ); if (_profile.length > 0) { return _profile[0]?.type === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" ? "๑ ขั้น" : profile?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; } return null; })() : "-", yearOld: octPreviousYear == 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: salaryPeriodAPRProfile.length > 0 ? (() => { const _profile = salaryPeriodAPRProfile .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) .map((profile) => ({ type: profile.type, })); return _profile[0]?.type === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" ? "๑ ขั้น" : profile?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; })() : "-", //เมษา ปีเดียวกัน type: salaryPeriodOCTProfile.length > 0 ? (() => { const _profile = salaryPeriodOCTProfile .filter((profileOCT) => profileOCT.citizenId === profile.citizenId) .map((profile) => ({ type: profile.type, })); return _profile[0]?.type === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" ? "๑ ขั้น" : _profile[0]?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; })() : "-", //ตุลา ปีเดียวกัน }; }); return new HttpSuccess({ template: "emp2-02", reportName: "emp2-02", data: { year: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))):"", yearOld: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))):"", yearOld2: salaryPeriod?.year?Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 2))):"", agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 03-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ได้รับการเสนอขอเลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้น * * @summary 03-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ได้รับการเสนอขอเลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้น * */ @Get("emp2-03/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_3(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const fifteenPoint = await this.salaryOrgEmployeeRepository.findOne({ where: { salaryPeriodId: salaryPeriodId, rootId: rootId, snapshot: "SNAP2", }, }); const fifteenPercentData = fifteenPoint?.fifteenPercent == undefined || fifteenPoint?.fifteenPercent == null ? "๐" : Extension.ToThaiNumber(String(fifteenPoint?.fifteenPercent)); const fifteenPointData = fifteenPoint?.fifteenPoint == undefined || fifteenPoint?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(fifteenPoint?.fifteenPoint)); const _salaryProfileEmployee = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", result: "DESC", }, }); if (!_salaryProfileEmployee) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const aprSalaryPeriodCurrent = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriod.year, isActive: true, }, }); const octPreviousYear = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod?.year - 1, isActive: true, }, }); const aprPreviousYear2 = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriod?.year - 1, isActive: true, }, }); let aprPreviousYearProfileCurrent: SalaryProfileEmployee[] = []; if (aprSalaryPeriodCurrent) { aprPreviousYearProfileCurrent = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: aprSalaryPeriodCurrent?.id, }, }, }); } let octPreviousYearProfile: SalaryProfileEmployee[] = []; if (octPreviousYear) { octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: octPreviousYear?.id, }, }, }); } let aprPreviousYearProfile2: SalaryProfileEmployee[] = []; if (aprPreviousYear2) { aprPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { type: Not(In(["NONE", "PENDING"])), salaryOrg: { snapshot: "SNAP2", salaryPeriodId: aprPreviousYear2?.id, rootId: rootId, }, }, }); } // ฟังก์ชันที่ใช้ตรวจสอบการตรงตามเงื่อนไข 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 .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("\n"); 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 ? `${profile.posTypeShort} ${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" ? "๐.๕ ขั้น" : _type === "FULL" ? "๑ ขั้น" : _type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; })() : "-", // เมษา type: profile.type === "HAFT" ? "๐.๕ ขั้น" : profile.type === "FULL" ? "๑ ขั้น" : profile.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ", score1: profile.result ?? "-", score2: "-", }; }); return new HttpSuccess({ template: "emp2-03", reportName: "emp2-03", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearOld: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))), yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice( -2, ), yearShortOld: Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), ).slice(-2), fifteenPercent: fifteenPercentData + fifteenPointData, agency: fifteenPoint?.root == null ? "" : fifteenPoint?.root, data: formattedData, }, }); } /** * API 04-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้สมควรได้เลื่อนขั้นค่าจ้าง (แบบ ลจ.กทม.1) * * @summary 04-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้สมควรได้เลื่อนขั้นค่าจ้าง (แบบ ลจ.กทม.1) * */ @Get("emp2-04/{rootId}/{salaryPeriodId}/{type}") async SalaryReportEmp2_4(@Path() rootId: string, @Path() salaryPeriodId: string, @Path() type: string = 'ALL') { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } let condition: any = { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }; condition.type = Not("NONE"); if(salaryPeriod.period == "APR"){ if(type == "HAFT"){ condition.type = "HAFT"; }else if(type == "FULL"){ condition.type = "FULL"; } }else{ if(type == "HAFT"){ condition.type = "HAFT"; }else if(type == "FULL"){ condition.type = "FULL"; }else if(type == "FULLHAFT"){ condition.type = "FULLHAFT"; } } const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: condition, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, 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.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", // reason: profile.remark, reason: `${profile.type === "FULL" ? "หนึ่งขั้น" : ""}\n` + `${profile.type === "FULLHAFT" ? "หนึ่งขั้นครึ่ง" : ""}\n` + `${profile.amountSpecial > 0 ? "ได้รับค่าตอบแทนพิเศษ\n" : ""}` + `${profile.isNext === true ? "(ได้รับเงินเดือนสูงกว่าขั้นสูงฯ)" : ""}`, // หมายเหตุ }; }); return new HttpSuccess({ template: "emp2-04", reportName: "emp2-04", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 05-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้สมควรได้รับค่าตอบแทนพิเศษ (แบบ ลจ.กทม.1/1) * * @summary 05-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้สมควรได้รับค่าตอบแทนพิเศษ (แบบ ลจ.กทม.1/1) * */ @Get("emp2-05/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_5(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: Not("NONE"), amountSpecial: MoreThan(0), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", amountSpecial: profile.amountSpecial ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", score: profile.result ?? "-", reason: null, }; }); return new HttpSuccess({ template: "emp2-05", reportName: "emp2-05", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 06-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่สมควรเลื่อนขั้นค่าจ้าง (แบบ ลจ.กทม.2) * * @summary 06-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่สมควรเลื่อนขั้นค่าจ้าง (แบบ ลจ.กทม.2) * */ @Get("emp2-06/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_6(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, type: "NONE", }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", reason: profile.remark, remark: null, }; }); return new HttpSuccess({ template: "emp2-06", reportName: "emp2-06", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 07-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ (แบบ ลจ.กทม.2/1) * * @summary 07-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ (แบบ ลจ.กทม.2/1) * */ @Get("emp2-07/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_7(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["NONE"]), // amountSpecial: MoreThan(0),xx salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม const filteredProfiles = await Promise.all( _salaryPeriod.map(async (profile) => { const salaryRankMax = await this.salaryEmployeeRankRepository .createQueryBuilder("rank") .leftJoin("rank.salaryEmployee_", "emp") .where("emp.isActive = :isActive", { isActive: true }) .andWhere("emp.group = :group", { group: profile.group }) .orderBy("rank.step", "DESC") .getOne(); const match = salaryRankMax != null && profile.salaryLevel != null && profile.salaryLevel === salaryRankMax.step && profile.amount === salaryRankMax.salaryMonth; if (!match) return null; return { profile, salaryRankMax }; }) ); const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); const formattedData = validProfiles.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", reason: profile.remark, score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", signature: null, }; }); return new HttpSuccess({ template: "emp2-07", reportName: "emp2-07", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 08-บัญชีแสดงวันลาในครึ่งปีที่แล้วมาของลูกจ้างประจำกรุงเทพมหานคร (แบบ ลจ.กทม.3) * * @summary 08-บัญชีแสดงวันลาในครึ่งปีที่แล้วมาของลูกจ้างประจำกรุงเทพมหานคร (แบบ ลจ.กทม.3) * */ @Get("emp2-08/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_8(@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: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, posLevel: profile.posLevel, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 09-รายชื่อลูกจ้างประจำกรุงเทพมหานครที่ครบเกษียณอายุราชการ * * @summary 09-รายชื่อลูกจ้างประจำกรุงเทพมหานครที่ครบเกษียณอายุราชการ * */ @Get("emp2-09/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_9(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const _salaryPeriodTarget = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { isRetired: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriodTarget) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const octPreviousYear = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod?.year - 1, }, }); const octPreviousYear2 = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriod?.year - 2, }, }); let octPreviousYearProfile: SalaryProfileEmployee[] = []; if (octPreviousYear) { octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { isRetired: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: octPreviousYear?.id, }, }, }); } let octPreviousYearProfile2: SalaryProfileEmployee[] = []; if (octPreviousYear2) { octPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg"], where: { isRetired: true, salaryOrg: { snapshot: "SNAP2", salaryPeriodId: octPreviousYear2?.id, rootId: rootId, }, }, }); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryPeriodTarget[0] == null ? "" : _salaryPeriodTarget[0].root; const formattedData = _salaryPeriodTarget.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("\n"); 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.toString()) : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, typeOld2: octPreviousYear2 && octPreviousYearProfile2.length > 0 ? (() => { const _profile = octPreviousYearProfile2.filter( (profileOCT2) => profileOCT2.citizenId === profile.citizenId, ); if (_profile.length > 0) { return _profile[0]?.type === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" ? "๑ ขั้น" : profile?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; } 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 === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" ? "๑ ขั้น" : profile?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; } return null; })() : null, typeOld: _salaryPeriodTarget.length > 0 ? (() => { const _profile = _salaryPeriodTarget .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) .map((profile) => ({ type: profile.type, })); return _profile[0]?.type === "HAFT" ? "๐.๕ ขั้น" : _profile[0]?.type === "FULL" ? "๑ ขั้น" : profile?.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ"; })() : null, //เมษา ปีเดียวกัน type: profile.type === "HAFT" ? "๐.๕ ขั้น" : profile.type === "FULL" ? "๑ ขั้น" : profile.type === "FULLHAFT" ? "๑.๕ ขั้น" : "ไม่ได้เลื่อนขั้นฯ", score1: profile.result, score2: null, reason: profile.remark, }; }); return new HttpSuccess({ template: "emp2-09", reportName: "emp2-09", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice( -2, ), yearShortOld: Extension.ToThaiNumber( String(Extension.ToThaiYear(salaryPeriod.year - 1)), ).slice(-2), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 10-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง/ค่าตอบแทนพิเศษ * * @summary 10-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง/ค่าตอบแทนพิเศษ * */ @Get("emp2-10/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_10(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, type: "NONE", }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const _root = await this.salaryOrgEmployeeRepository.findOne({ where: { rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); // const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, 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.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", posNumber: 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()) : "-", reason1: "-", //เหตุผลที่ไม่ได้เลื่อนขั้น reason2: "-", //เหตุผลที่ไม่ได้เลื่อนขั้น reason3: "-", //เหตุผลที่ไม่ได้เลื่อนขั้น score: profile.result ? Extension.ToThaiNumber(profile.result) : "-", reason: profile.remark, }; }); const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))); const yearOld = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year - 1))); return new HttpSuccess({ template: "emp2-10", reportName: "emp2-10", data: { year: year, yearSlice: year.slice(-2), yearOldSlice: yearOld.slice(-2), agency: _root?.root == null ? "" : _root?.root, data: formattedData, }, }); } /** * API 11-รายชื่อลูกจ้างประจำผู้มีผลการประเมินประสิทธิภาพและประสิทธิผลการปฏิบัติงานอยู่ในระดับดีเด่น * * @summary 11-รายชื่อลูกจ้างประจำผู้มีผลการประเมินประสิทธิภาพและประสิทธิผลการปฏิบัติงานอยู่ในระดับดีเด่น * */ @Get("emp2-11/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_11(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { isGood: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.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("\n"); 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 ? `${profile.posTypeShort} ${Extension.ToThaiNumber(profile.posLevel.toLocaleString())}` : "-", }; }); return new HttpSuccess({ template: "emp2-11", reportName: "emp2-11", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 12-คำสั่งเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับที่เกษียณอายุราชการ * * @summary 12-คำสั่งเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับที่เกษียณอายุราชการ * */ @Get("emp2-12/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_12(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrg = await this.salaryOrgEmployeeRepository.findOne({ where: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); if (!salaryOrg) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } return new HttpSuccess({ template: "emp2-12", reportName: "emp2-12", }); } /** * API 13-บัญชีรายละเอียดแสดงการเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ ที่เกษียณอายุราชการ * * @summary 13-บัญชีรายละเอียดแสดงการเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ ที่เกษียณอายุราชการ * */ @Get("emp2-13/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_13(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { isRetired: true, isNext: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!salaryProfile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root; const formattedData = salaryProfile.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("\n"); 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, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: "emp2-13", reportName: "emp2-13", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 14-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับการเลื่อนขั้นค่าจ้างที่เกษียณอายุราชการ * * @summary 14-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับการเลื่อนขั้นค่าจ้างที่เกษียณอายุราชการ * */ @Get("emp2-14/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_14(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, type: "NONE", isRetired: true, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, 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, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : null, reason: profile.remark ? profile.remark : null, }; }); return new HttpSuccess({ template: "emp2-14", reportName: "emp2-14", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 15-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับค่าตอบแทนพิเศษที่เกษียณอายุราชการ * * @summary 15-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับค่าตอบแทนพิเศษที่เกษียณอายุราชการ * */ @Get("emp2-15/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_15(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { isRetired: true, type: In(["NONE"]), // amountSpecial: MoreThan(0),xxx salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม const filteredProfiles = await Promise.all( _salaryPeriod.map(async (profile) => { const salaryRankMax = await this.salaryEmployeeRankRepository .createQueryBuilder("rank") .leftJoin("rank.salaryEmployee_", "emp") .where("emp.isActive = :isActive", { isActive: true }) .andWhere("emp.group = :group", { group: profile.group }) .orderBy("rank.step", "DESC") .getOne(); const match = salaryRankMax != null && profile.salaryLevel != null && profile.salaryLevel === salaryRankMax.step && profile.amount === salaryRankMax.salaryMonth; if (!match) return null; return { profile, salaryRankMax }; }) ); const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); const formattedData = validProfiles.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("\n"); 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()) : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: "emp2-15", reportName: "emp2-15", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 16-คำสั่งเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ * * @summary 16-คำสั่งเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ * */ @Get("emp2-16/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_16(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrg = await this.salaryOrgEmployeeRepository.findOne({ where: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); if (!salaryOrg) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } return new HttpSuccess({ template: "emp2-16", reportName: "emp2-16", }); } /** * API 17-บัญชีรายละเอียดแสดงการเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ (แนบท้ายคำสั่ง) * * @summary 17-บัญชีรายละเอียดแสดงการเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ (แนบท้ายคำสั่ง) * */ @Get("emp2-17/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_17(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryProfile = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { isNext: true, salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", type: "DESC", }, }); if (!salaryProfile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = salaryProfile[0] == null ? "" : salaryProfile[0].root; const formattedData = salaryProfile.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", reason: profile.type === "HAFT" ? "๐.๕ ขั้น" : profile.type === "FULL" ? "๑ ขั้น" : profile.type === "FULLHAFT" ? "๑.๕ ขั้น" : null, }; }); return new HttpSuccess({ template: "emp2-17", reportName: "emp2-17", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 18-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง * * @summary 18-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง * */ @Get("emp2-18/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_18(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, type: In(["NONE", "PENDING"]), isRetired: false, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", type: "DESC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, position: profile.position ? profile.position : "-", posLevel: profile.posLevel ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) : "-", posNumber: 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: profile.remark ?? null, }; }); return new HttpSuccess({ template: "emp2-18", reportName: "emp2-18", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 20-บัญชีรายละเอียดให้ลูกจ้างประจำกรุงเทพมหานครได้รับค่าตอบแทนพิเศษ (แนบท้ายคำสั่ง) * * @summary 20-บัญชีรายละเอียดให้ลูกจ้างประจำกรุงเทพมหานครได้รับค่าตอบแทนพิเศษ (แนบท้ายคำสั่ง) * */ @Get("emp2-20/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_20(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const _salaryProfileEmp = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: Not(In(["NONE", "PENDING"])), amountSpecial: MoreThan(0), salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", type: "DESC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryProfileEmp) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryProfileEmp[0] == null ? "" : _salaryProfileEmp[0].root; const formattedData = _salaryProfileEmp.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 positionParts = [ profile.position, profile.child4, profile.child3, profile.child2, profile.child1, profile.root, ]; const position = positionParts .filter((part) => part !== undefined && part !== null) .join("\n"); const fullName = `${profile.prefix}${profile.firstName} ${profile.lastName}`; return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, affiliation: affiliation, position: position, posLevel: profile.posLevel ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) : "-", posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", precentTwo: profile.positionSalaryAmountPer == 0.02 ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", //ร้อยละ 2 precentFour: profile.positionSalaryAmountPer == 0.04 ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", //ร้อยละ 4 precentSix: profile.positionSalaryAmountPer == 0.06 ? Extension.ToThaiNumber(profile.amountSpecial.toLocaleString()) : "-", //ร้อยละ 6 reason: null, }; }); return new HttpSuccess({ template: "emp2-20", reportName: "emp2-20", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 21-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับค่าตอบแทนพิเศษ * * @summary 21-บัญชีรายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ไม่ได้รับค่าตอบแทนพิเศษ * */ @Get("emp2-21/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_21(@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.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { type: In(["NONE"]), // amountSpecial: MoreThan(0),xxx salaryOrg: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; //หาคนที่เงินเดือนเท่ากับเงินเดือนสูงสุดในกลุ่ม const filteredProfiles = await Promise.all( _salaryPeriod.map(async (profile) => { const salaryRankMax = await this.salaryEmployeeRankRepository .createQueryBuilder("rank") .leftJoin("rank.salaryEmployee_", "emp") .where("emp.isActive = :isActive", { isActive: true }) .andWhere("emp.group = :group", { group: profile.group }) .orderBy("rank.step", "DESC") .getOne(); const match = salaryRankMax != null && profile.salaryLevel != null && profile.salaryLevel === salaryRankMax.step && profile.amount === salaryRankMax.salaryMonth; if (!match) return null; return { profile, salaryRankMax }; }) ); const validProfiles = filteredProfiles.filter((item): item is { profile: any, salaryRankMax: any } => item !== null); const formattedData = validProfiles.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("\n"); 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 ? `${profile.posTypeShort} ${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()) : "-", reason: null, }; }); return new HttpSuccess({ template: "emp2-21", reportName: "emp2-21", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 22-คำสั่งแก้ไขคำสั่งเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร (เฉพาะราย) * * @summary 22-คำสั่งแก้ไขคำสั่งเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร (เฉพาะราย) * */ @Get("emp2-22/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_22(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrg = await this.salaryOrgEmployeeRepository.findOne({ where: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); if (!salaryOrg) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } return new HttpSuccess({ template: "emp2-22", reportName: "emp2-22", }); } /** * API 23-บัญชีรายละเอียดแสดงการเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ (แนบท้ายคำสั่ง) * * @summary 23-บัญชีรายละเอียดแสดงการเลื่อนขั้นค่าจ้างและให้ลูกจ้างประจำกรุงเทพมหานครได้รับอัตราค่าจ้างสูงกว่าอัตราค่าจ้างขั้นสูงของตำแหน่งที่ได้รับแต่งตั้งในแต่ละระดับ (แนบท้ายคำสั่ง) * */ @Get("emp2-23/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_23(@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: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, `${profile.prefix}${profile.firstName} ${profile.lastName}`, ]; const fullName = fullNameParts .filter((part) => part !== undefined && part !== null) .join(" "); return { no: Extension.ToThaiNumber((index + 1).toLocaleString()), fullName: fullName, posLevel: profile.posLevel ? Extension.ToThaiNumber(profile.posLevel.toLocaleString()) : null, posNumber: Extension.ToThaiNumber(profile.orgShortName) + " " + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, reason: null, }; }); return new HttpSuccess({ template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), agency: agency, data: formattedData, }, }); } /** * API 24-คำสั่งยกเลิกคำสั่งเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร (เฉพาะราย) * * @summary 24-คำสั่งยกเลิกคำสั่งเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร (เฉพาะราย) * */ @Get("emp2-24/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_24(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, period: "OCT", isActive: true, }, }); if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrg = await this.salaryOrgEmployeeRepository.findOne({ where: { snapshot: "SNAP2", rootId: rootId, salaryPeriodId: salaryPeriodId, }, }); if (!salaryOrg) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } return new HttpSuccess({ template: "blank", reportName: "emp2-24", }); } /** * API 25-แบบฟอร์มบัญชีถือจ่ายอัตราค่าจ้างลูกจ้างประจำกรุงเทพมหานคร * * @summary 25-แบบฟอร์มบัญชีถือจ่ายอัตราค่าจ้างลูกจ้างประจำกรุงเทพมหานคร * */ @Get("emp2-25/{rootId}/{salaryPeriodId}") async SalaryReportEmp2_25(@Path() rootId: string, @Path() salaryPeriodId: string) { //งวดปีปัจจุบัน const salaryPeriodOCT = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, }, }); if (!salaryPeriodOCT) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriodOCT.year, }, }); if (!salaryPeriodAPR) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } let perviousYearAPR: any; let perviousYearOCT: any; let salaryProfilePerviousAPR: any; let salaryProfilePerviousOCT: any; //งวดปีก่อนหน้า perviousYearAPR = await this.salaryPeriodRepository.findOne({ where: { period: "APR", year: salaryPeriodOCT.year - 1, }, }); perviousYearOCT = await this.salaryPeriodRepository.findOne({ where: { period: "OCT", year: salaryPeriodOCT.year - 1, }, }); //ปีก่อนหน้า if (perviousYearAPR) { salaryProfilePerviousAPR = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", salaryPeriodId: perviousYearAPR.id, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); } if (perviousYearOCT) { salaryProfilePerviousOCT = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", salaryPeriodId: perviousYearOCT.id, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); } //ปีปัจุบัน const salaryProfileCurrentAPR = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", salaryPeriodId: salaryPeriodId, }, }, order: { orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!salaryProfileCurrentAPR) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const salaryProfileCurrentOCT = await this.salaryProfileEmployeeRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP2", salaryPeriodId: salaryPeriodId, }, }, order: { rootOrder: "ASC", child1Order: "ASC", child2Order: "ASC", child3Order: "ASC", child4Order: "ASC", orgShortName: "ASC", posMasterNo: "ASC", }, }); if (!salaryProfileCurrentOCT) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = salaryProfileCurrentOCT[0] == null ? "" : salaryProfileCurrentOCT[0].root; const formattedData = salaryProfileCurrentOCT.map((profile, index) => { //งวดปีก่อนหน้า let matchedAPRProfileOld: SalaryProfile | null = null; let matchedOCTProfileOld: SalaryProfile | null = null; if (salaryProfilePerviousAPR && salaryProfilePerviousAPR.length > 0) { matchedAPRProfileOld = salaryProfilePerviousAPR.find( (aprProfile_old: SalaryProfile) => aprProfile_old.citizenId === profile.citizenId, ); } if (salaryProfilePerviousOCT && salaryProfilePerviousOCT.length > 0) { matchedOCTProfileOld = salaryProfilePerviousOCT.find( (octProfile_old: SalaryProfile) => octProfile_old.citizenId === profile.citizenId, ); } const amountUseAPR_Old = matchedAPRProfileOld ? matchedAPRProfileOld.amountUse : 0; const amountUseOCT_Old = matchedOCTProfileOld ? matchedOCTProfileOld.amountUse : 0; const amountUseOld = amountUseAPR_Old + amountUseOCT_Old; //งวดปีปัจจุบัน const matchedAPRProfile = salaryProfileCurrentAPR.find( (aprProfile) => aprProfile.citizenId === profile.citizenId, ); const matchedOCTProfile = salaryProfileCurrentOCT.find( (octProfile) => octProfile.citizenId === profile.citizenId, ); const amountUseAPR = matchedAPRProfile ? matchedAPRProfile.amountUse : 0; const amountUseOCT = matchedOCTProfile ? matchedOCTProfile.amountUse : 0; const amountUse = amountUseAPR + amountUseOCT; const fullNameParts = [ profile.child4, profile.child3, profile.child2, profile.child1, profile.root, ]; const affiliation = fullNameParts .filter((part) => part !== undefined && part !== null) .join("\n"); 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 ? `${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()) : "-", positionSalaryAmount: profile.positionSalaryAmount ? Extension.ToThaiNumber(profile.positionSalaryAmount.toLocaleString()) : "-", amountUseOld: amountUseOld ? Extension.ToThaiNumber(amountUseOld.toLocaleString()) : "-", amountUse: amountUse ? Extension.ToThaiNumber(amountUse.toLocaleString()) : "-", reason: null, }; }); return new HttpSuccess({ template: "emp2-25", reportName: "emp2-25", data: { year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriodOCT.year))), agency: agency, data: formattedData, }, }); } // /** // * API ออกคำสั่ง 33 // * // * @summary ออกคำสั่ง 33 // * // * @param {string} id Guid, *Id ผังเงินเดือน // */ // @Post("command/33/resume") // async SalaryReport33Resume( // @Body() // body: { // result: { // id: string; // refCommandNo: string; // templateDoc: string; // mpCee?: string | null; // refCommandCode?: string | null; // refCommandName?: string | null; // }[]; // }, // @Request() request: RequestWithUser, // ) { // await Promise.all( // body.result.map(async (v) => { // const salary = await this.salaryProfileRepository.findOne({ // where: { // id: v.id, // }, // }); // if (salary != null) { // await new CallAPI() // .PostData(request, "/org/profile/salary", { // profileId: salary.profileId, // date: new Date(), // amount: salary.positionSalaryAmount, // positionSalaryAmount: salary.amountSpecial, // mouthSalaryAmount: null, // posNo: salary.orgShortName + salary.posMasterNo, // position: salary.position, // positionLine: null, // positionPathSide: null, // positionExecutive: salary.posExecutive, // positionType: salary.posType, // positionLevel: salary.posLevel, // refCommandNo: v.refCommandNo, // templateDoc: v.templateDoc, // refCommandCode: v.refCommandCode, // refCommandName: v.refCommandName, // }) // .then(async () => { // const before = null; // salary.status = "DONE"; // salary.lastUpdateUserId = request.user.sub; // salary.lastUpdateFullName = request.user.name; // salary.lastUpdatedAt = new Date(); // await this.salaryProfileRepository.save(salary, { data: request }); // setLogDataDiff(request, { before, after: salary }); // }); // } // }), // ); // return new HttpSuccess(); // } // /** // * API ออกคำสั่ง 34 // * // * @summary ออกคำสั่ง 34 // * // * @param {string} id Guid, *Id ผังเงินเดือน // */ // @Post("command/34/resume") // async SalaryReport34Resume( // @Body() // body: { // result: { // id: string; // refCommandNo: string; // templateDoc: string; // mpCee?: string | null; // refCommandCode?: string | null; // refCommandName?: string | null; // }[]; // }, // @Request() request: RequestWithUser, // ) { // await Promise.all( // body.result.map(async (v) => { // const salary = await this.salaryProfileRepository.findOne({ // where: { // id: v.id, // }, // }); // if (salary != null) { // await new CallAPI() // .PostData(request, "/org/profile/salary", { // profileId: salary.profileId, // date: new Date(), // amount: salary.positionSalaryAmount, // positionSalaryAmount: salary.amountSpecial, // mouthSalaryAmount: null, // posNo: salary.orgShortName + salary.posMasterNo, // position: salary.position, // positionLine: null, // positionPathSide: null, // positionExecutive: salary.posExecutive, // positionType: salary.posType, // positionLevel: salary.posLevel, // refCommandNo: v.refCommandNo, // templateDoc: v.templateDoc, // refCommandCode: v.refCommandCode, // refCommandName: v.refCommandName, // }) // .then(async () => { // const before = null; // salary.status = "DONE"; // salary.lastUpdateUserId = request.user.sub; // salary.lastUpdateFullName = request.user.name; // salary.lastUpdatedAt = new Date(); // await this.salaryProfileRepository.save(salary, { data: request }); // setLogDataDiff(request, { before, after: salary }); // }); // } // }), // ); // return new HttpSuccess(); // } // /** // * API ออกคำสั่ง 35 // * // * @summary ออกคำสั่ง 35 // * // * @param {string} id Guid, *Id ผังเงินเดือน // */ // @Post("command/35/resume") // async SalaryReport35Resume( // @Body() // body: { // result: { // id: string; // refCommandNo: string; // templateDoc: string; // mpCee?: string | null; // refCommandCode?: string | null; // refCommandName?: string | null; // }[]; // }, // @Request() request: RequestWithUser, // ) { // await Promise.all( // body.result.map(async (v) => { // const salary = await this.salaryProfileRepository.findOne({ // where: { // id: v.id, // }, // }); // if (salary != null) { // await new CallAPI() // .PostData(request, "/org/profile/salary", { // profileId: salary.profileId, // date: new Date(), // amount: salary.positionSalaryAmount, // positionSalaryAmount: salary.amountSpecial, // mouthSalaryAmount: null, // posNo: salary.orgShortName + salary.posMasterNo, // position: salary.position, // positionLine: null, // positionPathSide: null, // positionExecutive: salary.posExecutive, // positionType: salary.posType, // positionLevel: salary.posLevel, // refCommandNo: v.refCommandNo, // templateDoc: v.templateDoc, // refCommandCode: v.refCommandCode, // refCommandName: v.refCommandName, // }) // .then(async () => { // const before = null; // salary.status = "DONE"; // salary.lastUpdateUserId = request.user.sub; // salary.lastUpdateFullName = request.user.name; // salary.lastUpdatedAt = new Date(); // await this.salaryProfileRepository.save(salary, { data: request }); // setLogDataDiff(request, { before, after: salary }); // }); // } // }), // ); // return new HttpSuccess(); // } // /** // * API ออกคำสั่ง 36 // * // * @summary ออกคำสั่ง 36 // * // * @param {string} id Guid, *Id ผังเงินเดือน // */ // @Post("command/36/resume") // async SalaryReport36Resume( // @Body() // body: { // result: { // id: string; // refCommandNo: string; // templateDoc: string; // mpCee?: string | null; // refCommandCode?: string | null; // refCommandName?: string | null; // }[]; // }, // @Request() request: RequestWithUser, // ) { // await Promise.all( // body.result.map(async (v) => { // const salary = await this.salaryProfileEmployeeRepository.findOne({ // where: { // id: v.id, // }, // }); // if (salary != null) { // await new CallAPI() // .PostData(request, "/org/profile-employee/salary", { // profileEmployeeId: salary.profileId, // date: new Date(), // amount: salary.positionSalaryAmount, // positionSalaryAmount: salary.amountSpecial, // mouthSalaryAmount: null, // posNo: salary.orgShortName + salary.posMasterNo, // position: salary.position, // // positionLine: null, // // positionPathSide: null, // // positionExecutive: null, // positionType: salary.posType, // positionLevel: salary.posLevel ? String(salary.posLevel) : null, // refCommandNo: v.refCommandNo, // templateDoc: v.templateDoc, // refCommandCode: v.refCommandCode, // refCommandName: v.refCommandName, // }) // .then(async () => { // const before = null; // salary.status = "DONE"; // salary.lastUpdateUserId = request.user.sub; // salary.lastUpdateFullName = request.user.name; // salary.lastUpdatedAt = new Date(); // await this.salaryProfileEmployeeRepository.save(salary, { data: request }); // setLogDataDiff(request, { before, after: salary }); // }); // } // }), // ); // return new HttpSuccess(); // } // /** // * API ออกคำสั่ง 37 // * // * @summary ออกคำสั่ง 37 // * // * @param {string} id Guid, *Id ผังเงินเดือน // */ // @Post("command/37/resume") // async SalaryReport37Resume( // @Body() // body: { // result: { // id: string; // refCommandNo: string; // templateDoc: string; // mpCee?: string | null; // refCommandCode?: string | null; // refCommandName?: string | null; // }[]; // }, // @Request() request: RequestWithUser, // ) { // await Promise.all( // body.result.map(async (v) => { // const salary = await this.salaryProfileEmployeeRepository.findOne({ // where: { // id: v.id, // }, // }); // if (salary != null) { // await new CallAPI() // .PostData(request, "/org/profile-employee/salary", { // profileEmployeeId: salary.profileId, // date: new Date(), // amount: salary.positionSalaryAmount, // positionSalaryAmount: salary.amountSpecial, // mouthSalaryAmount: null, // posNo: salary.orgShortName + salary.posMasterNo, // position: salary.position, // positionLine: null, // positionPathSide: null, // positionExecutive: null, // positionType: salary.posType, // positionLevel: salary.posLevel, // refCommandNo: v.refCommandNo, // templateDoc: v.templateDoc, // refCommandCode: v.refCommandCode, // refCommandName: v.refCommandName, // }) // .then(async () => { // const before = null; // salary.status = "DONE"; // salary.lastUpdateUserId = request.user.sub; // salary.lastUpdateFullName = request.user.name; // salary.lastUpdatedAt = new Date(); // await this.salaryProfileEmployeeRepository.save(salary, { data: request }); // setLogDataDiff(request, { before, after: salary }); // }); // } // }), // ); // return new HttpSuccess(); // } /** * API ออกคำสั่ง 33 * * @summary ออกคำสั่ง 33 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Get("command/33/{id}") async SalaryReport33(@Path() id: string) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); const salaryRank = await this.salaryProfileRepository.find({ where: { salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), status: "PENDING", }, }); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: item.posLevel, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง 34 * * @summary ออกคำสั่ง 34 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Get("command/34/{id}") async SalaryReport34(@Path() id: string) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); const salaryRank = await this.salaryProfileRepository.find({ where: [ { salaryOrgId: In(salaryOrgs.map((x) => x.id)), amountSpecial: MoreThan(0), status: "PENDING", }, { salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: "NONE", status: "PENDING", }, ], }); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: item.posLevel, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง 35 * * @summary ออกคำสั่ง 35 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Get("command/35/{id}") async SalaryReport35(@Path() id: string) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); const salaryRank = await this.salaryProfileRepository.find({ where: { salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), status: "PENDING", isRetired: true, }, }); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: item.posLevel, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง 36 * * @summary ออกคำสั่ง 36 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Get("command/36/{id}") async SalaryReport36(@Path() id: string) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgEmployeeRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); const salaryRank = await this.salaryProfileEmployeeRepository.find({ where: { salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), status: "PENDING", }, }); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: `${item.posTypeShort}${item.posLevel}`, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง 37 * * @summary ออกคำสั่ง 37 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Get("command/37/{id}") async SalaryReport37(@Path() id: string) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgEmployeeRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); const salaryRank = await this.salaryProfileEmployeeRepository.find({ where: { salaryOrgId: In(salaryOrgs.map((x) => x.id)), amountSpecial: MoreThan(0), status: "PENDING", }, }); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: `${item.posTypeShort}${item.posLevel}`, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-33 * * @summary ออกคำสั่ง C-PM-33 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-33/{id}") async SalaryReport33Command( @Path() id: string, @Body() body: { type: string; rootId: string; }, ) { let conditionGroup = ""; if (body.type.trim().toUpperCase() == "GROUP1.1") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ชำนาญงาน') OR (salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ปฏิบัติงาน') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ปฏิบัติการ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ชำนาญการ')"; } else if (body.type.trim().toUpperCase() == "GROUP1.2") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'อาวุโส') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ชำนาญการพิเศษ') OR (salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'ต้น')"; } else if (body.type.trim().toUpperCase() == "GROUP2") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ทักษะพิเศษ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'เชี่ยวชาญ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ทรงคุณวุฒิ') OR (salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'สูง') OR (salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'ต้น') OR (salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'สูง')"; } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); } const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); let salaryRank = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") .andWhere("salaryProfile.rootId LIKE :rootId", { rootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, }) .andWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), // status: "PENDING", }) .andWhere( new Brackets((qb) => { qb.andWhere(conditionGroup); }), ) .andWhere("salaryProfile.status33 = :status", { status: "PENDING" }) .select([ "salaryProfile.id", "salaryProfile.orgShortName", "salaryProfile.posMasterNo", "salaryProfile.position", "salaryProfile.posType", "salaryProfile.posLevel", "salaryProfile.profileId", "salaryProfile.prefix", "salaryProfile.firstName", "salaryProfile.lastName", "salaryProfile.citizenId", "salaryProfile.amount", "salaryProfile.amountSpecial", "salaryProfile.amountUse", "salaryProfile.positionSalaryAmount", ]) .orderBy("salaryProfile.rootOrder", "ASC") .addOrderBy("salaryProfile.child1Order", "ASC") .addOrderBy("salaryProfile.child2Order", "ASC") .addOrderBy("salaryProfile.child3Order", "ASC") .addOrderBy("salaryProfile.child4Order", "ASC") .addOrderBy("salaryProfile.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: item.posLevel, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API รายชื่อออกคำสั่ง C-PM-34 * * @summary ออกคำสั่ง C-PM-34 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-34/{id}") async SalaryReport34Command( @Path() id: string, @Body() body: { type: string; rootId: string; }, ) { let conditionGroup = ""; if (body.type.trim().toUpperCase() == "GROUP1.1") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ชำนาญงาน') OR (salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ปฏิบัติงาน') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ปฏิบัติการ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ชำนาญการ')"; } else if (body.type.trim().toUpperCase() == "GROUP1.2") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'อาวุโส') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ชำนาญการพิเศษ') OR (salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'ต้น')"; } else if (body.type.trim().toUpperCase() == "GROUP2") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ทักษะพิเศษ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'เชี่ยวชาญ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ทรงคุณวุฒิ') OR (salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'สูง') OR (salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'ต้น') OR (salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'สูง')"; } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); } const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); let salaryRank = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") .andWhere("salaryProfile.rootId LIKE :rootId", { rootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, }) .andWhere( new Brackets((qb) => { qb.orWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), amountSpecial: MoreThan(0), type: Not("NONE"), // status: "PENDING", }); /*.orWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: "NONE", status: "PENDING", });*/ }), ) .andWhere( new Brackets((qb) => { qb.andWhere(conditionGroup); }), ) .andWhere("salaryProfile.status34 = :status", { status: "PENDING" }) .select([ "salaryProfile.id", "salaryProfile.orgShortName", "salaryProfile.posMasterNo", "salaryProfile.position", "salaryProfile.posType", "salaryProfile.posLevel", "salaryProfile.profileId", "salaryProfile.prefix", "salaryProfile.firstName", "salaryProfile.lastName", "salaryProfile.citizenId", "salaryProfile.amount", "salaryProfile.amountSpecial", "salaryProfile.amountUse", "salaryProfile.positionSalaryAmount", ]) .orderBy("salaryProfile.rootOrder", "ASC") .addOrderBy("salaryProfile.child1Order", "ASC") .addOrderBy("salaryProfile.child2Order", "ASC") .addOrderBy("salaryProfile.child3Order", "ASC") .addOrderBy("salaryProfile.child4Order", "ASC") .addOrderBy("salaryProfile.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: item.posLevel, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-35 * * @summary ออกคำสั่ง C-PM-35 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-35/{id}") async SalaryReport35Command( @Path() id: string, @Body() body: { type: string; rootId: string; }, ) { let conditionGroup = ""; if (body.type.trim().toUpperCase() == "GROUP1.1") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ชำนาญงาน') OR (salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ปฏิบัติงาน') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ปฏิบัติการ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ชำนาญการ')"; } else if (body.type.trim().toUpperCase() == "GROUP1.2") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'อาวุโส') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ชำนาญการพิเศษ') OR (salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'ต้น')"; } else if (body.type.trim().toUpperCase() == "GROUP2") { conditionGroup = "(salaryProfile.posType = 'ทั่วไป' AND salaryProfile.posLevel = 'ทักษะพิเศษ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'เชี่ยวชาญ') OR (salaryProfile.posType = 'วิชาการ' AND salaryProfile.posLevel = 'ทรงคุณวุฒิ') OR (salaryProfile.posType = 'อำนวยการ' AND salaryProfile.posLevel = 'สูง') OR (salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'ต้น') OR (salaryProfile.posType = 'บริหาร' AND salaryProfile.posLevel = 'สูง')"; } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); } const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); let salaryRank = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") .andWhere("salaryProfile.rootId LIKE :rootId", { rootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, }) .andWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), // status: "PENDING", isRetired: true, }) .andWhere( new Brackets((qb) => { qb.andWhere(conditionGroup); }), ) .andWhere("salaryProfile.status35 = :status", { status: "PENDING" }) .andWhere("salaryProfile.isRetired = :isRetired", { isRetired: true}) .select([ "salaryProfile.id", "salaryProfile.orgShortName", "salaryProfile.posMasterNo", "salaryProfile.position", "salaryProfile.posType", "salaryProfile.posLevel", "salaryProfile.profileId", "salaryProfile.prefix", "salaryProfile.firstName", "salaryProfile.lastName", "salaryProfile.citizenId", "salaryProfile.amount", "salaryProfile.amountSpecial", "salaryProfile.amountUse", "salaryProfile.positionSalaryAmount", ]) .orderBy("salaryProfile.rootOrder", "ASC") .addOrderBy("salaryProfile.child1Order", "ASC") .addOrderBy("salaryProfile.child2Order", "ASC") .addOrderBy("salaryProfile.child3Order", "ASC") .addOrderBy("salaryProfile.child4Order", "ASC") .addOrderBy("salaryProfile.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: item.posLevel, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-36 * * @summary ออกคำสั่ง C-PM-36 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-36/{id}") async SalaryReport36Command( @Path() id: string, @Body() body: { type: string; rootId: string; // isRetired?: boolean; }, ) { // let conditionGroup = ""; // if (body.type.trim().toUpperCase() == "GROUP1.1") { // conditionGroup = // "(salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'ชำนาญงาน') OR (salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'ปฏิบัติงาน') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ปฏิบัติการ') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ชำนาญการ')"; // } else if (body.type.trim().toUpperCase() == "GROUP1.2") { // conditionGroup = // "(salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'อาวุโส') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ชำนาญการพิเศษ') OR (salaryProfileEmployee.posType = 'อำนวยการ' AND salaryProfileEmployee.posLevel = 'ต้น')"; // } else if (body.type.trim().toUpperCase() == "GROUP2") { // conditionGroup = // "(salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'ทักษะพิเศษ') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'เชี่ยวชาญ') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ทรงคุณวุฒิ') OR (salaryProfileEmployee.posType = 'อำนวยการ' AND salaryProfileEmployee.posLevel = 'สูง') OR (salaryProfileEmployee.posType = 'บริหาร' AND salaryProfileEmployee.posLevel = 'ต้น') OR (salaryProfileEmployee.posType = 'บริหาร' AND salaryProfileEmployee.posLevel = 'สูง')"; // } else { // throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); // } const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgEmployeeRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); // let condition = "1=1"; // let parameters = {}; // if(body.isRetired === true){ // condition = "salaryProfileEmployee.isRetired = :isRetired" // parameters = { isRetired: true } // } let salaryRank = await AppDataSource.getRepository(SalaryProfileEmployee) .createQueryBuilder("salaryProfileEmployee") // .andWhere("salaryProfileEmployee.rootId LIKE :rootId", { // rootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, // }) .andWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), // status: "PENDING", }) // .andWhere( // new Brackets((qb) => { // qb.andWhere(conditionGroup); // }), // ) .andWhere("salaryProfileEmployee.status36 = :status", { status: "PENDING" }) .andWhere("salaryProfileEmployee.rootId = :rootId", { rootId: body.rootId }) // .andWhere(condition, parameters) .select([ "salaryProfileEmployee.id", "salaryProfileEmployee.orgShortName", "salaryProfileEmployee.posMasterNo", "salaryProfileEmployee.position", "salaryProfileEmployee.posType", "salaryProfileEmployee.posTypeShort", "salaryProfileEmployee.posLevel", "salaryProfileEmployee.profileId", "salaryProfileEmployee.prefix", "salaryProfileEmployee.firstName", "salaryProfileEmployee.lastName", "salaryProfileEmployee.citizenId", "salaryProfileEmployee.amount", "salaryProfileEmployee.amountSpecial", "salaryProfileEmployee.amountUse", "salaryProfileEmployee.positionSalaryAmount", ]) .orderBy("salaryProfileEmployee.rootOrder", "ASC") .addOrderBy("salaryProfileEmployee.child1Order", "ASC") .addOrderBy("salaryProfileEmployee.child2Order", "ASC") .addOrderBy("salaryProfileEmployee.child3Order", "ASC") .addOrderBy("salaryProfileEmployee.child4Order", "ASC") .addOrderBy("salaryProfileEmployee.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: `${item.posTypeShort ?? ""} ${item.posLevel ?? ""}`, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-37 * * @summary ออกคำสั่ง C-PM-37 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-37/{id}") async SalaryReport37Command( @Path() id: string, @Body() body: { type: string; rootId: string; // isRetired?: boolean; }, ) { // let conditionGroup = ""; // if (body.type.trim().toUpperCase() == "GROUP1.1") { // conditionGroup = // "(salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'ชำนาญงาน') OR (salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'ปฏิบัติงาน') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ปฏิบัติการ') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ชำนาญการ')"; // } else if (body.type.trim().toUpperCase() == "GROUP1.2") { // conditionGroup = // "(salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'อาวุโส') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ชำนาญการพิเศษ') OR (salaryProfileEmployee.posType = 'อำนวยการ' AND salaryProfileEmployee.posLevel = 'ต้น')"; // } else if (body.type.trim().toUpperCase() == "GROUP2") { // conditionGroup = // "(salaryProfileEmployee.posType = 'ทั่วไป' AND salaryProfileEmployee.posLevel = 'ทักษะพิเศษ') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'เชี่ยวชาญ') OR (salaryProfileEmployee.posType = 'วิชาการ' AND salaryProfileEmployee.posLevel = 'ทรงคุณวุฒิ') OR (salaryProfileEmployee.posType = 'อำนวยการ' AND salaryProfileEmployee.posLevel = 'สูง') OR (salaryProfileEmployee.posType = 'บริหาร' AND salaryProfileEmployee.posLevel = 'ต้น') OR (salaryProfileEmployee.posType = 'บริหาร' AND salaryProfileEmployee.posLevel = 'สูง')"; // } else { // throw new HttpError(HttpStatusCode.NOT_FOUND, "กลุ่มเป้าหมายไม่ถูกต้อง"); // } const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgEmployeeRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); // let condition = "1=1"; // let parameters = {}; // if(body.isRetired === true){ // condition = "salaryProfileEmployee.isRetired = :isRetired" // parameters = { isRetired: true } // } let salaryRank = await AppDataSource.getRepository(SalaryProfileEmployee) .createQueryBuilder("salaryProfileEmployee") // .andWhere("salaryProfileEmployee.rootId LIKE :rootId", { // rootId: body.type.trim().toUpperCase() == "GROUP1.1" ? body.rootId : `%%`, // }) .andWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), amountSpecial: MoreThan(0), // status: "PENDING", }) // .andWhere( // new Brackets((qb) => { // qb.andWhere(conditionGroup); // }), // ) .andWhere("salaryProfileEmployee.status37 = :status", { status: "PENDING" }) .andWhere("salaryProfileEmployee.rootId = :rootId", { rootId: body.rootId }) // .andWhere(condition, parameters) .select([ "salaryProfileEmployee.id", "salaryProfileEmployee.orgShortName", "salaryProfileEmployee.posMasterNo", "salaryProfileEmployee.position", "salaryProfileEmployee.posType", "salaryProfileEmployee.posTypeShort", "salaryProfileEmployee.posLevel", "salaryProfileEmployee.profileId", "salaryProfileEmployee.prefix", "salaryProfileEmployee.firstName", "salaryProfileEmployee.lastName", "salaryProfileEmployee.citizenId", "salaryProfileEmployee.amount", "salaryProfileEmployee.amountSpecial", "salaryProfileEmployee.amountUse", "salaryProfileEmployee.positionSalaryAmount", ]) .orderBy("salaryProfileEmployee.rootOrder", "ASC") .addOrderBy("salaryProfileEmployee.child1Order", "ASC") .addOrderBy("salaryProfileEmployee.child2Order", "ASC") .addOrderBy("salaryProfileEmployee.child3Order", "ASC") .addOrderBy("salaryProfileEmployee.child4Order", "ASC") .addOrderBy("salaryProfileEmployee.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: `${item.posTypeShort ?? ""} ${item.posLevel ?? ""}`, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-45 * * @summary ออกคำสั่ง C-PM-45 เลื่อนเงินเดือนลูกจ้างเกษียณ * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-45/{id}") async SalaryReport45Command( @Path() id: string, @Body() body: { type: string; rootId: string; }, ) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgEmployeeRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); let salaryRank = await AppDataSource.getRepository(SalaryProfileEmployee) .createQueryBuilder("salaryProfileEmployee") .andWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), type: In(["FULLHAFT", "FULL", "HAFT"]), }) .andWhere("salaryProfileEmployee.status36 = :status", { status: "PENDING" }) .andWhere("salaryProfileEmployee.rootId = :rootId", { rootId: body.rootId }) .andWhere("salaryProfileEmployee.isRetired = :isRetired",{ isRetired: true }) .select([ "salaryProfileEmployee.id", "salaryProfileEmployee.orgShortName", "salaryProfileEmployee.posMasterNo", "salaryProfileEmployee.position", "salaryProfileEmployee.posType", "salaryProfileEmployee.posTypeShort", "salaryProfileEmployee.posLevel", "salaryProfileEmployee.profileId", "salaryProfileEmployee.prefix", "salaryProfileEmployee.firstName", "salaryProfileEmployee.lastName", "salaryProfileEmployee.citizenId", "salaryProfileEmployee.amount", "salaryProfileEmployee.amountSpecial", "salaryProfileEmployee.amountUse", "salaryProfileEmployee.positionSalaryAmount", ]) .orderBy("salaryProfileEmployee.rootOrder", "ASC") .addOrderBy("salaryProfileEmployee.child1Order", "ASC") .addOrderBy("salaryProfileEmployee.child2Order", "ASC") .addOrderBy("salaryProfileEmployee.child3Order", "ASC") .addOrderBy("salaryProfileEmployee.child4Order", "ASC") .addOrderBy("salaryProfileEmployee.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: `${item.posTypeShort ?? ""} ${item.posLevel ?? ""}`, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-46 * * @summary ออกคำสั่ง C-PM-46 เงินพิเศษลูกจ้างเกษียณ * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command/C-PM-46/{id}") async SalaryReport46Command( @Path() id: string, @Body() body: { type: string; rootId: string; }, ) { const salary = await this.salaryPeriodRepository.findOne({ where: { id: id }, }); if (!salary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } const salaryOrgs = await this.salaryOrgEmployeeRepository.find({ where: { salaryPeriodId: salary.id, snapshot: "SNAP2" }, }); let salaryRank = await AppDataSource.getRepository(SalaryProfileEmployee) .createQueryBuilder("salaryProfileEmployee") .andWhere({ salaryOrgId: In(salaryOrgs.map((x) => x.id)), amountSpecial: MoreThan(0), }) .andWhere("salaryProfileEmployee.status37 = :status", { status: "PENDING" }) .andWhere("salaryProfileEmployee.rootId = :rootId", { rootId: body.rootId }) .andWhere("salaryProfileEmployee.isRetired = :isRetired",{ isRetired: true }) .select([ "salaryProfileEmployee.id", "salaryProfileEmployee.orgShortName", "salaryProfileEmployee.posMasterNo", "salaryProfileEmployee.position", "salaryProfileEmployee.posType", "salaryProfileEmployee.posTypeShort", "salaryProfileEmployee.posLevel", "salaryProfileEmployee.profileId", "salaryProfileEmployee.prefix", "salaryProfileEmployee.firstName", "salaryProfileEmployee.lastName", "salaryProfileEmployee.citizenId", "salaryProfileEmployee.amount", "salaryProfileEmployee.amountSpecial", "salaryProfileEmployee.amountUse", "salaryProfileEmployee.positionSalaryAmount", ]) .orderBy("salaryProfileEmployee.rootOrder", "ASC") .addOrderBy("salaryProfileEmployee.child1Order", "ASC") .addOrderBy("salaryProfileEmployee.child2Order", "ASC") .addOrderBy("salaryProfileEmployee.child3Order", "ASC") .addOrderBy("salaryProfileEmployee.child4Order", "ASC") .addOrderBy("salaryProfileEmployee.posMasterNo", "ASC") .getMany(); const _salaryRank = salaryRank.map((item) => ({ id: item.id, posMasterNo: `${item.orgShortName} ${item.posMasterNo}`, positionName: item.position, posType: item.posType, posLevel: `${item.posTypeShort ?? ""} ${item.posLevel ?? ""}`, profileId: item.profileId, prefix: item.prefix, firstName: item.firstName, lastName: item.lastName, citizenId: item.citizenId, amount: item.amount, amountSpecial: item.amountSpecial, amountUse: item.amountUse, positionSalaryAmount: item.positionSalaryAmount, })); return new HttpSuccess(_salaryRank); } /** * API ออกคำสั่ง C-PM-33 * * @summary ออกคำสั่ง C-PM-33 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command33/officer/report") async SalaryOfficerReportCommand33( @Body() body: { refIds: string[]; status: string; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status33: body.status.trim().toUpperCase(), })); await this.salaryProfileRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-34 * * @summary ออกคำสั่ง C-PM-34 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command34/officer/report") async SalaryOfficerReportCommand34( @Body() body: { refIds: string[]; status: string; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status34: body.status.trim().toUpperCase(), })); await this.salaryProfileRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-35 * * @summary ออกคำสั่ง C-PM-35 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command35/officer/report") async SalaryOfficerReportCommand35( @Body() body: { refIds: string[]; status: string; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status35: body.status.trim().toUpperCase(), })); await this.salaryProfileRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-36 * * @summary ออกคำสั่ง C-PM-36 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command36/employee/report") async SalaryEmployeeReportCommand36( @Body() body: { refIds: string[]; status: string; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileEmployeeRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status36: body.status.trim().toUpperCase(), })); await this.salaryProfileEmployeeRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-37 * * @summary ออกคำสั่ง C-PM-37 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command37/employee/report") async SalaryEmployeeReportCommand37( @Body() body: { refIds: string[]; status: string; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileEmployeeRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status37: body.status.trim().toUpperCase(), })); await this.salaryProfileEmployeeRepository.save(data); return new HttpSuccess(); } /** * เอกสารแนบท้าย ขรก. C-PM-33 * * @summary เอกสารแนบท้าย ขรก. C-PM-33 * */ @Post("command33/officer/report/attachment") async SalaryReportAttachment33( @Body() body: { refIds: { refId?: string; Sequence?: any | null; CitizenId?: any | null; Prefix?: any | null; FirstName?: any | null; LastName?: any | null; Amount?: any | null; PositionSalaryAmount?: any | null; MouthSalaryAmount?: any | null; RemarkHorizontal?: any | null; RemarkVertical?: any | null; CommandYear?: any | null; }[]; }, @Request() request: RequestWithUser, ) { let data = new Array(); await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { const _data = { no: Extension.ToThaiNumber((data.length + 1).toString()), fullName: `${v.Prefix}${v.FirstName} ${v.LastName}`, oc: salary.rootId == null ? salary.position == null ? "-" : salary.position : salary.child4 != null ? salary.position == null ? salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child3 != null ? salary.position == null ? salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child2 != null ? salary.position == null ? salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child1 != null ? salary.position == null ? salary.child1 + "/" + salary.root : salary.position + "/" + salary.child1 + "/" + salary.root : salary.root != null ? salary.position == null ? salary.root : salary.position + "/" + salary.root : "-", positionType: salary.posType ? salary.posType : "-", positionLevel: salary.posLevel ? Extension.ToThaiNumber(salary.posLevel.toString()) : "-", positionNumber: salary.orgShortName != null && salary.posMasterNo != null ? Extension.ToThaiNumber(salary.orgShortName + " " + salary.posMasterNo) : "-", amount: salary.amount ? Extension.ToThaiNumber(salary.amount.toLocaleString()) : "-", positionSalaryAmount: salary.positionSalaryAmount ? Extension.ToThaiNumber(salary.positionSalaryAmount.toLocaleString()) : "-", amountSpecial: salary.amountSpecial ? Extension.ToThaiNumber(salary.amountSpecial.toLocaleString()) : "-", remark: salary.remark ? salary.remark : "-", remarkVertical: v.RemarkVertical, remarkHorizontal: v.RemarkHorizontal, }; data.push(_data); } }), ); return new HttpSuccess(data); } /** * เอกสารแนบท้าย ขรก. C-PM-34 * * @summary เอกสารแนบท้าย ขรก. C-PM34 * */ @Post("command34/officer/report/attachment") async SalaryReportAttachment34( @Body() body: { refIds: { refId?: string; Sequence?: any | null; CitizenId?: any | null; Prefix?: any | null; FirstName?: any | null; LastName?: any | null; Amount?: any | null; PositionSalaryAmount?: any | null; MouthSalaryAmount?: any | null; RemarkHorizontal?: any | null; RemarkVertical?: any | null; CommandYear?: any | null; }[]; }, @Request() request: RequestWithUser, ) { let data = new Array(); await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { const _data = { no: Extension.ToThaiNumber((data.length + 1).toString()), fullName: `${v.Prefix}${v.FirstName} ${v.LastName}`, oc: salary.rootId == null ? salary.position == null ? "-" : salary.position : salary.child4 != null ? salary.position == null ? salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child3 != null ? salary.position == null ? salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child2 != null ? salary.position == null ? salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child1 != null ? salary.position == null ? salary.child1 + "/" + salary.root : salary.position + "/" + salary.child1 + "/" + salary.root : salary.root != null ? salary.position == null ? salary.root : salary.position + "/" + salary.root : "-", positionType: salary.posType ? salary.posType : "-", positionLevel: salary.posLevel ? Extension.ToThaiNumber(salary.posLevel.toString()) : "-", positionNumber: salary.orgShortName != null && salary.posMasterNo != null ? Extension.ToThaiNumber(salary.orgShortName + " " + salary.posMasterNo) : "-", amount: salary.amount ? Extension.ToThaiNumber(salary.amount.toLocaleString()) : "-", positionSalaryAmount: salary.positionSalaryAmount ? Extension.ToThaiNumber(salary.positionSalaryAmount.toLocaleString()) : "-", amountSpecial: salary.amountSpecial ? Extension.ToThaiNumber(salary.amountSpecial.toLocaleString()) : "-", remark: salary.remark ? salary.remark : "-", remarkVertical: v.RemarkVertical, remarkHorizontal: v.RemarkHorizontal, }; data.push(_data); } }), ); return new HttpSuccess(data); } /** * เอกสารแนบท้าย ขรก. C-PM-35 * * @summary เอกสารแนบท้าย ขรก. C-PM-35 * */ @Post("command35/officer/report/attachment") async SalaryReportAttachment35( @Body() body: { refIds: { refId?: string; Sequence?: any | null; CitizenId?: any | null; Prefix?: any | null; FirstName?: any | null; LastName?: any | null; Amount?: any | null; PositionSalaryAmount?: any | null; MouthSalaryAmount?: any | null; RemarkHorizontal?: any | null; RemarkVertical?: any | null; CommandYear?: any | null; }[]; }, @Request() request: RequestWithUser, ) { let data = new Array(); await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { const _data = { no: Extension.ToThaiNumber((data.length + 1).toString()), fullName: `${v.Prefix}${v.FirstName} ${v.LastName}`, oc: salary.rootId == null ? salary.position == null ? "-" : salary.position : salary.child4 != null ? salary.position == null ? salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child3 != null ? salary.position == null ? salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child2 != null ? salary.position == null ? salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child1 != null ? salary.position == null ? salary.child1 + "/" + salary.root : salary.position + "/" + salary.child1 + "/" + salary.root : salary.root != null ? salary.position == null ? salary.root : salary.position + "/" + salary.root : "-", positionType: salary.posType ? salary.posType : "-", positionLevel: salary.posLevel ? Extension.ToThaiNumber(salary.posLevel.toString()) : "-", positionNumber: salary.orgShortName != null && salary.posMasterNo != null ? Extension.ToThaiNumber(salary.orgShortName + " " + salary.posMasterNo) : "-", amount: salary.amount ? Extension.ToThaiNumber(salary.amount.toLocaleString()) : "-", positionSalaryAmount: salary.positionSalaryAmount ? Extension.ToThaiNumber(salary.positionSalaryAmount.toLocaleString()) : "-", amountSpecial: salary.amountSpecial ? Extension.ToThaiNumber(salary.amountSpecial.toLocaleString()) : "-", remark: salary.remark ? salary.remark : "-", remarkVertical: v.RemarkVertical, remarkHorizontal: v.RemarkHorizontal, }; data.push(_data); } }), ); return new HttpSuccess(data); } /** * เอกสารแนบท้าย ลูกจ้าง C-PM-36 * * @summary เอกสารแนบท้าย ลูกจ้าง C-PM-36 * */ @Post("command36/employee/report/attachment") async SalaryEmployeeReportAttachment36( @Body() body: { refIds: { refId?: string; Sequence?: any | null; CitizenId?: any | null; Prefix?: any | null; FirstName?: any | null; LastName?: any | null; Amount?: any | null; PositionSalaryAmount?: any | null; MouthSalaryAmount?: any | null; RemarkHorizontal?: any | null; RemarkVertical?: any | null; CommandYear?: any | null; }[]; }, @Request() request: RequestWithUser, ) { let data = new Array(); await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileEmployeeRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { const _data = { no: Extension.ToThaiNumber((data.length + 1).toString()), fullName: `${v.Prefix}${v.FirstName} ${v.LastName}`, oc: salary.rootId == null ? salary.position == null ? "-" : salary.position : salary.child4 != null ? salary.position == null ? salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child3 != null ? salary.position == null ? salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child2 != null ? salary.position == null ? salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child1 != null ? salary.position == null ? salary.child1 + "/" + salary.root : salary.position + "/" + salary.child1 + "/" + salary.root : salary.root != null ? salary.position == null ? salary.root : salary.position + "/" + salary.root : "-", positionType: salary.posType ? salary.posType : "-", positionLevel: salary.posLevel ? Extension.ToThaiNumber(salary.posLevel.toString()) : "-", positionNumber: salary.orgShortName != null && salary.posMasterNo != null ? Extension.ToThaiNumber(salary.orgShortName + " " + salary.posMasterNo) : "-", amount: salary.amount ? Extension.ToThaiNumber(salary.amount.toLocaleString()) : "-", positionSalaryAmount: salary.positionSalaryAmount ? Extension.ToThaiNumber(salary.positionSalaryAmount.toLocaleString()) : "-", amountSpecial: salary.amountSpecial ? Extension.ToThaiNumber(salary.amountSpecial.toLocaleString()) : "-", remark: salary.remark ? salary.remark : "-", remarkVertical: v.RemarkVertical, remarkHorizontal: v.RemarkHorizontal, }; data.push(_data); } }), ); return new HttpSuccess(data); } /** * เอกสารแนบท้าย ลูกจ้าง C-PM-37 * * @summary เอกสารแนบท้าย ลูกจ้าง C-PM-37 * */ @Post("command37/employee/report/attachment") async SalaryEmployeeReportAttachment37( @Body() body: { refIds: { refId?: string; Sequence?: any | null; CitizenId?: any | null; Prefix?: any | null; FirstName?: any | null; LastName?: any | null; Amount?: any | null; PositionSalaryAmount?: any | null; MouthSalaryAmount?: any | null; RemarkHorizontal?: any | null; RemarkVertical?: any | null; CommandYear?: any | null; }[]; }, @Request() request: RequestWithUser, ) { let data = new Array(); await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileEmployeeRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { const _data = { no: Extension.ToThaiNumber((data.length + 1).toString()), fullName: `${v.Prefix}${v.FirstName} ${v.LastName}`, oc: salary.rootId == null ? salary.position == null ? "-" : salary.position : salary.child4 != null ? salary.position == null ? salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child4 + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child3 != null ? salary.position == null ? salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child3 + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child2 != null ? salary.position == null ? salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.position + "/" + salary.child2 + "/" + salary.child1 + "/" + salary.root : salary.child1 != null ? salary.position == null ? salary.child1 + "/" + salary.root : salary.position + "/" + salary.child1 + "/" + salary.root : salary.root != null ? salary.position == null ? salary.root : salary.position + "/" + salary.root : "-", positionType: salary.posType ? salary.posType : "-", positionLevel: salary.posLevel ? Extension.ToThaiNumber(salary.posLevel.toString()) : "-", positionNumber: salary.orgShortName != null && salary.posMasterNo != null ? Extension.ToThaiNumber(salary.orgShortName + " " + salary.posMasterNo) : "-", amount: salary.amount ? Extension.ToThaiNumber(salary.amount.toLocaleString()) : "-", positionSalaryAmount: salary.positionSalaryAmount ? Extension.ToThaiNumber(salary.positionSalaryAmount.toLocaleString()) : "-", amountSpecial: salary.amountSpecial ? Extension.ToThaiNumber(salary.amountSpecial.toLocaleString()) : "-", remark: salary.remark ? salary.remark : "-", remarkVertical: v.RemarkVertical, remarkHorizontal: v.RemarkHorizontal, }; data.push(_data); } }), ); return new HttpSuccess(data); } /** * API ออกคำสั่ง C-PM-33 * * @summary ออกคำสั่ง C-PM-33 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command33/officer/report/excecute") async SalaryReportExcecute33( @Body() body: { refIds: { refId: string; // commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) commandNo: string | null; commandYear: number | null; commandId: string | null; remark: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; commandCode?: string | null; commandName?: string | null; commandDateSign: Date | null; }[]; }, @Request() request: RequestWithUser, ) { await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { await new CallAPI() .PostData(request, "/org/profile/salary/update", { profileId: salary.profileId, commandDateAffect: v.commandDateAffect, commandDateSign: v.commandDateSign, amount: v.amount, amountSpecial: v.amountSpecial, positionSalaryAmount: v.positionSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount, posNo: salary.posMasterNo.toString(), posNoAbb: salary.orgShortName, positionName: salary.position, positionExecutive: salary.posExecutive, positionExecutiveField: salary.positionExecutiveField, positionArea: salary.positionArea, positionType: salary.posType, positionLevel: salary.posLevel, commandId: v.commandId, remark: v.remark, orgRoot: salary.root, orgChild1: salary.child1, orgChild2: salary.child2, orgChild3: salary.child3, orgChild4: salary.child4, commandCode: v.commandCode, commandName: v.commandName, commandNo: v.commandNo, commandYear: v.commandYear, }) .then(async () => { const before = null; salary.status33 = "DONE"; salary.lastUpdateUserId = request.user.sub; salary.lastUpdateFullName = request.user.name; salary.lastUpdatedAt = new Date(); await this.salaryProfileRepository.save(salary, { data: request }); setLogDataDiff(request, { before, after: salary }); }); } }), ); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-34 * * @summary ออกคำสั่ง C-PM-34 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command34/officer/report/excecute") async SalaryReportExcecute34( @Body() body: { refIds: { refId: string; // commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) commandNo: string | null; commandYear: number | null; commandId: string | null; remark: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; commandCode?: string | null; commandName?: string | null; commandDateSign: Date | null; }[]; }, @Request() request: RequestWithUser, ) { await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { await new CallAPI() .PostData(request, "/org/profile/salary/update", { profileId: salary.profileId, commandDateAffect: v.commandDateAffect, commandDateSign: v.commandDateSign, amount: v.amount, amountSpecial: v.amountSpecial, positionSalaryAmount: v.positionSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount, posNo: salary.posMasterNo.toString(), posNoAbb: salary.orgShortName, positionName: salary.position, positionExecutive: salary.posExecutive, positionExecutiveField: salary.positionExecutiveField, positionArea: salary.positionArea, positionType: salary.posType, positionLevel: salary.posLevel, commandId: v.commandId, remark: v.remark, orgRoot: salary.root, orgChild1: salary.child1, orgChild2: salary.child2, orgChild3: salary.child3, orgChild4: salary.child4, commandCode: v.commandCode, commandName: v.commandName, commandNo: v.commandNo, commandYear: v.commandYear, }) .then(async () => { const before = null; salary.status34 = "DONE"; salary.lastUpdateUserId = request.user.sub; salary.lastUpdateFullName = request.user.name; salary.lastUpdatedAt = new Date(); await this.salaryProfileRepository.save(salary, { data: request }); setLogDataDiff(request, { before, after: salary }); }); } }), ); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-35 * * @summary ออกคำสั่ง C-PM-35 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command35/officer/report/excecute") async SalaryReportExcecute35( @Body() body: { refIds: { refId: string; // commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) commandNo: string | null; commandYear: number | null; commandId: string | null; remark: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; commandCode?: string | null; commandName?: string | null; commandDateSign: Date | null; }[]; }, @Request() request: RequestWithUser, ) { await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { await new CallAPI() .PostData(request, "/org/profile/salary/update", { profileId: salary.profileId, commandDateAffect: v.commandDateAffect, commandDateSign: v.commandDateSign, amount: v.amount, amountSpecial: v.amountSpecial, positionSalaryAmount: v.positionSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount, posNo: salary.posMasterNo.toString(), posNoAbb: salary.orgShortName, positionName: salary.position, positionExecutive: salary.posExecutive, positionExecutiveField: salary.positionExecutiveField, positionArea: salary.positionArea, positionType: salary.posType, positionLevel: salary.posLevel, commandId: v.commandId, remark: v.remark, orgRoot: salary.root, orgChild1: salary.child1, orgChild2: salary.child2, orgChild3: salary.child3, orgChild4: salary.child4, commandCode: v.commandCode, commandName: v.commandName, commandNo: v.commandNo, commandYear: v.commandYear, }) .then(async () => { const before = null; salary.status35 = "DONE"; salary.lastUpdateUserId = request.user.sub; salary.lastUpdateFullName = request.user.name; salary.lastUpdatedAt = new Date(); await this.salaryProfileRepository.save(salary, { data: request }); setLogDataDiff(request, { before, after: salary }); }); } }), ); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-36 * * @summary ออกคำสั่ง C-PM-36 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command36/employee/report/excecute") async SalaryEmployeeReportExcecute36( @Body() body: { refIds: { refId: string; // commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) commandDateSign?: Date | null; commandNo: string | null; commandYear: number | null; commandId: string | null; commandCode?: string | null; commandName?: string | null; templateDoc?: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; mpCee?: string | null; refCommandCode?: string | null; refCommandName?: string | null; remark?: string | null; }[]; }, @Request() request: RequestWithUser, ) { await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileEmployeeRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { await new CallAPI() .PostData(request, "/org/profile-employee/salary/update", { profileEmployeeId: salary.profileId, commandDateAffect: v.commandDateAffect, commandDateSign: v.commandDateSign, amount: v.amount, amountSpecial: v.amountSpecial, positionSalaryAmount: v.positionSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount, posNo: salary.posMasterNo != null ? salary.posMasterNo.toString() : null, posNoAbb: salary.orgShortName, positionName: salary.position, positionType: salary.posType, positionLevel: (salary.posTypeShort != null ? salary.posTypeShort + " " : "") + (salary.posLevel != null ? salary.posLevel.toString() : ""), remark: v.remark, orgRoot: salary.root, orgChild1: salary.child1, orgChild2: salary.child2, orgChild3: salary.child3, orgChild4: salary.child4, commandCode: v.commandCode, commandName: v.commandName, commandNo: v.commandNo, commandYear: v.commandYear, commandId: v.commandId, salaryLevel: salary.salaryLevel && salary.salaryLevelNew ? salary.salaryLevelNew : salary.salaryLevel, group: salary.groupNew ?? salary.group, }) .then(async () => { const before = null; salary.status36 = "DONE"; salary.lastUpdateUserId = request.user.sub; salary.lastUpdateFullName = request.user.name; salary.lastUpdatedAt = new Date(); await this.salaryProfileEmployeeRepository.save(salary, { data: request }); setLogDataDiff(request, { before, after: salary }); }); } }), ); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-37 * * @summary ออกคำสั่ง C-PM-37 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command37/employee/report/excecute") async SalaryEmployeeReportExcecute37( @Body() body: { refIds: { refId: string; // commandAffectDate: Date | null;//เก่า commandDateAffect: Date | null; //ใหม่ (ปรับตาม rabbitMQ ORG) commandDateSign?: Date | null; commandNo: string | null; commandYear: number | null; commandId: string | null; commandCode?: string | null; commandName?: string | null; templateDoc?: string | null; amount: Double | null; amountSpecial?: Double | null; positionSalaryAmount: Double | null; mouthSalaryAmount: Double | null; mpCee?: string | null; refCommandCode?: string | null; refCommandName?: string | null; remark?: string | null; }[]; }, @Request() request: RequestWithUser, ) { await Promise.all( body.refIds.map(async (v) => { const salary = await this.salaryProfileEmployeeRepository.findOne({ where: { id: v.refId, }, }); if (salary != null) { await new CallAPI() .PostData(request, "/org/profile-employee/salary/update", { profileEmployeeId: salary.profileId, commandDateAffect: v.commandDateAffect, commandDateSign: v.commandDateSign, amount: v.amount, amountSpecial: v.amountSpecial, positionSalaryAmount: v.positionSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount, posNo: salary.posMasterNo != null ? salary.posMasterNo.toString() : null, posNoAbb: salary.orgShortName, positionName: salary.position, positionType: salary.posType, positionLevel: (salary.posTypeShort != null ? salary.posTypeShort + " " : "") + (salary.posLevel != null ? salary.posLevel.toString() : ""), remark: v.remark, orgRoot: salary.root, orgChild1: salary.child1, orgChild2: salary.child2, orgChild3: salary.child3, orgChild4: salary.child4, commandCode: v.commandCode, commandName: v.commandName, commandNo: v.commandNo, commandYear: v.commandYear, commandId: v.commandId, salaryLevel: salary.salaryLevel && salary.salaryLevelNew ? salary.salaryLevelNew : salary.salaryLevel, group: salary.groupNew ?? salary.group, }) .then(async () => { const before = null; salary.status37 = "DONE"; salary.lastUpdateUserId = request.user.sub; salary.lastUpdateFullName = request.user.name; salary.lastUpdatedAt = new Date(); await this.salaryProfileEmployeeRepository.save(salary, { data: request }); setLogDataDiff(request, { before, after: salary }); }); } }), ); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-33 * * @summary ออกคำสั่ง C-PM-33 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command33/officer/report/delete") async SalaryOfficerReportCommandDelete33( @Body() body: { refIds: string[]; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status33: "PENDING", })); await this.salaryProfileRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-34 * * @summary ออกคำสั่ง C-PM-34 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command34/officer/report/delete") async SalaryOfficerReportCommandDelete34( @Body() body: { refIds: string[]; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status34: "PENDING", })); await this.salaryProfileRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-35 * * @summary ออกคำสั่ง C-PM-35 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command35/officer/report/delete") async SalaryOfficerReportCommandDelete35( @Body() body: { refIds: string[]; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status35: "PENDING", })); await this.salaryProfileRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-36 * * @summary ออกคำสั่ง C-PM-36 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command36/employee/report/delete") async SalaryEmployeeReportCommandDelete36( @Body() body: { refIds: string[]; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileEmployeeRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status36: "PENDING", })); await this.salaryProfileEmployeeRepository.save(data); return new HttpSuccess(); } /** * API ออกคำสั่ง C-PM-37 * * @summary ออกคำสั่ง C-PM-37 * * @param {string} id Guid, *Id ผังเงินเดือน */ @Post("command37/employee/report/delete") async SalaryEmployeeReportCommandDelete37( @Body() body: { refIds: string[]; }, @Request() request: RequestWithUser, ) { const salaryProfile = await this.salaryProfileEmployeeRepository.find({ where: { id: In(body.refIds) }, }); const data = salaryProfile.map((_data) => ({ ..._data, status37: "PENDING", })); await this.salaryProfileEmployeeRepository.save(data); return new HttpSuccess(); } }