This commit is contained in:
AdisakKanthawilang 2024-07-12 09:30:37 +07:00
parent 197867ea9f
commit f2a181e7ad

View file

@ -311,106 +311,150 @@ export class ReportController extends Controller {
if (requestBody.type == "KPI3") {
templateName = "KPI3";
reportName = "KPI3";
const userEvaluations_ = data?.kpiUserEvaluations?.length > 0
? data.kpiUserEvaluations.map((x:any, idx:number) => ({
no: Extension.ToThaiNumber((idx+1).toString()),
fullName: `${x.prefix}${x.firstName} ${x.lastName}`,
position: x.position ? x.position : "",
point1: x.summaryPoint >= 90.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
point2: x.summaryPoint >= 80.00 && x.summaryPoint <= 89.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
point3: x.summaryPoint >= 70.00 && x.summaryPoint <= 79.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
point4: x.summaryPoint >= 60.00 && x.summaryPoint <= 69.99 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
point5: x.summaryPoint < 60.00 ? Extension.ToThaiNumber(x.summaryPoint.toString()) : "",
remark: x.reasonEvaluator
}))
: [{}]
const prefixEvaluator_ = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].prefixEvaluator : ""
const firstNameEvaluator_ = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].firstNameEvaluator : ""
const lastNameEvaluator_ = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].lastNameEvaluator : ""
const fullNameEvaluator = prefixEvaluator_ != "" && firstNameEvaluator_ != "" && lastNameEvaluator_ != ""
? `${prefixEvaluator_}${firstNameEvaluator_} ${lastNameEvaluator_}`
: "-"
const commanderId = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].commanderId : ""
let prefixCommander = ""
let firstNameCommander = ""
let lastNameCommander = ""
let positionCommander = ""
let posTypeNameCommander = ""
let posLevelNameCommander = ""
let orgCommander = ""
if(commanderId != "" && commanderId != null) {
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: x.reasonEvaluator,
}))
: [{}];
const prefixEvaluator_ =
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].prefixEvaluator : "";
const firstNameEvaluator_ =
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].firstNameEvaluator : "";
const lastNameEvaluator_ =
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].lastNameEvaluator : "";
const fullNameEvaluator =
prefixEvaluator_ != "" && firstNameEvaluator_ != "" && lastNameEvaluator_ != ""
? `${prefixEvaluator_}${firstNameEvaluator_} ${lastNameEvaluator_}`
: "-";
const commanderId =
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].commanderId : "";
let prefixCommander = "";
let firstNameCommander = "";
let lastNameCommander = "";
let positionCommander = "";
let posTypeNameCommander = "";
let posLevelNameCommander = "";
let orgCommander = "";
if (commanderId != "" && commanderId != null) {
await new CallAPI()
.GetData(request, "org/profile/profileid/position/"+commanderId)
.then((x) => {
prefixCommander = x.prefix;
firstNameCommander = x.firstName;
lastNameCommander = x.lastName;
positionCommander = x.position;
orgCommander = x.root;
posTypeNameCommander = x.posTypeName;
posLevelNameCommander = x.posLevelName;
})
.catch((x) => {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
.GetData(request, "org/profile/profileid/position/" + commanderId)
.then((x) => {
prefixCommander = x.prefix;
firstNameCommander = x.firstName;
lastNameCommander = x.lastName;
positionCommander = x.position;
orgCommander = x.root;
posTypeNameCommander = x.posTypeName;
posLevelNameCommander = x.posLevelName;
})
.catch((x) => {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
}
const fullNameCommander = prefixCommander != "" && firstNameCommander != "" && firstNameCommander != ""
? `${prefixCommander}${firstNameCommander} ${lastNameCommander}`
: "-"
const fullNameCommander =
prefixCommander != "" && firstNameCommander != "" && firstNameCommander != ""
? `${prefixCommander}${firstNameCommander} ${lastNameCommander}`
: "-";
const commanderHighId = data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].commanderHighId : ""
let prefixCommanderHigh = ""
let firstNameCommanderHigh = ""
let lastNameCommanderHigh = ""
let positionCommanderHigh = ""
let posTypeNameCommanderHigh = ""
let posLevelNameCommanderHigh = ""
let orgCommanderHigh
if(commanderHighId != "" && commanderHighId != null) {
const commanderHighId =
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].commanderHighId : "";
let prefixCommanderHigh = "";
let firstNameCommanderHigh = "";
let lastNameCommanderHigh = "";
let positionCommanderHigh = "";
let posTypeNameCommanderHigh = "";
let posLevelNameCommanderHigh = "";
let orgCommanderHigh;
if (commanderHighId != "" && commanderHighId != null) {
await new CallAPI()
.GetData(request, "org/profile/profileid/position/"+commanderHighId)
.then((x) => {
prefixCommanderHigh = x.prefix;
firstNameCommanderHigh = x.firstName;
lastNameCommanderHigh = x.lastName;
positionCommanderHigh = x.position;
orgCommanderHigh = x.root;
posTypeNameCommanderHigh = x.posTypeName;
posLevelNameCommanderHigh = x.posLevelName;
})
.catch((x) => {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
.GetData(request, "org/profile/profileid/position/" + commanderHighId)
.then((x) => {
prefixCommanderHigh = x.prefix;
firstNameCommanderHigh = x.firstName;
lastNameCommanderHigh = x.lastName;
positionCommanderHigh = x.position;
orgCommanderHigh = x.root;
posTypeNameCommanderHigh = x.posTypeName;
posLevelNameCommanderHigh = x.posLevelName;
})
.catch((x) => {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
}
const fullNameCommanderHigh = prefixCommanderHigh != "" && firstNameCommanderHigh != "" && lastNameCommanderHigh != ""
? `${prefixCommanderHigh}${firstNameCommanderHigh} ${lastNameCommanderHigh}`
: "-"
const fullNameCommanderHigh =
prefixCommanderHigh != "" && firstNameCommanderHigh != "" && lastNameCommanderHigh != ""
? `${prefixCommanderHigh}${firstNameCommanderHigh} ${lastNameCommanderHigh}`
: "-";
formattedData = {
year: data?.year ? Extension.ToThaiNumber((data.year+543).toString()) : "-",
year: data?.year ? Extension.ToThaiNumber((data.year + 543).toString()) : "-",
period1: Extension.ToThaiNumber(period1),
period2: Extension.ToThaiNumber(period2),
durationKPI: data?.durationKPI,
root: data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
? data?.kpiUserEvaluations[0].orgEvaluator
: "-",
root:
data?.kpiUserEvaluations != null && data?.kpiUserEvaluations.length > 0
? data?.kpiUserEvaluations[0].orgEvaluator
: "-",
fullNameEvaluator: fullNameEvaluator,
positionEvaluator: data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].positionEvaluator : "-",
posTypeNameEvaluator: data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].posTypeNameEvaluator : "-",
posLevelNameEvaluator: data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].posLevelNameEvaluator : "-",
orgEvaluator: data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].orgEvaluator : "-",
positionEvaluator:
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].positionEvaluator : "-",
posTypeNameEvaluator:
data.kpiUserEvaluations.length > 0
? data.kpiUserEvaluations[0].posTypeNameEvaluator
: "-",
posLevelNameEvaluator:
data.kpiUserEvaluations.length > 0
? data.kpiUserEvaluations[0].posLevelNameEvaluator
: "-",
orgEvaluator:
data.kpiUserEvaluations.length > 0 ? data.kpiUserEvaluations[0].orgEvaluator : "-",
fullNameCommander: fullNameCommander,
positionCommander: positionCommander != "" && positionCommander != null ? positionCommander : "-",
posTypeNameCommander: posTypeNameCommander != "" && posTypeNameCommander != null ? posTypeNameCommander : "-",
posLevelNameCommander: posLevelNameCommander != "" && posLevelNameCommander != null ? posLevelNameCommander : "-",
positionCommander:
positionCommander != "" && positionCommander != null ? positionCommander : "-",
posTypeNameCommander:
posTypeNameCommander != "" && posTypeNameCommander != null ? posTypeNameCommander : "-",
posLevelNameCommander:
posLevelNameCommander != "" && posLevelNameCommander != null
? posLevelNameCommander
: "-",
orgCommander: orgCommander != "" && orgCommander != null ? orgCommander : "-",
fullNameCommanderHigh: fullNameCommanderHigh,
positionCommanderHigh: positionCommanderHigh != "" && positionCommanderHigh != null ? positionCommanderHigh : "-",
posTypeNameCommanderHigh: posTypeNameCommanderHigh != "" && posTypeNameCommanderHigh != null ? posTypeNameCommanderHigh : "-",
posLevelNameCommanderHigh: posLevelNameCommanderHigh != "" && posLevelNameCommanderHigh != null ? posLevelNameCommanderHigh : "-",
orgCommanderHigh: orgCommanderHigh != "" && orgCommanderHigh != null ? orgCommanderHigh : "-",
userEvaluations : userEvaluations_
}
positionCommanderHigh:
positionCommanderHigh != "" && positionCommanderHigh != null
? positionCommanderHigh
: "-",
posTypeNameCommanderHigh:
posTypeNameCommanderHigh != "" && posTypeNameCommanderHigh != null
? posTypeNameCommanderHigh
: "-",
posLevelNameCommanderHigh:
posLevelNameCommanderHigh != "" && posLevelNameCommanderHigh != null
? posLevelNameCommanderHigh
: "-",
orgCommanderHigh:
orgCommanderHigh != "" && orgCommanderHigh != null ? orgCommanderHigh : "-",
userEvaluations: userEvaluations_,
};
}
if (requestBody.type == "KPI4") {
templateName = "KPI4";
@ -917,37 +961,40 @@ export class ReportController extends Controller {
templateName = "KPI7";
reportName = "KPI7";
const userEvaluations_ = await Promise.all(data.kpiUserEvaluations.length > 0
? data.kpiUserEvaluations.map(async (x: any, idx: number) => {
const target_ = await this.kpiUserDevelopmentRepository.findOne({
where: { kpiUserEvaluationId: x.id}
});
return {
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: target_ ? target_.target: "",
timeEvaluator: x.timeEvaluator ? Extension.ToThaiNumber(x.timeEvaluator) : "",
developResults: "", //วิธีการวัดผลการพัฒนา
evaluationResults: x.evaluationResults
? Extension.EvaluationResult(x.evaluationResults)
: "",
}})
: [{}]
)
const userEvaluations_ = await Promise.all(
data.kpiUserEvaluations.length > 0
? data.kpiUserEvaluations.map(async (x: any, idx: number) => {
const target_ = await this.kpiUserDevelopmentRepository.findOne({
where: { kpiUserEvaluationId: x.id },
});
return {
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: target_ ? target_.target : "",
timeEvaluator: x.timeEvaluator ? Extension.ToThaiNumber(x.timeEvaluator) : "",
developResults: "", //วิธีการวัดผลการพัฒนา
evaluationResults: x.evaluationResults
? Extension.EvaluationResult(x.evaluationResults)
: "",
};
})
: [{}],
);
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: userEvaluations_
}
root:
data.kpiUserEvaluations != null && data.kpiUserEvaluations.length > 0
? data?.kpiUserEvaluations[0].orgEvaluator
: "-",
userEvaluations: userEvaluations_,
};
}
if (requestBody.type == "KPI8") {
templateName = "KPI8";
@ -964,65 +1011,69 @@ export class ReportController extends Controller {
.groupBy("kpiUserEvaluation.kpiPeriodId")
.select("MIN(kpiUserEvaluation.id) as id")
.getRawMany();
const userInfo = await this.kpiUserEvaluationRepository.find({
where: {
id: In(profileEvaluationIds.map((x: any) => x.id)),
},
});
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",
],
});
if (profileEvaluationIds.length > 0) {
const userInfo = await this.kpiUserEvaluationRepository.find({
where: {
id: In(profileEvaluationIds.map((x: any) => x.id)),
},
});
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",
],
});
const formattedUserDevelopmentLists = userDevelopmentLists.map(
(development: any, index: number) => ({
no: Extension.ToThaiNumber((index + 1).toString()),
...development,
summary: development.summary
? Extension.ToThaiNumber(development.summary.toString())
const formattedUserDevelopmentLists = userDevelopmentLists.map(
(development: any, index: number) => ({
no: Extension.ToThaiNumber((index + 1).toString()),
...development,
summary: development.summary
? Extension.ToThaiNumber(development.summary.toString())
: null,
point: development.point
? Extension.ToThaiNumber(development.point.toString())
: null,
}),
);
const fullNameParts = [
userInfo[0]?.child4,
userInfo[0]?.child3,
userInfo[0]?.child2,
userInfo[0]?.child1,
userInfo[0]?.org,
];
const affiliation = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
formattedData = {
fullName: userInfo
? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName
: null,
point: development.point ? Extension.ToThaiNumber(development.point.toString()) : null,
}),
);
const fullNameParts = [
userInfo[0]?.child4,
userInfo[0]?.child3,
userInfo[0]?.child2,
userInfo[0]?.child1,
userInfo[0]?.org,
];
const affiliation = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
formattedData = {
fullName: userInfo
? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName
: null,
affiliation: affiliation ?? null,
durationKPI: data?.durationKPI ?? null,
position: userInfo ? userInfo[0]?.position : null,
posType: userInfo ? userInfo[0]?.posTypeName : null,
posLevel: userInfo ? userInfo[0]?.posLevelName : null,
period1: Extension.ToThaiNumber(period1),
period2: Extension.ToThaiNumber(period2),
developments:
formattedUserDevelopmentLists.length > 0 ? formattedUserDevelopmentLists : [{}],
};
affiliation: affiliation ?? null,
durationKPI: data?.durationKPI ?? null,
position: userInfo ? userInfo[0]?.position : null,
posType: userInfo ? userInfo[0]?.posTypeName : null,
posLevel: userInfo ? userInfo[0]?.posLevelName : null,
period1: Extension.ToThaiNumber(period1),
period2: Extension.ToThaiNumber(period2),
developments:
formattedUserDevelopmentLists.length > 0 ? formattedUserDevelopmentLists : [{}],
};
}
}
}
if (requestBody.type == "KPI9") {