fix orderPeriod/report kpi8

This commit is contained in:
Bright 2024-07-12 16:10:39 +07:00
parent 9526799ec0
commit e8ff7f76cc
2 changed files with 64 additions and 55 deletions

View file

@ -215,7 +215,8 @@ export class kpiPeriodController extends Controller {
year !== 0 && year != null && year != undefined ? "kpiPeriod.year = :year" : "1=1",
{ year: year },
)
.orderBy("kpiPeriod.createdAt", "DESC")
.orderBy("kpiPeriod.startDate", "ASC")
.addOrderBy("kpiPeriod.year", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();

View file

@ -75,6 +75,7 @@ export class ReportController extends Controller {
where: {
kpiPeriodId: requestBody.periodId,
orgId: requestBody.root,
evaluationStatus: "KP7"
},
});
data = {
@ -1016,7 +1017,44 @@ export class ReportController extends Controller {
templateName = "KPI8";
reportName = "KPI8";
//use_filter
if (requestBody.profileId) {
let period_:any
let formattedUserDevelopmentLists:any
let userInfo:any
let userDevelopmentLists:any
let fullNameParts:any
let affiliation:any
if (requestBody.profileId && requestBody.periodId) {
period_ = await this.kpiPeriodRepository.findOne({
where: { id: String(requestBody.periodId) }
})
if(period_ && !period1 && !period2) {
if(period_?.durationKPI === "APR") {
period1 = `${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
let _period2 = await this.kpiPeriodRepository.findOne({
where: {
year: period_.year,
durationKPI: "OCT",
isActive: true,
},
});
period2 = _period2
? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
: "";
}
else if (period_?.durationKPI === "OCT"){
period2 = `${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
let _period1 = await this.kpiPeriodRepository.findOne({
where: {
year: period_.year,
durationKPI: "APR",
isActive: true,
},
});
period1 = _period1
? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
: "";
}
}
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
.createQueryBuilder("kpiUserEvaluation")
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
@ -1024,16 +1062,18 @@ export class ReportController extends Controller {
.andWhere("kpiUserEvaluation.kpiPeriodId = :kpiPeriodId", {
kpiPeriodId: requestBody.periodId,
})
.andWhere("kpiUserEvaluation.evaluationStatus = 'KP7'")
.groupBy("kpiUserEvaluation.kpiPeriodId")
.select("MIN(kpiUserEvaluation.id) as id")
.getRawMany();
if (profileEvaluationIds.length > 0) {
const userInfo = await this.kpiUserEvaluationRepository.find({
userInfo = await this.kpiUserEvaluationRepository.find({
where: {
id: In(profileEvaluationIds.map((x: any) => x.id)),
evaluationStatus: "KP7"
},
});
const userDevelopmentLists = await this.kpiUserDevelopmentRepository.find({
userDevelopmentLists = await this.kpiUserDevelopmentRepository.find({
where: {
kpiUserEvaluationId: In(profileEvaluationIds.map((x: any) => x.id)),
},
@ -1052,7 +1092,7 @@ export class ReportController extends Controller {
],
});
const formattedUserDevelopmentLists = userDevelopmentLists.map(
formattedUserDevelopmentLists = userDevelopmentLists.map(
(development: any, index: number) => ({
no: Extension.ToThaiNumber((index + 1).toString()),
...development,
@ -1065,65 +1105,33 @@ export class ReportController extends Controller {
}),
);
const fullNameParts = [
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)
affiliation = fullNameParts
.filter((part:any) => part !== undefined && part !== null)
.join("/");
const period_ = await this.kpiPeriodRepository.findOne({
where: { id: String(requestBody.periodId) }
})
if(period_ && !period1 && !period2) {
if(period_?.durationKPI === "APR") {
period1 = `${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
let _period2 = await this.kpiPeriodRepository.findOne({
where: {
year: period_.year,
durationKPI: "OCT",
isActive: true,
},
});
period2 = _period2
? `${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
: "";
}
else if (period_?.durationKPI === "OCT"){
period2 = `${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
let _period1 = await this.kpiPeriodRepository.findOne({
where: {
year: period_.year,
durationKPI: "APR",
isActive: true,
},
});
period1 = _period1
? `${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
: "";
}
}
formattedData = {
fullName: userInfo
? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName
: null,
affiliation: affiliation ?? null,
// durationKPI: data?.durationKPI ?? null,
durationKPI: period_ ? period_.durationKPI : null,
position: userInfo ? userInfo[0]?.position : null,
posType: userInfo ? userInfo[0]?.posTypeName : null,
posLevel: userInfo ? userInfo[0]?.posLevelName : null,
period1: period1 ? Extension.ToThaiNumber(period1) : "-",
period2: period2 ? Extension.ToThaiNumber(period2) : "-",
developments:
formattedUserDevelopmentLists.length > 0 ? formattedUserDevelopmentLists : [{}],
};
}
}
formattedData = {
year: period_ ? Extension.ToThaiNumber(period_.year.toString()) : "-",
fullName: userInfo
? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName
: "-",
affiliation: affiliation ?? "-",
durationKPI: period_ ? period_.durationKPI : "-",
position: userInfo ? userInfo[0]?.position : "-",
posType: userInfo ? userInfo[0]?.posTypeName : "-",
posLevel: userInfo ? userInfo[0]?.posLevelName : "-",
period1: period1 ? Extension.ToThaiNumber(period1) : "-",
period2: period2 ? Extension.ToThaiNumber(period2) : "-",
developments:
formattedUserDevelopmentLists ? formattedUserDevelopmentLists : [{}],
};
}
if (requestBody.type == "KPI9") {
templateName = "KPI9";