2024-06-13 11:34:25 +07:00
|
|
|
|
import {
|
|
|
|
|
|
Controller,
|
|
|
|
|
|
Get,
|
|
|
|
|
|
Post,
|
|
|
|
|
|
Put,
|
|
|
|
|
|
Delete,
|
|
|
|
|
|
Route,
|
|
|
|
|
|
Security,
|
|
|
|
|
|
Tags,
|
|
|
|
|
|
Body,
|
|
|
|
|
|
Path,
|
|
|
|
|
|
Request,
|
|
|
|
|
|
Query,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
} from "tsoa";
|
2024-06-13 11:34:25 +07:00
|
|
|
|
import { AppDataSource } from "../database/data-source";
|
2024-07-11 14:58:07 +07:00
|
|
|
|
import { Brackets, IsNull, Not, In } 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 { off } from "process";
|
|
|
|
|
|
import Extension from "../interfaces/extension";
|
2024-06-14 15:33:35 +07:00
|
|
|
|
import { KpiRole } from "../entities/kpiRole";
|
2024-06-27 18:14:43 +07:00
|
|
|
|
import { KpiPlan } from "../entities/kpiPlan";
|
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-06-14 15:33:35 +07:00
|
|
|
|
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
2024-06-27 18:14:43 +07:00
|
|
|
|
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
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(
|
|
|
|
|
|
@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;
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
if (requestBody.root && requestBody.periodId) {
|
2024-07-10 19:40:37 +07:00
|
|
|
|
// data = await this.kpiPeriodRepository.createQueryBuilder("period")
|
|
|
|
|
|
// .leftJoinAndSelect("period.kpiUserEvaluations", "kpiUserEvaluations")
|
|
|
|
|
|
// .where("period.id = :periodId", { periodId: requestBody.periodId })
|
|
|
|
|
|
// .andWhere("kpiUserEvaluations.orgId = :orgId", { orgId: requestBody.root })
|
|
|
|
|
|
// .getOne();
|
|
|
|
|
|
|
|
|
|
|
|
// if(data == null || data == undefined){
|
|
|
|
|
|
// throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการ ของหน่วยงานที่เลือก`);
|
|
|
|
|
|
// }
|
|
|
|
|
|
data = await this.kpiPeriodRepository.findOne({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: { id: requestBody.periodId },
|
|
|
|
|
|
});
|
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-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-07-10 18:34:23 +07:00
|
|
|
|
|
2024-07-11 17:32:25 +07:00
|
|
|
|
if (data.durationKPI == "APR") {
|
|
|
|
|
|
period1 = `${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",
|
|
|
|
|
|
isActive: true,
|
|
|
|
|
|
},
|
2024-07-10 18:34:23 +07:00
|
|
|
|
});
|
2024-07-11 17:32:25 +07:00
|
|
|
|
period2 = _period2
|
|
|
|
|
|
? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
|
|
|
|
|
|
: "";
|
|
|
|
|
|
} else if (data.durationKPI == "OCT") {
|
|
|
|
|
|
period2 = `${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",
|
|
|
|
|
|
isActive: true,
|
|
|
|
|
|
},
|
2024-07-10 18:34:23 +07:00
|
|
|
|
});
|
2024-07-11 17:32:25 +07:00
|
|
|
|
period1 = _period1
|
|
|
|
|
|
? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
|
|
|
|
|
|
: "";
|
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-10 18:34:23 +07:00
|
|
|
|
orgId: String(requestBody.root),
|
2024-07-11 17:32:25 +07:00
|
|
|
|
// child1Id: "" || IsNull(),
|
|
|
|
|
|
// child2Id: "" || IsNull(),
|
|
|
|
|
|
// child3Id: "" || IsNull(),
|
|
|
|
|
|
// child4Id: "" || IsNull(),
|
|
|
|
|
|
},
|
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(
|
|
|
|
|
|
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(),
|
|
|
|
|
|
)
|
|
|
|
|
|
: "๐";
|
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-07-11 17:32:25 +07:00
|
|
|
|
root:
|
|
|
|
|
|
data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
userEvaluations: [
|
|
|
|
|
|
{
|
2024-07-11 10:14:50 +07:00
|
|
|
|
no: userEvaluationOrg.length > 0 ? "๑" : "",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
root: userEvaluationOrg.length > 0 ? userEvaluationOrg[0].orgEvaluator ?? "" : "-",
|
2024-07-11 10:14:50 +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
|
|
|
|
|
|
.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")
|
|
|
|
|
|
: [{}];
|
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-07-11 17:32:25 +07:00
|
|
|
|
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,
|
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())
|
|
|
|
|
|
: "",
|
|
|
|
|
|
data: verygood,
|
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())
|
|
|
|
|
|
: "",
|
|
|
|
|
|
data: good,
|
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())
|
|
|
|
|
|
: "",
|
|
|
|
|
|
data: fair,
|
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())
|
|
|
|
|
|
: "",
|
|
|
|
|
|
data: improvment,
|
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";
|
2024-07-11 17:32:25 +07:00
|
|
|
|
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: "",
|
|
|
|
|
|
}))
|
|
|
|
|
|
: [{}];
|
2024-07-10 18:34:23 +07:00
|
|
|
|
// 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 = {
|
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-07-11 17:32:25 +07:00
|
|
|
|
root:
|
|
|
|
|
|
data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
fullNameEvaluator: "-",
|
|
|
|
|
|
positionEvaluator: "-",
|
|
|
|
|
|
posTypeNameEvaluator: "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
posLevelNameEvaluator: "-",
|
2024-07-10 18:34:23 +07:00
|
|
|
|
orgEvaluator: "-",
|
|
|
|
|
|
|
|
|
|
|
|
fullNameCommander: "-",
|
|
|
|
|
|
positionCommander: "-",
|
|
|
|
|
|
posTypeNameCommander: "-",
|
|
|
|
|
|
posLevelNameCommander: "-",
|
|
|
|
|
|
orgCommander: "-",
|
|
|
|
|
|
|
|
|
|
|
|
fullNameCommanderHigh: "-",
|
|
|
|
|
|
positionCommanderHigh: "-",
|
|
|
|
|
|
posTypeNameCommanderHigh: "-",
|
|
|
|
|
|
posLevelNameCommanderHigh: "-",
|
|
|
|
|
|
orgCommanderHigh: "-",
|
2024-07-11 17:32:25 +07:00
|
|
|
|
userEvaluations: userEvaluations_,
|
|
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI4") {
|
|
|
|
|
|
templateName = "KPI4";
|
|
|
|
|
|
reportName = "KPI4";
|
|
|
|
|
|
//use_filter
|
2024-07-11 14:58:07 +07:00
|
|
|
|
const yearNow = new Date().getFullYear();
|
|
|
|
|
|
if (requestBody.profileId) {
|
|
|
|
|
|
//ชั่วคราว
|
|
|
|
|
|
const profileEvaluationNowYearIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-11 17:23:10 +07:00
|
|
|
|
// .where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
2024-07-11 14:58:07 +07:00
|
|
|
|
// .where("kpiPeriod.year = :year", { year: yearNow })
|
|
|
|
|
|
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
|
|
|
|
|
.select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
.getRawMany();
|
|
|
|
|
|
// const profileEvaluationNextYearIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
// .createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
// .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
|
|
|
|
|
// .where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
|
|
|
|
|
// .where("kpiPeriod.year = :year", { year: yearNow + 1 })
|
|
|
|
|
|
// .groupBy("kpiUserEvaluation.kpiPeriodId")
|
|
|
|
|
|
// .select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
// .getRawMany();
|
|
|
|
|
|
// const profileEvaluationCombianIds = profileEvaluationNowYearIds.concat(profileEvaluationNextYearIds);
|
|
|
|
|
|
|
|
|
|
|
|
const profileEvaluations = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
|
|
|
|
|
where: { id: In(profileEvaluationNowYearIds.map((evaluation) => evaluation.id)) },
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const groupedEvaluations = profileEvaluations.reduce((acc: any, evaluation: any) => {
|
|
|
|
|
|
const year = evaluation.kpiPeriod.year;
|
|
|
|
|
|
const profileId = evaluation.profileId;
|
|
|
|
|
|
const key = `${profileId}-${year}`;
|
|
|
|
|
|
|
|
|
|
|
|
if (!acc[key]) {
|
|
|
|
|
|
acc[key] = {
|
|
|
|
|
|
fullName: evaluation.prefix + evaluation.firstName + " " + evaluation.lastName,
|
|
|
|
|
|
profileId: profileId,
|
|
|
|
|
|
year: Extension.ToThaiNumber(Extension.ToThaiYear(year).toString()), // Set year once here
|
|
|
|
|
|
evaluations: [],
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
acc[key].evaluations.push(evaluation);
|
|
|
|
|
|
return acc;
|
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
|
|
// สร้าง formatData
|
|
|
|
|
|
const combinedDatas = Object.values(groupedEvaluations).map((group: any) => {
|
|
|
|
|
|
const data: any = {
|
2024-07-11 17:23:10 +07:00
|
|
|
|
fullName: group.fullName ?? null,
|
|
|
|
|
|
year: group.year ?? null,
|
2024-07-11 14:58:07 +07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
group.evaluations.forEach((evaluation: any) => {
|
|
|
|
|
|
if (evaluation.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
data.summaryPointAPR1 =
|
|
|
|
|
|
evaluation.summaryPoint >= 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointAPR2 =
|
|
|
|
|
|
evaluation.summaryPoint >= 80 && evaluation.summaryPoint < 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointAPR3 =
|
|
|
|
|
|
evaluation.summaryPoint >= 70 && evaluation.summaryPoint < 80
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointAPR4 =
|
|
|
|
|
|
evaluation.summaryPoint >= 60 && evaluation.summaryPoint < 70
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointAPR5 =
|
|
|
|
|
|
evaluation.summaryPoint < 60
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.periodAPR = evaluation.kpiPeriod.durationKPI;
|
|
|
|
|
|
} else if (evaluation.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
data.summaryPointOCT1 =
|
|
|
|
|
|
evaluation.summaryPoint >= 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointOCT2 =
|
|
|
|
|
|
evaluation.summaryPoint >= 80 && evaluation.summaryPoint < 90
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointOCT3 =
|
|
|
|
|
|
evaluation.summaryPoint >= 70 && evaluation.summaryPoint < 80
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointOCT4 =
|
|
|
|
|
|
evaluation.summaryPoint >= 60 && evaluation.summaryPoint < 70
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
|
|
|
|
|
data.summaryPointOCT5 =
|
|
|
|
|
|
evaluation.summaryPoint < 60
|
|
|
|
|
|
? Extension.ToThaiNumber(evaluation.summaryPoint.toString())
|
|
|
|
|
|
: null;
|
2024-07-11 17:23:10 +07:00
|
|
|
|
data.periodOCT = evaluation.kpiPeriod.durationKPI ?? null;
|
2024-07-11 14:58:07 +07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
});
|
2024-07-11 17:23:10 +07:00
|
|
|
|
formattedData = {
|
|
|
|
|
|
combinedDatas: combinedDatas.length > 0 ? combinedDatas : [{}],
|
|
|
|
|
|
fullName: combinedDatas[0]["fullName"] ?? null,
|
2024-07-11 14:58:07 +07:00
|
|
|
|
};
|
|
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI5") {
|
|
|
|
|
|
templateName = "KPI5";
|
|
|
|
|
|
reportName = "KPI5";
|
|
|
|
|
|
//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;
|
|
|
|
|
|
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();
|
|
|
|
|
|
if (requestBody.profileId) {
|
|
|
|
|
|
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-11 17:23:10 +07:00
|
|
|
|
// .where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
|
|
|
|
|
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const combinedData: KPIData = profileEvaluation.reduce(
|
|
|
|
|
|
(acc: KPIData, x) => {
|
|
|
|
|
|
const fullNameParts = [x.child4, x.child3, x.child2, x.child1, x.org];
|
|
|
|
|
|
|
|
|
|
|
|
const affiliation = fullNameParts
|
|
|
|
|
|
.filter((part) => part !== undefined && part !== null)
|
|
|
|
|
|
.join("/");
|
|
|
|
|
|
|
|
|
|
|
|
if (!acc.fullName) {
|
|
|
|
|
|
acc.fullName = x.prefix + " " + x.firstName + " " + x.lastName;
|
|
|
|
|
|
acc.position = x.position;
|
|
|
|
|
|
acc.posType = x.posTypeName;
|
|
|
|
|
|
acc.posLevel = x.posLevelName;
|
|
|
|
|
|
acc.affiliation = affiliation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR1 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR1 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR1 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT1 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT1 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT1 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR2 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR2 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR2 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT2 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT2 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT2 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR3 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR3 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR3 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT3 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT3 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT3 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR4 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR4 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR4 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR4 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT4 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT4 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT4 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT4 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR5 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR5 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR5 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR5 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT5 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT5 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT5 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT5 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()),
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
formattedData = combinedData;
|
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
if (requestBody.profileId) {
|
|
|
|
|
|
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-11 17:23:10 +07:00
|
|
|
|
// .where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
relations: ["kpiPeriod"],
|
|
|
|
|
|
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const combinedData: KPIData = profileEvaluation.reduce(
|
|
|
|
|
|
(acc: KPIData, x) => {
|
|
|
|
|
|
const fullNameParts = [x.child4, x.child3, x.child2, x.child1, x.org];
|
|
|
|
|
|
|
|
|
|
|
|
const affiliation = fullNameParts
|
|
|
|
|
|
.filter((part) => part !== undefined && part !== null)
|
|
|
|
|
|
.join("/");
|
|
|
|
|
|
|
|
|
|
|
|
if (!acc.fullName) {
|
|
|
|
|
|
acc.fullName = x.prefix + " " + x.firstName + " " + x.lastName;
|
|
|
|
|
|
acc.position = x.position;
|
|
|
|
|
|
acc.posType = x.posTypeName;
|
|
|
|
|
|
acc.posLevel = x.posLevelName;
|
|
|
|
|
|
acc.affiliation = affiliation;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR1 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR1 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR1 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT1 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT1 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT1 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT1 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR2 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR2 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR2 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT2 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT2 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT2 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT2 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
|
|
|
|
|
|
acc.summaryPointAPR3 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointAPR3 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodAPR3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearAPR3 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
|
|
|
|
|
|
acc.summaryPointOCT3 = Extension.ToThaiNumber(x.summaryPoint.toString()) ?? null;
|
|
|
|
|
|
acc.textPointOCT3 = Extension.textPoint(x.summaryPoint) ?? null;
|
|
|
|
|
|
acc.periodOCT3 = x.kpiPeriod.durationKPI;
|
|
|
|
|
|
acc.yearOCT3 =
|
|
|
|
|
|
Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString()) ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()),
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
formattedData = combinedData;
|
|
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI7") {
|
|
|
|
|
|
templateName = "KPI7";
|
|
|
|
|
|
reportName = "KPI7";
|
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-07-11 17:32:25 +07:00
|
|
|
|
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)
|
|
|
|
|
|
: "",
|
|
|
|
|
|
}))
|
|
|
|
|
|
: [{}],
|
|
|
|
|
|
};
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI8") {
|
|
|
|
|
|
templateName = "KPI8";
|
|
|
|
|
|
reportName = "KPI8";
|
|
|
|
|
|
//use_filter
|
2024-07-11 17:32:25 +07:00
|
|
|
|
if (requestBody.profileId) {
|
2024-07-11 16:59:44 +07:00
|
|
|
|
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
|
|
|
|
|
.createQueryBuilder("kpiUserEvaluation")
|
|
|
|
|
|
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
2024-07-11 17:23:10 +07:00
|
|
|
|
// .where("kpiUserEvaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
2024-07-11 16:59:44 +07:00
|
|
|
|
.andWhere("kpiUserEvaluation.kpiPeriodId = :kpiPeriodId", {
|
|
|
|
|
|
kpiPeriodId: requestBody.periodId,
|
|
|
|
|
|
})
|
|
|
|
|
|
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
|
|
|
|
|
.select("MIN(kpiUserEvaluation.id) as id")
|
|
|
|
|
|
.getRawMany();
|
|
|
|
|
|
const userInfo = await this.kpiUserEvaluationRepository.find({
|
2024-07-11 17:32:25 +07:00
|
|
|
|
where: {
|
|
|
|
|
|
id: In(profileEvaluationIds.map((x: any) => x.id)),
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2024-07-11 16:59:44 +07:00
|
|
|
|
const userDevelopmentLists = await this.kpiUserDevelopmentRepository.find({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
kpiUserEvaluationId: In(profileEvaluationIds.map((x: any) => x.id)),
|
|
|
|
|
|
},
|
|
|
|
|
|
select: [
|
|
|
|
|
|
"id",
|
|
|
|
|
|
"name",
|
|
|
|
|
|
"target",
|
|
|
|
|
|
"summary",
|
|
|
|
|
|
"point",
|
|
|
|
|
|
"achievement0",
|
|
|
|
|
|
"achievement5",
|
|
|
|
|
|
"achievement10",
|
|
|
|
|
|
"isDevelopment10",
|
|
|
|
|
|
"isDevelopment20",
|
|
|
|
|
|
"isDevelopment70",
|
|
|
|
|
|
],
|
|
|
|
|
|
});
|
2024-07-11 17:32:25 +07:00
|
|
|
|
|
|
|
|
|
|
const formattedUserDevelopmentLists = userDevelopmentLists.map(
|
|
|
|
|
|
(development: any, index: number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((index + 1).toString()),
|
|
|
|
|
|
...development,
|
|
|
|
|
|
summary: development.summary
|
|
|
|
|
|
? Extension.ToThaiNumber(development.summary.toString())
|
2024-07-11 16:59:44 +07:00
|
|
|
|
: null,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
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,
|
2024-07-11 17:38:35 +07:00
|
|
|
|
position: userInfo ? userInfo[0]?.position : null,
|
|
|
|
|
|
posType: userInfo ? userInfo[0]?.posTypeName : null,
|
|
|
|
|
|
posLevel: userInfo ? userInfo[0]?.posLevelName : null,
|
2024-07-11 17:32:25 +07:00
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
developments: formattedUserDevelopmentLists,
|
|
|
|
|
|
} || [{}];
|
2024-07-11 16:59:44 +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-07-10 18:34:23 +07:00
|
|
|
|
formattedData = {
|
2024-07-11 17:32:25 +07:00
|
|
|
|
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)
|
|
|
|
|
|
: "",
|
|
|
|
|
|
}))
|
|
|
|
|
|
: [{}],
|
|
|
|
|
|
};
|
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),
|
|
|
|
|
|
positionEvaluator: kpiUserEvaluation.positionEvaluator,
|
|
|
|
|
|
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))),
|
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
|
|
|
|
}
|