fix report kpi
This commit is contained in:
parent
a9958c7e71
commit
b32e7a28f1
1 changed files with 32 additions and 19 deletions
|
|
@ -570,7 +570,6 @@ export class ReportController extends Controller {
|
|||
reportName = "KPI4";
|
||||
let combinedDatas: any;
|
||||
if (requestBody.profileId) {
|
||||
//ชั่วคราว
|
||||
const profileEvaluationNowYearIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
||||
.createQueryBuilder("kpiUserEvaluation")
|
||||
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
|
||||
|
|
@ -579,13 +578,24 @@ export class ReportController extends Controller {
|
|||
evaluationStatus: "KP7",
|
||||
})
|
||||
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
||||
.select("MIN(kpiUserEvaluation.id) as id")
|
||||
// .select("MIN(kpiUserEvaluation.id) as id")
|
||||
.select([
|
||||
"kpiUserEvaluation.kpiPeriodId as kpiPeriodId",
|
||||
"AVG(kpiUserEvaluation.summaryPoint) as avgSummaryPoint"
|
||||
])
|
||||
.getRawMany();
|
||||
|
||||
//ชั่วคราว
|
||||
// const profileEvaluations = await this.kpiUserEvaluationRepository.find({
|
||||
// relations: ["kpiPeriod"],
|
||||
// where: { id: In(profileEvaluationNowYearIds.map((evaluation) => evaluation.id)) },
|
||||
// });
|
||||
const profileEvaluations = await this.kpiUserEvaluationRepository.find({
|
||||
relations: ["kpiPeriod"],
|
||||
where: { id: In(profileEvaluationNowYearIds.map((evaluation) => evaluation.id)) },
|
||||
where: {
|
||||
kpiPeriodId: In(profileEvaluationNowYearIds.map((evaluation) => evaluation.kpiPeriodId)),
|
||||
profileId: requestBody.profileId,
|
||||
evaluationStatus: "KP7"
|
||||
},
|
||||
});
|
||||
|
||||
const groupedEvaluations = profileEvaluations.reduce((acc: any, evaluation: any) => {
|
||||
|
|
@ -601,7 +611,11 @@ export class ReportController extends Controller {
|
|||
evaluations: [],
|
||||
};
|
||||
}
|
||||
|
||||
const avgSummaryPoint = profileEvaluationNowYearIds.find(
|
||||
(e) => e.kpiPeriodId === evaluation.kpiPeriodId
|
||||
)?.avgSummaryPoint;
|
||||
|
||||
evaluation.summaryPoint = avgSummaryPoint;
|
||||
acc[key].evaluations.push(evaluation);
|
||||
return acc;
|
||||
}, {});
|
||||
|
|
@ -761,7 +775,7 @@ export class ReportController extends Controller {
|
|||
acc.position = x.position;
|
||||
acc.posType = x.posTypeName;
|
||||
acc.posLevel = x.posLevelName;
|
||||
acc.affiliation = affiliation ?? "-";
|
||||
acc.affiliation = affiliation == "" || affiliation == null ? "-" : affiliation;
|
||||
} else {
|
||||
acc.fullName = "-";
|
||||
acc.position = "-";
|
||||
|
|
@ -1096,7 +1110,6 @@ export class ReportController extends Controller {
|
|||
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
||||
.select("MIN(kpiUserEvaluation.id) as id")
|
||||
.getRawMany();
|
||||
// if (profileEvaluationIds.length > 0) {
|
||||
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
||||
relations: ["kpiPeriod"],
|
||||
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
||||
|
|
@ -1115,7 +1128,7 @@ export class ReportController extends Controller {
|
|||
acc.position = x.position;
|
||||
acc.posType = x.posTypeName;
|
||||
acc.posLevel = x.posLevelName;
|
||||
acc.affiliation = affiliation;
|
||||
acc.affiliation = affiliation == "" || affiliation == null ? "-" : affiliation;
|
||||
} else {
|
||||
acc.fullName = "-";
|
||||
acc.position = "-";
|
||||
|
|
@ -1294,7 +1307,6 @@ export class ReportController extends Controller {
|
|||
year2: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow - 1).toString()),
|
||||
year3: Extension.ToThaiNumber(Extension.ToThaiYear(yearNow).toString()),
|
||||
};
|
||||
// }
|
||||
}
|
||||
}
|
||||
if (requestBody.type == "KPI7") {
|
||||
|
|
@ -1389,31 +1401,32 @@ export class ReportController extends Controller {
|
|||
period_ = await this.kpiPeriodRepository.findOne({
|
||||
where: { id: String(requestBody.periodId) },
|
||||
});
|
||||
let durationKpi_APR = period_ && period_.durationKPI == "APR" ? `🗹` : `☐`
|
||||
let durationKpi_OCT = period_ && period_.durationKPI == "OCT" ? `🗹` : `☐`
|
||||
if (period_ && !period1 && !period2) {
|
||||
if (period_?.durationKPI === "APR") {
|
||||
period1 = `${Extension.ToThaiFullDate2(period_.startDate)} ถึง ${Extension.ToThaiFullDate2(period_.endDate)}`;
|
||||
period1 = `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${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)}`;
|
||||
? `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${Extension.ToThaiFullDate2(_period2?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period2?.endDate)}`
|
||||
: `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ๑ เมษายน ${Extension.ToThaiYear(period_.year)} ถึง ๓๑ กันยายน ${Extension.ToThaiYear(period_.year)}`;
|
||||
}
|
||||
else if (period_?.durationKPI === "OCT") {
|
||||
period2 = `${durationKpi_OCT} รอบที่ ๒ ตั้งแต่ ${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)}`
|
||||
: "";
|
||||
? `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ${Extension.ToThaiFullDate2(_period1?.startDate)} ถึง ${Extension.ToThaiFullDate2(_period1?.endDate)}`
|
||||
: `${durationKpi_APR} รอบที่ ๑ ตั้งแต่ ๑ ตุลาคม ${Extension.ToThaiYear(period_.year-1)} ถึง ๓๑ มีนาคม ${Extension.ToThaiYear(period_.year)}`;
|
||||
}
|
||||
}
|
||||
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
||||
|
|
@ -1500,7 +1513,7 @@ export class ReportController extends Controller {
|
|||
fullName: userInfo
|
||||
? userInfo[0]?.prefix + userInfo[0]?.firstName + " " + userInfo[0]?.lastName
|
||||
: "-",
|
||||
affiliation: affiliation ?? "-",
|
||||
affiliation: affiliation == "" || affiliation == null ? "-" : affiliation,
|
||||
durationKPI: period_ ? period_.durationKPI : "-",
|
||||
position: userInfo ? userInfo[0]?.position : "-",
|
||||
posType: userInfo ? userInfo[0]?.posTypeName : "-",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue