This commit is contained in:
Bright 2024-03-21 18:18:50 +07:00
parent af8ee9f6b6
commit d3dd7012a1

View file

@ -912,7 +912,6 @@ export class ReportController extends Controller {
const salaryPeriod = await this.salaryPeriodRepository.findOne({
where: {
id: salaryPeriodId,
period: "APR",
isActive: true,
},
});
@ -932,160 +931,304 @@ export class ReportController extends Controller {
},
relations: ["salaryProfiles"],
});
if(salaryPeriod.period === 'APR'){
const salaryProfile = await this.salaryProfileRepository.find({
where: {
salaryOrgId: salaryOrg?.id,
type: "FULL", //หนึ่งขั้น
}
});
//รอบปีก่อนๆ
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryOrg1_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryProfile1 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
type: "FULL",
},
});
//รอบปีก่อนหน้า
const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 1,
isActive: true,
},
});
const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 1,
isActive: true,
},
});
const salaryOrg2_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease2_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease2_OCT?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryProfile2 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]),
type: "FULL",
},
});
const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)));
const yearIncrease1 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-2)));
const yearIncrease2 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1)));
const fifteenPercent = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ?
"" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent));
const fifteenPoint = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ?
"." : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint));
return new HttpSuccess({
template: "gov1-03",
reportName: "gov1-03",
data: {
year: year,
yearIncrease1: yearIncrease1,
yearIncrease2: yearIncrease2,
yearIncreaseSlice: yearIncrease2.slice(-2),
yearSlice: year.slice(-2),
point: fifteenPercent + fifteenPoint,
root: salaryProfile[0]?.root,
profile: salaryProfile.map((item, index) => ({
no: Extension.ToThaiNumber(String(index + 1)),
fullname:
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
(item.root == undefined && item.root == null ? "" : item.root) +
"/" +
item.prefix +
item.firstName +
" " +
item.lastName, // สังกัด/ชื่อ-นามสกุล
posLevel: item.posLevel,
posMasterNo: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
amount:
item.amount == undefined || item.amount == null
? ""
: Extension.ToThaiNumber(String(item.amount.toLocaleString())),
salaryIncrease1:
salaryProfile1.length > 0
? salaryProfile1
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount)
: "", //การเลื่อนเงินเดือนปีก่อนๆหน้า
salaryIncrease2:
salaryProfile2.length > 0
? salaryProfile2
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount)
: "", //การเลื่อนเงินเดือนปีก่อนหน้า
score: null, //ผลการประเมินฯ
remark: null, //หมายเหตุ
})),
},
});
}
else if(salaryPeriod.period === 'OCT'){
//find period APR
const salaryPeriod_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod?.year,
isActive: true,
},
});
const salaryOrg_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
}
});
const salaryProfile_APR = await this.salaryProfileRepository.find({
where: {
salaryOrgId: salaryOrg_APR?.id,
type: In(["HAFT","FULL"]),
}
});
//end period APR
const salaryProfile = await this.salaryProfileRepository.find({
where: {
salaryOrgId: salaryOrg?.id,
type: "FULL", //หนึ่งขั้น
},
select: [
"id",
"prefix",
"firstName",
"lastName",
"root",
"position",
"posType",
"posLevel",
"orgShortName",
"posMasterNo",
"amount",
"amountSpecial",
],
});
//รอบปีก่อนๆ
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryOrg1_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryProfile1 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
type: "FULL",
},
});
//รอบปีก่อนหน้า
const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 1,
isActive: true,
},
});
const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 1,
isActive: true,
},
});
const salaryOrg2_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease2_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease2_OCT?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryProfile2 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]),
type: "FULL",
},
});
const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)));
const yearIncrease1 = Extension.ToThaiNumber(
String(Extension.ToThaiYear(salaryPeriod.year - 2)),
);
const yearIncrease2 = Extension.ToThaiNumber(
String(Extension.ToThaiYear(salaryPeriod.year - 1)),
);
const fifteenPercent =
salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null
? ""
: Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent));
const fifteenPoint =
salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null
? "."
: "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint));
return new HttpSuccess({
template: "gov1-03",
reportName: "gov1-03",
data: {
year: year,
yearIncrease1: yearIncrease1,
yearIncrease2: yearIncrease2,
yearIncreaseSlice: yearIncrease2.slice(-2),
yearSlice: year.slice(-2),
point: fifteenPercent + fifteenPoint,
root: salaryProfile[0]?.root,
profile: salaryProfile.map((item, index) => ({
no: Extension.ToThaiNumber(String(index + 1)),
fullname:
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
(item.root == undefined && item.root == null ? "" : item.root) +
"/" +
item.prefix +
item.firstName +
" " +
item.lastName, // สังกัด/ชื่อ-นามสกุล
posLevel: item.posLevel,
posMasterNo: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
amount:
item.amount == undefined || item.amount == null
? ""
: Extension.ToThaiNumber(String(item.amount.toLocaleString())),
salaryIncrease1:
salaryProfile1.length > 0
? salaryProfile1
const salaryProfile = await this.salaryProfileRepository.find({
where: {
salaryOrgId: salaryOrg?.id,
type: In(["FULLHAFT","FULL"]),
}
});
//รอบปีก่อนๆ
const salaryPeriodIncrease1_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryPeriodIncrease1_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 2,
isActive: true,
},
});
const salaryOrg1_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryOrg1_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease1_OCT?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryProfile1 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg1_APR?.id, salaryOrg1_OCT?.id]),
type: "FULL",
},
});
//รอบปีก่อนหน้า
const salaryPeriodIncrease2_APR = await this.salaryPeriodRepository.findOne({
where: {
period: "APR",
year: salaryPeriod.year - 1,
isActive: true,
},
});
const salaryPeriodIncrease2_OCT = await this.salaryPeriodRepository.findOne({
where: {
period: "OCT",
year: salaryPeriod.year - 1,
isActive: true,
},
});
const salaryOrg2_APR = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease2_APR?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryOrg2_OCT = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriodIncrease2_OCT?.id,
rootId: rootId,
snapshot: "SNAP2",
},
});
const salaryProfile2 = await this.salaryProfileRepository.find({
where: {
salaryOrgId: In([salaryOrg2_APR?.id, salaryOrg2_OCT?.id]),
type: "FULL",
},
});
const year = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year)));
const yearIncrease1 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-2)));
const yearIncrease2 = Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year-1)));
const fifteenPercent = salaryOrg?.fifteenPercent == undefined || salaryOrg?.fifteenPercent == null ?
"" : Extension.ToThaiNumber(String(salaryOrg?.fifteenPercent));
const fifteenPoint = salaryOrg?.fifteenPoint == undefined || salaryOrg?.fifteenPoint == null ?
"." : "." + Extension.ToThaiNumber(String(salaryOrg?.fifteenPoint));
return new HttpSuccess({
template: "gov2-03",
reportName: "gov2-03",
data: {
year: year,
yearIncrease1: yearIncrease1,
yearIncrease2: yearIncrease2,
yearIncreaseSlice: yearIncrease2.slice(-2),
yearSlice: year.slice(-2),
point: fifteenPercent + fifteenPoint,
root: salaryProfile[0]?.root,
profile: salaryProfile.map((item, index) => ({
no: Extension.ToThaiNumber(String(index + 1)),
fullname:
(item.child4 == undefined && item.child4 == null ? "" : item.child4 + "/") +
(item.child3 == undefined && item.child3 == null ? "" : item.child3 + "/") +
(item.child2 == undefined && item.child2 == null ? "" : item.child2 + "/") +
(item.child1 == undefined && item.child1 == null ? "" : item.child1 + "/") +
(item.root == undefined && item.root == null ? "" : item.root) +
"/" +
item.prefix +
item.firstName +
" " +
item.lastName, // สังกัด/ชื่อ-นามสกุล
posLevel: item.posLevel,
posMasterNo: item.orgShortName + Extension.ToThaiNumber(String(item.posMasterNo)),
amount:
item.amount == undefined || item.amount == null
? ""
: Extension.ToThaiNumber(String(item.amount.toLocaleString())),
salaryIncrease1:
salaryProfile1.length > 0
? salaryProfile1
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount)
: "", //การเลื่อนเงินเดือนปีก่อนๆหน้า
salaryIncrease2:
salaryProfile2.length > 0
? salaryProfile2
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount)
: "", //การเลื่อนเงินเดือนปีก่อนหน้า
salaryIncreaseAPR:
salaryProfile_APR.length > 0
? salaryProfile_APR
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount)
: "", //การเลื่อนเงินเดือนปีก่อนๆหน้า
salaryIncrease2:
salaryProfile2.length > 0
? salaryProfile2
.filter((profile) => profile.citizenId === item.citizenId)
.map((profile) => profile.amount)
: "", //การเลื่อนเงินเดือนปีก่อนหน้า
score: null, //ผลการประเมินฯ
remark: null, //หมายเหตุ
})),
},
});
: "", //การเลื่อนเงินเดือนรอบเมษา
Type: item.type === "FULL" ? "หนึ่งขั้น" : "หนึ่งขั้นครึ่ง",
score1: null, //ผลการประเมินฯ ครั้งที่ 1
score2: null, //ผลการประเมินฯ ครั้งที่ 2
})),
},
});
}
}
/**