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

View file

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