From 2f179d7e86dc1712c5b44ac457f28cba0ca5f851 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 27 Feb 2024 16:12:32 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82?= =?UTF-8?q?=E0=B9=80=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7?= =?UTF-8?q?=E0=B8=AD=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 119 +++++++++++++++++----- 1 file changed, 96 insertions(+), 23 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index ecc820c..d901853 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -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);