Merge branch 'develop' into adiDev

# Conflicts:
#	src/controllers/SalaryPeriodController.ts
This commit is contained in:
AdisakKanthawilang 2025-04-28 10:51:48 +07:00
commit 3e84da2c50
2 changed files with 70 additions and 35 deletions

View file

@ -67,59 +67,66 @@ export class SalaryPeriodController extends Controller {
if (!salaryPeriod) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน");
}
const data = {
group1id:
salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
: salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
)?.id,
group1IsClose:
salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
: salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
)?.isClose,
group2id:
salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
: salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
)?.id,
group2IsClose:
salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
: salaryPeriod.salaryOrgs &&
salaryPeriod.salaryOrgs.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
@ -1577,12 +1584,12 @@ export class SalaryPeriodController extends Controller {
// : `profile.isRetired = false`
// : "1=1",
body.isRetire == null
? `profile.isRetired = false`
: body.isRetire == "1"
? `profile.isRetired = true`
: body.isRetire == "0"
? `profile.isRetired = false`
: "1=1",
? `profile.isRetired = false`
: body.isRetire == "1"
? `profile.isRetired = true`
: body.isRetire == "0"
? `profile.isRetired = false`
: "1=1",
)
.andWhere({
salaryOrgId: salaryOrg.id,
@ -2681,7 +2688,7 @@ export class SalaryPeriodController extends Controller {
}),
);
if (salaryPeriod.period != "SPECIAL") {
console.log(`step1`)
console.log(`step1`);
await Promise.all(
orgProfiles.map(async (profile: any) => {
let group = "GROUP1";
@ -2695,7 +2702,7 @@ export class SalaryPeriodController extends Controller {
) {
group = "GROUP2";
}
console.log(`step2`)
console.log(`step2`);
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
@ -2704,9 +2711,9 @@ export class SalaryPeriodController extends Controller {
group: group,
},
});
console.log(`step3`)
console.log(`step3`);
if (salaryOrgNew != null) {
console.log(`step4`)
console.log(`step4`);
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
delete salaryProfileNew.id;
@ -2722,7 +2729,7 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.lastUpdatedAt = new Date();
if (snapshot == "SNAP2") {
console.log(`step5`)
console.log(`step5`);
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
@ -2743,11 +2750,13 @@ export class SalaryPeriodController extends Controller {
salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve;
salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired;
}
console.log(`step6`)
console.log(`step6`);
await this.salaryProfileRepository.save(salaryProfileNew, { data: request });
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`);
}else{
console.log(
`✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`,
);
} else {
console.warn(`⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrg สำหรับ rootId: ${profile.rootId}`);
}
}),
@ -2788,8 +2797,15 @@ export class SalaryPeriodController extends Controller {
},
});
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
<<<<<<< HEAD
salaryProfileNew.salaryLevel = salaryOld && salaryOld.salaryLevelNew ? salaryOld.salaryLevelNew : salaryOld?.salaryLevel;
salaryProfileNew.group = salaryOld && salaryOld.groupNew ? salaryOld.groupNew : salaryOld?.group;
=======
salaryProfileNew.salaryLevel =
salaryOld && salaryOld.salaryLevelNew
? salaryOld.salaryLevelNew
: salaryOld?.salaryLevel;
>>>>>>> develop
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
@ -2802,9 +2818,13 @@ export class SalaryPeriodController extends Controller {
}
await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request });
setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew });
console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfileEmployee: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`);
}else{
console.warn(`⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrgEmployee สำหรับ rootId: ${profile.rootId}`);
console.log(
`✅ [SNAP: ${snapshot}] บันทึก SalaryProfileEmployee: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`,
);
} else {
console.warn(
`⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrgEmployee สำหรับ rootId: ${profile.rootId}`,
);
}
}),
);
@ -3802,6 +3822,14 @@ export class SalaryPeriodController extends Controller {
item.isClose = body.isClose;
await this.salaryOrgRepository.save(item);
}
const salaryPeriodEmp = await this.salaryOrgEmployeeRepository.find({
where: { salaryPeriodId: salaryPeriodId, snapshot: snapShot },
});
for await (const item of salaryPeriodEmp) {
item.isClose = body.isClose;
await this.salaryOrgEmployeeRepository.save(item);
}
return new HttpSuccess();
}
}

View file

@ -69,56 +69,64 @@ export class SalaryPeriodEmployeeController extends Controller {
}
const data = {
group1id:
salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find(
salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find(
: salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
)?.id,
group1IsClose:
salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
: salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP1" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
)?.isClose,
group2id:
salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find(
salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find(
: salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
)?.id,
group2IsClose:
salaryPeriod.salaryOrgs &&salaryPeriod.salaryOrgs.find(
salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
x.snapshot == body.snapshot.toLocaleUpperCase(),
) == null
? null
: salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find(
: salaryPeriod.salaryOrgEmployees &&
salaryPeriod.salaryOrgEmployees.find(
(x) =>
x.group == "GROUP2" &&
x.rootId == body.rootId &&
@ -128,7 +136,6 @@ export class SalaryPeriodEmployeeController extends Controller {
period: salaryPeriod.period,
};
return new HttpSuccess(data);
}