diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 6a9ebc0..66a48ce 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -212,7 +212,7 @@ export class ReportController extends Controller { * @summary รายชื่อข้าราชการผู้ที่ครองตำแหน่ง ณ วันที่ 1 มีนาคม * */ - @Get("gov1-01/{rootId}/{salaryPeriodId}") + @Get("gov-01/{rootId}/{salaryPeriodId}") async SalaryReport1(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { @@ -222,16 +222,13 @@ export class ReportController extends Controller { if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } - const salaryPeriodAPR = await this.salaryProfileRepository.find({ + const _salaryPeriod = await this.salaryProfileRepository.find({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { salaryOrg: { snapshot: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, - salaryPeriod: { - period: "APR", - }, }, }, order: { @@ -240,13 +237,13 @@ export class ReportController extends Controller { }, }); - if (!salaryPeriodAPR) { + if (!_salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } - const agency = salaryPeriodAPR[0] == null ? "" : salaryPeriodAPR[0].root; + const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root; - const formattedData = salaryPeriodAPR.map((profile, index) => { + const formattedData = _salaryPeriod.map((profile, index) => { const fullNameParts = [ profile?.child4, profile?.child3, @@ -274,12 +271,10 @@ export class ReportController extends Controller { }); return new HttpSuccess({ - template: "gov1-01", - reportName: "gov1-01", + template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", + reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01", data: { - date: Extension.ToThaiNumber( - Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), - ), + year: Extension.ToThaiNumber((salaryPeriod.year + 543).toString()), agency: agency, data: formattedData, }, @@ -292,7 +287,7 @@ export class ReportController extends Controller { * @summary บัญชีการคำนวณโควตาเลื่อนเงินเดือน รอบเมษายน * */ - @Get("gov1-02/{rootId}/{salaryPeriodId}") + @Get("gov-02/{rootId}/{salaryPeriodId}") async SalaryReport2(@Path() rootId: string, @Path() salaryPeriodId: string) { const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { @@ -302,181 +297,564 @@ export class ReportController extends Controller { if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน"); } - const salaryPeriodAPR = await this.salaryOrgRepository.find({ + const _salaryPeriod = await this.salaryOrgRepository.find({ relations: ["salaryPeriod", "salaryProfiles"], where: { snapshot: "SNAP1", rootId: rootId, salaryPeriodId: salaryPeriodId, - salaryPeriod: { - period: "APR", - }, }, order: { group: "ASC" }, }); const agency = - salaryPeriodAPR[0] == null || salaryPeriodAPR[0].salaryProfiles[0] == null + _salaryPeriod[0] == null || _salaryPeriod[0].salaryProfiles[0] == null ? "" - : salaryPeriodAPR[0].salaryProfiles[0].root; + : _salaryPeriod[0].salaryProfiles[0].root; + if (salaryPeriod.period == "APR") { + let data1 = _salaryPeriod.find((x) => x.group == "GROUP2"); + let formattedData1; + if (data1 != null) { + formattedData1 = { + total: Extension.ToThaiNumber(data1.total.toString()), + fifteenPercent: Extension.ToThaiNumber(data1.fifteenPercent.toString()), + full: Extension.ToThaiNumber( + data1.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), + ), + haft: Extension.ToThaiNumber( + data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data1.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), + ), + reason: null, + }; + } + let data2 = _salaryPeriod.find((x) => x.group == "GROUP1"); + let formattedData2; + if (data2 != null) { + formattedData2 = { + total: Extension.ToThaiNumber(data2.total.toString()), + fifteenPercent: Extension.ToThaiNumber(data2.fifteenPercent.toString()), + full: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .filter((x) => x.type == "FULL") + .length.toString(), + ), + haft: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .filter((x) => x.type == "HAFT") + .length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .filter((x) => x.type == "NONE") + .length.toString(), + ), + reason: null, + }; + } + let data3 = _salaryPeriod.find((x) => x.group == "GROUP1"); + let formattedData3; + if (data3 != null) { + formattedData3 = { + total: Extension.ToThaiNumber(data3.total.toString()), + fifteenPercent: Extension.ToThaiNumber(data3.fifteenPercent.toString()), + full: Extension.ToThaiNumber( + data3.salaryProfiles + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .filter((x) => x.type == "FULL") + .length.toString(), + ), + haft: Extension.ToThaiNumber( + data3.salaryProfiles + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .filter((x) => x.type == "HAFT") + .length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data3.salaryProfiles + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .filter((x) => x.type == "NONE") + .length.toString(), + ), + reason: null, + }; + } + let data4 = _salaryPeriod.find((x) => x.group == "GROUP1"); + let formattedData4; + if (data4 != null) { + formattedData4 = { + total: Extension.ToThaiNumber(data4.total.toString()), + fifteenPercent: Extension.ToThaiNumber(data4.fifteenPercent.toString()), + full: Extension.ToThaiNumber( + data4.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), + ), + haft: Extension.ToThaiNumber( + data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data4.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), + ), + reason: null, + }; + } - let data1 = salaryPeriodAPR.find((x) => x.group == "GROUP2"); - let formattedData1; - if (data1 != null) { - formattedData1 = { - total: Extension.ToThaiNumber(data1.salaryProfiles.length.toString()), - fifteenPercent: Extension.ToThaiNumber(data1.fifteenPercent.toString()), - full: Extension.ToThaiNumber( - data1.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), - ), - haft: Extension.ToThaiNumber( - data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), - ), - notPromoted: Extension.ToThaiNumber( - data1.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), - ), - reason: null, - }; - } - let data2 = salaryPeriodAPR.find((x) => x.group == "GROUP1"); - let formattedData2; - if (data2 != null) { - formattedData2 = { - total: Extension.ToThaiNumber( - data2.salaryProfiles - .filter( - (x) => - x.posLevel == "อาวุโส" || - x.posLevel == "ชำนาญการพิเศษ" || - (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), - ) - .length.toString(), - ), - fifteenPercent: Extension.ToThaiNumber(data2.fifteenPercent.toString()), - full: Extension.ToThaiNumber( - data2.salaryProfiles - .filter( - (x) => - x.posLevel == "อาวุโส" || - x.posLevel == "ชำนาญการพิเศษ" || - (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), - ) - .filter((x) => x.type == "FULL") - .length.toString(), - ), - haft: Extension.ToThaiNumber( - data2.salaryProfiles - .filter( - (x) => - x.posLevel == "อาวุโส" || - x.posLevel == "ชำนาญการพิเศษ" || - (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), - ) - .filter((x) => x.type == "HAFT") - .length.toString(), - ), - notPromoted: Extension.ToThaiNumber( - data2.salaryProfiles - .filter( - (x) => - x.posLevel == "อาวุโส" || - x.posLevel == "ชำนาญการพิเศษ" || - (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), - ) - .filter((x) => x.type == "NONE") - .length.toString(), - ), - reason: null, - }; - } - let data3 = salaryPeriodAPR.find((x) => x.group == "GROUP1"); - let formattedData3; - if (data3 != null) { - formattedData3 = { - total: Extension.ToThaiNumber( - data3.salaryProfiles - .filter( - (x) => - x.posLevel == "ปฏิบัติงาน" || - x.posLevel == "ชำนาญงาน" || - x.posLevel == "ปฏิบัติการ" || - x.posLevel == "ชำนาญการ", - ) - .length.toString(), - ), - fifteenPercent: Extension.ToThaiNumber(data3.fifteenPercent.toString()), - full: Extension.ToThaiNumber( - data3.salaryProfiles - .filter( - (x) => - x.posLevel == "ปฏิบัติงาน" || - x.posLevel == "ชำนาญงาน" || - x.posLevel == "ปฏิบัติการ" || - x.posLevel == "ชำนาญการ", - ) - .filter((x) => x.type == "FULL") - .length.toString(), - ), - haft: Extension.ToThaiNumber( - data3.salaryProfiles - .filter( - (x) => - x.posLevel == "ปฏิบัติงาน" || - x.posLevel == "ชำนาญงาน" || - x.posLevel == "ปฏิบัติการ" || - x.posLevel == "ชำนาญการ", - ) - .filter((x) => x.type == "HAFT") - .length.toString(), - ), - notPromoted: Extension.ToThaiNumber( - data3.salaryProfiles - .filter( - (x) => - x.posLevel == "ปฏิบัติงาน" || - x.posLevel == "ชำนาญงาน" || - x.posLevel == "ปฏิบัติการ" || - x.posLevel == "ชำนาญการ", - ) - .filter((x) => x.type == "NONE") - .length.toString(), - ), - reason: null, - }; - } - let data4 = salaryPeriodAPR.find((x) => x.group == "GROUP1"); - let formattedData4; - if (data4 != null) { - formattedData4 = { - total: Extension.ToThaiNumber(data4.salaryProfiles.length.toString()), - fifteenPercent: Extension.ToThaiNumber(data4.fifteenPercent.toString()), - full: Extension.ToThaiNumber( - data4.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), - ), - haft: Extension.ToThaiNumber( - data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), - ), - notPromoted: Extension.ToThaiNumber( - data4.salaryProfiles.filter((x) => x.type == "NONE").length.toString(), - ), - reason: null, - }; - } + return new HttpSuccess({ + template: "gov1-02", + reportName: "gov1-02", + data: { + date: Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), + ), + dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())), + agency: agency, + data1: formattedData1, + data2: formattedData2, + data3: formattedData3, + data4: formattedData4, + }, + }); + } else { + let data1 = _salaryPeriod.find((x) => x.group == "GROUP2"); + const _salaryPeriodAPR = await this.salaryOrgRepository.find({ + where: { + snapshot: "SNAP1", + rootId: rootId, + salaryPeriod: { + period: "APR", + year: salaryPeriod.year, + }, + }, + order: { group: "ASC" }, + }); + let formattedData1; + if (data1 != null) { + const haftSalary = data1.salaryProfiles + .filter((x) => x.type == "HAFT") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); - return new HttpSuccess({ - template: "gov1-02", - reportName: "gov1-02", - data: { - date: Extension.ToThaiNumber( - Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), - ), - dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())), - agency: agency, - data1: formattedData1, - data2: formattedData2, - data3: formattedData3, - data4: formattedData4, - }, - }); + const fullSalary = data1.salaryProfiles + .filter((x) => x.type == "FULL") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + const fullHaftSalary = data1.salaryProfiles + .filter((x) => x.type == "NONE") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + formattedData1 = { + totalSalary: Extension.ToThaiNumber(data1.currentAmount.toString()), + totalUser: Extension.ToThaiNumber(data1.total.toString()), + sixPercentAmount: Extension.ToThaiNumber(data1.sixPercentAmount.toString()), + spentAmount: Extension.ToThaiNumber(data1.spentAmount.toString()), + remainingAmount: Extension.ToThaiNumber( + (data1.sixPercentAmount - data1.spentAmount).toString(), + ), + haft: Extension.ToThaiNumber( + data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + full: Extension.ToThaiNumber( + data1.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), + ), + fullHaft: Extension.ToThaiNumber( + data1.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data1.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: Extension.ToThaiNumber( + ( + data1.sixPercentAmount - + data1.spentAmount - + haftSalary - + fullSalary - + fullHaftSalary + ).toString(), + ), + reason: null, + }; + } + let data2 = _salaryPeriod.find((x) => x.group == "GROUP1"); + let formattedData2; + if (data2 != null) { + const haftSalary = data2.salaryProfiles + .filter((x) => x.type == "HAFT") + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + + const fullSalary = data2.salaryProfiles + .filter((x) => x.type == "FULL") + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + const fullHaftSalary = data2.salaryProfiles + .filter((x) => x.type == "NONE") + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + + formattedData2 = { + totalSalary: Extension.ToThaiNumber(data2.currentAmount.toString()), + totalUser: Extension.ToThaiNumber(data2.total.toString()), + sixPercentAmount: Extension.ToThaiNumber(data2.sixPercentAmount.toString()), + spentAmount: Extension.ToThaiNumber(data2.spentAmount.toString()), + remainingAmount: Extension.ToThaiNumber( + (data2.sixPercentAmount - data2.spentAmount).toString(), + ), + haft: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .filter((x) => x.type == "HAFT") + .length.toString(), + ), + full: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .filter((x) => x.type == "FULL") + .length.toString(), + ), + fullHaft: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .filter((x) => x.type == "HAFT") + .length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data2.salaryProfiles + .filter( + (x) => + x.posLevel == "อาวุโส" || + x.posLevel == "ชำนาญการพิเศษ" || + (x.posLevel == "ต้น" && x.posType == "อำนวยการ"), + ) + .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: Extension.ToThaiNumber( + ( + data2.sixPercentAmount - + data2.spentAmount - + haftSalary - + fullSalary - + fullHaftSalary + ).toString(), + ), + reason: null, + }; + } + let data3 = _salaryPeriod.find((x) => x.group == "GROUP1"); + let formattedData3; + if (data3 != null) { + const haftSalary = data3.salaryProfiles + .filter((x) => x.type == "HAFT") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + + const fullSalary = data3.salaryProfiles + .filter((x) => x.type == "FULL") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + const fullHaftSalary = data3.salaryProfiles + .filter((x) => x.type == "NONE") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + formattedData3 = { + totalSalary: Extension.ToThaiNumber(data3.currentAmount.toString()), + totalUser: Extension.ToThaiNumber(data3.total.toString()), + sixPercentAmount: Extension.ToThaiNumber(data3.sixPercentAmount.toString()), + spentAmount: Extension.ToThaiNumber(data3.spentAmount.toString()), + remainingAmount: Extension.ToThaiNumber( + (data3.sixPercentAmount - data3.spentAmount).toString(), + ), + haft: Extension.ToThaiNumber( + data3.salaryProfiles + .filter((x) => x.type == "HAFT") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .length.toString(), + ), + full: Extension.ToThaiNumber( + data3.salaryProfiles + .filter((x) => x.type == "FULL") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .length.toString(), + ), + fullHaft: Extension.ToThaiNumber( + data3.salaryProfiles + .filter((x) => x.type == "HAFT") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data3.salaryProfiles + .filter((x) => x.type == "NONE") + .filter( + (x) => + x.posLevel == "ปฏิบัติงาน" || + x.posLevel == "ชำนาญงาน" || + x.posLevel == "ปฏิบัติการ" || + x.posLevel == "ชำนาญการ", + ) + .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: Extension.ToThaiNumber( + ( + data3.sixPercentAmount - + data3.spentAmount - + haftSalary - + fullSalary - + fullHaftSalary + ).toString(), + ), + reason: null, + }; + } + let data4 = _salaryPeriod.find((x) => x.group == "GROUP1"); + let formattedData4; + if (data4 != null) { + const haftSalary = data4.salaryProfiles + .filter((x) => x.type == "HAFT") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + + const fullSalary = data4.salaryProfiles + .filter((x) => x.type == "FULL") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + const fullHaftSalary = data4.salaryProfiles + .filter((x) => x.type == "NONE") + .reduce((accumulator, object: any) => { + return ( + accumulator + + (object.amount == null ? 0 : object.amount) + + (object.amountSpecial == null ? 0 : object.amountSpecial) + ); + }, 0); + formattedData4 = { + totalSalary: Extension.ToThaiNumber(data4.currentAmount.toString()), + totalUser: Extension.ToThaiNumber(data4.total.toString()), + sixPercentAmount: Extension.ToThaiNumber(data4.sixPercentAmount.toString()), + spentAmount: Extension.ToThaiNumber(data4.spentAmount.toString()), + remainingAmount: Extension.ToThaiNumber( + (data4.sixPercentAmount - data4.spentAmount).toString(), + ), + haft: Extension.ToThaiNumber( + data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + full: Extension.ToThaiNumber( + data4.salaryProfiles.filter((x) => x.type == "FULL").length.toString(), + ), + fullHaft: Extension.ToThaiNumber( + data4.salaryProfiles.filter((x) => x.type == "HAFT").length.toString(), + ), + notPromoted: Extension.ToThaiNumber( + data4.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: Extension.ToThaiNumber( + ( + data4.sixPercentAmount - + data4.spentAmount - + haftSalary - + fullSalary - + fullHaftSalary + ).toString(), + ), + reason: null, + }; + } + + return new HttpSuccess({ + template: "gov2-02", + reportName: "gov2-02", + data: { + date: Extension.ToThaiNumber( + Extension.ToThaiFullDate(new Date(`${salaryPeriod.year}-03-01`)), + ), + dateNow: Extension.ToThaiNumber(Extension.ToThaiFullDate(new Date())), + agency: agency, + data1: formattedData1, + data2: formattedData2, + data3: formattedData3, + data4: formattedData4, + }, + }); + } } /** @@ -547,8 +925,12 @@ export class ReportController extends Controller { (item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") + (item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") + (item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") + - (item.root == undefined && item.root == null ? "" : item.root)+ - "/" + item.prefix + item.firstName + " " + item.lastName, // สังกัด/ชื่อ-นามสกุล + (item.root == undefined && item.root == null ? "" : item.root) + + "/" + + item.prefix + + item.firstName + + " " + + item.lastName, // สังกัด/ชื่อ-นามสกุล posLevel: item.posLevel, posMasterNo: Extension.ToThaiNumber(String(item.posMasterNo)), amount: @@ -559,8 +941,8 @@ export class ReportController extends Controller { salaryIncrease2: null, //การเลื่อนเงินเดือนปีก่อนหน้า score: null, //ผลการประเมินฯ remark: null, //หมายเหตุ - })) - } + })), + }, }); } @@ -618,10 +1000,10 @@ export class ReportController extends Controller { "amountSpecial", ], order: { - "posMasterNo": "ASC", - } + posMasterNo: "ASC", + }, }); - + return new HttpSuccess({ template: "gov1-04", reportName: "gov1-04",