From aeb034a654916a774e0b56a811aaf8673b1a0af1 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 28 Feb 2024 18:03:36 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20call?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 60 ++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 92140f8..bd33cba 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -139,11 +139,26 @@ export class SalaryPeriodController extends Controller { @Delete("profile/{id}") async deleteSalaryProfile(@Path() id: string) { const salaryProfile = await this.salaryProfileRepository.findOne({ + relations: ["salaryOrg"], where: { id: id }, }); if (!salaryProfile) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการขอเงินเดือนผู้ใช้งานนี้ในระบบ"); } + // หาจำนวน Quota คงเหลือ + if(salaryProfile?.salaryOrg.snapshot == "SNAP1"){ + const amountFullType = await this.salaryProfileRepository.count({ + where:{ + 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.salaryProfileRepository.remove(salaryProfile); return new HttpSuccess(); } @@ -242,7 +257,20 @@ export class SalaryPeriodController extends Controller { } else { throw new HttpError(HttpStatusCode.NOT_FOUND, "ประเภทการเลื่อนขึ้นเงินเดือนไม่ถูกต้อง"); } - + // หาจำนวน Quota คงเหลือ + if(salaryProfile?.salaryOrg.snapshot == "SNAP1"){ + const amountFullType = await this.salaryProfileRepository.count({ + where:{ + 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.salaryProfileRepository.save(salaryProfile); return new HttpSuccess(); } @@ -269,6 +297,21 @@ export class SalaryPeriodController extends Controller { if (!salaryOrg) { 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); + } + salaryProfile.salaryOrgId = salaryOrg.id; await this.salaryProfileRepository.save(salaryProfile); return new HttpSuccess(); @@ -456,6 +499,21 @@ export class SalaryPeriodController extends Controller { if (!salaryOrg) { 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,