Merge branch 'develop' of github.com:Frappet/bma-ehr-salary into develop

This commit is contained in:
Kittapath 2024-03-26 23:08:44 +07:00
commit e1e16cabc7

View file

@ -3259,59 +3259,130 @@ export class ReportController extends Controller {
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
}
const _salaryPeriod = await this.salaryProfileRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
const salaryPeriodAPR = await this.salaryPeriodRepository.findOne({
where: {
salaryOrg: {
snapshot: "SNAP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
},
year: salaryPeriod.year,
period: "APR",
},
order: {
orgShortName: "ASC",
posMasterNo: "ASC",
});
if (!salaryPeriodAPR) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือนรอบเดือนเมษายน");
}
const aprSnap2 = await this.salaryOrgEmployeeRepository.findOne({
relations: ["salaryPeriod", "salaryProfiles"],
where: {
snapshot: "SNAP2",
rootId: rootId,
salaryPeriodId: salaryPeriodAPR.id,
},
});
if (!_salaryPeriod) {
if (!aprSnap2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const agency = _salaryPeriod[0] == null ? "" : _salaryPeriod[0].root;
const formattedData = _salaryPeriod.map((profile, index) => {
const fullNameParts = [
profile.child4,
profile.child3,
profile.child2,
profile.child1,
profile.root,
`${profile.prefix}${profile.firstName} ${profile.lastName}`,
];
const fullName = fullNameParts
.filter((part) => part !== undefined && part !== null)
.join("/");
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName,
posLevel: profile.posLevel,
posNumber:
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
reason: null,
};
const octSnap1 = await this.salaryOrgEmployeeRepository.findOne({
relations: ["salaryPeriod", "salaryProfiles"],
where: {
snapshot: "SNAP1",
group: "GROUP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
},
});
if (!octSnap1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const octSnap2 = await this.salaryOrgEmployeeRepository.findOne({
relations: ["salaryPeriod", "salaryProfiles"],
where: {
snapshot: "SNAP2",
group: "GROUP1",
rootId: rootId,
salaryPeriodId: salaryPeriodId,
},
});
if (!octSnap2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
let fullHaftTotalAmount = 0;
let fullHaftCount = 0;
let fullTotalAmount = 0;
let fullCount = 0;
let haftTotalAmount = 0;
let haftCount = 0;
let noneCount = 0;
if (octSnap2 && octSnap2.salaryProfiles) {
octSnap2.salaryProfiles.forEach((profile) => {
switch (profile.type) {
case "FULLHAFT":
fullHaftTotalAmount += profile.amount ?? 0;
fullHaftCount++;
break;
case "FULL":
fullTotalAmount += profile.amount ?? 0;
fullCount++;
break;
case "HAFT":
haftTotalAmount += profile.amount ?? 0;
haftCount++;
break;
case "NONE":
noneCount++;
break;
default:
break;
}
});
}
const emp2step = new Set();
if (octSnap2 && aprSnap2) {
octSnap2.salaryProfiles.forEach(octProfile => {
aprSnap2.salaryProfiles.forEach(aprProfile => {
if (octProfile.citizenId === aprProfile.citizenId &&
((octProfile.type === 'FULL' && aprProfile.type === 'FULL') ||
(octProfile.type === 'HAFT' && aprProfile.type === 'FULLHAFT') ||
(octProfile.type === 'FULLHAFT' && aprProfile.type === 'HAFT'))) {
emp2step.add(octProfile.citizenId);
}
});
});
}
const totalEmp2step = emp2step.size??0;
const agency = octSnap1.salaryProfiles[0] == null ? "" : octSnap1.salaryProfiles[0].root;
return new HttpSuccess({
template: salaryPeriod.period == "APR" ? "emp1-01" : "gov2-01",
reportName: salaryPeriod.period == "APR" ? "emp1-01" : "gov2-01",
template: "emp2-01",
reportName: "emp2-01",
data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
yearShort: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))).slice(-2),
agency: agency,
data: formattedData,
totalUser: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.total.toString()),
totalSalary: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.currentAmount.toString()),
sixPercent: octSnap1 == null ? "" : Extension.ToThaiNumber(octSnap1.sixPercentAmount.toString()),
remainingAmountApr: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.useAmount.toString()), //จำนวนเงินที่ใช้เลื่อนขั้นค่าจ้างไปแล้วในวันที่ 1 เม.ย.
remainingAmountOct: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.spentAmount.toString()), //เหลือเงินใช้เลื่อนขั้นค่าจ้างในวันที่ 1 ต.ค.
totalOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.total.toString()), //จำนวน(คน)(โควตาเลื่อนขั้นค่าจ้าง)
fifteenPercentOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.fifteenPercent.toString()),
totalUseOld: aprSnap2 == null ? "" : Extension.ToThaiNumber(aprSnap2.quantityUsed.toString()), //พิจารณาให้(คน)(โควตาเลื่อนขั้นค่าจ้าง)
full2: Extension.ToThaiNumber(totalEmp2step.toString()), //เลื่อนขั้นค่าจ้างรวมทั้งปีสองขั้นจำนวน(คน)
fullHaft: Extension.ToThaiNumber(fullHaftCount.toString()), //จำนวน(คน)(หนึ่งขั้นครึ่ง)
fullHaftSalary: Extension.ToThaiNumber(fullHaftTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้นครึ่ง)
full: Extension.ToThaiNumber(fullCount.toString()), //จำนวน(คน)(หนึ่งขั้น)
fullSalary: Extension.ToThaiNumber(fullTotalAmount.toString()), //ใช้เงิน(หนึ่งขั้น)
haft: Extension.ToThaiNumber(haftCount.toString()), //จำนวน(คน)(ครึ่งขั้น)
haftSalary: Extension.ToThaiNumber(haftTotalAmount.toString()), //ใช้เงิน(ครึ่งขั้น)
notPromoted: Extension.ToThaiNumber(noneCount.toString()), //ไม่ได้เลื่อนขั้นค่าจ้างจำนวน(คน)
total: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.useAmount.toString()), //รวมใช้เงิน
summary: octSnap2 == null ? "" : Extension.ToThaiNumber(octSnap2.remainingAmount.toString()), //เหลือเงิน
},
});
}
@ -3331,7 +3402,7 @@ export class ReportController extends Controller {
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขึ้นเงินเดือน");
}
const _salaryPeriod = await this.salaryProfileRepository.find({
const _salaryPeriod = await this.salaryProfileEmployeeRepository.find({
relations: ["salaryOrg", "salaryOrg.salaryPeriod"],
where: {
salaryOrg: {
@ -3369,17 +3440,20 @@ export class ReportController extends Controller {
return {
no: Extension.ToThaiNumber((index + 1).toLocaleString()),
fullName: fullName,
posLevel: profile.posLevel,
position: profile.position,
posNumber:
profile.orgShortName + Extension.ToThaiNumber(profile.posMasterNo.toLocaleString()),
amount: profile.amount ? Extension.ToThaiNumber(profile.amount.toLocaleString()) : null,
reason: null,
// typeOld2:, //ปีงบประมาณพ.ศ...(จำนวนขั้น)การเลื่อนขั้นค่าจ้าง
// typeOld1:, //ปีงบประมาณพ.ศ...(จำนวนขั้น)การเลื่อนขั้นค่าจ้าง
// typeOld:, //1 เมษายน(จำนวนขั้น)การเลื่อนขั้นค่าจ้าง
// type:, //หน่วยงานพิจารณาเลื่อนขั้นค่าจ้าง 1 ต.ค. (จำนวนขั้น)
};
});
return new HttpSuccess({
template: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
reportName: salaryPeriod.period == "APR" ? "gov1-01" : "gov2-01",
template: "emp2-02",
reportName: "emp2-02",
data: {
year: Extension.ToThaiNumber(String(Extension.ToThaiYear(salaryPeriod.year))),
agency: agency,