From 037fa442a50b29f1ef6414c2b21f70d7ad01fc26 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 29 Feb 2024 10:29:51 +0700 Subject: [PATCH] cal Quota and fix bug --- src/controllers/SalaryPeriodController.ts | 66 ++++++++++++++--------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index bd33cba..266fcf2 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -145,8 +145,11 @@ export class SalaryPeriodController extends Controller { if (!salaryProfile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ"); } + + await this.salaryProfileRepository.remove(salaryProfile); + // หาจำนวน Quota คงเหลือ - if(salaryProfile?.salaryOrg.snapshot == "SNAP1"){ + if(salaryProfile.salaryOrg.snapshot == "SNAP1"){ const amountFullType = await this.salaryProfileRepository.count({ where:{ salaryOrgId:salaryProfile?.salaryOrg.id, @@ -158,8 +161,7 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.remainQuota = calRemainQuota; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); } - - await this.salaryProfileRepository.remove(salaryProfile); + return new HttpSuccess(); } @@ -224,6 +226,10 @@ export class SalaryPeriodController extends Controller { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; salaryProfile.positionSalaryAmount = salaryProfile.amount; + } else if (salaryProfile.type == "PENDING") { + salaryProfile.amountSpecial = 0; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = 0; } else if (salaryProfile.type == "HAFT") { salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryHalfSpecial; salaryProfile.amountUse = @@ -257,6 +263,9 @@ export class SalaryPeriodController extends Controller { } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); } + + await this.salaryProfileRepository.save(salaryProfile); + // หาจำนวน Quota คงเหลือ if(salaryProfile?.salaryOrg.snapshot == "SNAP1"){ const amountFullType = await this.salaryProfileRepository.count({ @@ -270,8 +279,6 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.remainQuota = calRemainQuota; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); } - - await this.salaryProfileRepository.save(salaryProfile); return new HttpSuccess(); } @@ -298,8 +305,11 @@ export class SalaryPeriodController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มการขอเลื่อนเงินเดือน"); } - //หาจำนวน Quota คงเหลือ - if(salaryOrg.snapshot == "SNAP1"){ + salaryProfile.salaryOrgId = salaryOrg.id; + await this.salaryProfileRepository.save(salaryProfile); + + //หาจำนวน Quota คงเหลือ + if(salaryOrg.snapshot == "SNAP1"){ const amountFullType = await this.salaryProfileRepository.count({ where:{ salaryOrgId:salaryOrg.id, @@ -311,9 +321,6 @@ export class SalaryPeriodController extends Controller { salaryOrg.remainQuota = calRemainQuota; await this.salaryOrgRepository.save(salaryOrg); } - - salaryProfile.salaryOrgId = salaryOrg.id; - await this.salaryProfileRepository.save(salaryProfile); return new HttpSuccess(); } @@ -377,6 +384,10 @@ export class SalaryPeriodController extends Controller { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; salaryProfile.positionSalaryAmount = salaryProfile.amount; + } else if (body.type == "PENDING") { + salaryProfile.amountSpecial = 0; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = 0; } else if (body.type == "HAFT") { salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryHalfSpecial; salaryProfile.amountUse = @@ -500,20 +511,6 @@ export class SalaryPeriodController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - //หาจำนวน Quota คงเหลือ - if(salaryOrg.snapshot == "SNAP1"){ - const amountFullType = await this.salaryProfileRepository.count({ - where:{ - salaryOrgId:salaryOrg.id, - type:"FULL" - } - }); - const calRemainQuota = salaryOrg.fifteenPercent - amountFullType; - salaryOrg.quantityUsed = amountFullType; - salaryOrg.remainQuota = calRemainQuota; - await this.salaryOrgRepository.save(salaryOrg); - } - const salaryOrgAll = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salaryOrg.salaryPeriodId, @@ -585,7 +582,11 @@ export class SalaryPeriodController extends Controller { salaryProfile.amountSpecial = 0; salaryProfile.amountUse = 0; salaryProfile.positionSalaryAmount = salaryProfile.amount; - } else if (salaryProfile.type == "HAFT") { + } else if (salaryProfile.type == "PENDING") { + salaryProfile.amountSpecial = 0; + salaryProfile.amountUse = 0; + salaryProfile.positionSalaryAmount = 0; + }else if (salaryProfile.type == "HAFT") { salaryProfile.amountSpecial = salaryRanks == null ? 0 : salaryRanks.salaryHalfSpecial; salaryProfile.amountUse = salaryRanks == null || @@ -627,6 +628,21 @@ export class SalaryPeriodController extends Controller { salaryProfile.lastUpdateUserId = request.user.sub; salaryProfile.lastUpdateFullName = request.user.name; await this.salaryProfileRepository.save(salaryProfile); + + //หาจำนวน Quota คงเหลือ + if(salaryOrg.snapshot == "SNAP1"){ + const amountFullType = await this.salaryProfileRepository.count({ + where:{ + salaryOrgId:salaryOrg.id, + type:"FULL" + } + }); + const calRemainQuota = salaryOrg.fifteenPercent - amountFullType; + salaryOrg.quantityUsed = amountFullType; + salaryOrg.remainQuota = calRemainQuota; + await this.salaryOrgRepository.save(salaryOrg); + } + return new HttpSuccess(salaryProfile.id); }