diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 2d2caff..2bb41d6 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -11,7 +11,7 @@ import { Path, Request, Query, -} from "tsoa"; +} from "tsoa"; import { AppDataSource } from "../database/data-source"; import { Brackets, IsNull, Not, In } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; @@ -53,7 +53,7 @@ export class ReportController extends Controller { //KPI1, KPI2, KPI3, KPI7, KPI9 let data: any; - let dataKpiUserEvaluations: any + let dataKpiUserEvaluations: any; let period1: any; let period2: any; @@ -68,92 +68,125 @@ export class ReportController extends Controller { // throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการ ของหน่วยงานที่เลือก`); // } data = await this.kpiPeriodRepository.findOne({ - where: { id: requestBody.periodId } - }) + where: { id: requestBody.periodId }, + }); dataKpiUserEvaluations = await this.kpiUserEvaluationRepository.find({ - where: { + where: { kpiPeriodId: requestBody.periodId, - orgId: requestBody.root - } - }) + orgId: requestBody.root, + }, + }); data = { id: data.id, year: data.year, - durationKPI: data.durationKPI, + durationKPI: data.durationKPI, startDate: data.startDate, endDate: data.endDate, - kpiUserEvaluations: dataKpiUserEvaluations - } + kpiUserEvaluations: dataKpiUserEvaluations, + }; - if(data.durationKPI == "APR") { - period1 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}` + if (data.durationKPI == "APR") { + period1 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`; let _period2 = await this.kpiPeriodRepository.findOne({ - where: { - year: data.year, durationKPI: "OCT", isActive: true - } + where: { + year: data.year, + durationKPI: "OCT", + isActive: true, + }, }); - period2 = _period2 ? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}` : "" - } - else if(data.durationKPI == "OCT"){ - period2 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}` + period2 = _period2 + ? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}` + : ""; + } else if (data.durationKPI == "OCT") { + period2 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`; let _period1 = await this.kpiPeriodRepository.findOne({ - where: { - year: data.year, durationKPI: "APR", isActive: true - } + where: { + year: data.year, + durationKPI: "APR", + isActive: true, + }, }); - period1 = _period1 ? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}` : "" + period1 = _period1 + ? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}` + : ""; } } if (requestBody.type == "KPI1") { templateName = "KPI1"; reportName = "KPI1"; - /*ROOT*/ + /*ROOT*/ const userEvaluationOrg = await this.kpiUserEvaluationRepository.find({ - where: { + where: { orgId: String(requestBody.root), - // child1Id: "" || IsNull(), - // child2Id: "" || IsNull(), - // child3Id: "" || IsNull(), - // child4Id: "" || IsNull(), - } + // child1Id: "" || IsNull(), + // child2Id: "" || IsNull(), + // child3Id: "" || IsNull(), + // child4Id: "" || IsNull(), + }, }); - const resultAll = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.length.toString()) - : "๐" - const result = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults != "PENDING").length.toString()) - : "๐" - const excellent = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "EXCELLENT").length.toString()) - : "๐" - const verygood = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "VERY_GOOD").length.toString()) - : "๐" - const good = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "GOOD").length.toString()) - : "๐" - const fair = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "FAIR").length.toString()) - : "๐" - const improvment = userEvaluationOrg.length > 0 - ? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "IMPROVEMENT").length.toString()) - : "๐" + const resultAll = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber(userEvaluationOrg.length.toString()) + : "๐"; + const result = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber( + userEvaluationOrg + .filter((x: any) => x.evaluationResults != "PENDING") + .length.toString(), + ) + : "๐"; + const excellent = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber( + userEvaluationOrg + .filter((x: any) => x.evaluationResults == "EXCELLENT") + .length.toString(), + ) + : "๐"; + const verygood = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber( + userEvaluationOrg + .filter((x: any) => x.evaluationResults == "VERY_GOOD") + .length.toString(), + ) + : "๐"; + const good = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber( + userEvaluationOrg.filter((x: any) => x.evaluationResults == "GOOD").length.toString(), + ) + : "๐"; + const fair = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber( + userEvaluationOrg.filter((x: any) => x.evaluationResults == "FAIR").length.toString(), + ) + : "๐"; + const improvment = + userEvaluationOrg.length > 0 + ? Extension.ToThaiNumber( + userEvaluationOrg + .filter((x: any) => x.evaluationResults == "IMPROVEMENT") + .length.toString(), + ) + : "๐"; /*END ROOT*/ formattedData = { - year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "-", + year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", period1: Extension.ToThaiNumber(period1), period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, - root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator - : "-", + root: + data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 + ? data?.kpiUserEvaluations[0].orgEvaluator + : "-", userEvaluations: [ { no: userEvaluationOrg.length > 0 ? "๑" : "", - root: userEvaluationOrg.length > 0 - ? userEvaluationOrg[0].orgEvaluator ?? "" - : "-", + root: userEvaluationOrg.length > 0 ? userEvaluationOrg[0].orgEvaluator ?? "" : "-", resultAll: userEvaluationOrg.length > 0 ? resultAll : "", result: userEvaluationOrg.length > 0 ? result : "", excellent: userEvaluationOrg.length > 0 ? excellent : "", @@ -161,119 +194,163 @@ export class ReportController extends Controller { good: userEvaluationOrg.length > 0 ? good : "", fair: userEvaluationOrg.length > 0 ? fair : "", improvment: userEvaluationOrg.length > 0 ? improvment : "", - } - ] - } + }, + ], + }; } if (requestBody.type == "KPI2") { templateName = "KPI2"; reportName = "KPI2"; - const excellent = data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x:any, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", - })).filter((x:any) => x.evaluationResults == "EXCELLENT") - : [{}] - const verygood = data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x:any, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", - })).filter((x:any) => x.evaluationResults == "VERY_GOOD") - : [{}] - const good = data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x:any, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", - })).filter((x:any) => x.evaluationResults == "GOOD") - : [{}] - const fair = data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x:any, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", - })).filter((x:any) => x.evaluationResults == "FAIR") - : [{}] - const improvment = data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x:any, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - org: x.org ? x.org : "", - })).filter((x:any) => x.evaluationResults == "IMPROVEMENT") - : [{}] + const excellent = + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations + .map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + org: x.org ? x.org : "", + })) + .filter((x: any) => x.evaluationResults == "EXCELLENT") + : [{}]; + const verygood = + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations + .map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + org: x.org ? x.org : "", + })) + .filter((x: any) => x.evaluationResults == "VERY_GOOD") + : [{}]; + const good = + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations + .map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + org: x.org ? x.org : "", + })) + .filter((x: any) => x.evaluationResults == "GOOD") + : [{}]; + const fair = + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations + .map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + org: x.org ? x.org : "", + })) + .filter((x: any) => x.evaluationResults == "FAIR") + : [{}]; + const improvment = + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations + .map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + org: x.org ? x.org : "", + })) + .filter((x: any) => x.evaluationResults == "IMPROVEMENT") + : [{}]; formattedData = { - year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "-", + year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", period1: Extension.ToThaiNumber(period1), period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, - root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator - : "-", - excellents: { - count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(excellent.length.toString()) : "", - data: excellent + root: + data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 + ? data?.kpiUserEvaluations[0].orgEvaluator + : "-", + excellents: { + count: + data.kpiUserEvaluations.length > 0 + ? Extension.ToThaiNumber(excellent.length.toString()) + : "", + data: excellent, }, - verygoods: { - count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(verygood.length.toString()) : "", - data: verygood + verygoods: { + count: + data.kpiUserEvaluations.length > 0 + ? Extension.ToThaiNumber(verygood.length.toString()) + : "", + data: verygood, }, - goods: { - count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(good.length.toString()) : "", - data: good + goods: { + count: + data.kpiUserEvaluations.length > 0 + ? Extension.ToThaiNumber(good.length.toString()) + : "", + data: good, }, - fairs: { - count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(fair.length.toString()) : "", - data: fair + fairs: { + count: + data.kpiUserEvaluations.length > 0 + ? Extension.ToThaiNumber(fair.length.toString()) + : "", + data: fair, }, - improvments: { - count: data.kpiUserEvaluations.length > 0 ? Extension.ToThaiNumber(improvment.length.toString()) : "", - data: improvment + improvments: { + count: + data.kpiUserEvaluations.length > 0 + ? Extension.ToThaiNumber(improvment.length.toString()) + : "", + data: improvment, }, - } + }; } if (requestBody.type == "KPI3") { templateName = "KPI3"; reportName = "KPI3"; - const userEvaluations_ = data?.kpiUserEvaluations?.length > 0 - ? data.kpiUserEvaluations.map((x:any, idx:number) => ({ - no: Extension.ToThaiNumber((idx+1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - point1: x.summaryPoint >= 90.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", - point2: x.summaryPoint >= 80.00 && x.summaryPoint <= 89.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", - point3: x.summaryPoint >= 70.00 && x.summaryPoint <= 79.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", - point4: x.summaryPoint >= 60.00 && x.summaryPoint <= 69.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", - point5: x.summaryPoint < 60.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", - remark: "" - })) - : [{}] + const userEvaluations_ = + data?.kpiUserEvaluations?.length > 0 + ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + point1: + x.summaryPoint >= 90.0 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", + point2: + x.summaryPoint >= 80.0 && x.summaryPoint <= 89.99 + ? Extension.ToThaiNumber(x.summaryPoint.toString()) + : "", + point3: + x.summaryPoint >= 70.0 && x.summaryPoint <= 79.99 + ? Extension.ToThaiNumber(x.summaryPoint.toString()) + : "", + point4: + x.summaryPoint >= 60.0 && x.summaryPoint <= 69.99 + ? Extension.ToThaiNumber(x.summaryPoint.toString()) + : "", + point5: + x.summaryPoint < 60.0 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "", + remark: "", + })) + : [{}]; // const prefixEvaluator_ = data.kpiUserEvaluations.find((x:any) => x.prefixEvaluator); // const firstNameEvaluator_ = data.kpiUserEvaluations.firstNameEvaluator ? data.kpiUserEvaluations.firstNameEvaluator : ""; // const lastNameEvaluator_ = data.kpiUserEvaluations.lastNameEvaluator ? data.kpiUserEvaluations.lastNameEvaluator : ""; formattedData = { - year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "-", + year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", period1: Extension.ToThaiNumber(period1), period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, - root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator - : "-", + root: + data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 + ? data?.kpiUserEvaluations[0].orgEvaluator + : "-", fullNameEvaluator: "-", positionEvaluator: "-", posTypeNameEvaluator: "-", - posLevelNameEvaluator: "-", + posLevelNameEvaluator: "-", orgEvaluator: "-", fullNameCommander: "-", @@ -287,8 +364,8 @@ export class ReportController extends Controller { posTypeNameCommanderHigh: "-", posLevelNameCommanderHigh: "-", orgCommanderHigh: "-", - userEvaluations : userEvaluations_ - } + userEvaluations: userEvaluations_, + }; } if (requestBody.type == "KPI4") { templateName = "KPI4"; @@ -795,34 +872,38 @@ export class ReportController extends Controller { templateName = "KPI7"; reportName = "KPI7"; formattedData = { - year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "-", + year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", period1: Extension.ToThaiNumber(period1), period2: Extension.ToThaiNumber(period2), durationKPI: data?.durationKPI, - root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator - : "-", - userEvaluations: data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ - no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - developName: x.topicEvaluator ? x.topicEvaluator : "", - developEvaluator: x.developEvaluator ? x.developEvaluator : "", - target: "", //เป้าหมาย - timeEvaluator: x.timeEvaluator ? x.timeEvaluator : "", - developResults: "", //วิธีการวัดผลการพัฒนา - evaluationResults: x.evaluationResults ? Extension.EvaluationResult(x.evaluationResults) : "", - })) - : [{}], - } + root: + data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 + ? data?.kpiUserEvaluations[0].orgEvaluator + : "-", + userEvaluations: + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + developName: x.topicEvaluator ? x.topicEvaluator : "", + developEvaluator: x.developEvaluator ? x.developEvaluator : "", + target: "", //เป้าหมาย + timeEvaluator: x.timeEvaluator ? x.timeEvaluator : "", + developResults: "", //วิธีการวัดผลการพัฒนา + evaluationResults: x.evaluationResults + ? Extension.EvaluationResult(x.evaluationResults) + : "", + })) + : [{}], + }; } if (requestBody.type == "KPI8") { templateName = "KPI8"; reportName = "KPI8"; //use_filter - if (requestBody.profileId) { + if (requestBody.profileId) { const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation) .createQueryBuilder("kpiUserEvaluation") .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") @@ -834,10 +915,10 @@ export class ReportController extends Controller { .select("MIN(kpiUserEvaluation.id) as id") .getRawMany(); const userInfo = await this.kpiUserEvaluationRepository.find({ - where: { - id: In(profileEvaluationIds.map((x: any) => x.id)), - }, - }); + where: { + id: In(profileEvaluationIds.map((x: any) => x.id)), + }, + }); const userDevelopmentLists = await this.kpiUserDevelopmentRepository.find({ where: { kpiUserEvaluationId: In(profileEvaluationIds.map((x: any) => x.id)), @@ -856,57 +937,66 @@ export class ReportController extends Controller { "isDevelopment70", ], }); - - const formattedUserDevelopmentLists = userDevelopmentLists.map( - (development: any, index: number) => ({ - no: Extension.ToThaiNumber((index + 1).toString()), - ...development, - summary: development.summary - ? Extension.ToThaiNumber(development.summary.toString()) - : null, - point: development.point ? Extension.ToThaiNumber(development.point.toString()) : null, - }), - ); - - const fullNameParts = [userInfo[0]?.child4, userInfo[0]?.child3, userInfo[0]?.child2, userInfo[0]?.child1, userInfo[0]?.org]; - const affiliation = fullNameParts - .filter((part) => part !== undefined && part !== null) - .join("/"); - formattedData = { - fullName: userInfo - ? userInfo[0].prefix + userInfo[0].firstName + " " + userInfo[0].lastName + + const formattedUserDevelopmentLists = userDevelopmentLists.map( + (development: any, index: number) => ({ + no: Extension.ToThaiNumber((index + 1).toString()), + ...development, + summary: development.summary + ? Extension.ToThaiNumber(development.summary.toString()) : null, - affiliation: affiliation ?? null, - durationKPI: data?.durationKPI ?? null, - position: userInfo ? userInfo[0].position : null, - posType: userInfo ? userInfo[0].posTypeName : null, - posLevel: userInfo ? userInfo[0].posLevelName : null, - period1: Extension.ToThaiNumber(period1), - period2: Extension.ToThaiNumber(period2), - developments: formattedUserDevelopmentLists, - } || [{}]; + point: development.point ? Extension.ToThaiNumber(development.point.toString()) : null, + }), + ); + + const fullNameParts = [ + userInfo[0]?.child4, + userInfo[0]?.child3, + userInfo[0]?.child2, + userInfo[0]?.child1, + userInfo[0]?.org, + ]; + const affiliation = fullNameParts + .filter((part) => part !== undefined && part !== null) + .join("/"); + formattedData = { + fullName: userInfo + ? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName + : null, + affiliation: affiliation ?? null, + durationKPI: data?.durationKPI ?? null, + position: userInfo ? userInfo[0].position : null, + posType: userInfo ? userInfo[0].posTypeName : null, + posLevel: userInfo ? userInfo[0].posLevelName : null, + period1: Extension.ToThaiNumber(period1), + period2: Extension.ToThaiNumber(period2), + developments: formattedUserDevelopmentLists, + } || [{}]; } } if (requestBody.type == "KPI9") { templateName = "KPI9"; reportName = "KPI9"; formattedData = { - root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 - ? data?.kpiUserEvaluations[0].orgEvaluator - : "-", - period: data?.durationKPI == "APR" ? "๑": data?.durationKPI == "OCT" ? "๒" : "-", - year: data.year ? Extension.ToThaiNumber((data.year+543).toString()) : "-", - userEvaluations: data.kpiUserEvaluations.length > 0 - ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ - no: Extension.ToThaiNumber((idx + 1).toString()), - fullName: `${x.prefix}${x.firstName} ${x.lastName}`, - position: x.position ? x.position : "", - posLevelName: x.posLevelName ? x.posLevelName : "", - evaluationResults: x.evaluationResults ? Extension.EvaluationResult(x.evaluationResults) : "", - })) - : [{}] - , - } + root: + data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0 + ? data?.kpiUserEvaluations[0].orgEvaluator + : "-", + period: data?.durationKPI == "APR" ? "๑" : data?.durationKPI == "OCT" ? "๒" : "-", + year: data.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-", + userEvaluations: + data.kpiUserEvaluations.length > 0 + ? data.kpiUserEvaluations.map((x: any, idx: number) => ({ + no: Extension.ToThaiNumber((idx + 1).toString()), + fullName: `${x.prefix}${x.firstName} ${x.lastName}`, + position: x.position ? x.position : "", + posLevelName: x.posLevelName ? x.posLevelName : "", + evaluationResults: x.evaluationResults + ? Extension.EvaluationResult(x.evaluationResults) + : "", + })) + : [{}], + }; } return new HttpSuccess({ @@ -952,26 +1042,26 @@ export class ReportController extends Controller { startDateApr: kpiUserEvaluation.kpiPeriod == null || - kpiUserEvaluation.kpiPeriod.startDate == null || - kpiUserEvaluation.kpiPeriod.durationKPI != "APR" + kpiUserEvaluation.kpiPeriod.startDate == null || + kpiUserEvaluation.kpiPeriod.durationKPI != "APR" ? "-" : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate)), endDateApr: kpiUserEvaluation.kpiPeriod == null || - kpiUserEvaluation.kpiPeriod.endDate == null || - kpiUserEvaluation.kpiPeriod.durationKPI != "APR" + kpiUserEvaluation.kpiPeriod.endDate == null || + kpiUserEvaluation.kpiPeriod.durationKPI != "APR" ? "-" : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)), startDateOct: kpiUserEvaluation.kpiPeriod == null || - kpiUserEvaluation.kpiPeriod.startDate == null || - kpiUserEvaluation.kpiPeriod.durationKPI != "OCT" + kpiUserEvaluation.kpiPeriod.startDate == null || + kpiUserEvaluation.kpiPeriod.durationKPI != "OCT" ? "-" : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate)), endDateOct: kpiUserEvaluation.kpiPeriod == null || - kpiUserEvaluation.kpiPeriod.endDate == null || - kpiUserEvaluation.kpiPeriod.durationKPI != "OCT" + kpiUserEvaluation.kpiPeriod.endDate == null || + kpiUserEvaluation.kpiPeriod.durationKPI != "OCT" ? "-" : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)),