2024-08-21 22:09:46 +07:00
|
|
|
|
import { Controller, Get, Post, Route, Security, Tags, Body, Path, Request } from "tsoa";
|
2024-06-13 11:34:25 +07:00
|
|
|
|
import { AppDataSource } from "../database/data-source";
|
2024-08-30 16:32:13 +07:00
|
|
|
|
import { In, Not } from "typeorm";
|
2024-06-13 11:34:25 +07:00
|
|
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
|
|
|
|
import HttpError from "../interfaces/http-error";
|
|
|
|
|
|
import HttpStatusCode from "../interfaces/http-status";
|
2024-06-14 11:01:34 +07:00
|
|
|
|
import { KpiPeriod } from "../entities/kpiPeriod";
|
|
|
|
|
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
2024-06-14 14:15:30 +07:00
|
|
|
|
import Extension from "../interfaces/extension";
|
2024-07-10 18:34:23 +07:00
|
|
|
|
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
|
2024-07-11 14:58:07 +07:00
|
|
|
|
import CallAPI from "../interfaces/call-api";
|
2024-06-13 11:34:25 +07:00
|
|
|
|
@Route("api/v1/kpi/report")
|
|
|
|
|
|
@Tags("Report")
|
|
|
|
|
|
@Security("bearerAuth")
|
|
|
|
|
|
export class ReportController extends Controller {
|
2024-06-14 11:01:34 +07:00
|
|
|
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
|
|
|
|
|
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
2024-07-10 18:34:23 +07:00
|
|
|
|
private kpiUserDevelopmentRepository = AppDataSource.getRepository(KpiUserDevelopment);
|
2024-06-14 15:33:35 +07:00
|
|
|
|
|
|
|
|
|
|
@Post("announcement")
|
2024-06-14 11:01:34 +07:00
|
|
|
|
async GetReportAnnouncement(
|
2024-07-11 21:23:49 +07:00
|
|
|
|
@Request() request: { user: Record<string, any> },
|
2024-06-14 11:01:34 +07:00
|
|
|
|
@Body()
|
2024-06-14 15:33:35 +07:00
|
|
|
|
requestBody: {
|
2024-06-25 13:55:36 +07:00
|
|
|
|
type: string;
|
|
|
|
|
|
root?: string | null;
|
|
|
|
|
|
periodId?: string | null;
|
2024-06-27 17:35:13 +07:00
|
|
|
|
profileId?: string | null;
|
|
|
|
|
|
// filters?: string | null;
|
2024-06-27 18:20:23 +07:00
|
|
|
|
// keyword?: string | null;
|
2024-06-14 15:33:35 +07:00
|
|
|
|
},
|
2024-06-14 11:01:34 +07:00
|
|
|
|
) {
|
2024-06-25 13:55:36 +07:00
|
|
|
|
let templateName: any;
|
|
|
|
|
|
let reportName: any;
|
|
|
|
|
|
let formattedData: any;
|
2024-07-10 18:34:23 +07:00
|
|
|
|
|
|
|
|
|
|
//KPI1, KPI2, KPI3, KPI7, KPI9
|
|
|
|
|
|
let data: any;
|
2025-02-05 18:10:59 +07:00
|
|
|
|
let durationKpi_APR: string ="";
|
|
|
|
|
|
let durationKpi_OCT: string ="";
|
2024-07-11 17:32:25 +07:00
|
|
|
|
let dataKpiUserEvaluations: any;
|
2024-07-10 18:34:23 +07:00
|
|
|
|
let period1: any;
|
|
|
|
|
|
let period2: any;
|
2024-09-03 15:39:45 +07:00
|
|
|
|
let rootName: any;
|
2024-07-10 18:34:23 +07:00
|
|
|
|
if (requestBody.root && requestBody.periodId) {
|
2024-07-10 19:40:37 +07:00
|
|
|
|
data = await this.kpiPeriodRepository.findOne({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: { id: requestBody.periodId },
|
|
|
|
|
|
});
|
2025-02-05 18:10:59 +07:00
|
|
|
|
durationKpi_APR = data && data.durationKPI == "APR" ? `🗹` : `☐`
|
|
|
|
|
|
durationKpi_OCT = data && data.durationKPI == "OCT" ? `🗹` : `☐`
|
2024-07-10 19:40:37 +07:00
|
|
|
|
dataKpiUserEvaluations = await this.kpiUserEvaluationRepository.find({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: {
|
2024-07-11 10:14:50 +07:00
|
|
|
|
kpiPeriodId: requestBody.periodId,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
orgId: requestBody.root,
|
2024-08-21 22:09:46 +07:00
|
|
|
|
evaluationStatus: "KP7",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
},
|
|
|
|
|
|
});
|
2024-09-03 15:39:45 +07:00
|
|
|
|
await new CallAPI().GetData(request, `/org/root/${requestBody.root}`).then((x) => {
|
|
|
|
|
|
rootName = x.orgRootName;
|
|
|
|
|
|
});
|
2024-07-10 19:40:37 +07:00
|
|
|
|
data = {
|
|
|
|
|
|
id: data.id,
|
|
|
|
|
|
year: data.year,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
durationKPI: data.durationKPI,
|
2024-07-10 19:40:37 +07:00
|
|
|
|
startDate: data.startDate,
|
|
|
|
|
|
endDate: data.endDate,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
kpiUserEvaluations: dataKpiUserEvaluations,
|
2024-09-03 15:39:45 +07:00
|
|
|
|
rootName: rootName,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
};
|
2024-07-10 18:34:23 +07:00
|
|
|
|
|
2024-07-11 17:32:25 +07:00
|
|
|
|
if (data.durationKPI == "APR") {
|
2025-02-05 18:10:59 +07:00
|
|
|
|
period1 = `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`;
|
2024-07-10 18:34:23 +07:00
|
|
|
|
let _period2 = await this.kpiPeriodRepository.findOne({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: {
|
|
|
|
|
|
year: data.year,
|
|
|
|
|
|
durationKPI: "OCT",
|
|
|
|
|
|
},
|
2024-07-10 18:34:23 +07:00
|
|
|
|
});
|
2024-07-11 17:32:25 +07:00
|
|
|
|
period2 = _period2
|
2025-02-05 18:10:59 +07:00
|
|
|
|
? `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
|
|
|
|
|
|
: `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ๑ เมษายน ${Extension.ToThaiYear(data.year)} ถึง ๓๑ กันยายน ${Extension.ToThaiYear(data.year)}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (data.durationKPI == "OCT") {
|
|
|
|
|
|
period2 = `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`;
|
2024-07-10 18:34:23 +07:00
|
|
|
|
let _period1 = await this.kpiPeriodRepository.findOne({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: {
|
|
|
|
|
|
year: data.year,
|
|
|
|
|
|
durationKPI: "APR",
|
|
|
|
|
|
},
|
2024-07-10 18:34:23 +07:00
|
|
|
|
});
|
2024-07-11 17:32:25 +07:00
|
|
|
|
period1 = _period1
|
2025-02-05 18:10:59 +07:00
|
|
|
|
? `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
|
|
|
|
|
|
: `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ๑ ตุลาคม ${Extension.ToThaiYear(data.year-1)} ถึง ๓๑ มีนาคม ${Extension.ToThaiYear(data.year)}`;
|
2024-07-10 18:34:23 +07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-25 13:55:36 +07:00
|
|
|
|
if (requestBody.type == "KPI1") {
|
|
|
|
|
|
templateName = "KPI1";
|
|
|
|
|
|
reportName = "KPI1";
|
2024-07-11 17:32:25 +07:00
|
|
|
|
/*ROOT*/
|
2024-07-10 18:34:23 +07:00
|
|
|
|
const userEvaluationOrg = await this.kpiUserEvaluationRepository.find({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: {
|
2024-07-16 13:41:02 +07:00
|
|
|
|
orgId: String(requestBody?.root),
|
2024-08-21 22:09:46 +07:00
|
|
|
|
kpiPeriodId: String(requestBody?.periodId),
|
2024-07-11 17:32:25 +07:00
|
|
|
|
},
|
2024-07-10 18:34:23 +07:00
|
|
|
|
});
|
2024-07-11 17:32:25 +07:00
|
|
|
|
const resultAll =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.length.toString())
|
|
|
|
|
|
: "๐";
|
|
|
|
|
|
const result =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(
|
2024-08-21 22:09:46 +07:00
|
|
|
|
userEvaluationOrg.filter((x: any) => x.evaluationStatus == "KP7").length.toString(),
|
2024-07-11 17:32:25 +07:00
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
|
|
|
|
|
const excellent =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(
|
|
|
|
|
|
userEvaluationOrg
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.filter(
|
|
|
|
|
|
(x: any) => x.evaluationResults == "EXCELLENT" && x.evaluationStatus == "KP7",
|
|
|
|
|
|
)
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.length.toString(),
|
|
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
|
|
|
|
|
const verygood =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(
|
|
|
|
|
|
userEvaluationOrg
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.filter(
|
|
|
|
|
|
(x: any) => x.evaluationResults == "VERY_GOOD" && x.evaluationStatus == "KP7",
|
|
|
|
|
|
)
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.length.toString(),
|
|
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
|
|
|
|
|
const good =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(
|
2024-07-16 13:41:02 +07:00
|
|
|
|
userEvaluationOrg
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "GOOD" && x.evaluationStatus == "KP7")
|
|
|
|
|
|
.length.toString(),
|
2024-07-11 17:32:25 +07:00
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
|
|
|
|
|
const fair =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(
|
2024-07-16 13:41:02 +07:00
|
|
|
|
userEvaluationOrg
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "FAIR" && x.evaluationStatus == "KP7")
|
|
|
|
|
|
.length.toString(),
|
2024-07-11 17:32:25 +07:00
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
|
|
|
|
|
const improvment =
|
|
|
|
|
|
userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(
|
|
|
|
|
|
userEvaluationOrg
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.filter(
|
|
|
|
|
|
(x: any) => x.evaluationResults == "IMPROVEMENT" && x.evaluationStatus == "KP7",
|
|
|
|
|
|
)
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.length.toString(),
|
|
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
2024-07-10 18:34:23 +07:00
|
|
|
|
/*END ROOT*/
|
|
|
|
|
|
formattedData = {
|
2024-07-11 17:32:25 +07:00
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
durationKPI: data?.durationKPI,
|
2024-09-03 15:39:45 +07:00
|
|
|
|
root: data && data.rootName != null ? data.rootName : "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
userEvaluations: [
|
|
|
|
|
|
{
|
2024-08-26 13:46:45 +07:00
|
|
|
|
no: userEvaluationOrg.length > 0 ? "๑" : "-",
|
|
|
|
|
|
root: data && data.rootName != null ? data.rootName : "-",
|
|
|
|
|
|
resultAll: userEvaluationOrg.length > 0 ? resultAll : "-",
|
|
|
|
|
|
result: userEvaluationOrg.length > 0 ? result : "-",
|
|
|
|
|
|
excellent: userEvaluationOrg.length > 0 ? excellent : "-",
|
|
|
|
|
|
verygood: userEvaluationOrg.length > 0 ? verygood : "-",
|
|
|
|
|
|
good: userEvaluationOrg.length > 0 ? good : "-",
|
|
|
|
|
|
fair: userEvaluationOrg.length > 0 ? fair : "-",
|
|
|
|
|
|
improvment: userEvaluationOrg.length > 0 ? improvment : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-08-26 13:46:45 +07:00
|
|
|
|
resultAll_: userEvaluationOrg.length > 0 ? resultAll : "-",
|
|
|
|
|
|
result_: userEvaluationOrg.length > 0 ? result : "-",
|
|
|
|
|
|
excellent_: userEvaluationOrg.length > 0 ? excellent : "-",
|
|
|
|
|
|
verygood_: userEvaluationOrg.length > 0 ? verygood : "-",
|
|
|
|
|
|
good_: userEvaluationOrg.length > 0 ? good : "-",
|
|
|
|
|
|
fair_: userEvaluationOrg.length > 0 ? fair : "-",
|
|
|
|
|
|
improvment_: userEvaluationOrg.length > 0 ? improvment : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
};
|
2024-06-14 11:01:34 +07:00
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
if (requestBody.type == "KPI2") {
|
|
|
|
|
|
templateName = "KPI2";
|
|
|
|
|
|
reportName = "KPI2";
|
2024-07-11 17:32:25 +07:00
|
|
|
|
const excellent =
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations
|
2024-07-16 13:41:02 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "EXCELLENT")
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.map((x: any, idx: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
|
|
|
|
|
org: x.org ? x.org : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
}))
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-07-11 17:32:25 +07:00
|
|
|
|
const verygood =
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations
|
2024-07-16 13:41:02 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "VERY_GOOD")
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.map((x: any, idx: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
|
|
|
|
|
org: x.org ? x.org : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
}))
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-07-11 17:32:25 +07:00
|
|
|
|
const good =
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations
|
2024-07-16 13:41:02 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "GOOD")
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.map((x: any, idx: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
|
|
|
|
|
org: x.org ? x.org : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
}))
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-07-11 17:32:25 +07:00
|
|
|
|
const fair =
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations
|
2024-07-16 13:41:02 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "FAIR")
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.map((x: any, idx: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
|
|
|
|
|
org: x.org ? x.org : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
}))
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-07-11 17:32:25 +07:00
|
|
|
|
const improvment =
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations
|
2024-07-16 13:41:02 +07:00
|
|
|
|
.filter((x: any) => x.evaluationResults == "IMPROVEMENT")
|
2024-07-11 17:32:25 +07:00
|
|
|
|
.map((x: any, idx: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
|
|
|
|
|
org: x.org ? x.org : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
}))
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-07-10 18:34:23 +07:00
|
|
|
|
formattedData = {
|
2024-07-11 17:32:25 +07:00
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
durationKPI: data?.durationKPI,
|
2024-09-03 15:39:45 +07:00
|
|
|
|
root: data && data.rootName != null ? data.rootName : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
excellents: {
|
|
|
|
|
|
count:
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(excellent.length.toString())
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "๐",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
data:
|
|
|
|
|
|
excellent.length > 0
|
|
|
|
|
|
? excellent
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-10 18:34:23 +07:00
|
|
|
|
},
|
2024-07-11 17:32:25 +07:00
|
|
|
|
verygoods: {
|
|
|
|
|
|
count:
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(verygood.length.toString())
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "๐",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
data:
|
|
|
|
|
|
verygood.length > 0
|
|
|
|
|
|
? verygood
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-10 18:34:23 +07:00
|
|
|
|
},
|
2024-07-11 17:32:25 +07:00
|
|
|
|
goods: {
|
|
|
|
|
|
count:
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(good.length.toString())
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "๐",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
data:
|
|
|
|
|
|
good.length > 0
|
|
|
|
|
|
? good
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-10 18:34:23 +07:00
|
|
|
|
},
|
2024-07-11 17:32:25 +07:00
|
|
|
|
fairs: {
|
|
|
|
|
|
count:
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(fair.length.toString())
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "๐",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
data:
|
|
|
|
|
|
fair.length > 0
|
|
|
|
|
|
? fair
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-10 18:34:23 +07:00
|
|
|
|
},
|
2024-07-11 17:32:25 +07:00
|
|
|
|
improvments: {
|
|
|
|
|
|
count:
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(improvment.length.toString())
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "๐",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
data:
|
|
|
|
|
|
improvment.length > 0
|
|
|
|
|
|
? improvment
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
org: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-10 18:34:23 +07:00
|
|
|
|
},
|
2024-07-11 17:32:25 +07:00
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI3") {
|
|
|
|
|
|
templateName = "KPI3";
|
|
|
|
|
|
reportName = "KPI3";
|
2025-02-11 19:34:50 +07:00
|
|
|
|
const groupedEvaluations: any[] = [];
|
|
|
|
|
|
let fullNameCommander: string = "-";
|
|
|
|
|
|
let positionCommander: string = "-";
|
|
|
|
|
|
let posTypeNameCommander: string = "-";
|
|
|
|
|
|
let posLevelNameCommander: string = "-";
|
|
|
|
|
|
let orgCommander: string = "-";
|
|
|
|
|
|
let fullNameCommanderHigh: string = "-";
|
|
|
|
|
|
let positionCommanderHigh: string = "-";
|
|
|
|
|
|
let posTypeNameCommanderHigh: string = "-";
|
|
|
|
|
|
let posLevelNameCommanderHigh: string = "-";
|
|
|
|
|
|
let orgCommanderHigh: string = "-";
|
|
|
|
|
|
let idx:number=0
|
|
|
|
|
|
for (const x of data?.kpiUserEvaluations || []) {
|
|
|
|
|
|
let group = groupedEvaluations.find(
|
|
|
|
|
|
(g) =>
|
|
|
|
|
|
g.evaluatorId === x.evaluatorId &&
|
|
|
|
|
|
g.commanderId === x.commanderId &&
|
|
|
|
|
|
g.commanderHighId === x.commanderHighId
|
|
|
|
|
|
);
|
|
|
|
|
|
if (x.commanderId != "" && x.commanderId != null) {
|
|
|
|
|
|
await new CallAPI()
|
|
|
|
|
|
.GetData(request, "/org/profile/profileid/position/" + x.commanderId)
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
fullNameCommander = `${res.prefix}${res.firstName} ${res.lastName}`;
|
|
|
|
|
|
positionCommander = res.position;
|
|
|
|
|
|
posTypeNameCommander = res.posTypeName;
|
|
|
|
|
|
posLevelNameCommander = res.posLevelName;
|
|
|
|
|
|
orgCommander = res.root;
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (x.commanderHighId != "" && x.commanderHighId != null) {
|
|
|
|
|
|
await new CallAPI()
|
|
|
|
|
|
.GetData(request, "/org/profile/profileid/position/" + x.commanderHighId)
|
|
|
|
|
|
.then((res) => {
|
|
|
|
|
|
fullNameCommanderHigh = `${res.prefix}${res.firstName} ${res.lastName}`;
|
|
|
|
|
|
positionCommanderHigh = res.position;
|
|
|
|
|
|
posTypeNameCommanderHigh = res.posTypeName;
|
|
|
|
|
|
posLevelNameCommanderHigh = res.posLevelName;
|
|
|
|
|
|
orgCommanderHigh = res.root;
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!group) {
|
|
|
|
|
|
group = {
|
|
|
|
|
|
evaluatorId: x.evaluatorId,
|
|
|
|
|
|
commanderId: x.commanderId,
|
|
|
|
|
|
commanderHighId: x.commanderHighId,
|
|
|
|
|
|
fullNameEvaluator: `${x.prefixEvaluator}${x.firstNameEvaluator} ${x.lastNameEvaluator}`,
|
|
|
|
|
|
positionEvaluator: x.positionEvaluator,
|
|
|
|
|
|
posTypeNameEvaluator: x.posTypeNameEvaluator,
|
|
|
|
|
|
posLevelNameEvaluator: x.posLevelNameEvaluator,
|
|
|
|
|
|
orgEvaluator: x.orgEvaluator,
|
|
|
|
|
|
fullNameCommander: fullNameCommander,
|
|
|
|
|
|
positionCommander: positionCommander,
|
|
|
|
|
|
posTypeNameCommander: posTypeNameCommander,
|
|
|
|
|
|
posLevelNameCommander: posLevelNameCommander,
|
|
|
|
|
|
orgCommander: orgCommander,
|
|
|
|
|
|
fullNameCommanderHigh: fullNameCommanderHigh,
|
|
|
|
|
|
positionCommanderHigh: positionCommanderHigh,
|
|
|
|
|
|
posTypeNameCommanderHigh: posTypeNameCommanderHigh,
|
|
|
|
|
|
posLevelNameCommanderHigh: posLevelNameCommanderHigh,
|
|
|
|
|
|
orgCommanderHigh: orgCommanderHigh,
|
|
|
|
|
|
evaluationResults: [],
|
|
|
|
|
|
};
|
|
|
|
|
|
groupedEvaluations.push(group);
|
|
|
|
|
|
}
|
|
|
|
|
|
group.evaluationResults.push({
|
|
|
|
|
|
no: idx != null ? Extension.ToThaiNumber((idx + 1).toString()) : "-",
|
|
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${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: x.reasonEvaluator,
|
|
|
|
|
|
});
|
|
|
|
|
|
idx ++;
|
2024-07-11 21:23:49 +07:00
|
|
|
|
}
|
2025-02-11 19:34:50 +07:00
|
|
|
|
const _userEvaluations = groupedEvaluations.length > 0
|
|
|
|
|
|
? groupedEvaluations
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
evaluatorId: "-",
|
|
|
|
|
|
commanderId: "-",
|
|
|
|
|
|
commanderHighId: "-",
|
|
|
|
|
|
fullNameEvaluator: "-",
|
|
|
|
|
|
positionEvaluator: "-",
|
|
|
|
|
|
posTypeNameEvaluator: "-",
|
|
|
|
|
|
posLevelNameEvaluator: "-",
|
|
|
|
|
|
orgEvaluator: "-",
|
|
|
|
|
|
fullNameCommander: "-",
|
|
|
|
|
|
positionCommander: "-",
|
|
|
|
|
|
posTypeNameCommander: "-",
|
|
|
|
|
|
posLevelNameCommander: "-",
|
|
|
|
|
|
orgCommander: "-",
|
|
|
|
|
|
fullNameCommanderHigh: "-",
|
|
|
|
|
|
positionCommanderHigh: "-",
|
|
|
|
|
|
posTypeNameCommanderHigh: "-",
|
|
|
|
|
|
posLevelNameCommanderHigh: "-",
|
|
|
|
|
|
orgCommanderHigh: "-",
|
|
|
|
|
|
evaluationResults: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
point1: "-",
|
|
|
|
|
|
point2: "-",
|
|
|
|
|
|
point3: "-",
|
|
|
|
|
|
point4: "-",
|
|
|
|
|
|
point5: "-",
|
|
|
|
|
|
remark: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-07-10 18:34:23 +07:00
|
|
|
|
formattedData = {
|
2024-07-12 09:30:37 +07:00
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
2025-02-11 19:34:50 +07:00
|
|
|
|
evaluations: _userEvaluations,
|
2024-07-12 09:30:37 +07:00
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI4") {
|
|
|
|
|
|
templateName = "KPI4";
|
|
|
|
|
|
reportName = "KPI4";
|
2024-07-15 16:43:34 +07:00
|
|
|
|
let combinedDatas: any;
|
2024-07-11 14:58:07 +07:00
|
|
|
|
if (requestBody.profileId) {
|
|
|
|
|
|
const profileEvaluationNowYearIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-15 16:43:34 +07:00
|
|
|
|
.where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
2024-07-16 13:46:41 +07:00
|
|
|
|
.andWhere("kpiUserEvaluation.evaluationStatus = :evaluationStatus", {
|
|
|
|
|
|
evaluationStatus: "KP7",
|
|
|
|
|
|
})
|
2024-07-11 14:58:07 +07:00
|
|
|
|
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
2025-02-06 13:05:38 +07:00
|
|
|
|
// .select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
.select([
|
|
|
|
|
|
"kpiUserEvaluation.kpiPeriodId as kpiPeriodId",
|
|
|
|
|
|
"AVG(kpiUserEvaluation.summaryPoint) as avgSummaryPoint"
|
|
|
|
|
|
])
|
2024-07-11 14:58:07 +07:00
|
|
|
|
.getRawMany();
|
|
|
|
|
|
|
2025-02-06 13:05:38 +07:00
|
|
|
|
// const profileEvaluations = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
// relations: ["kpiPeriod"],
|
|
|
|
|
|
// where: { id: In(profileEvaluationNowYearIds.map((evaluation) => evaluation.id)) },
|
|
|
|
|
|
// });
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const profileEvaluations = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
2025-02-06 13:05:38 +07:00
|
|
|
|
where: {
|
|
|
|
|
|
kpiPeriodId: In(profileEvaluationNowYearIds.map((evaluation) => evaluation.kpiPeriodId)),
|
|
|
|
|
|
profileId: requestBody.profileId,
|
|
|
|
|
|
evaluationStatus: "KP7"
|
|
|
|
|
|
},
|
2024-08-21 22:09:46 +07:00
|
|
|
|
});
|
2024-07-11 14:58:07 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const groupedEvaluations = profileEvaluations.reduce((acc: any, evaluation: any) => {
|
|
|
|
|
|
const year = evaluation.kpiPeriod.year;
|
|
|
|
|
|
const profileId = evaluation.profileId;
|
|
|
|
|
|
const key = `${profileId}-${year}`;
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (!acc[key]) {
|
|
|
|
|
|
acc[key] = {
|
|
|
|
|
|
fullName: evaluation.prefix + evaluation.firstName + " " + evaluation.lastName,
|
|
|
|
|
|
profileId: profileId,
|
|
|
|
|
|
year: year ? Extension.ToThaiNumber(Extension.ToThaiYear(year).toString()) : null,
|
|
|
|
|
|
evaluations: [],
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-02-06 13:05:38 +07:00
|
|
|
|
const avgSummaryPoint = profileEvaluationNowYearIds.find(
|
|
|
|
|
|
(e) => e.kpiPeriodId === evaluation.kpiPeriodId
|
|
|
|
|
|
)?.avgSummaryPoint;
|
|
|
|
|
|
|
|
|
|
|
|
evaluation.summaryPoint = avgSummaryPoint;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc[key].evaluations.push(evaluation);
|
|
|
|
|
|
return acc;
|
|
|
|
|
|
}, {});
|
2024-07-11 14:58:07 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
// สร้าง formatData
|
|
|
|
|
|
combinedDatas = Object.values(groupedEvaluations).map((group: any) => {
|
|
|
|
|
|
const data: any = {
|
|
|
|
|
|
fullName: group.fullName ?? null,
|
|
|
|
|
|
year: group.year ?? null,
|
|
|
|
|
|
};
|
2024-07-11 14:58:07 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
group.evaluations.forEach((evaluation: any) => {
|
|
|
|
|
|
if (evaluation.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
data.summaryPointAPR1 =
|
|
|
|
|
|
evaluation.summaryPoint >= 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointAPR2 =
|
|
|
|
|
|
evaluation.summaryPoint >= 80 && evaluation.summaryPoint < 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointAPR3 =
|
|
|
|
|
|
evaluation.summaryPoint >= 70 && evaluation.summaryPoint < 80
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointAPR4 =
|
|
|
|
|
|
evaluation.summaryPoint >= 60 && evaluation.summaryPoint < 70
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointAPR5 =
|
|
|
|
|
|
evaluation.summaryPoint < 60
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
|
|
|
|
|
data.periodAPR = evaluation.kpiPeriod.durationKPI ?? "-";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (evaluation.kpiPeriod.durationKPI === "OCT") {
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointOCT1 =
|
|
|
|
|
|
evaluation.summaryPoint >= 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointOCT2 =
|
|
|
|
|
|
evaluation.summaryPoint >= 80 && evaluation.summaryPoint < 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointOCT3 =
|
|
|
|
|
|
evaluation.summaryPoint >= 70 && evaluation.summaryPoint < 80
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointOCT4 =
|
|
|
|
|
|
evaluation.summaryPoint >= 60 && evaluation.summaryPoint < 70
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
data.summaryPointOCT5 =
|
|
|
|
|
|
evaluation.summaryPoint < 60
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: "-";
|
|
|
|
|
|
data.periodOCT = evaluation.kpiPeriod.durationKPI ?? "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
return data;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
formattedData = {
|
|
|
|
|
|
combinedDatas: combinedDatas.length > 0 ? combinedDatas : [{}],
|
|
|
|
|
|
fullName: combinedDatas.length > 0 ? combinedDatas[0]["fullName"] : "-",
|
|
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI5") {
|
|
|
|
|
|
templateName = "KPI5";
|
|
|
|
|
|
reportName = "KPI5";
|
2024-07-11 14:58:07 +07:00
|
|
|
|
interface KPIData {
|
|
|
|
|
|
fullName: string | null;
|
|
|
|
|
|
position: string | null;
|
|
|
|
|
|
posType: string | null;
|
|
|
|
|
|
posLevel: string | null;
|
|
|
|
|
|
affiliation: string | null;
|
|
|
|
|
|
summaryPointAPR1: string | null;
|
|
|
|
|
|
textPointAPR1: string | null;
|
|
|
|
|
|
periodAPR1: string | null;
|
|
|
|
|
|
yearAPR1: string | null;
|
|
|
|
|
|
summaryPointOCT1: string | null;
|
|
|
|
|
|
textPointOCT1: string | null;
|
|
|
|
|
|
periodOCT1: string | null;
|
|
|
|
|
|
yearOCT1: string | null;
|
|
|
|
|
|
summaryPointAPR2: string | null;
|
|
|
|
|
|
textPointAPR2: string | null;
|
|
|
|
|
|
periodAPR2: string | null;
|
|
|
|
|
|
yearAPR2: string | null;
|
|
|
|
|
|
summaryPointOCT2: string | null;
|
|
|
|
|
|
textPointOCT2: string | null;
|
|
|
|
|
|
periodOCT2: string | null;
|
|
|
|
|
|
yearOCT2: string | null;
|
|
|
|
|
|
summaryPointAPR3: string | null;
|
|
|
|
|
|
textPointAPR3: string | null;
|
|
|
|
|
|
periodAPR3: string | null;
|
|
|
|
|
|
yearAPR3: string | null;
|
|
|
|
|
|
summaryPointOCT3: string | null;
|
|
|
|
|
|
textPointOCT3: string | null;
|
|
|
|
|
|
periodOCT3: string | null;
|
|
|
|
|
|
yearOCT3: string | null;
|
|
|
|
|
|
summaryPointAPR4: string | null;
|
|
|
|
|
|
textPointAPR4: string | null;
|
|
|
|
|
|
periodAPR4: string | null;
|
|
|
|
|
|
yearAPR4: string | null;
|
|
|
|
|
|
summaryPointOCT4: string | null;
|
|
|
|
|
|
textPointOCT4: string | null;
|
|
|
|
|
|
periodOCT4: string | null;
|
|
|
|
|
|
yearOCT4: string | null;
|
|
|
|
|
|
summaryPointAPR5: string | null;
|
|
|
|
|
|
textPointAPR5: string | null;
|
|
|
|
|
|
periodAPR5: string | null;
|
|
|
|
|
|
yearAPR5: string | null;
|
|
|
|
|
|
summaryPointOCT5: string | null;
|
|
|
|
|
|
textPointOCT5: string | null;
|
|
|
|
|
|
periodOCT5: string | null;
|
|
|
|
|
|
yearOCT5: string | null;
|
|
|
|
|
|
year1: string | null;
|
|
|
|
|
|
year2: string | null;
|
|
|
|
|
|
year3: string | null;
|
|
|
|
|
|
year4: string | null;
|
|
|
|
|
|
year5: string | null;
|
|
|
|
|
|
}
|
|
|
|
|
|
const yearNow = new Date().getFullYear();
|
2025-02-06 14:53:01 +07:00
|
|
|
|
let _summaryPointApr: number[] = [];
|
|
|
|
|
|
let _summaryPointOct: number[] = [];
|
2024-07-11 14:58:07 +07:00
|
|
|
|
if (requestBody.profileId) {
|
|
|
|
|
|
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-15 17:19:38 +07:00
|
|
|
|
.where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
2024-07-16 13:46:41 +07:00
|
|
|
|
.andWhere("kpiUserEvaluation.evaluationStatus = :evaluationStatus", {
|
|
|
|
|
|
evaluationStatus: "KP7",
|
|
|
|
|
|
})
|
2024-07-11 14:58:07 +07:00
|
|
|
|
.andWhere("kpiPeriod.year BETWEEN :startYear AND :endYear", {
|
|
|
|
|
|
startYear: yearNow - 4,
|
|
|
|
|
|
endYear: yearNow,
|
|
|
|
|
|
})
|
|
|
|
|
|
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
|
|
|
|
|
.select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
.getRawMany();
|
2025-02-05 18:10:59 +07:00
|
|
|
|
|
2025-02-06 14:53:01 +07:00
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
|
|
let _calAvg = await this.kpiUserEvaluationRepository
|
|
|
|
|
|
.createQueryBuilder("evaluation")
|
|
|
|
|
|
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
|
|
|
|
|
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
|
|
|
|
|
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
|
|
|
|
|
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
|
|
|
|
|
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "APR" })
|
|
|
|
|
|
.select("AVG(evaluation.summaryPoint)", "average")
|
|
|
|
|
|
.getRawOne();
|
|
|
|
|
|
_summaryPointApr.push(_calAvg.average);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
|
|
let _calAvg = await this.kpiUserEvaluationRepository
|
|
|
|
|
|
.createQueryBuilder("evaluation")
|
|
|
|
|
|
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
|
|
|
|
|
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
|
|
|
|
|
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
|
|
|
|
|
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
|
|
|
|
|
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "OCT" })
|
|
|
|
|
|
.select("AVG(evaluation.summaryPoint)", "average")
|
|
|
|
|
|
.getRawOne();
|
|
|
|
|
|
_summaryPointOct.push(_calAvg.average);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
|
|
|
|
|
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
|
|
|
|
|
});
|
2024-07-11 14:58:07 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const combinedData: KPIData = profileEvaluation.reduce(
|
|
|
|
|
|
(acc: KPIData, x) => {
|
|
|
|
|
|
const fullNameParts = [x.child4, x.child3, x.child2, x.child1, x.org];
|
2025-02-05 18:10:59 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const affiliation = fullNameParts
|
|
|
|
|
|
.filter((part) => part !== undefined && part !== null)
|
2025-02-06 15:53:51 +07:00
|
|
|
|
.join(" ");
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (!acc.fullName) {
|
|
|
|
|
|
acc.fullName = x.prefix + " " + x.firstName + " " + x.lastName;
|
|
|
|
|
|
acc.position = x.position;
|
|
|
|
|
|
acc.posType = x.posTypeName;
|
|
|
|
|
|
acc.posLevel = x.posLevelName;
|
2025-02-06 13:05:38 +07:00
|
|
|
|
acc.affiliation = affiliation == "" || affiliation == null ? "-" : affiliation;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
|
|
|
|
|
acc.fullName = "-";
|
|
|
|
|
|
acc.position = "-";
|
|
|
|
|
|
acc.posType = "-";
|
|
|
|
|
|
acc.posLevel = "-";
|
|
|
|
|
|
acc.affiliation = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR1 = _summaryPointApr.length > 4
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[4].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR1 = _summaryPointApr.length > 4 ? Extension.textPoint(_summaryPointApr[4]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR1 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR1 = "-";
|
|
|
|
|
|
acc.textPointAPR1 = "-";
|
|
|
|
|
|
acc.periodAPR1 = "-";
|
|
|
|
|
|
acc.yearAPR1 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT1 = _summaryPointOct.length > 4
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[4].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT1 = _summaryPointOct.length > 4 ? Extension.textPoint(_summaryPointOct[4]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT1 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT1 = "-";
|
|
|
|
|
|
acc.textPointOCT1 = "-";
|
|
|
|
|
|
acc.periodOCT1 = "-";
|
|
|
|
|
|
acc.yearOCT1 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR2 = _summaryPointApr.length > 3
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[3].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR2 = _summaryPointApr.length > 3 ? Extension.textPoint(_summaryPointApr[3]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR2 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR2 = "-";
|
|
|
|
|
|
acc.textPointAPR2 = "-";
|
|
|
|
|
|
acc.periodAPR2 = "-";
|
|
|
|
|
|
acc.yearAPR2 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT2 = _summaryPointOct.length > 3
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[3].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT2 = _summaryPointOct.length > 3 ? Extension.textPoint(_summaryPointOct[3]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT2 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT2 = "-";
|
|
|
|
|
|
acc.textPointOCT2 = "-";
|
|
|
|
|
|
acc.periodOCT2 = "-";
|
|
|
|
|
|
acc.yearOCT2 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR3 = _summaryPointApr.length > 2
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[2].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR3 = _summaryPointApr.length > 2 ? Extension.textPoint(_summaryPointApr[2]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR3 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR3 = "-";
|
|
|
|
|
|
acc.textPointAPR3 = "-";
|
|
|
|
|
|
acc.periodAPR3 = "-";
|
|
|
|
|
|
acc.yearAPR3 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT3 = _summaryPointOct.length > 2
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[2].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT3 = _summaryPointOct.length > 2 ? Extension.textPoint(_summaryPointOct[2]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT3 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT3 = "-";
|
|
|
|
|
|
acc.textPointOCT3 = "-";
|
|
|
|
|
|
acc.periodOCT3 = "-";
|
|
|
|
|
|
acc.yearOCT3 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR4 = _summaryPointApr.length > 1
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[1].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR4 = _summaryPointApr.length > 1 ? Extension.textPoint(_summaryPointApr[1]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR4 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR4 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR4 = "-";
|
|
|
|
|
|
acc.textPointAPR4 = "-";
|
|
|
|
|
|
acc.periodAPR4 = "-";
|
|
|
|
|
|
acc.yearAPR4 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT4 = _summaryPointOct.length > 1
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[1].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT4 = _summaryPointOct.length > 1 ? Extension.textPoint(_summaryPointOct[1]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT4 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT4 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT4 = "-";
|
|
|
|
|
|
acc.textPointOCT4 = "-";
|
|
|
|
|
|
acc.periodOCT4 = "-";
|
|
|
|
|
|
acc.yearOCT4 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR5 = _summaryPointApr.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[0].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR5 = _summaryPointApr.length > 0 ? Extension.textPoint(_summaryPointApr[0]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR5 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR5 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR5 = "-";
|
|
|
|
|
|
acc.textPointAPR5 = "-";
|
|
|
|
|
|
acc.periodAPR5 = "-";
|
|
|
|
|
|
acc.yearAPR5 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT5 = _summaryPointOct.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[0].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT5 = _summaryPointOct.length > 0 ? Extension.textPoint(_summaryPointOct[0]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT5 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT5 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT5 = "-";
|
|
|
|
|
|
acc.textPointOCT5 = "-";
|
|
|
|
|
|
acc.periodOCT5 = "-";
|
|
|
|
|
|
acc.yearOCT5 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
return acc;
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
fullName: null,
|
|
|
|
|
|
position: null,
|
|
|
|
|
|
posType: null,
|
|
|
|
|
|
posLevel: null,
|
|
|
|
|
|
affiliation: null,
|
|
|
|
|
|
summaryPointAPR1: null,
|
|
|
|
|
|
textPointAPR1: null,
|
|
|
|
|
|
periodAPR1: null,
|
|
|
|
|
|
yearAPR1: null,
|
|
|
|
|
|
summaryPointOCT1: null,
|
|
|
|
|
|
textPointOCT1: null,
|
|
|
|
|
|
periodOCT1: null,
|
|
|
|
|
|
yearOCT1: null,
|
|
|
|
|
|
summaryPointAPR2: null,
|
|
|
|
|
|
textPointAPR2: null,
|
|
|
|
|
|
periodAPR2: null,
|
|
|
|
|
|
yearAPR2: null,
|
|
|
|
|
|
summaryPointOCT2: null,
|
|
|
|
|
|
textPointOCT2: null,
|
|
|
|
|
|
periodOCT2: null,
|
|
|
|
|
|
yearOCT2: null,
|
|
|
|
|
|
summaryPointAPR3: null,
|
|
|
|
|
|
textPointAPR3: null,
|
|
|
|
|
|
periodAPR3: null,
|
|
|
|
|
|
yearAPR3: null,
|
|
|
|
|
|
summaryPointOCT3: null,
|
|
|
|
|
|
textPointOCT3: null,
|
|
|
|
|
|
periodOCT3: null,
|
|
|
|
|
|
yearOCT3: null,
|
|
|
|
|
|
summaryPointAPR4: null,
|
|
|
|
|
|
textPointAPR4: null,
|
|
|
|
|
|
periodAPR4: null,
|
|
|
|
|
|
yearAPR4: null,
|
|
|
|
|
|
summaryPointOCT4: null,
|
|
|
|
|
|
textPointOCT4: null,
|
|
|
|
|
|
periodOCT4: null,
|
|
|
|
|
|
yearOCT4: null,
|
|
|
|
|
|
summaryPointAPR5: null,
|
|
|
|
|
|
textPointAPR5: null,
|
|
|
|
|
|
periodAPR5: null,
|
|
|
|
|
|
yearAPR5: null,
|
|
|
|
|
|
summaryPointOCT5: null,
|
|
|
|
|
|
textPointOCT5: null,
|
|
|
|
|
|
periodOCT5: null,
|
|
|
|
|
|
yearOCT5: null,
|
|
|
|
|
|
year1: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 4).toString()),
|
|
|
|
|
|
year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 3).toString()),
|
|
|
|
|
|
year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 2).toString()),
|
|
|
|
|
|
year4: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()),
|
|
|
|
|
|
year5: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()),
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2024-09-03 15:39:45 +07:00
|
|
|
|
formattedData =
|
|
|
|
|
|
profileEvaluation.length > 0
|
|
|
|
|
|
? combinedData
|
|
|
|
|
|
: {
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posType: "-",
|
|
|
|
|
|
posLevel: "-",
|
|
|
|
|
|
affiliation: "-",
|
|
|
|
|
|
summaryPointAPR1: "-",
|
|
|
|
|
|
textPointAPR1: "-",
|
|
|
|
|
|
periodAPR1: "-",
|
|
|
|
|
|
yearAPR1: "-",
|
|
|
|
|
|
summaryPointOCT1: "-",
|
|
|
|
|
|
textPointOCT1: "-",
|
|
|
|
|
|
periodOCT1: "-",
|
|
|
|
|
|
yearOCT1: "-",
|
|
|
|
|
|
summaryPointAPR2: "-",
|
|
|
|
|
|
textPointAPR2: "-",
|
|
|
|
|
|
periodAPR2: "-",
|
|
|
|
|
|
yearAPR2: "-",
|
|
|
|
|
|
summaryPointOCT2: "-",
|
|
|
|
|
|
textPointOCT2: "-",
|
|
|
|
|
|
periodOCT2: "-",
|
|
|
|
|
|
yearOCT2: "-",
|
|
|
|
|
|
summaryPointAPR3: "-",
|
|
|
|
|
|
textPointAPR3: "-",
|
|
|
|
|
|
periodAPR3: "-",
|
|
|
|
|
|
yearAPR3: "-",
|
|
|
|
|
|
summaryPointOCT3: "-",
|
|
|
|
|
|
textPointOCT3: "-",
|
|
|
|
|
|
periodOCT3: "-",
|
|
|
|
|
|
yearOCT3: "-",
|
|
|
|
|
|
summaryPointAPR4: "-",
|
|
|
|
|
|
textPointAPR4: "-",
|
|
|
|
|
|
periodAPR4: "-",
|
|
|
|
|
|
yearAPR4: "-",
|
|
|
|
|
|
summaryPointOCT4: "-",
|
|
|
|
|
|
textPointOCT4: "-",
|
|
|
|
|
|
periodOCT4: "-",
|
|
|
|
|
|
yearOCT4: "-",
|
|
|
|
|
|
summaryPointAPR5: "-",
|
|
|
|
|
|
textPointAPR5: "-",
|
|
|
|
|
|
periodAPR5: "-",
|
|
|
|
|
|
yearAPR5: "-",
|
|
|
|
|
|
summaryPointOCT5: "-",
|
|
|
|
|
|
textPointOCT5: "-",
|
|
|
|
|
|
periodOCT5: "-",
|
|
|
|
|
|
yearOCT5: "-",
|
|
|
|
|
|
year1: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 4).toString()),
|
|
|
|
|
|
year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 3).toString()),
|
|
|
|
|
|
year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 2).toString()),
|
|
|
|
|
|
year4: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()),
|
|
|
|
|
|
year5: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()),
|
|
|
|
|
|
};
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI6") {
|
|
|
|
|
|
templateName = "KPI6";
|
|
|
|
|
|
reportName = "KPI6";
|
|
|
|
|
|
//use_filter
|
2024-07-11 14:58:07 +07:00
|
|
|
|
interface KPIData {
|
|
|
|
|
|
fullName: string | null;
|
|
|
|
|
|
position: string | null;
|
|
|
|
|
|
posType: string | null;
|
|
|
|
|
|
posLevel: string | null;
|
|
|
|
|
|
affiliation: string | null;
|
|
|
|
|
|
summaryPointAPR1: string | null;
|
|
|
|
|
|
textPointAPR1: string | null;
|
|
|
|
|
|
periodAPR1: string | null;
|
|
|
|
|
|
yearAPR1: string | null;
|
|
|
|
|
|
summaryPointOCT1: string | null;
|
|
|
|
|
|
textPointOCT1: string | null;
|
|
|
|
|
|
periodOCT1: string | null;
|
|
|
|
|
|
yearOCT1: string | null;
|
|
|
|
|
|
summaryPointAPR2: string | null;
|
|
|
|
|
|
textPointAPR2: string | null;
|
|
|
|
|
|
periodAPR2: string | null;
|
|
|
|
|
|
yearAPR2: string | null;
|
|
|
|
|
|
summaryPointOCT2: string | null;
|
|
|
|
|
|
textPointOCT2: string | null;
|
|
|
|
|
|
periodOCT2: string | null;
|
|
|
|
|
|
yearOCT2: string | null;
|
|
|
|
|
|
summaryPointAPR3: string | null;
|
|
|
|
|
|
textPointAPR3: string | null;
|
|
|
|
|
|
periodAPR3: string | null;
|
|
|
|
|
|
yearAPR3: string | null;
|
|
|
|
|
|
summaryPointOCT3: string | null;
|
|
|
|
|
|
textPointOCT3: string | null;
|
|
|
|
|
|
periodOCT3: string | null;
|
|
|
|
|
|
yearOCT3: string | null;
|
|
|
|
|
|
year1: string | null;
|
|
|
|
|
|
year2: string | null;
|
|
|
|
|
|
year3: string | null;
|
|
|
|
|
|
}
|
|
|
|
|
|
const yearNow = new Date().getFullYear();
|
2025-02-06 14:53:01 +07:00
|
|
|
|
let _summaryPointApr: number[] = [];
|
|
|
|
|
|
let _summaryPointOct: number[] = [];
|
2024-07-11 14:58:07 +07:00
|
|
|
|
if (requestBody.profileId) {
|
|
|
|
|
|
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-15 17:19:38 +07:00
|
|
|
|
.where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
2024-07-16 13:46:41 +07:00
|
|
|
|
.andWhere("kpiUserEvaluation.evaluationStatus = :evaluationStatus", {
|
|
|
|
|
|
evaluationStatus: "KP7",
|
|
|
|
|
|
})
|
2024-07-11 14:58:07 +07:00
|
|
|
|
.andWhere("kpiPeriod.year BETWEEN :startYear AND :endYear", {
|
|
|
|
|
|
startYear: yearNow - 2,
|
|
|
|
|
|
endYear: yearNow,
|
|
|
|
|
|
})
|
|
|
|
|
|
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
|
|
|
|
|
.select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
.getRawMany();
|
2025-02-06 14:53:01 +07:00
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
|
|
let _calAvg = await this.kpiUserEvaluationRepository
|
|
|
|
|
|
.createQueryBuilder("evaluation")
|
|
|
|
|
|
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
|
|
|
|
|
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
|
|
|
|
|
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
|
|
|
|
|
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
|
|
|
|
|
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "APR" })
|
|
|
|
|
|
.select("AVG(evaluation.summaryPoint)", "average")
|
|
|
|
|
|
.getRawOne();
|
|
|
|
|
|
_summaryPointApr.push(_calAvg.average);
|
|
|
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < 3; i++) {
|
|
|
|
|
|
let _calAvg = await this.kpiUserEvaluationRepository
|
|
|
|
|
|
.createQueryBuilder("evaluation")
|
|
|
|
|
|
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
|
|
|
|
|
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
|
|
|
|
|
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
|
|
|
|
|
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
|
|
|
|
|
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "OCT" })
|
|
|
|
|
|
.select("AVG(evaluation.summaryPoint)", "average")
|
|
|
|
|
|
.getRawOne();
|
|
|
|
|
|
_summaryPointOct.push(_calAvg.average);
|
|
|
|
|
|
}
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
|
|
|
|
|
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
|
|
|
|
|
});
|
2024-07-11 14:58:07 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const combinedData: KPIData = profileEvaluation.reduce(
|
|
|
|
|
|
(acc: KPIData, x) => {
|
|
|
|
|
|
const fullNameParts = [x.child4, x.child3, x.child2, x.child1, x.org];
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const affiliation = fullNameParts
|
|
|
|
|
|
.filter((part) => part !== undefined && part !== null)
|
2025-02-06 15:53:51 +07:00
|
|
|
|
.join(" ");
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (!acc.fullName) {
|
|
|
|
|
|
acc.fullName = x.prefix + " " + x.firstName + " " + x.lastName;
|
|
|
|
|
|
acc.position = x.position;
|
|
|
|
|
|
acc.posType = x.posTypeName;
|
|
|
|
|
|
acc.posLevel = x.posLevelName;
|
2025-02-06 13:05:38 +07:00
|
|
|
|
acc.affiliation = affiliation == "" || affiliation == null ? "-" : affiliation;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
|
|
|
|
|
acc.fullName = "-";
|
|
|
|
|
|
acc.position = "-";
|
|
|
|
|
|
acc.posType = "-";
|
|
|
|
|
|
acc.posLevel = "-";
|
|
|
|
|
|
acc.affiliation = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR1 = _summaryPointApr.length > 2
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[2].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR1 = _summaryPointApr.length > 2 ? Extension.textPoint(_summaryPointApr[2]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR1 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR1 = "-";
|
|
|
|
|
|
acc.textPointAPR1 = "-";
|
|
|
|
|
|
acc.periodAPR1 = "-";
|
|
|
|
|
|
acc.yearAPR1 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT1 = _summaryPointOct.length > 2
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[2].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT1 = _summaryPointOct.length > 2 ? Extension.textPoint(_summaryPointOct[2]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT1 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT1 = "-";
|
|
|
|
|
|
acc.textPointOCT1 = "-";
|
|
|
|
|
|
acc.periodOCT1 = "-";
|
|
|
|
|
|
acc.yearOCT1 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR2 = _summaryPointApr.length > 1
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[1].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR2 = _summaryPointApr.length > 1 ? Extension.textPoint(_summaryPointApr[1]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR2 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR2 = "-";
|
|
|
|
|
|
acc.textPointAPR2 = "-";
|
|
|
|
|
|
acc.periodAPR2 = "-";
|
|
|
|
|
|
acc.yearAPR2 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT2 = _summaryPointOct.length > 1
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[1].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT2 = _summaryPointOct.length > 1 ? Extension.textPoint(_summaryPointOct[1]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT2 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT2 = "-";
|
|
|
|
|
|
acc.textPointOCT2 = "-";
|
|
|
|
|
|
acc.periodOCT2 = "-";
|
|
|
|
|
|
acc.yearOCT2 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointAPR3 = _summaryPointApr.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointApr[0].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointAPR3 = _summaryPointApr.length > 0 ? Extension.textPoint(_summaryPointApr[0]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodAPR3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR3 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointAPR3 = "-";
|
|
|
|
|
|
acc.textPointAPR3 = "-";
|
|
|
|
|
|
acc.periodAPR3 = "-";
|
|
|
|
|
|
acc.yearAPR3 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.summaryPointOCT3 = _summaryPointOct.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(_summaryPointOct[0].toString())
|
2024-08-21 22:09:46 +07:00
|
|
|
|
: null;
|
2025-02-06 14:53:01 +07:00
|
|
|
|
acc.textPointOCT3 = _summaryPointOct.length > 0 ? Extension.textPoint(_summaryPointOct[0]) : null;
|
2024-08-21 22:09:46 +07:00
|
|
|
|
acc.periodOCT3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT3 = x.kpiPeriod.year
|
|
|
|
|
|
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
|
|
|
|
|
: null;
|
2024-12-16 11:55:34 +07:00
|
|
|
|
} else {
|
2025-01-14 18:45:26 +07:00
|
|
|
|
acc.summaryPointOCT3 = "-";
|
|
|
|
|
|
acc.textPointOCT3 = "-";
|
|
|
|
|
|
acc.periodOCT3 = "-";
|
|
|
|
|
|
acc.yearOCT3 = "-";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}
|
2024-07-12 10:19:49 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
return acc;
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
fullName: null,
|
|
|
|
|
|
position: null,
|
|
|
|
|
|
posType: null,
|
|
|
|
|
|
posLevel: null,
|
|
|
|
|
|
affiliation: null,
|
|
|
|
|
|
summaryPointAPR1: null,
|
|
|
|
|
|
textPointAPR1: null,
|
|
|
|
|
|
periodAPR1: null,
|
|
|
|
|
|
yearAPR1: null,
|
|
|
|
|
|
summaryPointOCT1: null,
|
|
|
|
|
|
textPointOCT1: null,
|
|
|
|
|
|
periodOCT1: null,
|
|
|
|
|
|
yearOCT1: null,
|
|
|
|
|
|
summaryPointAPR2: null,
|
|
|
|
|
|
textPointAPR2: null,
|
|
|
|
|
|
periodAPR2: null,
|
|
|
|
|
|
yearAPR2: null,
|
|
|
|
|
|
summaryPointOCT2: null,
|
|
|
|
|
|
textPointOCT2: null,
|
|
|
|
|
|
periodOCT2: null,
|
|
|
|
|
|
yearOCT2: null,
|
|
|
|
|
|
summaryPointAPR3: null,
|
|
|
|
|
|
textPointAPR3: null,
|
|
|
|
|
|
periodAPR3: null,
|
|
|
|
|
|
yearAPR3: null,
|
|
|
|
|
|
summaryPointOCT3: null,
|
|
|
|
|
|
textPointOCT3: null,
|
|
|
|
|
|
periodOCT3: null,
|
|
|
|
|
|
yearOCT3: null,
|
|
|
|
|
|
year1: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 2).toString()),
|
|
|
|
|
|
year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()),
|
|
|
|
|
|
year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()),
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
2024-09-03 15:39:45 +07:00
|
|
|
|
formattedData =
|
|
|
|
|
|
profileEvaluation.length > 0
|
|
|
|
|
|
? combinedData
|
|
|
|
|
|
: {
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posType: "-",
|
|
|
|
|
|
posLevel: "-",
|
|
|
|
|
|
affiliation: "-",
|
|
|
|
|
|
summaryPointAPR1: "-",
|
|
|
|
|
|
textPointAPR1: "-",
|
|
|
|
|
|
periodAPR1: "-",
|
|
|
|
|
|
yearAPR1: "-",
|
|
|
|
|
|
summaryPointOCT1: "-",
|
|
|
|
|
|
textPointOCT1: "-",
|
|
|
|
|
|
periodOCT1: "-",
|
|
|
|
|
|
yearOCT1: "-",
|
|
|
|
|
|
summaryPointAPR2: "-",
|
|
|
|
|
|
textPointAPR2: "-",
|
|
|
|
|
|
periodAPR2: "-",
|
|
|
|
|
|
yearAPR2: "-",
|
|
|
|
|
|
summaryPointOCT2: "-",
|
|
|
|
|
|
textPointOCT2: "-",
|
|
|
|
|
|
periodOCT2: "-",
|
|
|
|
|
|
yearOCT2: "-",
|
|
|
|
|
|
summaryPointAPR3: "-",
|
|
|
|
|
|
textPointAPR3: "-",
|
|
|
|
|
|
periodAPR3: "-",
|
|
|
|
|
|
yearAPR3: "-",
|
|
|
|
|
|
summaryPointOCT3: "-",
|
|
|
|
|
|
textPointOCT3: "-",
|
|
|
|
|
|
periodOCT3: "-",
|
|
|
|
|
|
yearOCT3: "-",
|
|
|
|
|
|
year1: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 2).toString()),
|
|
|
|
|
|
year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()),
|
|
|
|
|
|
year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()),
|
|
|
|
|
|
};
|
2024-07-11 14:58:07 +07:00
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI7") {
|
|
|
|
|
|
templateName = "KPI7";
|
|
|
|
|
|
reportName = "KPI7";
|
2024-07-11 21:23:49 +07:00
|
|
|
|
|
2024-07-12 09:30:37 +07:00
|
|
|
|
const userEvaluations_ = await Promise.all(
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations.map(async (x: any, idx: number) => {
|
2024-08-21 22:09:46 +07:00
|
|
|
|
/*รอ Fe เพิ่ม UI*/
|
|
|
|
|
|
// const target_ = await this.kpiUserDevelopmentRepository.findOne({
|
2024-07-16 13:41:02 +07:00
|
|
|
|
// where: { kpiUserEvaluationId: x.id },
|
|
|
|
|
|
// });
|
2024-08-21 22:09:46 +07:00
|
|
|
|
// const isDev70 = target_ && target_?.isDevelopment70 === true
|
|
|
|
|
|
// ? "🗹 70 การลงมือปฏิบัติ (โดยผู้บังคับบัญชามอบหมาย)"
|
2024-07-16 13:41:02 +07:00
|
|
|
|
// : ""
|
2024-08-21 22:09:46 +07:00
|
|
|
|
// const isDev20 = target_ && target_?.isDevelopment20 === true
|
|
|
|
|
|
// ? "🗹 20 การเรียนรู้จากผู้อื่น (Coach/Mentor/Consulting)"
|
2024-07-16 13:41:02 +07:00
|
|
|
|
// : ""
|
2024-08-21 22:09:46 +07:00
|
|
|
|
// const isDev10 = target_ && target_?.isDevelopment10 === true
|
|
|
|
|
|
// ? "🗹 10 การฝึกอบรมอื่นๆ"
|
2024-07-16 13:41:02 +07:00
|
|
|
|
// : ""
|
2024-07-12 09:30:37 +07:00
|
|
|
|
return {
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
|
|
|
|
|
developName: x.topicEvaluator ? x.topicEvaluator : "-",
|
|
|
|
|
|
developEvaluator: x.developEvaluator ? x.developEvaluator : "-",
|
2024-07-16 13:41:02 +07:00
|
|
|
|
target: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
timeEvaluator: x.timeEvaluator ? Extension.ToThaiNumber(x.timeEvaluator) : "-",
|
|
|
|
|
|
developResults: "-",
|
2024-07-12 09:30:37 +07:00
|
|
|
|
evaluationResults: x.evaluationResults
|
|
|
|
|
|
? Extension.EvaluationResult(x.evaluationResults)
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "-",
|
2024-07-12 09:30:37 +07:00
|
|
|
|
};
|
|
|
|
|
|
})
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
developName: "-",
|
|
|
|
|
|
developEvaluator: "-",
|
|
|
|
|
|
target: "-",
|
|
|
|
|
|
timeEvaluator: "-",
|
|
|
|
|
|
developResults: "-",
|
|
|
|
|
|
evaluationResults: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-12 09:30:37 +07:00
|
|
|
|
);
|
2024-07-10 18:34:23 +07:00
|
|
|
|
formattedData = {
|
2024-07-11 21:23:49 +07:00
|
|
|
|
year: data.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
2024-07-11 21:23:49 +07:00
|
|
|
|
durationKPI: data.durationKPI,
|
2024-09-03 15:39:45 +07:00
|
|
|
|
root: data && data.rootName != null ? data.rootName : "-",
|
|
|
|
|
|
userEvaluations:
|
|
|
|
|
|
userEvaluations_.length > 0
|
|
|
|
|
|
? userEvaluations_
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
developName: "-",
|
|
|
|
|
|
developEvaluator: "-",
|
|
|
|
|
|
target: "-",
|
|
|
|
|
|
timeEvaluator: "-",
|
|
|
|
|
|
developResults: "-",
|
|
|
|
|
|
evaluationResults: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-12 09:30:37 +07:00
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI8") {
|
|
|
|
|
|
templateName = "KPI8";
|
|
|
|
|
|
reportName = "KPI8";
|
|
|
|
|
|
//use_filter
|
2024-08-21 22:09:46 +07:00
|
|
|
|
let period_: any;
|
|
|
|
|
|
let formattedUserDevelopmentLists: any;
|
|
|
|
|
|
let userInfo: any;
|
|
|
|
|
|
let userDevelopmentLists: any;
|
|
|
|
|
|
let fullNameParts: any;
|
|
|
|
|
|
let affiliation: any;
|
2024-07-12 16:10:39 +07:00
|
|
|
|
if (requestBody.profileId && requestBody.periodId) {
|
|
|
|
|
|
period_ = await this.kpiPeriodRepository.findOne({
|
2024-08-21 22:09:46 +07:00
|
|
|
|
where: { id: String(requestBody.periodId) },
|
|
|
|
|
|
});
|
2025-02-06 13:05:38 +07:00
|
|
|
|
let durationKpi_APR = period_ && period_.durationKPI == "APR" ? `🗹` : `☐`
|
|
|
|
|
|
let durationKpi_OCT = period_ && period_.durationKPI == "OCT" ? `🗹` : `☐`
|
2024-08-21 22:09:46 +07:00
|
|
|
|
if (period_ && !period1 && !period2) {
|
|
|
|
|
|
if (period_?.durationKPI === "APR") {
|
2025-02-06 13:05:38 +07:00
|
|
|
|
period1 = `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
|
2024-07-12 16:10:39 +07:00
|
|
|
|
let _period2 = await this.kpiPeriodRepository.findOne({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
year: period_.year,
|
|
|
|
|
|
durationKPI: "OCT",
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2024-08-21 22:09:46 +07:00
|
|
|
|
period2 = _period2
|
2025-02-06 13:05:38 +07:00
|
|
|
|
? `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
|
|
|
|
|
|
: `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ๑ เมษายน ${Extension.ToThaiYear(period_.year)} ถึง ๓๑ กันยายน ${Extension.ToThaiYear(period_.year)}`;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (period_?.durationKPI === "OCT") {
|
|
|
|
|
|
period2 = `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
|
2024-07-12 16:10:39 +07:00
|
|
|
|
let _period1 = await this.kpiPeriodRepository.findOne({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
year: period_.year,
|
|
|
|
|
|
durationKPI: "APR",
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
period1 = _period1
|
2025-02-06 13:05:38 +07:00
|
|
|
|
? `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
|
|
|
|
|
|
: `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ๑ ตุลาคม ${Extension.ToThaiYear(period_.year-1)} ถึง ๓๑ มีนาคม ${Extension.ToThaiYear(period_.year)}`;
|
2024-07-12 16:10:39 +07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-11 16:59:44 +07:00
|
|
|
|
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-15 16:43:34 +07:00
|
|
|
|
.where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
2024-07-11 16:59:44 +07:00
|
|
|
|
.andWhere("kpiUserEvaluation.kpiPeriodId = :kpiPeriodId", {
|
|
|
|
|
|
kpiPeriodId: requestBody.periodId,
|
|
|
|
|
|
})
|
2024-07-12 16:10:39 +07:00
|
|
|
|
.andWhere("kpiUserEvaluation.evaluationStatus = 'KP7'")
|
2024-07-11 16:59:44 +07:00
|
|
|
|
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
|
|
|
|
|
.select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
.getRawMany();
|
2024-07-12 09:30:37 +07:00
|
|
|
|
if (profileEvaluationIds.length > 0) {
|
2024-07-12 16:10:39 +07:00
|
|
|
|
userInfo = await this.kpiUserEvaluationRepository.find({
|
2024-07-12 09:30:37 +07:00
|
|
|
|
where: {
|
|
|
|
|
|
id: In(profileEvaluationIds.map((x: any) => x.id)),
|
2024-08-21 22:09:46 +07:00
|
|
|
|
evaluationStatus: "KP7",
|
2024-07-12 09:30:37 +07:00
|
|
|
|
},
|
|
|
|
|
|
});
|
2024-07-12 16:10:39 +07:00
|
|
|
|
userDevelopmentLists = await this.kpiUserDevelopmentRepository.find({
|
2024-07-12 09:30:37 +07:00
|
|
|
|
where: {
|
|
|
|
|
|
kpiUserEvaluationId: In(profileEvaluationIds.map((x: any) => x.id)),
|
|
|
|
|
|
},
|
|
|
|
|
|
select: [
|
|
|
|
|
|
"id",
|
|
|
|
|
|
"name",
|
|
|
|
|
|
"target",
|
|
|
|
|
|
"summary",
|
|
|
|
|
|
"point",
|
|
|
|
|
|
"achievement0",
|
|
|
|
|
|
"achievement5",
|
|
|
|
|
|
"achievement10",
|
|
|
|
|
|
"isDevelopment10",
|
|
|
|
|
|
"isDevelopment20",
|
|
|
|
|
|
"isDevelopment70",
|
|
|
|
|
|
],
|
|
|
|
|
|
});
|
2024-07-16 15:24:43 +07:00
|
|
|
|
const dev10text = "การลงมือปฏิบัติ (โดยผู้บังคับบัญชามอบหมาย)";
|
|
|
|
|
|
const dev20text = "การเรียนรู้จากผู้อื่น (Coach/Mentor/Consulting)";
|
|
|
|
|
|
const dev70text = "การลงมือปฏิบัติ (โดยผู้บังคับบัญชามอบหมาย)";
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const combianText = [dev10text, dev20text, dev70text];
|
|
|
|
|
|
|
2024-07-12 16:10:39 +07:00
|
|
|
|
formattedUserDevelopmentLists = userDevelopmentLists.map(
|
2024-07-12 09:30:37 +07:00
|
|
|
|
(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,
|
2024-07-16 15:24:43 +07:00
|
|
|
|
pointText: (development.point = 0
|
|
|
|
|
|
? development.achievement0
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: (development.point == 5
|
2024-07-16 15:24:43 +07:00
|
|
|
|
? development.achievement5
|
2025-02-05 18:10:59 +07:00
|
|
|
|
: (development.point == 10 ? development.achievement10 : null))),
|
2024-07-16 15:24:43 +07:00
|
|
|
|
isDevelopmentText: [
|
|
|
|
|
|
development.isDevelopment10,
|
|
|
|
|
|
development.isDevelopment20,
|
|
|
|
|
|
development.isDevelopment70,
|
|
|
|
|
|
]
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.map((x: any, index) => (x ? combianText[index] : null))
|
|
|
|
|
|
.filter((x: any) => x !== null)
|
2025-02-06 15:53:51 +07:00
|
|
|
|
.join(" "),
|
2024-07-12 09:30:37 +07:00
|
|
|
|
}),
|
|
|
|
|
|
);
|
2024-07-11 17:32:25 +07:00
|
|
|
|
|
2024-07-12 16:10:39 +07:00
|
|
|
|
fullNameParts = [
|
2024-07-12 09:30:37 +07:00
|
|
|
|
userInfo[0]?.child4,
|
|
|
|
|
|
userInfo[0]?.child3,
|
|
|
|
|
|
userInfo[0]?.child2,
|
|
|
|
|
|
userInfo[0]?.child1,
|
|
|
|
|
|
userInfo[0]?.org,
|
|
|
|
|
|
];
|
2024-07-12 16:10:39 +07:00
|
|
|
|
affiliation = fullNameParts
|
2024-08-21 22:09:46 +07:00
|
|
|
|
.filter((part: any) => part !== undefined && part !== null)
|
2025-02-06 15:53:51 +07:00
|
|
|
|
.join(" ");
|
2024-07-12 09:30:37 +07:00
|
|
|
|
}
|
2024-07-11 16:59:44 +07:00
|
|
|
|
}
|
2024-07-12 16:10:39 +07:00
|
|
|
|
formattedData = {
|
2024-08-21 22:09:46 +07:00
|
|
|
|
year: period_ ? Extension.ToThaiNumber((period_.year + 543).toString()) : "-",
|
2024-07-12 16:10:39 +07:00
|
|
|
|
fullName: userInfo
|
|
|
|
|
|
? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName
|
|
|
|
|
|
: "-",
|
2025-02-06 13:05:38 +07:00
|
|
|
|
affiliation: affiliation == "" || affiliation == null ? "-" : affiliation,
|
2024-07-12 16:10:39 +07:00
|
|
|
|
durationKPI: period_ ? period_.durationKPI : "-",
|
|
|
|
|
|
position: userInfo ? userInfo[0]?.position : "-",
|
|
|
|
|
|
posType: userInfo ? userInfo[0]?.posTypeName : "-",
|
|
|
|
|
|
posLevel: userInfo ? userInfo[0]?.posLevelName : "-",
|
|
|
|
|
|
period1: period1 ? Extension.ToThaiNumber(period1) : "-",
|
|
|
|
|
|
period2: period2 ? Extension.ToThaiNumber(period2) : "-",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
developments: formattedUserDevelopmentLists
|
|
|
|
|
|
? formattedUserDevelopmentLists
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
name: "-",
|
|
|
|
|
|
target: "-",
|
|
|
|
|
|
summary: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-12 16:10:39 +07:00
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI9") {
|
2024-07-03 15:28:48 +07:00
|
|
|
|
templateName = "KPI9";
|
|
|
|
|
|
reportName = "KPI9";
|
2024-09-03 15:39:45 +07:00
|
|
|
|
if (data && data.kpiUserEvaluations.length == 0) {
|
2024-08-30 16:32:13 +07:00
|
|
|
|
//แก้ไขกรณีมีผู้ประเมินที่มีผลการประเมินดีเด่น แต่ RootId ไม่ตรงกับหน่วยงานที่ filter
|
2024-09-03 15:39:45 +07:00
|
|
|
|
let userEvaInRoot: any;
|
|
|
|
|
|
let userEvaOutRoot: any[];
|
2024-08-30 16:32:13 +07:00
|
|
|
|
userEvaInRoot = await this.kpiUserEvaluationRepository.findOne({
|
|
|
|
|
|
select: ["org"],
|
|
|
|
|
|
where: {
|
2024-09-03 15:39:45 +07:00
|
|
|
|
kpiPeriodId: String(requestBody.periodId),
|
|
|
|
|
|
orgId: String(requestBody.root),
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
if (userEvaInRoot) {
|
|
|
|
|
|
userEvaOutRoot = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
where: {
|
2024-08-30 16:32:13 +07:00
|
|
|
|
kpiPeriodId: String(requestBody.periodId),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
orgId: Not(String(requestBody.root)),
|
|
|
|
|
|
org: userEvaInRoot.org,
|
|
|
|
|
|
evaluationStatus: "KP7",
|
2024-08-30 16:32:13 +07:00
|
|
|
|
},
|
|
|
|
|
|
});
|
2024-09-03 15:39:45 +07:00
|
|
|
|
if (userEvaOutRoot.length > 0) {
|
|
|
|
|
|
data.kpiUserEvaluations = userEvaOutRoot;
|
2024-08-30 16:32:13 +07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-09-03 15:39:45 +07:00
|
|
|
|
|
2024-08-21 22:09:46 +07:00
|
|
|
|
const userEvaluations_ =
|
|
|
|
|
|
data.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data.kpiUserEvaluations
|
|
|
|
|
|
.filter(
|
|
|
|
|
|
(x: any) =>
|
|
|
|
|
|
x.evaluationResults == "EXCELLENT" || x.evaluationResults == "VERY_GOOD",
|
|
|
|
|
|
)
|
|
|
|
|
|
.map((x: any, idx: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx + 1).toString()),
|
2024-09-03 15:39:45 +07:00
|
|
|
|
fullName:
|
|
|
|
|
|
x.prefix != null && x.firstName != null && x.lastName != null
|
|
|
|
|
|
? `${x.prefix}${x.firstName} ${x.lastName}`
|
|
|
|
|
|
: "-",
|
2024-08-26 13:46:45 +07:00
|
|
|
|
position: x.position ? x.position : "-",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "-",
|
2024-08-21 22:09:46 +07:00
|
|
|
|
evaluationResults: x.evaluationResults
|
|
|
|
|
|
? Extension.EvaluationResult(x.evaluationResults)
|
2024-08-26 13:46:45 +07:00
|
|
|
|
: "-",
|
2024-08-21 22:09:46 +07:00
|
|
|
|
}))
|
2024-09-03 15:39:45 +07:00
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
evaluationResults: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
];
|
2024-08-30 16:32:13 +07:00
|
|
|
|
|
2024-07-10 18:34:23 +07:00
|
|
|
|
formattedData = {
|
2024-09-03 15:39:45 +07:00
|
|
|
|
root: data && data.rootName != null ? data.rootName : "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
period: data?.durationKPI == "APR" ? "๑" : data?.durationKPI == "OCT" ? "๒" : "-",
|
|
|
|
|
|
year: data.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-",
|
2024-09-03 15:39:45 +07:00
|
|
|
|
userEvaluations:
|
|
|
|
|
|
userEvaluations_.length > 0
|
|
|
|
|
|
? userEvaluations_
|
|
|
|
|
|
: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "-",
|
|
|
|
|
|
fullName: "-",
|
|
|
|
|
|
position: "-",
|
|
|
|
|
|
posLevelName: "-",
|
|
|
|
|
|
evaluationResults: "-",
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2024-07-11 17:32:25 +07:00
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
2024-06-27 17:35:13 +07:00
|
|
|
|
|
2024-06-13 11:34:25 +07:00
|
|
|
|
return new HttpSuccess({
|
2024-06-25 13:55:36 +07:00
|
|
|
|
template: templateName,
|
|
|
|
|
|
reportName: reportName,
|
2024-06-13 11:34:25 +07:00
|
|
|
|
data: formattedData,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-06-27 17:35:13 +07:00
|
|
|
|
|
2024-07-04 10:31:07 +07:00
|
|
|
|
@Get("kpi-user/{id}")
|
2024-06-30 20:51:04 +07:00
|
|
|
|
async GetReportKpi9(@Path() id?: string) {
|
|
|
|
|
|
const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
|
|
|
|
|
where: { id: id },
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!kpiUserEvaluation) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน");
|
2024-06-27 18:14:43 +07:00
|
|
|
|
|
2024-06-30 20:51:04 +07:00
|
|
|
|
let formattedData = {
|
|
|
|
|
|
durationKPI: kpiUserEvaluation.kpiPeriod.durationKPI,
|
|
|
|
|
|
fullname:
|
|
|
|
|
|
(kpiUserEvaluation.prefix == null ? "" : kpiUserEvaluation.prefix) +
|
|
|
|
|
|
"" +
|
|
|
|
|
|
(kpiUserEvaluation.firstName == null ? "" : kpiUserEvaluation.firstName) +
|
|
|
|
|
|
" " +
|
|
|
|
|
|
(kpiUserEvaluation.lastName == null ? "" : kpiUserEvaluation.lastName),
|
|
|
|
|
|
position: kpiUserEvaluation.position,
|
|
|
|
|
|
posTypeName: kpiUserEvaluation.posTypeName,
|
|
|
|
|
|
posLevelName: kpiUserEvaluation.posLevelName,
|
|
|
|
|
|
org: kpiUserEvaluation.org,
|
2024-06-28 15:03:02 +07:00
|
|
|
|
|
2024-06-30 20:51:04 +07:00
|
|
|
|
fullnameEvaluator:
|
|
|
|
|
|
(kpiUserEvaluation.prefixEvaluator == null ? "" : kpiUserEvaluation.prefixEvaluator) +
|
|
|
|
|
|
"" +
|
|
|
|
|
|
(kpiUserEvaluation.firstNameEvaluator == null ? "" : kpiUserEvaluation.firstNameEvaluator) +
|
|
|
|
|
|
" " +
|
|
|
|
|
|
(kpiUserEvaluation.lastNameEvaluator == null ? "" : kpiUserEvaluation.lastNameEvaluator),
|
2025-01-14 18:45:26 +07:00
|
|
|
|
|
|
|
|
|
|
fullnameCommander:
|
|
|
|
|
|
(kpiUserEvaluation.prefixCommander == null ? "" : kpiUserEvaluation.prefixCommander) +
|
|
|
|
|
|
"" +
|
|
|
|
|
|
(kpiUserEvaluation.firstNameCommander == null ? "" : kpiUserEvaluation.firstNameCommander) +
|
|
|
|
|
|
" " +
|
|
|
|
|
|
(kpiUserEvaluation.lastNameCommander == null ? "" : kpiUserEvaluation.lastNameCommander),
|
|
|
|
|
|
|
|
|
|
|
|
fullnameCommanderHigh:
|
|
|
|
|
|
(kpiUserEvaluation.prefixCommanderHigh == null
|
|
|
|
|
|
? ""
|
|
|
|
|
|
: kpiUserEvaluation.prefixCommanderHigh) +
|
|
|
|
|
|
"" +
|
|
|
|
|
|
(kpiUserEvaluation.firstNameCommanderHigh == null
|
|
|
|
|
|
? ""
|
|
|
|
|
|
: kpiUserEvaluation.firstNameCommanderHigh) +
|
|
|
|
|
|
" " +
|
|
|
|
|
|
(kpiUserEvaluation.lastNameCommanderHigh == null
|
|
|
|
|
|
? ""
|
|
|
|
|
|
: kpiUserEvaluation.lastNameCommanderHigh),
|
2024-06-30 20:51:04 +07:00
|
|
|
|
positionEvaluator: kpiUserEvaluation.positionEvaluator,
|
2025-01-14 18:45:26 +07:00
|
|
|
|
positionCommander: kpiUserEvaluation.positionCommander,
|
|
|
|
|
|
positionCommanderHigh: kpiUserEvaluation.positionCommanderHigh,
|
2024-06-30 20:51:04 +07:00
|
|
|
|
posTypeNameEvaluator: kpiUserEvaluation.posTypeNameEvaluator,
|
|
|
|
|
|
posLevelNameEvaluator: kpiUserEvaluation.posLevelNameEvaluator,
|
|
|
|
|
|
orgEvaluator: kpiUserEvaluation.orgEvaluator,
|
2024-06-28 15:03:02 +07:00
|
|
|
|
|
2024-06-30 20:51:04 +07:00
|
|
|
|
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year))),
|
2025-01-14 18:45:26 +07:00
|
|
|
|
yearOld: Extension.ToThaiNumber(
|
|
|
|
|
|
String(Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year + 1)),
|
|
|
|
|
|
),
|
2024-06-28 15:03:02 +07:00
|
|
|
|
|
2024-06-30 20:51:04 +07:00
|
|
|
|
startDateApr:
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
2024-07-11 17:32:25 +07:00
|
|
|
|
kpiUserEvaluation.kpiPeriod.startDate == null ||
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "APR"
|
2024-06-30 20:51:04 +07:00
|
|
|
|
? "-"
|
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate)),
|
|
|
|
|
|
endDateApr:
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
2024-07-11 17:32:25 +07:00
|
|
|
|
kpiUserEvaluation.kpiPeriod.endDate == null ||
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "APR"
|
2024-06-30 20:51:04 +07:00
|
|
|
|
? "-"
|
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)),
|
|
|
|
|
|
startDateOct:
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
2024-07-11 17:32:25 +07:00
|
|
|
|
kpiUserEvaluation.kpiPeriod.startDate == null ||
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "OCT"
|
2024-06-30 20:51:04 +07:00
|
|
|
|
? "-"
|
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate)),
|
|
|
|
|
|
endDateOct:
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod == null ||
|
2024-07-11 17:32:25 +07:00
|
|
|
|
kpiUserEvaluation.kpiPeriod.endDate == null ||
|
|
|
|
|
|
kpiUserEvaluation.kpiPeriod.durationKPI != "OCT"
|
2024-06-30 20:51:04 +07:00
|
|
|
|
? "-"
|
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.endDate)),
|
2024-06-28 15:03:02 +07:00
|
|
|
|
|
2024-06-30 20:51:04 +07:00
|
|
|
|
evaluationResults: kpiUserEvaluation.evaluationResults,
|
|
|
|
|
|
totalPoint1: Extension.ToThaiNumber(kpiUserEvaluation.totalPoint1.toLocaleString()),
|
|
|
|
|
|
totalPoint2: Extension.ToThaiNumber(
|
|
|
|
|
|
(kpiUserEvaluation.totalPoint2_2 + kpiUserEvaluation.totalPoint2_1).toLocaleString(),
|
|
|
|
|
|
),
|
|
|
|
|
|
summaryPoint: Extension.ToThaiNumber(kpiUserEvaluation.summaryPoint.toLocaleString()),
|
|
|
|
|
|
weightPoint1: Extension.ToThaiNumber(kpiUserEvaluation.weightPoint1.toLocaleString()),
|
|
|
|
|
|
weightPoint2: Extension.ToThaiNumber(kpiUserEvaluation.weightPoint2.toLocaleString()),
|
|
|
|
|
|
summaryWeight: Extension.ToThaiNumber(kpiUserEvaluation.summaryWeight.toLocaleString()),
|
2024-06-28 15:03:02 +07:00
|
|
|
|
|
2024-06-30 20:51:04 +07:00
|
|
|
|
topicEvaluator: kpiUserEvaluation.topicEvaluator,
|
|
|
|
|
|
developEvaluator: kpiUserEvaluation.developEvaluator,
|
|
|
|
|
|
timeEvaluator: kpiUserEvaluation.timeEvaluator,
|
|
|
|
|
|
reasonEvaluator: kpiUserEvaluation.reasonEvaluator,
|
|
|
|
|
|
isReasonCommander: kpiUserEvaluation.isReasonCommander,
|
|
|
|
|
|
reasonCommander: kpiUserEvaluation.reasonCommander,
|
|
|
|
|
|
isReasonCommanderHigh: kpiUserEvaluation.isReasonCommanderHigh,
|
|
|
|
|
|
reasonCommanderHigh: kpiUserEvaluation.reasonCommanderHigh,
|
|
|
|
|
|
openDate:
|
|
|
|
|
|
kpiUserEvaluation.openDate == null
|
|
|
|
|
|
? null
|
|
|
|
|
|
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.openDate)),
|
|
|
|
|
|
};
|
2024-06-27 17:35:13 +07:00
|
|
|
|
|
|
|
|
|
|
return new HttpSuccess({
|
2024-07-04 10:31:07 +07:00
|
|
|
|
template: "KPIUser",
|
|
|
|
|
|
reportName: "KPIUser",
|
2024-06-27 18:14:43 +07:00
|
|
|
|
data: formattedData,
|
2024-06-27 17:35:13 +07:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2024-06-13 11:34:25 +07:00
|
|
|
|
}
|