From 5af1ef281a958768c2f5d3b52c7fa2bc6bfc848c Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 5 Mar 2024 18:30:47 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=A3=E0=B8=B2=E0=B8=A2=E0=B8=87=E0=B8=B2?= =?UTF-8?q?=E0=B8=99=E0=B9=81=E0=B8=9A=E0=B8=9A=201=20=E0=B8=81=E0=B8=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/Report_1_Controller.ts | 100 +++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/controllers/Report_1_Controller.ts diff --git a/src/controllers/Report_1_Controller.ts b/src/controllers/Report_1_Controller.ts new file mode 100644 index 0000000..e831b58 --- /dev/null +++ b/src/controllers/Report_1_Controller.ts @@ -0,0 +1,100 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Body, + Path, + Request, + Example, + SuccessResponse, + Response, + Query, +} 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, IsNull, Not } from "typeorm"; +import { SalaryProfile } from "../entities/SalaryProfile"; +import { SalaryPeriod } from "../entities/SalaryPeriod"; +import { SalaryOrg } from "../entities/SalaryOrg"; +import Extension from "../interfaces/extension"; + +@Route("api/v1/salary/report/1") +@Tags("Report") +// @Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class Report_1_Controller extends Controller { + private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); + private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg); + private salaryProfile = AppDataSource.getRepository(SalaryProfile); + + /** + * API รายงานแบบ 1 กท + * + * @summary รายงานแบบ 1 กท + * + * @param {string} rootId Guid, *Id Root + * @param {string} salaryPeriodId Guid, *Id Period + */ + @Get("{rootId}/{salaryPeriodId}") + async SalaryReport4( + @Path() rootId : string = "c6164a42-539d-401a-b289-653282c08e37", + @Path() salaryPeriodId: string = "31cfc7de-b93b-4998-bbf1-25c21f141ac2", + ) { + const salaryOrg = await this.salaryOrgRepository.findOne({ + where: { + salaryPeriodId: salaryPeriodId, + rootId: rootId, + snapshot: "SNAP2", + }, + order: { + group: "ASC" + } + // 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"] + }); + + const mapData = { + effectiveDate : salaryPeriod?.effectiveDate, + profile: salaryProfile.map((item, index) => ({ + no: index+1, + fullname: item.prefix + item.firstName +" "+ item.lastName, + position: item.position + " / " + item.posType, + posLevel: item.posLevel, + orgShortName: item.orgShortName+item.posMasterNo, + amount: item.amount, + amountSpecial: item.amountSpecial, + root: item.root, + score: null, //สรุปผลการประเมินฯ ระดับและคะแนน + remark: null //หมายเหตุ + })) + } + return mapData + } +}