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 { Salarys } from "../entities/Salarys"; import { SalaryRanks } from "../entities/SalaryRanks"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import Extension from "../interfaces/extension"; import { SalaryPeriod } from "../entities/SalaryPeriod"; import { SalaryProfile } from "../entities/SalaryProfile"; @Route("api/v1/salary/report") @Tags("Report") @Security("bearerAuth") @Response( HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class Report2Controller extends Controller { private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile); private salaryRepository = AppDataSource.getRepository(Salarys); private salaryRankRepository = AppDataSource.getRepository(SalaryRanks); private poTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); /** * API รายชื่อข้าราชการผู้ที่ครองตำแหน่ง * * @summary รายชื่อข้าราชการผู้ที่ครองตำแหน่ง * */ @Post("report1") async report1(@Body() body: { rootId: string; salaryPeriodId: string;}) { const salaryPeriodAPR = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg:{ snapshot:"SNAP1", rootId:body.rootId, salaryPeriodId: body.salaryPeriodId, salaryPeriod:{ period:"APR" } }, }, }); if (!salaryPeriodAPR) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } const agency = salaryPeriodAPR[0]?.root; const formattedData = salaryPeriodAPR.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: index + 1, fullName: fullName?fullName:"", posLevel: profile?.posLevel?profile?.posLevel:"", posNumber: profile?.posMasterNo?profile?.posMasterNo:"", amount: profile?.amount?profile?.amount:"", reason: null, }; }); return new HttpSuccess({ agency: agency, data: formattedData }); } }