From 72557983d6755a3e7db43d0f7dd28f55c94c2d30 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Tue, 5 Mar 2024 10:43:08 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 92 +++++++++++++++-------- 1 file changed, 59 insertions(+), 33 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 2faf5fd..a211e49 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -246,7 +246,10 @@ export class SalaryPeriodController extends Controller { if (salaryProfile.type == "NONE") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryAmount = + salaryProfile.amount == null + ? 0 + : salaryProfile.amount + salaryProfile.amountUse - salaryProfile.amountSpecial; } else if (salaryProfile.type == "PENDING") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; @@ -262,9 +265,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryHalf - salaryProfile.amount; + : salaryRanks.salaryHalf - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; + salaryRanks == null || salaryRanks.salaryHalf == null + ? 0 + : salaryRanks.salaryHalf + salaryProfile.amountUse; } else if (salaryProfile.type == "FULL") { salaryProfile.amountSpecial = salaryRanks == null || salaryRanks.salaryFullSpecial == null @@ -276,9 +281,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFull == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFull - salaryProfile.amount; + : salaryRanks.salaryFull - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; + salaryRanks == null || salaryRanks.salaryFull == null + ? 0 + : salaryRanks.salaryFull + salaryProfile.amountUse; } else if (salaryProfile.type == "FULLHAFT") { salaryProfile.amountSpecial = salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null @@ -290,9 +297,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFullHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFullHalf - salaryProfile.amount; + : salaryRanks.salaryFullHalf - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; + salaryRanks == null || salaryRanks.salaryFullHalf == null + ? 0 + : salaryRanks.salaryFullHalf + salaryProfile.amountUse; } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); } @@ -401,7 +410,6 @@ export class SalaryPeriodController extends Controller { */ @Post("change/type") async changeType(@Body() body: { profileId: string; type: string }) { - const salaryProfile = await this.salaryProfileRepository.findOne({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], where: { id: body.profileId }, @@ -412,7 +420,7 @@ export class SalaryPeriodController extends Controller { body.type = body.type.toUpperCase(); //ตรวจสอบงวดเมษาว่าเลื่อนกี่ขั้น - if(body.type == "FULLHAFT"){ + if (body.type == "FULLHAFT") { if (salaryProfile?.salaryOrg?.salaryPeriod?.period === "OCT") { const checkPreviousType = await this.salaryProfileRepository.findOne({ relations: ["salaryOrg", "salaryOrg.salaryPeriod"], @@ -421,15 +429,18 @@ export class SalaryPeriodController extends Controller { salaryOrg: { salaryPeriod: { period: "APR", - year: salaryProfile?.salaryOrg?.salaryPeriod?.year //ปีที่ตรงกันด้วย + year: salaryProfile?.salaryOrg?.salaryPeriod?.year, //ปีที่ตรงกันด้วย }, - snapshot: "SNAP2" + snapshot: "SNAP2", }, - type: "FULL" + type: "FULL", }, }); - if(checkPreviousType){ - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถเลื่อนขั้นบุคลากรเกิน 2 ขั้นต่อปีได้"); + if (checkPreviousType) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถเลื่อนขั้นบุคลากรเกิน 2 ขั้นต่อปีได้", + ); } } } @@ -476,7 +487,8 @@ export class SalaryPeriodController extends Controller { if (body.type == "NONE") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryAmount = + salaryProfile.amount == null ? 0 : salaryProfile.amount + salaryProfile.amountUse; } else if (body.type == "PENDING") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; @@ -492,9 +504,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryHalf - salaryProfile.amount; + : salaryRanks.salaryHalf - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; + salaryRanks == null || salaryRanks.salaryHalf == null + ? 0 + : salaryRanks.salaryHalf + salaryProfile.amountUse; } else if (body.type == "FULL") { salaryProfile.amountSpecial = salaryRanks == null || salaryRanks.salaryFullSpecial == null @@ -506,9 +520,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFull == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFull - salaryProfile.amount; + : salaryRanks.salaryFull - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; + salaryRanks == null || salaryRanks.salaryFull == null + ? 0 + : salaryRanks.salaryFull + salaryProfile.amountUse; } else if (body.type == "FULLHAFT") { salaryProfile.amountSpecial = salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null @@ -520,9 +536,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFullHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFullHalf - salaryProfile.amount; + : salaryRanks.salaryFullHalf - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; + salaryRanks == null || salaryRanks.salaryFullHalf == null + ? 0 + : salaryRanks.salaryFullHalf + salaryProfile.amountUse; } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); } @@ -535,27 +553,28 @@ export class SalaryPeriodController extends Controller { if (salaryProfile.salaryOrg.salaryPeriod.period == "APR") { const amountFullType = await this.salaryProfileRepository.count({ where: { - salaryOrgId: salaryProfile?.salaryOrg.id, + salaryOrgId: salaryProfile.salaryOrg.id, type: "FULL", }, }); const calRemainQuota = salaryProfile.salaryOrg.fifteenPercent - amountFullType; salaryProfile.salaryOrg.quantityUsed = amountFullType; salaryProfile.salaryOrg.remainQuota = calRemainQuota; - await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); + await this.salaryOrgRepository.save(salaryProfile.salaryOrg); } else if (salaryProfile.salaryOrg.salaryPeriod.period == "OCT") { const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") .select("SUM(salaryProfile.amountUse)", "totalAmount") .where({ - salaryOrgId: salaryProfile?.salaryOrg.id, + salaryOrgId: salaryProfile.salaryOrg.id, type: "FULL", }) .getRawOne(); - const calRemainAmount = salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + const calRemainAmount = + salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; - await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); + await this.salaryOrgRepository.save(salaryProfile.salaryOrg); } } } @@ -727,7 +746,8 @@ export class SalaryPeriodController extends Controller { if (salaryProfile.type == "NONE") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; - salaryProfile.positionSalaryAmount = salaryProfile.amount == null ? 0 : salaryProfile.amount; + salaryProfile.positionSalaryAmount = + salaryProfile.amount == null ? 0 : salaryProfile.amount + salaryProfile.amountUse; } else if (salaryProfile.type == "PENDING") { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; @@ -743,9 +763,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryHalf - salaryProfile.amount; + : salaryRanks.salaryHalf - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryHalf == null ? 0 : salaryRanks.salaryHalf; + salaryRanks == null || salaryRanks.salaryHalf == null + ? 0 + : salaryRanks.salaryHalf + salaryProfile.amountUse; } else if (salaryProfile.type == "FULL") { salaryProfile.amountSpecial = salaryRanks == null || salaryRanks.salaryFullSpecial == null @@ -757,9 +779,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFull == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFull - salaryProfile.amount; + : salaryRanks.salaryFull - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryFull == null ? 0 : salaryRanks.salaryFull; + salaryRanks == null || salaryRanks.salaryFull == null + ? 0 + : salaryRanks.salaryFull + salaryProfile.amountUse; } else if (salaryProfile.type == "FULLHAFT") { salaryProfile.amountSpecial = salaryRanks == null || salaryRanks.salaryFullHalfSpecial == null @@ -771,9 +795,11 @@ export class SalaryPeriodController extends Controller { salaryRanks.salaryFullHalf == null || salaryProfile.amount == null ? 0 - : salaryRanks.salaryFullHalf - salaryProfile.amount; + : salaryRanks.salaryFullHalf - salaryProfile.amount - salaryProfile.amountSpecial; salaryProfile.positionSalaryAmount = - salaryRanks == null || salaryRanks.salaryFullHalf == null ? 0 : salaryRanks.salaryFullHalf; + salaryRanks == null || salaryRanks.salaryFullHalf == null + ? 0 + : salaryRanks.salaryFullHalf + salaryProfile.amountUse; } else { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0;