From b1a0d1bb8541aceb8659eb4918d1a1e49814d325 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 3 Apr 2024 19:41:18 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=84=E0=B8=B3=E0=B8=99=E0=B8=A7=E0=B8=99?= =?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=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=88?= =?UTF-8?q?=E0=B8=B2=E0=B8=87=E0=B9=80=E0=B8=84=E0=B8=A5=E0=B8=AA=E0=B8=9E?= =?UTF-8?q?=E0=B8=AD=E0=B8=94=E0=B8=B5=E0=B8=82=E0=B8=B1=E0=B9=89=E0=B8=99?= =?UTF-8?q?=E0=B8=AA=E0=B8=B9=E0=B8=87=E0=B8=AA=E0=B8=B8=E0=B8=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SalaryPeriodEmployeeController.ts | 188 ++++++++++++++++-- 1 file changed, 168 insertions(+), 20 deletions(-) diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index aadf96c..b8296cd 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -572,12 +572,58 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.amountSpecial = 0; } } else { - salaryProfile.isNext = false; - salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = salaryProfile.amount; - salaryProfile.positionSalaryDayAmount = 0; - salaryProfile.positionSalaryAmountPer = 0; - salaryProfile.amountSpecial = 0; + if (salaryFormula != null && salaryFormula.salaryMax == salaryProfile.amount) { + let salaryRankAmountMax = await this.salaryRankRepository.findOne({ + where: { + salaryMonth: salaryFormula.salaryMax, + salaryEmployee_: { + id: salaryFormula.salaryEmployee.id, + }, + }, + }); + salaryProfile.isNext = true; + salaryProfile.amountUse = salaryFormula.salaryMax - salaryProfile.amount; + salaryProfile.positionSalaryAmount = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth; + salaryProfile.positionSalaryDayAmount = + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay; + salaryProfile.groupNew = salaryFormula.salaryEmployee.group; + salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + if (salaryRankAmountMax != null) { + if (step - salaryRankAmountMax.step <= 0.5) { + salaryProfile.positionSalaryAmountPer = 0.02; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.02; + } else if (step - salaryRankAmountMax.step <= 1) { + salaryProfile.positionSalaryAmountPer = 0.04; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.04; + } else { + salaryProfile.positionSalaryAmountPer = 0.06; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.06; + } + } else { + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } + } else { + salaryProfile.isNext = false; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = salaryProfile.amount; + salaryProfile.positionSalaryDayAmount = 0; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } } } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); @@ -999,13 +1045,64 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.amountSpecial = 0; } } else { - salaryProfile.isNext = false; - salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = - salaryProfile.amount == null ? 0 : salaryProfile.amount; - salaryProfile.positionSalaryDayAmount = 0; - salaryProfile.positionSalaryAmountPer = 0; - salaryProfile.amountSpecial = 0; + if ( + salaryFormula != null && + salaryFormula.salaryMax != null && + salaryFormula.salaryMax == salaryProfile.amount + ) { + let salaryRankAmountMax = await this.salaryRankRepository.findOne({ + where: { + salaryMonth: salaryFormula.salaryMax, + salaryEmployee_: { + id: salaryFormula.salaryEmployee.id, + }, + }, + }); + salaryProfile.isNext = true; + salaryProfile.amountUse = + salaryFormula.salaryMax - (salaryProfile.amount == null ? 0 : salaryProfile.amount); + salaryProfile.positionSalaryAmount = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth; + salaryProfile.positionSalaryDayAmount = + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay; + salaryProfile.groupNew = salaryFormula.salaryEmployee.group; + salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + if (salaryRankAmountMax != null) { + if (step - salaryRankAmountMax.step <= 0.5) { + salaryProfile.positionSalaryAmountPer = 0.02; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.02; + } else if (step - salaryRankAmountMax.step <= 1) { + salaryProfile.positionSalaryAmountPer = 0.04; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.04; + } else { + salaryProfile.positionSalaryAmountPer = 0.06; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.06; + } + } else { + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } + } else { + salaryProfile.isNext = false; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = + salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryDayAmount = 0; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } } } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); @@ -1530,13 +1627,64 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.amountSpecial = 0; } } else { - salaryProfile.isNext = false; - salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = - salaryProfile.amount == null ? 0 : salaryProfile.amount; - salaryProfile.positionSalaryDayAmount = 0; - salaryProfile.positionSalaryAmountPer = 0; - salaryProfile.amountSpecial = 0; + if ( + salaryFormula != null && + salaryFormula.salaryMax != null && + salaryFormula.salaryMax == salaryProfile.amount + ) { + let salaryRankAmountMax = await this.salaryRankRepository.findOne({ + where: { + salaryMonth: salaryFormula.salaryMax, + salaryEmployee_: { + id: salaryFormula.salaryEmployee.id, + }, + }, + }); + salaryProfile.isNext = true; + salaryProfile.amountUse = + salaryFormula.salaryMax - (salaryProfile.amount == null ? 0 : salaryProfile.amount); + salaryProfile.positionSalaryAmount = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth; + salaryProfile.positionSalaryDayAmount = + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.salaryDay; + salaryProfile.groupNew = salaryFormula.salaryEmployee.group; + salaryProfile.salaryLevelNew = salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + salaryRankAmountMax == null ? 0 : salaryRankAmountMax.step; + if (salaryRankAmountMax != null) { + if (step - salaryRankAmountMax.step <= 0.5) { + salaryProfile.positionSalaryAmountPer = 0.02; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.02; + } else if (step - salaryRankAmountMax.step <= 1) { + salaryProfile.positionSalaryAmountPer = 0.04; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.04; + } else { + salaryProfile.positionSalaryAmountPer = 0.06; + salaryProfile.amountSpecial = + salaryRankAmountMax == null || salaryRankAmountMax.salaryMonth == null + ? 0 + : salaryRankAmountMax.salaryMonth * 0.06; + } + } else { + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } + } else { + salaryProfile.isNext = false; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = + salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryDayAmount = 0; + salaryProfile.positionSalaryAmountPer = 0; + salaryProfile.amountSpecial = 0; + } } } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง");