คำสั่งวินัย

This commit is contained in:
Kittapath 2024-06-30 20:51:04 +07:00
parent 40f45b01e6
commit d6f0f583c3
2 changed files with 241 additions and 115 deletions

View file

@ -77,7 +77,6 @@ export class kpiReasonController extends Controller {
where: { id: id }, where: { id: id },
relations: ["kpiUserEvaluation"], relations: ["kpiUserEvaluation"],
}); });
let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonPlan(), requestBody); let kpiUserEvaluationReason = Object.assign(new KpiUserEvaluationReasonPlan(), requestBody);
kpiUserEvaluationReason.type = type.trim().toUpperCase(); kpiUserEvaluationReason.type = type.trim().toUpperCase();
if (type.trim().toUpperCase() == "PROBLEM") { if (type.trim().toUpperCase() == "PROBLEM") {
@ -204,10 +203,39 @@ export class kpiReasonController extends Controller {
@Get("{type}/plan/{user}/{id}") @Get("{type}/plan/{user}/{id}")
async listKpiUserPlanReason(@Path() id: string, @Path() type: string, @Path() user: string) { async listKpiUserPlanReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") { if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() }, where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() },
}); });
return new HttpSuccess(kpiUserEvaluationReason); return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else { } else {
if (user.trim().toUpperCase() == "USER") { if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
@ -392,10 +420,39 @@ export class kpiReasonController extends Controller {
@Get("{type}/role/{user}/{id}") @Get("{type}/role/{user}/{id}")
async listKpiUserRoleReason(@Path() id: string, @Path() type: string, @Path() user: string) { async listKpiUserRoleReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") { if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: { kpiUserRoleId: id, type: type.trim().toUpperCase() }, where: { kpiUserRoleId: id, type: type.trim().toUpperCase() },
}); });
return new HttpSuccess(kpiUserEvaluationReason); return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else { } else {
if (user.trim().toUpperCase() == "USER") { if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
@ -582,10 +639,39 @@ export class kpiReasonController extends Controller {
@Get("{type}/special/{user}/{id}") @Get("{type}/special/{user}/{id}")
async listKpiUserSpecialReason(@Path() id: string, @Path() type: string, @Path() user: string) { async listKpiUserSpecialReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") { if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() }, where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() },
}); });
return new HttpSuccess(kpiUserEvaluationReason); return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else { } else {
if (user.trim().toUpperCase() == "USER") { if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
@ -772,10 +858,39 @@ export class kpiReasonController extends Controller {
@Path() user: string, @Path() user: string,
) { ) {
if (type.trim().toUpperCase() == "PROBLEM") { if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() }, where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() },
}); });
return new HttpSuccess(kpiUserEvaluationReason); return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else { } else {
if (user.trim().toUpperCase() == "USER") { if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
@ -958,10 +1073,39 @@ export class kpiReasonController extends Controller {
@Get("{type}/capacity/{user}/{id}") @Get("{type}/capacity/{user}/{id}")
async listKpiUserCapacityReason(@Path() id: string, @Path() type: string, @Path() user: string) { async listKpiUserCapacityReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROBLEM") { if (type.trim().toUpperCase() == "PROBLEM") {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() }, where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() },
}); });
return new HttpSuccess(kpiUserEvaluationReason); return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "COMMANDERHIGH") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
return new HttpSuccess(kpiUserEvaluationReason);
}
} else { } else {
if (user.trim().toUpperCase() == "USER") { if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({ const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({

View file

@ -132,61 +132,46 @@ export class ReportController extends Controller {
}); });
} }
@Post("kpi9/{profileId}") @Post("kpi9/{id}")
async GetReportKpi9(@Path() profileId?: string | null) { async GetReportKpi9(@Path() id?: string) {
let formattedData: any;
if (profileId) {
const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({ const kpiUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
relations: ["kpiUserRoles", "kpiUserPlanneds", "kpiUserSpecials", "kpiUserCapacitys"], relations: ["kpiPeriod"],
where: { profileId: profileId }, where: { id: id },
}); });
if (!kpiUserEvaluation) if (!kpiUserEvaluation) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ประเมิน");
//period let formattedData = {
const period = await this.kpiPeriodRepository.findOneBy({ durationKPI: kpiUserEvaluation.kpiPeriod.durationKPI,
id: kpiUserEvaluation?.kpiPeriodId,
});
if (!period) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงวดการประเมิน");
const kpiRole = await this.kpiRoleRepository.find({
where: { kpiPeriodId: period?.id },
});
const kpiPlan = await this.kpiPlanRepository.find({
where: { kpiPeriodId: period?.id },
});
formattedData = {
fullname: fullname:
kpiUserEvaluation.prefix + kpiUserEvaluation.firstName + " " + kpiUserEvaluation.lastName, (kpiUserEvaluation.prefix == null ? "" : kpiUserEvaluation.prefix) +
"" +
(kpiUserEvaluation.firstName == null ? "" : kpiUserEvaluation.firstName) +
" " +
(kpiUserEvaluation.lastName == null ? "" : kpiUserEvaluation.lastName),
position: kpiUserEvaluation.position, position: kpiUserEvaluation.position,
posTypeName: kpiUserEvaluation.posTypeName, posTypeName: kpiUserEvaluation.posTypeName,
posLevelName: kpiUserEvaluation.posLevelName, posLevelName: kpiUserEvaluation.posLevelName,
org: kpiUserEvaluation.org, org: kpiUserEvaluation.org,
fullnameEvaluator: fullnameEvaluator:
kpiUserEvaluation.prefixEvaluator + (kpiUserEvaluation.prefixEvaluator == null ? "" : kpiUserEvaluation.prefixEvaluator) +
kpiUserEvaluation.firstNameEvaluator + "" +
(kpiUserEvaluation.firstNameEvaluator == null ? "" : kpiUserEvaluation.firstNameEvaluator) +
" " + " " +
kpiUserEvaluation.lastNameEvaluator, (kpiUserEvaluation.lastNameEvaluator == null ? "" : kpiUserEvaluation.lastNameEvaluator),
positionEvaluator: kpiUserEvaluation.positionEvaluator, positionEvaluator: kpiUserEvaluation.positionEvaluator,
posTypeNameEvaluator: kpiUserEvaluation.posTypeNameEvaluator, posTypeNameEvaluator: kpiUserEvaluation.posTypeNameEvaluator,
posLevelNameEvaluator: kpiUserEvaluation.posLevelNameEvaluator, posLevelNameEvaluator: kpiUserEvaluation.posLevelNameEvaluator,
rootEvaluator: kpiUserEvaluation.orgEvaluator, orgEvaluator: kpiUserEvaluation.orgEvaluator,
year: Extension.ToThaiNumber( year: Extension.ToThaiNumber(String(Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year))),
String(Extension.ToThaiYear(kpiUserEvaluation.kpiPeriod.year)),
),
startDateApr: startDateApr:
kpiUserEvaluation.kpiPeriod == null || kpiUserEvaluation.kpiPeriod == null ||
kpiUserEvaluation.kpiPeriod.startDate == null || kpiUserEvaluation.kpiPeriod.startDate == null ||
kpiUserEvaluation.kpiPeriod.durationKPI != "APR" kpiUserEvaluation.kpiPeriod.durationKPI != "APR"
? "-" ? "-"
: Extension.ToThaiNumber( : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate)),
Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate),
),
endDateApr: endDateApr:
kpiUserEvaluation.kpiPeriod == null || kpiUserEvaluation.kpiPeriod == null ||
kpiUserEvaluation.kpiPeriod.endDate == null || kpiUserEvaluation.kpiPeriod.endDate == null ||
@ -198,9 +183,7 @@ export class ReportController extends Controller {
kpiUserEvaluation.kpiPeriod.startDate == null || kpiUserEvaluation.kpiPeriod.startDate == null ||
kpiUserEvaluation.kpiPeriod.durationKPI != "OCT" kpiUserEvaluation.kpiPeriod.durationKPI != "OCT"
? "-" ? "-"
: Extension.ToThaiNumber( : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate)),
Extension.ToThaiFullDate(kpiUserEvaluation.kpiPeriod.startDate),
),
endDateOct: endDateOct:
kpiUserEvaluation.kpiPeriod == null || kpiUserEvaluation.kpiPeriod == null ||
kpiUserEvaluation.kpiPeriod.endDate == null || kpiUserEvaluation.kpiPeriod.endDate == null ||
@ -211,7 +194,7 @@ export class ReportController extends Controller {
evaluationResults: kpiUserEvaluation.evaluationResults, evaluationResults: kpiUserEvaluation.evaluationResults,
totalPoint1: Extension.ToThaiNumber(kpiUserEvaluation.totalPoint1.toLocaleString()), totalPoint1: Extension.ToThaiNumber(kpiUserEvaluation.totalPoint1.toLocaleString()),
totalPoint2: Extension.ToThaiNumber( totalPoint2: Extension.ToThaiNumber(
kpiUserEvaluation.totalPoint2_2 + kpiUserEvaluation.totalPoint2_1.toLocaleString(), (kpiUserEvaluation.totalPoint2_2 + kpiUserEvaluation.totalPoint2_1).toLocaleString(),
), ),
summaryPoint: Extension.ToThaiNumber(kpiUserEvaluation.summaryPoint.toLocaleString()), summaryPoint: Extension.ToThaiNumber(kpiUserEvaluation.summaryPoint.toLocaleString()),
weightPoint1: Extension.ToThaiNumber(kpiUserEvaluation.weightPoint1.toLocaleString()), weightPoint1: Extension.ToThaiNumber(kpiUserEvaluation.weightPoint1.toLocaleString()),
@ -231,7 +214,6 @@ export class ReportController extends Controller {
? null ? null
: Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.openDate)), : Extension.ToThaiNumber(Extension.ToThaiFullDate(kpiUserEvaluation.openDate)),
}; };
}
return new HttpSuccess({ return new HttpSuccess({
template: "KPI9", template: "KPI9",