diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index a1744e9..14c35fb 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -31,6 +31,10 @@ import { SalaryProfile } from "../entities/SalaryProfile"; import Extension from "../interfaces/extension"; import { SalaryEmployee } from "../entities/SalaryEmployee"; import { SalaryRankEmployee } from "../entities/SalaryRankEmployee"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; +import { SalaryOrgEmployee } from "../entities/SalaryOrgEmployee"; +import { SalaryProfileEmployee } from "../entities/SalaryProfileEmployee"; @Route("api/v1/salary/report") @Tags("Report") @Security("bearerAuth") @@ -40,15 +44,19 @@ import { SalaryRankEmployee } from "../entities/SalaryRankEmployee"; ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class ReportController extends Controller { + private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); 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 poTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); - private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); + private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel); private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg); + private salaryOrgEmployeeRepository = AppDataSource.getRepository(SalaryOrgEmployee); private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile); + private salaryProfileEmployeeRepository = AppDataSource.getRepository(SalaryProfileEmployee); /** * API รายงานอัตราเงินเดือน @@ -1453,4 +1461,1454 @@ export class ReportController extends Controller { }; return mapData; } + + /** + * API 00-สรุปรายการเอกสารลูกจ้างที่ต้องส่ง สกจ รอบเมษายน + * + * @summary 00-สรุปรายการเอกสารลูกจ้างที่ต้องส่ง สกจ รอบเมษายน + * + */ + @Get("emp-00/{rootId}/{salaryPeriodId}") + async SalaryReportEmp0(@Path() rootId: string, @Path() salaryPeriodId: string) { + return new HttpSuccess({ + template: "emp1-00", + reportName: "emp1-00", + data: {}, + }); + } + + /** + * API 01-บัญชีคำนวณโควตา + * + * @summary 01-บัญชีคำนวณโควตา + * + */ + @Get("emp-01/{rootId}/{salaryPeriodId}") + async SalaryReportEmp1(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryOrgEmployeeRepository.findOne({ + relations: ["salaryPeriod", "salaryProfiles"], + where: { + snapshot: "SNAP2", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }); + + const agency = + _salaryPeriod == null || _salaryPeriod.salaryProfiles[0] == null + ? "" + : _salaryPeriod.salaryProfiles[0].root; + + if (salaryPeriod.period == "APR") { + return new HttpSuccess({ + template: "emp1-01", + reportName: "emp1-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + total: + _salaryPeriod == null ? "" : Extension.ToThaiNumber(_salaryPeriod.total.toString()), + fifteenPercent: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber(_salaryPeriod.fifteenPercent.toString()), + full: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), + ), + haft: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + notPromoted: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), + ), + reason: null, + }, + }); + } else { + const _salaryPeriodAPR1 = await this.salaryOrgEmployeeRepository.findOne({ + where: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriod: { + period: "APR", + year: salaryPeriod.year, + }, + }, + }); + const haftSalary = + _salaryPeriod == null + ? 0 + : _salaryPeriod.salaryProfiles + .filter((x) => x.type == "HAFT") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amountUse == null ? 0 : object.amountUse) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + + const fullSalary = + _salaryPeriod == null + ? 0 + : _salaryPeriod.salaryProfiles + .filter((x) => x.type == "FULL") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amountUse == null ? 0 : object.amountUse) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + const fullHaftSalary = + _salaryPeriod == null + ? 0 + : _salaryPeriod.salaryProfiles + .filter((x) => x.type == "FULLHAFT") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amountUse == null ? 0 : object.amountUse) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + return new HttpSuccess({ + template: "emp2-01", + reportName: "emp2-01", + data: { + date: Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), + ), + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())), + agency: agency, + totalSalary: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber(_salaryPeriod.currentAmount.toString()), + totalUser: + _salaryPeriod == null ? "" : Extension.ToThaiNumber(_salaryPeriod.total.toString()), + sixPercentAmount: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber(_salaryPeriod.sixPercentAmount.toString()), + spentAmount: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber(_salaryPeriod.spentAmount.toString()), + remainingAmount: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + (_salaryPeriod.sixPercentAmount - _salaryPeriod.spentAmount).toString(), + ), + fifteenPercentOld: Extension.ToThaiNumber( + (_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.fifteenPercent).toString(), + ), + totalOld: Extension.ToThaiNumber( + (_salaryPeriodAPR1 == null ? 0 : _salaryPeriodAPR1.total).toString(), + ), + haft: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + full: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), + ), + fullHaft: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles + .filter((x) => x.type == "FULLHAFT") + .length.toString(), + ), + notPromoted: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + _salaryPeriod.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), + ), + haftSalary: Extension.ToThaiNumber(haftSalary.toString()), + fullSalary: Extension.ToThaiNumber(fullSalary.toString()), + fullHaftSalary: Extension.ToThaiNumber(fullHaftSalary.toString()), + total: Extension.ToThaiNumber((haftSalary + fullSalary + fullHaftSalary).toString()), + summary: + _salaryPeriod == null + ? "" + : Extension.ToThaiNumber( + ( + _salaryPeriod.sixPercentAmount - + _salaryPeriod.spentAmount - + haftSalary - + fullSalary - + fullHaftSalary + ).toString(), + ), + reason: null, + }, + }); + } + } + /** + * API 02-รายชื่อลูกจ้างประจำผู้ครองตำแหน่ง ณ วันที่ 1 มีนาคม + * + * @summary 02-รายชื่อลูกจ้างประจำผู้ครองตำแหน่ง ณ วันที่ 1 มีนาคม + * + */ + @Get("emp-02/{rootId}/{salaryPeriodId}") + async SalaryReportEmp2(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + amount: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + position: profile.position, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "emp1-02" : "emp2-02", + reportName: salaryPeriod.period == "APR" ? "emp1-02" : "emp2-02", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 03-รายชื่อลูกจ้างประจำที่ได้รับการเสนอขอเลื่อนขั้นค่าจ้างหนึ่งขั้น + * + * @summary 03-รายชื่อลูกจ้างประจำที่ได้รับการเสนอขอเลื่อนขั้นค่าจ้างหนึ่งขั้น + * + */ + @Get("emp-03/{rootId}/{salaryPeriodId}") + async SalaryReportEmp3(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + amount: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + const fifteenPercent = + (_salaryPeriod[0].salaryOrg == null || _salaryPeriod[0].salaryOrg.fifteenPercent == null + ? "" + : _salaryPeriod[0].salaryOrg.fifteenPercent.toString()) + + "." + + (_salaryPeriod[0].salaryOrg == null || _salaryPeriod[0].salaryOrg.fifteenPoint == null + ? "๐๐" + : _salaryPeriod[0].salaryOrg.fifteenPoint.toString()); + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + position: profile.position, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "emp1-03" : "emp2-03", + reportName: salaryPeriod.period == "APR" ? "emp1-03" : "emp2-03", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + fifteenPercent: Extension.ToThaiNumber(fifteenPercent), + yearShort: Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year)).substr(-2), + ), + yearShortOld: Extension.ToThaiNumber( + String(Extension.ToThaiYear(salaryPeriod.year - 1)).substr(-2), + ), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 04-แบบ ลจ.กทม.1-รายชื่อลูกจ้างผู้สมควรได้เลื่อนขั้นค่าจ้าง + * + * @summary 04-แบบ ลจ.กทม.1-รายชื่อลูกจ้างผู้สมควรได้เลื่อนขั้นค่าจ้าง + * + */ + @Get("emp-04/{rootId}/{salaryPeriodId}") + async SalaryReportEmp4(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 05-แบบ ลจ.กทม.1-1-รายชื่อลูกจ้างผู้สมควรได้รับค่าตอบแทนพิเศษ + * + * @summary 05-แบบ ลจ.กทม.1-1-รายชื่อลูกจ้างผู้สมควรได้รับค่าตอบแทนพิเศษ + * + */ + @Get("emp-05/{rootId}/{salaryPeriodId}") + async SalaryReportEmp5(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 06-แบบ ลจ.กทม.2-รายชื่อลูกจ้างผู้ไม่สมควรเลื่อนขั้นค่าจ้าง + * + * @summary 06-แบบ ลจ.กทม.2-รายชื่อลูกจ้างผู้ไม่สมควรเลื่อนขั้นค่าจ้าง + * + */ + @Get("emp-06/{rootId}/{salaryPeriodId}") + async SalaryReportEmp6(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 07-แบบ ลจ.กทม.2-1-รายชื่อลูกจ้างผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ + * + * @summary 07-แบบ ลจ.กทม.2-1-รายชื่อลูกจ้างผู้ไม่สมควรได้รับค่าตอบแทนพิเศษ + * + */ + @Get("emp-07/{rootId}/{salaryPeriodId}") + async SalaryReportEmp7(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง + * + * @summary 08-แบบ ลจ.กทม.3-บัญชีแสดงวันลาในครึ่งปีของลูกจ้าง + * + */ + @Get("emp-08/{rootId}/{salaryPeriodId}") + async SalaryReportEmp8(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 09-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับเลื่อนขั้นค่าจ้างในวันที่ 1 เมษา ย้อนหลัง 3 ครั้ง + * + * @summary 09-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับเลื่อนขั้นค่าจ้างในวันที่ 1 เมษา ย้อนหลัง 3 ครั้ง + * + */ + @Get("emp-09/{rootId}/{salaryPeriodId}") + async SalaryReportEmp9(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 10-รายชื่อลูกจ้างประจำผู้มีผลการประเมินดีเด่น + * + * @summary 10-รายชื่อลูกจ้างประจำผู้มีผลการประเมินดีเด่น + * + */ + @Get("emp-10/{rootId}/{salaryPeriodId}") + async SalaryReportEmp10(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 11-คำสั่ง + * + * @summary 11-คำสั่ง + * + */ + @Get("emp-11/{rootId}/{salaryPeriodId}") + async SalaryReportEmp11(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 12-บัญชีรายละเอียดผู้ได้รับอัตราค่าจ้างสูงกว่าขั้นสูง (แนบท้ายคำสั่ง) + * + * @summary 12-บัญชีรายละเอียดผู้ได้รับอัตราค่าจ้างสูงกว่าขั้นสูง (แนบท้ายคำสั่ง) + * + */ + @Get("emp-12/{rootId}/{salaryPeriodId}") + async SalaryReportEmp12(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 13-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง + * + * @summary 13-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับการเลื่อนขั้นค่าจ้าง + * + */ + @Get("emp-13/{rootId}/{salaryPeriodId}") + async SalaryReportEmp13(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 14-คำสั่ง + * + * @summary 14-คำสั่ง + * + */ + @Get("emp-14/{rootId}/{salaryPeriodId}") + async SalaryReportEmp14(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง) + * + * @summary 15-บัญชีรายละเอียดลูกจ้างประจำที่ได้รับค่าตอบแทนพิเศษ(แนบท้ายคำสั่ง) + * + */ + @Get("emp-15/{rootId}/{salaryPeriodId}") + async SalaryReportEmp15(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 16-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ + * + * @summary 16-บัญชีรายชื่อลูกจ้างประจำผู้ไม่ได้รับค่าตอบแทนพิเศษ + * + */ + @Get("emp-16/{rootId}/{salaryPeriodId}") + async SalaryReportEmp16(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 17-คำสั่ง + * + * @summary 17-คำสั่ง + * + */ + @Get("emp-17/{rootId}/{salaryPeriodId}") + async SalaryReportEmp17(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } + /** + * API 18-คำสั่ง + * + * @summary 18-คำสั่ง + * + */ + @Get("emp-18/{rootId}/{salaryPeriodId}") + async SalaryReportEmp18(@Path() rootId: string, @Path() salaryPeriodId: string) { + const salaryPeriod = await this.salaryPeriodRepository.findOne({ + where: { + id: salaryPeriodId, + }, + }); + if (!salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); + } + const _salaryPeriod = await this.salaryProfileRepository.find({ + relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + where: { + salaryOrg: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriodId: salaryPeriodId, + }, + }, + order: { + orgShortName: "ASC", + posMasterNo: "ASC", + }, + }); + + if (!_salaryPeriod) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; + + const formattedData = _salaryPeriod.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: Extension.ToThaiNumber((index + 1).toLocaleString()), + fullName: fullName, + posLevel: profile.posLevel, + posNumber: + profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), + amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, + reason: null, + }; + }); + + return new HttpSuccess({ + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + data: { + year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), + agency: agency, + data: formattedData, + }, + }); + } }