แก้ไขเงินเดือน

This commit is contained in:
Bright 2024-02-27 16:12:32 +07:00
parent 94cece9fc5
commit 2f179d7e86

View file

@ -138,10 +138,58 @@ export class SalaryPeriodController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
salaryProfile.amount = body.amount;
// salaryProfile.amountSpecial = xxxx;
// salaryProfile.amountUse = xxxx;
// salaryProfile.positionSalaryAmount = xxxx;
//xxxxxx คำนวนเงินเดือนใหม่
//Type & Level
const Type = await this.posTypeRepository.findOne({
where: {
posTypeName: salaryProfile.posType,
},
});
if (!Type) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทตำแหน่ง");
}
const Level = await this.posLevelRepository.findOne({
where: {
posTypeId: Type.id,
posLevelName: salaryProfile.posLevel,
},
});
if (!Level) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
}
//Salary
const salarys = await this.salaryRepository.findOne({
where: {
posTypeId : Level.posTypeId,
posLevelId : Level.id,
isActive : true
}
});
//SalaryRank
const SalaryRanks = await this.salaryRankRepository.findOne({
where: {
salaryId: salarys?.id,
salary: salaryProfile.amount
}
});
if (!SalaryRanks) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผังเงินเดือน");
}
if (salaryProfile.type == "NONE") {
} else if (salaryProfile.type == "HAFT") {
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
} else if (salaryProfile.type == "FULL") {
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
} else if (salaryProfile.type == "FULLHAFT") {
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);
}
await this.salaryProfileRepository.save(salaryProfile);
return new HttpSuccess();
}
@ -190,24 +238,54 @@ export class SalaryPeriodController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ");
}
body.type = body.type.toUpperCase();
//xxxxxx คำนวนเงินเดือนใหม่
//Type & Level
const Type = await this.posTypeRepository.findOne({
where: {
posTypeName: salaryProfile.posType,
},
});
if (!Type) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทตำแหน่ง");
}
const Level = await this.posLevelRepository.findOne({
where: {
posTypeId: Type.id,
posLevelName: salaryProfile.posLevel,
},
});
if (!Level) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบระดับตำแหน่ง");
}
//Salary
const salarys = await this.salaryRepository.findOne({
where: {
posTypeId : Level.posTypeId,
posLevelId : Level.id,
isActive : true
}
});
//SalaryRank
const SalaryRanks = await this.salaryRankRepository.findOne({
where: {
salaryId: salarys?.id,
salary: salaryProfile.amount
}
});
if (body.type == "NONE") {
//xxxx เงินไม่เปลืี่ยน
} else if (body.type == "HAFT") {
//xxxx เลื่อน0.5ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
} else if (body.type == "FULL") {
//xxxx เลื่อน1ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
} else if (body.type == "FULLHAFT") {
//xxxx เลื่อน1.0ขั้น
// salaryProfile.amountSpecial = 0;
// salaryProfile.amountUse = 0;
// salaryProfile.positionSalaryAmount = 0;
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");
}
@ -348,21 +426,16 @@ export class SalaryPeriodController extends Controller {
}
});
//xxxxxx คำนวนเงินเดือนใหม่
if (salaryProfile.type == "NONE") {
//xxxx เงินไม่เปลืี่ยน
} else if (salaryProfile.type == "HAFT") {
//xxxx เลื่อน0.5ขั้น
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryHalf);
} else if (salaryProfile.type == "FULL") {
//xxxx เลื่อน1ขั้น
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFull) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFull);
} else if (salaryProfile.type == "FULLHAFT") {
//xxxx เลื่อน1.0ขั้น
salaryProfile.amountSpecial = Number(SalaryRanks?.salaryFullHalfSpecial);
salaryProfile.amountUse = Number(SalaryRanks?.salaryFullHalf) - salaryProfile.amount;
salaryProfile.positionSalaryAmount = Number(SalaryRanks?.salaryFullHalf);