2024-06-13 11:34:25 +07:00
|
|
|
|
import {
|
|
|
|
|
|
Controller,
|
|
|
|
|
|
Get,
|
|
|
|
|
|
Post,
|
|
|
|
|
|
Put,
|
|
|
|
|
|
Delete,
|
|
|
|
|
|
Route,
|
|
|
|
|
|
Security,
|
|
|
|
|
|
Tags,
|
|
|
|
|
|
Body,
|
|
|
|
|
|
Path,
|
|
|
|
|
|
Request,
|
|
|
|
|
|
Query,
|
|
|
|
|
|
} from "tsoa";
|
|
|
|
|
|
import { AppDataSource } from "../database/data-source";
|
2024-07-10 18:34:23 +07:00
|
|
|
|
import { Brackets, IsNull, 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 { 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-06-14 14:15:30 +07:00
|
|
|
|
|
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-10 19:40:37 +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({
|
|
|
|
|
|
where: { id: requestBody.periodId }
|
|
|
|
|
|
})
|
|
|
|
|
|
dataKpiUserEvaluations = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
kpiPeriodId: String(requestBody.periodId),
|
|
|
|
|
|
orgId: requestBody.root
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
data = {
|
|
|
|
|
|
id: data.id,
|
|
|
|
|
|
year: data.year,
|
|
|
|
|
|
durationKPI: data.durationKPI,
|
|
|
|
|
|
startDate: data.startDate,
|
|
|
|
|
|
endDate: data.endDate,
|
|
|
|
|
|
kpiUserEvaluations: dataKpiUserEvaluations
|
|
|
|
|
|
}
|
2024-07-10 18:34:23 +07:00
|
|
|
|
|
|
|
|
|
|
if(data.durationKPI == "APR") {
|
|
|
|
|
|
period1 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`
|
|
|
|
|
|
let _period2 = await this.kpiPeriodRepository.findOne({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
year: data.year, durationKPI: "OCR", isActive: true
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
period2 = _period2 ? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}` : ""
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(data.durationKPI == "OCT"){
|
|
|
|
|
|
period2 = `${Extension.ToThaiFullDate2(data.startDate)} ถึง ${Extension.ToThaiFullDate2(data.endDate)}`
|
|
|
|
|
|
let _period1 = await this.kpiPeriodRepository.findOne({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
year: data.year, durationKPI: "APR", isActive: true
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
period1 = _period1 ? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}` : ""
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-25 13:55:36 +07:00
|
|
|
|
if (requestBody.type == "KPI1") {
|
|
|
|
|
|
templateName = "KPI1";
|
|
|
|
|
|
reportName = "KPI1";
|
2024-07-10 18:34:23 +07:00
|
|
|
|
/*ROOT*/
|
|
|
|
|
|
const userEvaluationOrg = await this.kpiUserEvaluationRepository.find({
|
|
|
|
|
|
where: {
|
|
|
|
|
|
orgId: String(requestBody.root),
|
|
|
|
|
|
// child1Id: "" || IsNull(),
|
|
|
|
|
|
// child2Id: "" || IsNull(),
|
|
|
|
|
|
// child3Id: "" || IsNull(),
|
|
|
|
|
|
// child4Id: "" || IsNull(),
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
const resultAll = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
const result = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults != "PENDING").length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
const excellent = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "EXCELLENT").length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
const verygood = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "VERY_GOOD").length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
const good = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "GOOD").length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
const fair = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "FAIR").length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
const improvment = userEvaluationOrg.length > 0
|
|
|
|
|
|
? Extension.ToThaiNumber(userEvaluationOrg.filter((x:any) => x.evaluationResults == "IMPROVEMENT").length.toString())
|
|
|
|
|
|
: "๐"
|
|
|
|
|
|
/*END ROOT*/
|
|
|
|
|
|
formattedData = {
|
|
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
|
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
durationKPI: data?.durationKPI,
|
|
|
|
|
|
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "",
|
|
|
|
|
|
userEvaluations: [
|
|
|
|
|
|
{
|
|
|
|
|
|
no: "๑",
|
|
|
|
|
|
root: userEvaluationOrg.length > 0
|
|
|
|
|
|
? userEvaluationOrg[0].orgEvaluator ?? ""
|
|
|
|
|
|
: "",
|
|
|
|
|
|
resultAll: resultAll,
|
|
|
|
|
|
result: result,
|
|
|
|
|
|
excellent: excellent,
|
|
|
|
|
|
verygood: verygood,
|
|
|
|
|
|
good: good,
|
|
|
|
|
|
fair: fair,
|
|
|
|
|
|
improvment: improvment,
|
|
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
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-10 18:34:23 +07:00
|
|
|
|
const excellent = data.length > 0
|
|
|
|
|
|
? data.fla((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.length > 0
|
|
|
|
|
|
? data.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.length > 0
|
|
|
|
|
|
? data.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.length > 0
|
|
|
|
|
|
? data.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.length > 0
|
|
|
|
|
|
? data.map((x:any, idx:number) => ({
|
|
|
|
|
|
no: Extension.ToThaiNumber((idx+1).toString()),
|
|
|
|
|
|
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
|
|
|
|
|
|
position: x.position ? x.position : "",
|
|
|
|
|
|
posLevelName: x.posLevelName ? x.posLevelName : "",
|
|
|
|
|
|
org: x.org ? x.org : "",
|
|
|
|
|
|
})).filter((x:any) => x.evaluationResults == "IMPROVEMENT")
|
|
|
|
|
|
: []
|
|
|
|
|
|
formattedData = {
|
|
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
|
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
durationKPI: data?.durationKPI,
|
|
|
|
|
|
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "",
|
|
|
|
|
|
excellents: {
|
|
|
|
|
|
count: Extension.ToThaiNumber(excellent.length.toString()),
|
|
|
|
|
|
data: excellent
|
|
|
|
|
|
},
|
|
|
|
|
|
verygoods: {
|
|
|
|
|
|
count: Extension.ToThaiNumber(verygood.length.toString()),
|
|
|
|
|
|
data: verygood
|
|
|
|
|
|
},
|
|
|
|
|
|
goods: {
|
|
|
|
|
|
count: Extension.ToThaiNumber(good.length.toString()),
|
|
|
|
|
|
data: good
|
|
|
|
|
|
},
|
|
|
|
|
|
fairs: {
|
|
|
|
|
|
count: Extension.ToThaiNumber(fair.length.toString()),
|
|
|
|
|
|
data: fair
|
|
|
|
|
|
},
|
|
|
|
|
|
improvments: {
|
|
|
|
|
|
count: Extension.ToThaiNumber(improvment.length.toString()),
|
|
|
|
|
|
data: improvment
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI3") {
|
|
|
|
|
|
templateName = "KPI3";
|
|
|
|
|
|
reportName = "KPI3";
|
2024-07-10 18:34:23 +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.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
|
|
|
|
|
point2: x.summaryPoint >= 80.00 && x.summaryPoint <= 89.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
|
|
|
|
|
point3: x.summaryPoint >= 70.00 && x.summaryPoint <= 79.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
|
|
|
|
|
point4: x.summaryPoint >= 60.00 && x.summaryPoint <= 69.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
|
|
|
|
|
point5: x.summaryPoint < 60.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
|
|
|
|
|
|
remark: ""
|
|
|
|
|
|
}))
|
|
|
|
|
|
: []
|
|
|
|
|
|
// const prefixEvaluator_ = data.kpiUserEvaluations.find((x:any) => x.prefixEvaluator);
|
|
|
|
|
|
// const firstNameEvaluator_ = data.kpiUserEvaluations.firstNameEvaluator ? data.kpiUserEvaluations.firstNameEvaluator : "";
|
|
|
|
|
|
// const lastNameEvaluator_ = data.kpiUserEvaluations.lastNameEvaluator ? data.kpiUserEvaluations.lastNameEvaluator : "";
|
|
|
|
|
|
formattedData = {
|
|
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
|
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
durationKPI: data?.durationKPI,
|
|
|
|
|
|
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "",
|
|
|
|
|
|
fullNameEvaluator: "-",
|
|
|
|
|
|
positionEvaluator: "-",
|
|
|
|
|
|
posTypeNameEvaluator: "-",
|
|
|
|
|
|
posLevelNameEvaluator: "-",
|
|
|
|
|
|
orgEvaluator: "-",
|
|
|
|
|
|
|
|
|
|
|
|
fullNameCommander: "-",
|
|
|
|
|
|
positionCommander: "-",
|
|
|
|
|
|
posTypeNameCommander: "-",
|
|
|
|
|
|
posLevelNameCommander: "-",
|
|
|
|
|
|
orgCommander: "-",
|
|
|
|
|
|
|
|
|
|
|
|
fullNameCommanderHigh: "-",
|
|
|
|
|
|
positionCommanderHigh: "-",
|
|
|
|
|
|
posTypeNameCommanderHigh: "-",
|
|
|
|
|
|
posLevelNameCommanderHigh: "-",
|
|
|
|
|
|
orgCommanderHigh: "-",
|
|
|
|
|
|
userEvaluations : userEvaluations_
|
|
|
|
|
|
}
|
2024-06-25 13:55:36 +07:00
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI4") {
|
|
|
|
|
|
templateName = "KPI4";
|
|
|
|
|
|
reportName = "KPI4";
|
|
|
|
|
|
//use_filter
|
|
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI5") {
|
|
|
|
|
|
templateName = "KPI5";
|
|
|
|
|
|
reportName = "KPI5";
|
|
|
|
|
|
//use_filter
|
|
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI6") {
|
|
|
|
|
|
templateName = "KPI6";
|
|
|
|
|
|
reportName = "KPI6";
|
|
|
|
|
|
//use_filter
|
|
|
|
|
|
}
|
|
|
|
|
|
if (requestBody.type == "KPI7") {
|
|
|
|
|
|
templateName = "KPI7";
|
|
|
|
|
|
reportName = "KPI7";
|
2024-07-10 18:34:23 +07:00
|
|
|
|
formattedData = {
|
|
|
|
|
|
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "",
|
|
|
|
|
|
period1: Extension.ToThaiNumber(period1),
|
|
|
|
|
|
period2: Extension.ToThaiNumber(period2),
|
|
|
|
|
|
durationKPI: data?.durationKPI,
|
|
|
|
|
|
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "",
|
|
|
|
|
|
userEvaluations: data.kpiUserEvaluations.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
|
|
|
|
|
|
}
|
|
|
|
|
|
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 = {
|
|
|
|
|
|
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
|
|
|
|
|
|
? data?.kpiUserEvaluations[0].orgEvaluator
|
|
|
|
|
|
: "",
|
|
|
|
|
|
period: data?.durationKPI == "APR" ? "๑": data?.durationKPI == "OCT" ? "๒" : "-",
|
|
|
|
|
|
year: Extension.ToThaiNumber((data.year+543).toString()),
|
|
|
|
|
|
userEvaluations: 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-10 18:34:23 +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-10 18:34:23 +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-10 18:34:23 +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-10 18:34:23 +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
|
|
|
|
}
|