เพิ่ม snap รอบพิเศษ

This commit is contained in:
Kittapath 2024-03-07 15:38:21 +07:00
parent 33a5cf2a57
commit b7da166a82

View file

@ -1140,60 +1140,61 @@ export class SalaryPeriodController extends Controller {
await this.salaryOrgRepository.save(salaryOrgNew);
}),
);
await Promise.all(
orgProfiles.map(async (profile: any) => {
let group = "GROUP1";
if (
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
(profile.posType == "บริหาร" && profile.posLevel == "สูง")
) {
group = "GROUP2";
}
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
delete profile.id;
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? "PENDING" : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
if (salaryPeriod.period != "SPECIAL") {
await Promise.all(
orgProfiles.map(async (profile: any) => {
let group = "GROUP1";
if (
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
(profile.posType == "บริหาร" && profile.posLevel == "สูง")
) {
group = "GROUP2";
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
}),
);
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
delete profile.id;
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? "PENDING" : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
}),
);
}
const salaryOrgNew = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
@ -1258,7 +1259,7 @@ export class SalaryPeriodController extends Controller {
await this.salaryOrgRepository.save(_salaryOrg);
}),
);
} else {
} else if (salaryPeriod.period == "APR") {
await Promise.all(
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
if (snapshot == "SNAP2") {
@ -1422,58 +1423,60 @@ export class SalaryPeriodController extends Controller {
}),
);
await Promise.all(
orgProfiles.map(async (profile: any) => {
let group = "GROUP1";
if (
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
(profile.posType == "บริหาร" && profile.posLevel == "สูง")
) {
group = "GROUP2";
}
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
if (salaryPeriod.period != "SPECIAL") {
await Promise.all(
orgProfiles.map(async (profile: any) => {
let group = "GROUP1";
if (
(profile.posType == "ทั่วไป" && profile.posLevel == "ทักษะพิเศษ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "เชี่ยวชาญ") ||
(profile.posType == "วิชาการ" && profile.posLevel == "ทรงคุณวุฒิ") ||
(profile.posType == "อำนวยการ" && profile.posLevel == "สูง") ||
(profile.posType == "บริหาร" && profile.posLevel == "ต้น") ||
(profile.posType == "บริหาร" && profile.posLevel == "สูง")
) {
group = "GROUP2";
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
}),
);
const salaryOrgNew = await this.salaryOrgRepository.findOne({
where: {
salaryPeriodId: salaryPeriod.id,
rootId: profile.rootId,
snapshot: snapshot,
group: group,
},
});
if (salaryOrgNew != null) {
let salaryProfileNew = Object.assign(new SalaryProfile(), profile);
salaryProfileNew.salaryOrgId = salaryOrgNew.id;
salaryProfileNew.revisionId = salaryPeriod.revisionId;
salaryProfileNew.createdUserId = request.user.sub;
salaryProfileNew.createdFullName = request.user.name;
salaryProfileNew.lastUpdateUserId = request.user.sub;
salaryProfileNew.lastUpdateFullName = request.user.name;
if (snapshot == "SNAP2") {
const salaryOrgOld = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" },
});
const salaryOld = await this.salaryProfileRepository.findOne({
where: {
citizenId: salaryProfileNew.citizenId,
salaryOrgId: In(salaryOrgOld.map((x) => x.id)),
},
});
salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type;
salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount;
salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial;
salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse;
salaryProfileNew.positionSalaryAmount =
salaryOld == null ? 0 : salaryOld.positionSalaryAmount;
}
await this.salaryProfileRepository.save(salaryProfileNew);
}
}),
);
}
const salaryOrgNew = await this.salaryOrgRepository.find({
where: { salaryPeriodId: salaryPeriod.id, snapshot: snapshot },
@ -1538,7 +1541,7 @@ export class SalaryPeriodController extends Controller {
await this.salaryOrgRepository.save(_salaryOrg);
}),
);
} else {
} else if (salaryPeriod.period == "APR") {
await Promise.all(
salaryOrgNew.map(async (_salaryOrg: SalaryOrg) => {
if (snapshot == "SNAP2") {