From 18c75fc3cc140597a68b07541b1a4aabb5258d78 Mon Sep 17 00:00:00 2001 From: Bright Date: Wed, 6 Mar 2024 17:03:24 +0700 Subject: [PATCH] no message --- src/controllers/Report_1_Controller.ts | 228 ++++++++++++++++++++++--- 1 file changed, 203 insertions(+), 25 deletions(-) diff --git a/src/controllers/Report_1_Controller.ts b/src/controllers/Report_1_Controller.ts index 348598a..d4ff762 100644 --- a/src/controllers/Report_1_Controller.ts +++ b/src/controllers/Report_1_Controller.ts @@ -20,7 +20,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, IsNull, Not } from "typeorm"; +import { In, IsNull, Not, MoreThan } from "typeorm"; import { SalaryProfile } from "../entities/SalaryProfile"; import { SalaryPeriod } from "../entities/SalaryPeriod"; import { SalaryOrg } from "../entities/SalaryOrg"; @@ -40,18 +40,33 @@ export class Report_1_Controller extends Controller { private salaryProfile = AppDataSource.getRepository(SalaryProfile); /** - * API รายงานแบบ 1 กท + * API รายงานแบบ 1 กท รอบเมษายน * - * @summary รายงานแบบ 1 กท + * @summary รายงานแบบ 1 กท รอบเมษายน * * @param {string} rootId Guid, *Id Root * @param {string} salaryPeriodId Guid, *Id Period */ - @Get("{rootId}/{salaryPeriodId}") + @Get("04/{rootId}/{salaryPeriodId}") async SalaryReport4( - @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37", - @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2", + // @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37", + // @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2", + @Path() rootId : string, + @Path() salaryPeriodId: string, ) { + + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + period: "APR", + isActive: true + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + const salaryOrg = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriodId, @@ -63,21 +78,14 @@ export class Report_1_Controller extends Controller { } // relations: ["salaryProfiles"], }); - if (!salaryOrg) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); - } - const salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { - id: String(salaryOrg.salaryPeriodId), - period: "APR", - isActive: true - }, - }); - + const salaryProfile = await this.salaryProfile.find({ - where: { salaryOrgId: salaryOrg.id}, - select: ["id", "prefix" , "firstName", "lastName", "root", - "position", "posType", "posLevel", "orgShortName", "posMasterNo", "amount", "amountSpecial"] + where: { salaryOrgId: salaryOrg?.id}, + select: [ + "id", "prefix" , "firstName", "lastName", "root", + "position", "posType", "posLevel", "orgShortName", + "posMasterNo", "amount", "amountSpecial" + ] }); const mapData = { @@ -86,16 +94,186 @@ export class Report_1_Controller extends Controller { profile: salaryProfile.map((item, index) => ({ no: index+1, fullname: item.prefix + item.firstName +" "+ item.lastName, - position: item.position + " / " + item.posType, + position: item.position + "/" + item.posType, posLevel: item.posLevel, orgShortName: item.orgShortName+item.posMasterNo, - amount: item.amount, - amountSpecial: item.amountSpecial, - root: item.root, + amount: item.amount == null ? 0 : item.amount, + amountSpecial: item.amountSpecial == null ? 0 : item.amountSpecial, score: null, //สรุปผลการประเมินฯ ระดับและคะแนน remark: null //หมายเหตุ })) } return mapData - } + } + + /** + * API รายงานคำสั่งเลื่อนเงินเดือน รอบเมษายน + * + * @summary รายงานคำสั่งเลื่อนเงินเดือน รอบเมษายน + * + * @param {string} rootId Guid, *Id Root + * @param {string} salaryPeriodId Guid, *Id Period + */ + @Get("07/{rootId}/{salaryPeriodId}") + async SalaryReport7( + // @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37", + // @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2", + @Path() rootId : string, + @Path() salaryPeriodId: string, + ) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + period: "APR", + isActive: true + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodId, + rootId: rootId, + snapshot: "SNAP2", + }, + order: { + group: "ASC" + }, + relations: ["salaryProfiles"], + }); + + const salaryProfile = await this.salaryProfile.find({ + where: { + salaryOrgId: salaryOrg?.id, + amountSpecial: IsNull() || 0, + amountUse: MoreThan(1), + }, + select: [ + "id", "prefix" , "firstName", "lastName", "root", + "position", "posType", "posLevel", "orgShortName", "posMasterNo", + "amount", "amountUse", "positionSalaryAmount" + ], + order: { + posMasterNo: "ASC" + } + }); + + const mapData = salaryProfile.map((item, index) => ({ + no: index+1, + fullname: item.prefix + item.firstName +" "+ item.lastName, + position: item.position, + posType: item.posType, + posLevel: item.posLevel, + posMasterNo: item.posMasterNo, + amount: item.amount, + positionSalaryAmount: item.positionSalaryAmount, + remark: null + })); + + return mapData; + } + + /** + * API รายงานคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน + * + * @summary รายงานคำสั่งคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน รอบเมษายน + * + * @param {string} rootId Guid, *Id Root + * @param {string} salaryPeriodId Guid, *Id Period + */ + @Get("08/{rootId}/{salaryPeriodId}") + async SalaryReport8( + // @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37", + // @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2", + @Path() rootId : string, + @Path() salaryPeriodId: string, + ) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + period: "APR", + isActive: true + }, + }); + + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } + + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodId, + rootId: rootId, + snapshot: "SNAP2", + }, + order: { + group: "ASC" + }, + relations: ["salaryProfiles"], + }); + + const salaryProfileSpecial = await this.salaryProfile.find({ + where: { + salaryOrgId: salaryOrg?.id, + amountSpecial: MoreThan(1), + }, + select: [ + "id", "prefix" , "firstName", "lastName", "root", + "position", "posType", "posLevel", "orgShortName", + "posMasterNo", "amount", "amountSpecial", + ], + order: { + posMasterNo: "ASC" + } + }); + + const salaryProfileNoAmount = await this.salaryProfile.find({ + where: { + salaryOrgId: salaryOrg?.id, + amountUse: IsNull() || 0, + positionSalaryAmount: IsNull() || 0, + }, + select: [ + "id", "prefix" , "firstName", "lastName", "root", + "position", "posType", "posLevel", "orgShortName", + "posMasterNo", "amount", + ], + order: { + posMasterNo: "ASC" + } + }); + + + const profileSpecial = salaryProfileSpecial.map((item, index) => ({ + no: index+1, + fullname: item.prefix + item.firstName +" "+ item.lastName, + position: item.position, + posType: item.posType, + posLevel: item.posLevel, + posMasterNo: item.posMasterNo, + amount: item.amount, + amountSpecial: item.amountSpecial, + remark: null + })); + + const profileNoAmount = salaryProfileNoAmount.map((item, index) => ({ + no: index+1, + fullname: item.prefix + item.firstName +" "+ item.lastName, + position: item.position, + posType: item.posType, + posLevel: item.posLevel, + posMasterNo: item.posMasterNo, + amount: item.amount, + remark: null + })); + + const mapData = { + profileSpecial, + profileNoAmount + } + return mapData; + } }