From 6d1b908c8cd5e3cb8908b217a370d98f4f2781bb Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 24 Oct 2024 10:48:41 +0700 Subject: [PATCH] no message --- src/controllers/ReportController.ts | 441 +++++++++++++++++++++++++++- 1 file changed, 440 insertions(+), 1 deletion(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index ded0593..92d6806 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -15,7 +15,7 @@ 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 } from "typeorm"; +import { In, Not, IsNull, MoreThan, Double, Brackets } from "typeorm"; import { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; import { PosType } from "../entities/PosType"; @@ -6747,6 +6747,445 @@ export class ReportController extends Controller { return new HttpSuccess(_salaryRank); } + /** + * API ออกคำสั่ง 33 + * + * @summary ออกคำสั่ง 33 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/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.status = :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", + ]) + .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, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 34 + * + * @summary ออกคำสั่ง 34 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/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), + status: "PENDING", + }).orWhere({ + salaryOrgId: In(salaryOrgs.map((x) => x.id)), + type: "NONE", + status: "PENDING", + }); + }), + ) + .andWhere( + new Brackets((qb) => { + qb.andWhere(conditionGroup); + }), + ) + .andWhere("salaryProfile.status = :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", + ]) + .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, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 35 + * + * @summary ออกคำสั่ง 35 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/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.status = :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", + ]) + .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, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 36 + * + * @summary ออกคำสั่ง 36 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/36/{id}") + async SalaryReport36Command( + @Path() id: string, + @Body() + body: { + type: string; + rootId: string; + }, + ) { + // 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 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.status = :status", { status: "PENDING" }) + .select([ + "salaryProfileEmployee.id", + "salaryProfileEmployee.orgShortName", + "salaryProfileEmployee.posMasterNo", + "salaryProfileEmployee.position", + "salaryProfileEmployee.posType", + "salaryProfileEmployee.posLevel", + "salaryProfileEmployee.profileId", + "salaryProfileEmployee.prefix", + "salaryProfileEmployee.firstName", + "salaryProfileEmployee.lastName", + "salaryProfileEmployee.citizenId", + ]) + .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, + })); + + return new HttpSuccess(_salaryRank); + } + + /** + * API ออกคำสั่ง 37 + * + * @summary ออกคำสั่ง 37 + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Post("command/37/{id}") + async SalaryReport37Command( + @Path() id: string, + @Body() + body: { + type: string; + rootId: string; + }, + ) { + // 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 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.status = :status", { status: "PENDING" }) + .select([ + "salaryProfileEmployee.id", + "salaryProfileEmployee.orgShortName", + "salaryProfileEmployee.posMasterNo", + "salaryProfileEmployee.position", + "salaryProfileEmployee.posType", + "salaryProfileEmployee.posLevel", + "salaryProfileEmployee.profileId", + "salaryProfileEmployee.prefix", + "salaryProfileEmployee.firstName", + "salaryProfileEmployee.lastName", + "salaryProfileEmployee.citizenId", + ]) + .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, + })); + + return new HttpSuccess(_salaryRank); + } + /** * API ออกคำสั่ง *