diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 0dd3677..71b59cc 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -28,7 +28,9 @@ 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 Extension from "../interfaces/extension"; +import { SalaryEmployee } from "../entities/SalaryEmployee"; +import { SalaryRankEmployee } from "../entities/SalaryRankEmployee"; @Route("api/v1/salary/report") @Tags("Report") @Security("bearerAuth") @@ -39,7 +41,9 @@ import Extension from "../interfaces/extension"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class ReportController extends Controller { 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 salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); @@ -56,7 +60,7 @@ export class ReportController extends Controller { @Get("{id}") async SalaryReport(@Path() id: string) { const salarys = await this.salaryRepository.findOne({ - where: { id: id } + where: { id: id }, }); if (!salarys) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); @@ -84,46 +88,124 @@ export class ReportController extends Controller { order: { salary: "DESC", salaryHalf: "DESC", - } + }, }); const mapSalaryRank = salaryRank.map((item, index) => ({ // 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()+"*)"), + 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: salarys.name == "OFFICER" ? "ผังข้าราชการกรุงเทพมหานครสามัญ" : - salarys.name == "EMPLOYEE" ? "ผังลูกจ้างประจำกรุงเทพมหานคร" : "", + return new HttpSuccess({ + template: "SalaryRank", + reportName: "SalaryRank", + data: { + nameType: + salarys.name == "OFFICER" + ? "ผังข้าราชการกรุงเทพมหานครสามัญ" + : salarys.name == "EMPLOYEE" + ? "ผังลูกจ้างประจำกรุงเทพมหานคร" + : "", 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()), + 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 - } + 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, index) => ({ + 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 มีนาคม * @@ -131,9 +213,7 @@ export class ReportController extends Controller { * */ @Get("gov1-01/{rootId}/{salaryPeriodId}") - async SalaryReport1( - @Path() rootId: string, - @Path() salaryPeriodId: string) { + async SalaryReport1(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriodAPR = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { @@ -243,10 +323,7 @@ export class ReportController extends Controller { * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov1-03/{rootId}/{salaryPeriodId}") - async SalaryReport3( - @Path() rootId: string, - @Path() salaryPeriodId: string, - ) { + async SalaryReport3(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, @@ -328,10 +405,7 @@ export class ReportController extends Controller { * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov1-04/{rootId}/{salaryPeriodId}") - async SalaryReport4( - @Path() rootId: string, - @Path() salaryPeriodId: string, - ) { + async SalaryReport4(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, @@ -357,9 +431,9 @@ export class ReportController extends Controller { }); const salaryProfile = await this.salaryProfileRepository.find({ - where: { + where: { salaryOrgId: salaryOrg?.id, - type: Not("NONE") //ทุก Type ยกเว้นไม่ได้เลื่อน + type: Not("NONE"), //ทุก Type ยกเว้นไม่ได้เลื่อน }, select: [ "id", @@ -417,10 +491,7 @@ export class ReportController extends Controller { * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov1-05/{rootId}/{salaryPeriodId}") - async SalaryReport5( - @Path() rootId: string, - @Path() salaryPeriodId: string, - ){ + async SalaryReport5(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, @@ -446,9 +517,9 @@ export class ReportController extends Controller { }); const salaryProfile = await this.salaryProfileRepository.find({ - where: { + where: { salaryOrgId: salaryOrg?.id, - type: "NONE" //ไม่ได้เลื่อน + type: "NONE", //ไม่ได้เลื่อน }, select: [ "id", @@ -497,17 +568,17 @@ export class ReportController extends Controller { return mapData; } -// /* API แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก -// * -// * @summary แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก -// * -// * @param {string} rootId Guid, *Id Root -// * @param {string} salaryPeriodId Guid, *Id Period -// */ -// @Get("gov1-06/{rootId}/{salaryPeriodId}") -// async SalaryReport6(){ + // /* API แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก + // * + // * @summary แบบ 3 กท บัญชีแสดงวันลาครึ่งปี ขรก + // * + // * @param {string} rootId Guid, *Id Root + // * @param {string} salaryPeriodId Guid, *Id Period + // */ + // @Get("gov1-06/{rootId}/{salaryPeriodId}") + // async SalaryReport6(){ -// } + // } /** * API คำสั่งเลื่อนเงินเดือน รอบเมษายน @@ -518,10 +589,7 @@ export class ReportController extends Controller { * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov1-07/{rootId}/{salaryPeriodId}") - async SalaryReport7( - @Path() rootId: string, - @Path() salaryPeriodId: string, - ) { + async SalaryReport7(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, @@ -602,10 +670,7 @@ export class ReportController extends Controller { * @param {string} salaryPeriodId Guid, *Id Period */ @Get("gov1-08/{rootId}/{salaryPeriodId}") - async SalaryReport8( - @Path() rootId: string, - @Path() salaryPeriodId: string, - ) { + async SalaryReport8(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, @@ -716,5 +781,4 @@ export class ReportController extends Controller { }; return mapData; } - }