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