From 94cece9fc563755dd0e01df34e7719d0ba5e75ba Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 27 Feb 2024 13:03:34 +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=B9=83=E0=B8=AB=E0=B8=A1=E0=B9=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 60 +++++++++++++++++++---- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index ca47924..ecc820c 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -23,6 +23,10 @@ import { CreateSalaryPeriod, SalaryPeriod, UpdateSalaryPeriod } from "../entitie import Extension from "../interfaces/extension"; import { SalaryOrg } from "../entities/SalaryOrg"; import { CreateSalaryProfile, SalaryProfile } from "../entities/SalaryProfile"; +import { PosType } from "../entities/PosType"; +import { PosLevel } from "../entities/PosLevel"; +import { Salarys } from "../entities/Salarys"; +import { SalaryRanks } from "../entities/SalaryRanks"; @Route("api/v1/salary/period") @Tags("Salary") @@ -31,6 +35,10 @@ export class SalaryPeriodController extends Controller { private salaryPeriodRepository = AppDataSource.getRepository(SalaryPeriod); private salaryOrgRepository = AppDataSource.getRepository(SalaryOrg); private salaryProfileRepository = AppDataSource.getRepository(SalaryProfile); + private posTypeRepository = AppDataSource.getRepository(PosType); + private posLevelRepository = AppDataSource.getRepository(PosLevel); + private salaryRepository = AppDataSource.getRepository(Salarys); + private salaryRankRepository = AppDataSource.getRepository(SalaryRanks); /** * API รอบล่าสุด @@ -306,24 +314,58 @@ export class SalaryPeriodController extends Controller { const salaryProfile = Object.assign(new SalaryProfile(), requestBody); salaryProfile.type = salaryProfile.type.toUpperCase(); + //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 + } + }); + //xxxxxx คำนวนเงินเดือนใหม่ if (salaryProfile.type == "NONE") { //xxxx เงินไม่เปลืี่ยน } else if (salaryProfile.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 (salaryProfile.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 (salaryProfile.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, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); }