From c3b47b4867b205dc33eeb00728ec31b89f3cd892 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 8 Mar 2024 14:51:10 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B8=84=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=84?= =?UTF-8?q?=E0=B8=99=E0=B9=80=E0=B8=82=E0=B9=89=E0=B8=B2=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=9A=E0=B8=9A=E0=B9=80=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80?= =?UTF-8?q?=E0=B8=94=E0=B8=B7=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 | 34 ++++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 6ff22a2..f9cef22 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -1082,39 +1082,47 @@ export class SalaryPeriodController extends Controller { // หาจำนวน Quota คงเหลือ if (salaryOrg.snapshot == "SNAP1") { + const _salaryOrg = await this.salaryOrgRepository.findOne({ + where: { + id: salaryOrg.id, + }, + }); + if (!_salaryOrg) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); + } if (salaryOrg.salaryPeriod.period == "APR") { - salaryOrg.total = salaryOrg.salaryProfiles.length; - salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100); - salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100; + _salaryOrg.total = salaryOrg.salaryProfiles.length; + _salaryOrg.fifteenPercent = Math.floor((salaryOrg.salaryProfiles.length * 15) / 100); + _salaryOrg.fifteenPoint = (salaryOrg.salaryProfiles.length * 15) % 100; const amountFullType = await this.salaryProfileRepository.count({ where: { - salaryOrgId: salaryOrg?.id, + salaryOrgId: salaryOrg.id, type: "FULL", }, }); const calRemainQuota = salaryOrg.fifteenPercent - amountFullType; - salaryOrg.quantityUsed = amountFullType; - salaryOrg.remainQuota = calRemainQuota; - await this.salaryOrgRepository.save(salaryOrg); + _salaryOrg.quantityUsed = amountFullType; + _salaryOrg.remainQuota = calRemainQuota; + await this.salaryOrgRepository.save(_salaryOrg); } else if (salaryOrg.salaryPeriod.period == "OCT") { const totalProfile = Extension.sumObjectValues(salaryOrg.salaryProfiles, "amount"); - salaryOrg.currentAmount = totalProfile; - salaryOrg.sixPercentAmount = totalProfile * 0.06; + _salaryOrg.currentAmount = totalProfile; + _salaryOrg.sixPercentAmount = totalProfile * 0.06; const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") .select("SUM(salaryProfile.amountUse)", "totalAmount") .where({ - salaryOrgId: salaryOrg?.id, + salaryOrgId: salaryOrg.id, type: In(["HAFT", "FULL", "FULLHAFT"]), }) .getRawOne(); const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; - salaryOrg.useAmount = sumAmountUse.totalAmount; - salaryOrg.remainingAmount = calRemainAmount; - await this.salaryOrgRepository.save(salaryOrg); + _salaryOrg.useAmount = sumAmountUse.totalAmount; + _salaryOrg.remainingAmount = calRemainAmount; + await this.salaryOrgRepository.save(_salaryOrg); } }