From 79f9c1637de6faf43bfe40efe2d578b9ca2356dd Mon Sep 17 00:00:00 2001 From: Bright Date: Fri, 29 Mar 2024 11:12:45 +0700 Subject: [PATCH] no message --- src/controllers/TumReportController.ts | 411 +------------------------ 1 file changed, 8 insertions(+), 403 deletions(-) diff --git a/src/controllers/TumReportController.ts b/src/controllers/TumReportController.ts index e3aa6f6..1d829ba 100644 --- a/src/controllers/TumReportController.ts +++ b/src/controllers/TumReportController.ts @@ -58,362 +58,6 @@ import { private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile); private salaryProfileEmployeeRepository = AppDataSource.getRepository(SalaryProfileEmployee); - - /** - * API 01-บัญชีการคำนวณวงเงินเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร - * - * @summary 01-บัญชีการคำนวณวงเงินเลื่อนขั้นค่าจ้างลูกจ้างประจำกรุงเทพมหานคร - * - */ - @Get("emp2-01/{rootId}/{salaryPeriodId}") - async SalaryReportEmp2_1(@Path() rootId: string, @Path() salaryPeriodId: string) { - const salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { - id: salaryPeriodId, - }, - }); - if (!salaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); - } - - const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ - where: { - year: salaryPeriod.year, - period: "APR", - }, - }); - if (!salaryPeriodAPR) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนรอบเดือนเมษายน"); - } - - const aprSnap2 = await this.salaryOrgEmployeeRepository.findOne({ - relations: ["salaryPeriod", "salaryProfiles"], - where: { - snapshot: "SNAP2", - rootId: rootId, - salaryPeriodId: salaryPeriodAPR.id, - }, - }); - - if (!aprSnap2) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } - - const octSnap1 = await this.salaryOrgEmployeeRepository.findOne({ - relations: ["salaryPeriod", "salaryProfiles"], - where: { - snapshot: "SNAP1", - group: "GROUP1", - rootId: rootId, - salaryPeriodId: salaryPeriodId, - }, - }); - - if (!octSnap1) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } - - const octSnap2 = await this.salaryOrgEmployeeRepository.findOne({ - relations: ["salaryPeriod", "salaryProfiles"], - where: { - snapshot: "SNAP2", - group: "GROUP1", - rootId: rootId, - salaryPeriodId: salaryPeriodId, - }, - }); - - if (!octSnap2) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } - let fullHaftTotalAmount: any = 0; - let fullHaftCount: any = 0; - let fullTotalAmount: any = 0; - let fullCount: any = 0; - let haftTotalAmount: any = 0; - let haftCount: any = 0; - let noneCount: any = 0; - - if (octSnap2 && octSnap2.salaryProfiles) { - octSnap2.salaryProfiles.forEach((profile: any) => { - switch (profile.type) { - case "FULLHAFT": - fullHaftTotalAmount += profile.amount ?? 0; - fullHaftCount++; - break; - case "FULL": - fullTotalAmount += profile.amount ?? 0; - fullCount++; - break; - case "HAFT": - haftTotalAmount += profile.amount ?? 0; - haftCount++; - break; - case "NONE": - noneCount++; - break; - default: - break; - } - }); - } - - const emp2step = new Set(); - if (octSnap2 && aprSnap2) { - octSnap2.salaryProfiles.forEach((octProfile) => { - aprSnap2.salaryProfiles.forEach((aprProfile) => { - if ( - octProfile.citizenId === aprProfile.citizenId && - ((octProfile.type === "FULL" && aprProfile.type === "FULL") || - (octProfile.type === "HAFT" && aprProfile.type === "FULLHAFT") || - (octProfile.type === "FULLHAFT" && aprProfile.type === "HAFT")) - ) { - emp2step.add(octProfile.citizenId); - } - }); - }); - } - const totalEmp2step = emp2step.size ?? 0; - - const agency = octSnap1.salaryProfiles[0] == null ? "" : octSnap1.salaryProfiles[0].root; - return new HttpSuccess({ - template: "emp2-01", - reportName: "emp2-01", - data: { - year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice( - -2, - ), - agency: agency, - totalUser: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.total.toString()), - totalSalary: - octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toString()), - sixPercent: - octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toString()), - remainingAmountApr: - aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย. - remainingAmountOct: - octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค. - totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง) - fifteenPercentOld: - aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.fifteenPercent.toString()), - totalUseOld: - aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง) - full2: totalEmp2step == null ? "" : Extension.ToThaiNumber(totalEmp2step.toString()), //เลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้นจำนวน(คน) - fullHaft: fullHaftCount == null ? "" : Extension.ToThaiNumber(fullHaftCount.toString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง) - fullHaftSalary: - fullHaftTotalAmount == null ? "" : Extension.ToThaiNumber(fullHaftTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้นครึ่ง) - full: fullCount == null ? "" : Extension.ToThaiNumber(fullCount.toString()), //จำนวน(คน)(หนึ่งขั้น) - fullSalary: - fullTotalAmount == null ? "" : Extension.ToThaiNumber(fullTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้น) - haft: haftCount == null ? "" : Extension.ToThaiNumber(haftCount.toString()), //จำนวน(คน)(ครึ่งขั้น) - haftSalary: - haftTotalAmount == null ? "" : Extension.ToThaiNumber(haftTotalAmount.toString()), //ใช้เงิน(ครึ่งขั้น) - notPromoted: noneCount == null ? "" : Extension.ToThaiNumber(noneCount.toString()), //ไม่ได้เลื่อนขั้นค่าจ้างจำนวน(คน) - total: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.useAmount.toString()), //รวมใช้เงิน - summary: - octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.remainingAmount.toString()), //เหลือเงิน - }, - }); - } - /** - * API 02-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ครองตำแหน่ง - * - * @summary 02-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ครองตำแหน่ง - * - */ - @Get("emp2-02/{rootId}/{salaryPeriodId}") - async SalaryReportEmp2_2(@Path() rootId: string, @Path() salaryPeriodId: string) { - const salaryPeriod = await this.salaryPeriodRepository.findOne({ - where: { - id: salaryPeriodId, - period: "OCT", - }, - }); - if (!salaryPeriod) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); - } - - const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({ - where: { - period: "APR", - year: salaryPeriod?.year, - }, - }); - if (!salaryPeriodAPR) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); - } - - const salaryPeriodAPRProfile = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg"], - where: { - salaryOrg: { - snapshot: "SNAP2", - rootId: rootId, - salaryPeriodId: salaryPeriodAPR?.id, - }, - }, - }); - - const octPreviousYear = await this.salaryPeriodRepository.findOne({ - where: { - period: "OCT", - year: salaryPeriod?.year - 1, - }, - }); - - const octPreviousYear2 = await this.salaryPeriodRepository.findOne({ - where: { - period: "OCT", - year: salaryPeriod?.year - 2, - }, - }); - - let octPreviousYearProfile: SalaryProfileEmployee[] = []; - if (octPreviousYear) { - octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg"], - where: { - salaryOrg: { - snapshot: "SNAP2", - rootId: rootId, - salaryPeriodId: octPreviousYear?.id, - }, - }, - }); - } - - let octPreviousYearProfile2: SalaryProfileEmployee[] = []; - if (octPreviousYear2) { - octPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg"], - where: { - salaryOrg: { - snapshot: "SNAP2", - salaryPeriodId: octPreviousYear2?.id, - rootId: rootId, - }, - }, - }); - } - - const _salaryPeriod = await this.salaryProfileEmployeeRepository.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: any, index: number) => { - if (!profile) { - return null; - } - 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, - posNumber: - profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()), - amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null, - yearOld2: octPreviousYear2 == null ? null : Extension.ToThaiNumber(octPreviousYear2.year.toString()), - typeOld2: - octPreviousYear2 && octPreviousYearProfile2.length > 0 ? (() => { - const _profile = octPreviousYearProfile2 - .filter((profileOCT2) => profileOCT2.citizenId === profile.citizenId); - if (_profile.length > 0) { - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; - } - return null; - })() - : null, - yearOld: octPreviousYear == null ? null : Extension.ToThaiNumber(octPreviousYear.year.toString()), - typeOld1: - octPreviousYear && octPreviousYearProfile.length > 0 ? (() => { - const _profile = octPreviousYearProfile - .filter((profileOCT) => profileOCT.citizenId === profile.citizenId); - if (_profile.length > 0) { - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; - } - return null; - })() - : null, - typeOld: - salaryPeriodAPRProfile.length > 0 - ? (() => { - const _profile = salaryPeriodAPRProfile - .filter((profileAPR) => profileAPR.citizenId === profile.citizenId) - .map((profile) => ({ - type: profile.type, - })); - return _profile[0]?.type === "HAFT" - ? "๐.๕ ขั้น" - : _profile[0]?.type === "FULL" - ? "๑ ขั้น" - : profile?.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ"; - })() - : null, //เมษา ปีเดียวกัน - type: - profile.type === "HAFT" - ? "๐.๕ ขั้น" - : profile.type === "FULL" - ? "๑ ขั้น" - : profile.type === "FULLHAFT" - ? "๑.๕ ขั้น" - : "ไม่ได้เลื่อนขั้นฯ", //หน่วยงานพิจารณาเลื่อนขั้นค่าจ้าง 1 ต.ค. (จำนวนขั้น) - }; - }); - - return new HttpSuccess({ - template: "emp2-02", - reportName: "emp2-02", - data: { - year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))), - agency: agency, - data: formattedData, - }, - }); - } /** * API 03-รายชื่อลูกจ้างประจำกรุงเทพมหานครผู้ได้รับการเสนอขอเลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้น * @@ -421,7 +65,7 @@ import { * */ @Get("emp2-03/{rootId}/{salaryPeriodId}") - async SalaryReportEmp2_3(@Path() rootId: string, @Path() salaryPeriodId: string) { + async SalaryReportEmp2_3(@Path() rootId: string='b43e886b-008c-49d3-8df3-97a5b0f3cd2a', @Path() salaryPeriodId: string='2ec16330-ea28-4f51-8ac5-4f60295288a5') { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId, @@ -441,16 +85,19 @@ import { "fifteenPercent" ] }) + const fifteenPercentData = fifteenPoint?.fifteenPercent == undefined || fifteenPoint?.fifteenPercent == null ? "๐" : Extension.ToThaiNumber(String(fifteenPoint?.fifteenPercent)); + const fifteenPointData = fifteenPoint?.fifteenPoint == undefined || fifteenPoint?.fifteenPoint == null ? ".๐๐" : "." + Extension.ToThaiNumber(String(fifteenPoint?.fifteenPoint)); + const _salaryPeriodTarget = await this.salaryProfileEmployeeRepository.find({ - relations: ["salaryOrg", "salaryOrg.salaryPeriod"], + relations: ["salaryOrg"], where: { type: "FULL", salaryOrg: { @@ -464,7 +111,7 @@ import { posMasterNo: "ASC", }, }); - + if (!_salaryPeriodTarget) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } @@ -482,7 +129,7 @@ import { year: salaryPeriod?.year - 2, }, }); - + let octPreviousYearProfile: SalaryProfileEmployee[] = []; if (octPreviousYear) { octPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ @@ -513,50 +160,8 @@ import { }); } - // const aprPreviousYear = await this.salaryPeriodRepository.findOne({ - // where: { - // period: "APR", - // year: salaryPeriod?.year - 1, - // }, - // }); - - // const aprPreviousYear2 = await this.salaryPeriodRepository.findOne({ - // where: { - // period: "APR", - // year: salaryPeriod?.year - 2, - // }, - // }); - - // let aprPreviousYearProfile: SalaryProfileEmployee[] = []; - // if (aprPreviousYear) { - // aprPreviousYearProfile = await this.salaryProfileEmployeeRepository.find({ - // relations: ["salaryOrg"], - // where: { - // salaryOrg: { - // snapshot: "SNAP2", - // rootId: rootId, - // salaryPeriodId: aprPreviousYear?.id, - // }, - // }, - // }); - // } - - // let aprPreviousYearProfile2: SalaryProfileEmployee[] = []; - // if (aprPreviousYear2) { - // aprPreviousYearProfile2 = await this.salaryProfileEmployeeRepository.find({ - // relations: ["salaryOrg"], - // where: { - // salaryOrg: { - // snapshot: "SNAP2", - // salaryPeriodId: aprPreviousYear2?.id, - // rootId: rootId, - // }, - // }, - // }); - // } - const agency = _salaryPeriodTarget[0] == null ? "" : _salaryPeriodTarget[0].root; - + const formattedData = _salaryPeriodTarget.map((profile, index) => { const fullNameParts = [ profile.child4,