KPI แบบฟอร์ม 1 #1243

This commit is contained in:
Bright 2025-02-15 15:10:19 +07:00
parent 8678a4b62b
commit 3161ccce3d

View file

@ -8,6 +8,9 @@ import { KpiPeriod } from "../entities/kpiPeriod";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
import Extension from "../interfaces/extension";
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
import { KpiCapacity } from "../entities/kpiCapacity";
import { KpiPlan } from "../entities/kpiPlan";
import { KpiRole } from "../entities/kpiRole";
import CallAPI from "../interfaces/call-api";
@Route("api/v1/kpi/report")
@Tags("Report")
@ -16,6 +19,9 @@ export class ReportController extends Controller {
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
private kpiUserDevelopmentRepository = AppDataSource.getRepository(KpiUserDevelopment);
private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity);
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
@Post("announcement")
async GetReportAnnouncement(
@ -1765,4 +1771,218 @@ export class ReportController extends Controller {
data: formattedData,
});
}
/**
* API Report
*
* @summary Report
*
* @param {string} id Guid, *Id
*/
@Get("list/{id}")
async GetReportKpiListGroup1(@Path() id?: string) {
const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
relations: [
"kpiPeriod",
"kpiUserPlanneds",
"kpiUserRoles",
"kpiUserSpecials",
"kpiUserCapacitys",
"kpiUserDevelopments"
],
where: {
id: id
},
order: {
createdAt: "DESC",
kpiUserPlanneds: {
createdAt: "DESC"
},
kpiUserSpecials: {
createdAt: "DESC"
},
kpiUserCapacitys: {
createdAt: "DESC"
}
}
});
if (!kpiUserEvaluation) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน");
const isGroup2: boolean = ["ทั่วไป", "วิชาการ"].includes(kpiUserEvaluation.posTypeName);
const Plan = await this.kpiPlanRepository.find();
const Role = await this.kpiRoleRepository.find();
const Capacitys = await this.kpiCapacityRepository.find({
where: {
type: In(["HEAD", "EXECUTIVE", "GROUP"])
}
});
let durationKpi_APR = kpiUserEvaluation.kpiPeriod && kpiUserEvaluation.kpiPeriod.durationKPI == "APR" ? `🗹` : ``
let durationKpi_OCT = kpiUserEvaluation.kpiPeriod && kpiUserEvaluation.kpiPeriod.durationKPI == "OCT" ? `🗹` : ``
let period1:string="";
let period2:string="";
if(kpiUserEvaluation.kpiPeriod) {
if (kpiUserEvaluation.kpiPeriod.durationKPI === "APR") {
period1 = `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.startDate)} ถึง ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.endDate)}`;
let _period2 = await this.kpiPeriodRepository.findOne({
where: {
year: kpiUserEvaluation.kpiPeriod.year,
durationKPI: "OCT",
},
});
period2 = _period2
? `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
: `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ๑ เมษายน ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)} ถึง ๓๑ กันยายน ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)}`;
}
else if (kpiUserEvaluation.kpiPeriod.durationKPI === "OCT") {
period2 = `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.startDate)} ถึง ${Extension.ToThaiFullDate2(kpiUserEvaluation.kpiPeriod.endDate)}`;
let _period1 = await this.kpiPeriodRepository.findOne({
where: {
year: kpiUserEvaluation.kpiPeriod.year,
durationKPI: "APR",
},
});
period1 = _period1
? `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
: `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ๑ ตุลาคม ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year-1)} ถึง ๓๑ มีนาคม ${Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)}`;
}
}
let mapData = {
year: kpiUserEvaluation.kpiPeriod
? Extension.ToThaiNumber((kpiUserEvaluation.kpiPeriod.year+543).toString())
: "-",
period: period1 != "" && period2 != ""
? Extension.ToThaiNumber(`${period1} ${period2}`)
: "-",
fullName: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName}`,
position: kpiUserEvaluation.position ? kpiUserEvaluation.position : "-",
posTypeName: kpiUserEvaluation.posTypeName ? kpiUserEvaluation.posTypeName : "-",
posLevelName: kpiUserEvaluation.posLevelName ? kpiUserEvaluation.posLevelName : "-",
org: kpiUserEvaluation.org ? kpiUserEvaluation.org : "-",
fullnameEvaluator:
`${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator}`,
positionEvaluator: kpiUserEvaluation.positionEvaluator,
posTypeNameEvaluator: kpiUserEvaluation.posTypeNameEvaluator,
posLevelNameEvaluator: kpiUserEvaluation.posLevelNameEvaluator,
orgEvaluator: kpiUserEvaluation.orgEvaluator,
fullnameCommander:
`${kpiUserEvaluation.prefixCommander}${kpiUserEvaluation.firstNameCommander} ${kpiUserEvaluation.lastNameCommander}`,
positionCommander: kpiUserEvaluation.positionCommander ? kpiUserEvaluation.positionCommander : "-",
fullnameCommanderHigh:
`${kpiUserEvaluation.prefixCommanderHigh}${kpiUserEvaluation.firstNameCommanderHigh} ${kpiUserEvaluation.lastNameCommanderHigh}`,
positionCommanderHigh: kpiUserEvaluation.positionCommanderHigh ? kpiUserEvaluation.positionCommanderHigh : "-",
planneds: kpiUserEvaluation.kpiUserPlanneds
.map(
x => ({
name: Plan.find(y => y.id === x.kpiPlanId)?.includingName || "-",
target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-",
point1: x.point == 1 ? "✔" : "-",
point2: x.point == 2 ? "✔" : "-",
point3: x.point == 3 ? "✔" : "-",
point4: x.point == 4 ? "✔" : "-",
point5: x.point == 5 ? "✔" : "-",
weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-",
achievement: Extension.ToThaiNumber(`ระดับ ${x.point}`),
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
roles: kpiUserEvaluation.kpiUserRoles
.map(
x => ({
name: Role.find(y => y.id === x.kpiRoleId)?.includingName || "-",
target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-",
point1: x.point == 1 ? "✔" : "-",
point2: x.point == 2 ? "✔" : "-",
point3: x.point == 3 ? "✔" : "-",
point4: x.point == 4 ? "✔" : "-",
point5: x.point == 5 ? "✔" : "-",
weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-",
achievement: Extension.ToThaiNumber(`ระดับ ${x.point}`),
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
specials: kpiUserEvaluation.kpiUserSpecials
.map(
x => ({
name: x.includingName ?? "-",
target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-",
point1: x.point == 1 ? "✔" : "-",
point2: x.point == 2 ? "✔" : "-",
point3: x.point == 3 ? "✔" : "-",
point4: x.point == 4 ? "✔" : "-",
point5: x.point == 5 ? "✔" : "-",
weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-",
achievement: Extension.ToThaiNumber(`ระดับ ${x.point}`),
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
develops: kpiUserEvaluation.kpiUserDevelopments
.map(
x => ({
name: x.name ?? "-",
target: x.target ? Extension.ToThaiNumber(x.target.toLocaleString()) : "-",
achievement10: x.point == 10 ? `🗹 ${x.achievement10}` : `${x.achievement10}`,
achievement5: x.point == 5 ? `🗹 ${x.achievement5}` : `${x.achievement5}`,
achievement0: x.point == 0 ? `🗹 ${x.achievement0}` : `${x.achievement0}`,
isDevelopment70: x.isDevelopment70 == true ? `🗹 ๗๐ การลงมือปฏิบัติ(โดยผู้บังคับบัญชามอบหมาย)` : `☐ ๗๐ การลงมือปฏิบัติ(โดยผู้บังคับบัญชามอบหมาย)`,
isDevelopment20: x.isDevelopment20 == true ? `🗹 ๒๐ การเรียนรู้จากผู้อื่น Coach/Mentor/Consulting` : `☐ ๒๐ การเรียนรู้จากผู้อื่น Coach/Mentor/Consulting`,
isDevelopment10: x.isDevelopment10 == true ? `🗹 ๑๐ การฝึกอบรมอื่น ๆ` : `☐ ๑๐ การฝึกอบรมอื่น ๆ`,
point: x.point ? Extension.ToThaiNumber(x.point.toLocaleString()) : "-",
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
headCaps: kpiUserEvaluation.kpiUserCapacitys
.filter(
x => Capacitys.some(y => y.id === x.kpiCapacityId && y.type === "HEAD")
).map(
x => ({
name: `- ${Capacitys.find(y => y.id === x.kpiCapacityId)?.name}`,
level: x.level ? Extension.ToThaiNumber(x.level.toLocaleString()) : "-",
weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-",
point1: x.point == 1 ? "✔" : "-",
point2: x.point == 2 ? "✔" : "-",
point3: x.point == 3 ? "✔" : "-",
point4: x.point == 4 ? "✔" : "-",
point5: x.point == 5 ? "✔" : "-",
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
executiveCaps: kpiUserEvaluation.kpiUserCapacitys
.filter(
x => Capacitys.some(y => y.id === x.kpiCapacityId && y.type === "EXECUTIVE")
).map(
x => ({
name: `- ${Capacitys.find(y => y.id === x.kpiCapacityId)?.name}`,
level: x.level ? Extension.ToThaiNumber(x.level.toLocaleString()) : "-",
weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-",
point1: x.point == 1 ? "✔" : "-",
point2: x.point == 2 ? "✔" : "-",
point3: x.point == 3 ? "✔" : "-",
point4: x.point == 4 ? "✔" : "-",
point5: x.point == 5 ? "✔" : "-",
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
groupCaps: kpiUserEvaluation.kpiUserCapacitys
.filter(
x => Capacitys.some(y => y.id === x.kpiCapacityId && y.type === "GROUP")
).map(
x => ({
name: `- ${Capacitys.find(y => y.id === x.kpiCapacityId)?.name}`,
level: x.level ? Extension.ToThaiNumber(x.level.toLocaleString()) : "-",
weight: x.weight ? Extension.ToThaiNumber(x.weight.toLocaleString()) : "-",
point1: x.point == 1 ? "✔" : "-",
point2: x.point == 2 ? "✔" : "-",
point3: x.point == 3 ? "✔" : "-",
point4: x.point == 4 ? "✔" : "-",
point5: x.point == 5 ? "✔" : "-",
summary: x.summary ? Extension.ToThaiNumber(x.summary.toLocaleString()) : "-",
})
),
};
return new HttpSuccess({
template: !isGroup2 ? "KPI_ListGroup1" : "KPI_ListGroup2&3",
reportName: !isGroup2 ? "KPI_ListGroup1" : "KPI_ListGroup2&3",
data: mapData,
});
}
}