fix report kpi (ปรับค่าเฉลี่ย)
This commit is contained in:
parent
b32e7a28f1
commit
0c4959e0d0
1 changed files with 102 additions and 48 deletions
|
|
@ -741,6 +741,8 @@ export class ReportController extends Controller {
|
|||
year5: string | null;
|
||||
}
|
||||
const yearNow = new Date().getFullYear();
|
||||
let _summaryPointApr: number[] = [];
|
||||
let _summaryPointOct: number[] = [];
|
||||
if (requestBody.profileId) {
|
||||
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
||||
.createQueryBuilder("kpiUserEvaluation")
|
||||
|
|
@ -757,6 +759,31 @@ export class ReportController extends Controller {
|
|||
.select("MIN(kpiUserEvaluation.id) as id")
|
||||
.getRawMany();
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
let _calAvg = await this.kpiUserEvaluationRepository
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
||||
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
||||
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
||||
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
||||
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "APR" })
|
||||
.select("AVG(evaluation.summaryPoint)", "average")
|
||||
.getRawOne();
|
||||
_summaryPointApr.push(_calAvg.average);
|
||||
}
|
||||
for (let i = 0; i < 5; i++) {
|
||||
let _calAvg = await this.kpiUserEvaluationRepository
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
||||
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
||||
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
||||
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
||||
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "OCT" })
|
||||
.select("AVG(evaluation.summaryPoint)", "average")
|
||||
.getRawOne();
|
||||
_summaryPointOct.push(_calAvg.average);
|
||||
}
|
||||
|
||||
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
||||
relations: ["kpiPeriod"],
|
||||
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
||||
|
|
@ -785,10 +812,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR1 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR1 = _summaryPointApr.length > 4
|
||||
? Extension.ToThaiNumber(_summaryPointApr[4].toString())
|
||||
: null;
|
||||
acc.textPointAPR1 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR1 = _summaryPointApr.length > 4 ? Extension.textPoint(_summaryPointApr[4]) : null;
|
||||
acc.periodAPR1 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR1 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -801,10 +828,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT1 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT1 = _summaryPointOct.length > 4
|
||||
? Extension.ToThaiNumber(_summaryPointOct[4].toString())
|
||||
: null;
|
||||
acc.textPointOCT1 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT1 = _summaryPointOct.length > 4 ? Extension.textPoint(_summaryPointOct[4]) : null;
|
||||
acc.periodOCT1 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT1 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -817,10 +844,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR2 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR2 = _summaryPointApr.length > 3
|
||||
? Extension.ToThaiNumber(_summaryPointApr[3].toString())
|
||||
: null;
|
||||
acc.textPointAPR2 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR2 = _summaryPointApr.length > 3 ? Extension.textPoint(_summaryPointApr[3]) : null;
|
||||
acc.periodAPR2 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR2 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -833,10 +860,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT2 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT2 = _summaryPointOct.length > 3
|
||||
? Extension.ToThaiNumber(_summaryPointOct[3].toString())
|
||||
: null;
|
||||
acc.textPointOCT2 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT2 = _summaryPointOct.length > 3 ? Extension.textPoint(_summaryPointOct[3]) : null;
|
||||
acc.periodOCT2 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT2 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -849,10 +876,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR3 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR3 = _summaryPointApr.length > 2
|
||||
? Extension.ToThaiNumber(_summaryPointApr[2].toString())
|
||||
: null;
|
||||
acc.textPointAPR3 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR3 = _summaryPointApr.length > 2 ? Extension.textPoint(_summaryPointApr[2]) : null;
|
||||
acc.periodAPR3 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR3 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -865,10 +892,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT3 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT3 = _summaryPointOct.length > 2
|
||||
? Extension.ToThaiNumber(_summaryPointOct[2].toString())
|
||||
: null;
|
||||
acc.textPointOCT3 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT3 = _summaryPointOct.length > 2 ? Extension.textPoint(_summaryPointOct[2]) : null;
|
||||
acc.periodOCT3 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT3 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -881,10 +908,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR4 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR4 = _summaryPointApr.length > 1
|
||||
? Extension.ToThaiNumber(_summaryPointApr[1].toString())
|
||||
: null;
|
||||
acc.textPointAPR4 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR4 = _summaryPointApr.length > 1 ? Extension.textPoint(_summaryPointApr[1]) : null;
|
||||
acc.periodAPR4 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR4 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -897,10 +924,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT4 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT4 = _summaryPointOct.length > 1
|
||||
? Extension.ToThaiNumber(_summaryPointOct[1].toString())
|
||||
: null;
|
||||
acc.textPointOCT4 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT4 = _summaryPointOct.length > 1 ? Extension.textPoint(_summaryPointOct[1]) : null;
|
||||
acc.periodOCT4 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT4 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -913,10 +940,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR5 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR5 = _summaryPointApr.length > 0
|
||||
? Extension.ToThaiNumber(_summaryPointApr[0].toString())
|
||||
: null;
|
||||
acc.textPointAPR5 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR5 = _summaryPointApr.length > 0 ? Extension.textPoint(_summaryPointApr[0]) : null;
|
||||
acc.periodAPR5 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR5 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -929,10 +956,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT5 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT5 = _summaryPointOct.length > 0
|
||||
? Extension.ToThaiNumber(_summaryPointOct[0].toString())
|
||||
: null;
|
||||
acc.textPointOCT5 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT5 = _summaryPointOct.length > 0 ? Extension.textPoint(_summaryPointOct[0]) : null;
|
||||
acc.periodOCT5 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT5 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -1095,6 +1122,8 @@ export class ReportController extends Controller {
|
|||
year3: string | null;
|
||||
}
|
||||
const yearNow = new Date().getFullYear();
|
||||
let _summaryPointApr: number[] = [];
|
||||
let _summaryPointOct: number[] = [];
|
||||
if (requestBody.profileId) {
|
||||
const profileEvaluationIds = await AppDataSource.getRepository(KpiUserEvaluation)
|
||||
.createQueryBuilder("kpiUserEvaluation")
|
||||
|
|
@ -1110,6 +1139,31 @@ export class ReportController extends Controller {
|
|||
.groupBy("kpiUserEvaluation.kpiPeriodId")
|
||||
.select("MIN(kpiUserEvaluation.id) as id")
|
||||
.getRawMany();
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let _calAvg = await this.kpiUserEvaluationRepository
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
||||
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
||||
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
||||
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
||||
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "APR" })
|
||||
.select("AVG(evaluation.summaryPoint)", "average")
|
||||
.getRawOne();
|
||||
_summaryPointApr.push(_calAvg.average);
|
||||
}
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let _calAvg = await this.kpiUserEvaluationRepository
|
||||
.createQueryBuilder("evaluation")
|
||||
.leftJoin("evaluation.kpiPeriod", "kpiPeriod")
|
||||
.where("evaluation.profileId = :profileId", { profileId: requestBody.profileId })
|
||||
.andWhere("evaluation.evaluationStatus = :status", { status: "KP7" })
|
||||
.andWhere("kpiPeriod.year = :year", { year: yearNow - i })
|
||||
.andWhere("kpiPeriod.durationKPI = :duration", { duration: "OCT" })
|
||||
.select("AVG(evaluation.summaryPoint)", "average")
|
||||
.getRawOne();
|
||||
_summaryPointOct.push(_calAvg.average);
|
||||
}
|
||||
const profileEvaluation = await this.kpiUserEvaluationRepository.find({
|
||||
relations: ["kpiPeriod"],
|
||||
where: { id: In(profileEvaluationIds.map((evaluation) => evaluation.id)) },
|
||||
|
|
@ -1138,10 +1192,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR1 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR1 = _summaryPointApr.length > 2
|
||||
? Extension.ToThaiNumber(_summaryPointApr[2].toString())
|
||||
: null;
|
||||
acc.textPointAPR1 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR1 = _summaryPointApr.length > 2 ? Extension.textPoint(_summaryPointApr[2]) : null;
|
||||
acc.periodAPR1 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR1 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -1154,10 +1208,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT1 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT1 = _summaryPointOct.length > 2
|
||||
? Extension.ToThaiNumber(_summaryPointOct[2].toString())
|
||||
: null;
|
||||
acc.textPointOCT1 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT1 = _summaryPointOct.length > 2 ? Extension.textPoint(_summaryPointOct[2]) : null;
|
||||
acc.periodOCT1 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT1 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -1170,10 +1224,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR2 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR2 = _summaryPointApr.length > 1
|
||||
? Extension.ToThaiNumber(_summaryPointApr[1].toString())
|
||||
: null;
|
||||
acc.textPointAPR2 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR2 = _summaryPointApr.length > 1 ? Extension.textPoint(_summaryPointApr[1]) : null;
|
||||
acc.periodAPR2 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR2 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -1186,10 +1240,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT2 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT2 = _summaryPointOct.length > 1
|
||||
? Extension.ToThaiNumber(_summaryPointOct[1].toString())
|
||||
: null;
|
||||
acc.textPointOCT2 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT2 = _summaryPointOct.length > 1 ? Extension.textPoint(_summaryPointOct[1]) : null;
|
||||
acc.periodOCT2 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT2 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -1202,10 +1256,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
|
||||
acc.summaryPointAPR3 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointAPR3 = _summaryPointApr.length > 0
|
||||
? Extension.ToThaiNumber(_summaryPointApr[0].toString())
|
||||
: null;
|
||||
acc.textPointAPR3 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointAPR3 = _summaryPointApr.length > 0 ? Extension.textPoint(_summaryPointApr[0]) : null;
|
||||
acc.periodAPR3 = x.kpiPeriod.durationKPI;
|
||||
acc.yearAPR3 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
@ -1218,10 +1272,10 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
|
||||
acc.summaryPointOCT3 = x.summaryPoint
|
||||
? Extension.ToThaiNumber(x.summaryPoint.toString())
|
||||
acc.summaryPointOCT3 = _summaryPointOct.length > 0
|
||||
? Extension.ToThaiNumber(_summaryPointOct[0].toString())
|
||||
: null;
|
||||
acc.textPointOCT3 = x.summaryPoint ? Extension.textPoint(x.summaryPoint) : null;
|
||||
acc.textPointOCT3 = _summaryPointOct.length > 0 ? Extension.textPoint(_summaryPointOct[0]) : null;
|
||||
acc.periodOCT3 = x.kpiPeriod.durationKPI;
|
||||
acc.yearOCT3 = x.kpiPeriod.year
|
||||
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue