From 8c7ea649852f5de8665b3384c8c8dfd8aedccf5c Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 6 Mar 2024 18:28:05 +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=82=E0=B8=84=E0=B8=A7=E0=B8=95=E0=B9=89=E0=B8=B2=E0=B8=95?= =?UTF-8?q?=E0=B8=AD=E0=B8=99=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=E0=B8=84=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryPeriodController.ts | 26 ++++++++++++++++++----- src/entities/Salarys.ts | 16 ++++++-------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index ea6fcfb..b3a6060 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -175,7 +175,9 @@ export class SalaryPeriodController extends Controller { }) .getRawOne(); const calRemainAmount = - salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + salaryProfile.salaryOrg.sixPercentAmount - + sumAmountUse.totalAmount - + salaryProfile.salaryOrg.spentAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); @@ -322,7 +324,9 @@ export class SalaryPeriodController extends Controller { }) .getRawOne(); const calRemainAmount = - salaryProfile?.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + salaryProfile.salaryOrg.sixPercentAmount - + sumAmountUse.totalAmount - + salaryProfile.salaryOrg.spentAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); @@ -381,7 +385,8 @@ export class SalaryPeriodController extends Controller { type: In(["HAFT", "FULL", "FULLHAFT"]), }) .getRawOne(); - const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + const calRemainAmount = + salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; salaryOrg.useAmount = sumAmountUse.totalAmount; salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryOrg); @@ -555,7 +560,9 @@ export class SalaryPeriodController extends Controller { }) .getRawOne(); const calRemainAmount = - salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + salaryProfile.salaryOrg.sixPercentAmount - + sumAmountUse.totalAmount - + salaryProfile.salaryOrg.spentAmount; salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile.salaryOrg); @@ -793,6 +800,10 @@ export class SalaryPeriodController extends Controller { // หาจำนวน Quota คงเหลือ if (salaryOrg.snapshot == "SNAP1") { 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; + const amountFullType = await this.salaryProfileRepository.count({ where: { salaryOrgId: salaryOrg.id, @@ -804,6 +815,10 @@ export class SalaryPeriodController extends Controller { 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; + const sumAmountUse = await AppDataSource.getRepository(SalaryProfile) .createQueryBuilder("salaryProfile") .select("SUM(salaryProfile.amountUse)", "totalAmount") @@ -812,7 +827,8 @@ export class SalaryPeriodController extends Controller { type: In(["HAFT", "FULL", "FULLHAFT"]), }) .getRawOne(); - const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount; + const calRemainAmount = + salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; salaryOrg.useAmount = sumAmountUse.totalAmount; salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryOrg); diff --git a/src/entities/Salarys.ts b/src/entities/Salarys.ts index dd65fea..f93995d 100644 --- a/src/entities/Salarys.ts +++ b/src/entities/Salarys.ts @@ -80,7 +80,6 @@ export class Salarys extends EntityBase { } export class CreateSalary { - @Column() salaryType: string; @@ -94,13 +93,13 @@ export class CreateSalary { isActive: boolean; @Column() - date?: Date; + date?: Date | null; @Column() - startDate?: Date; + startDate?: Date | null; @Column() - endDate?: Date; + endDate?: Date | null; @Column() details?: string | null; @@ -110,7 +109,6 @@ export class CreateSalary { } export class UpdateSalary { - @Column() salaryType: string; @@ -124,13 +122,13 @@ export class UpdateSalary { isActive: boolean; @Column() - date?: Date; + date?: Date | null; @Column() - startDate?: Date; + startDate?: Date | null; @Column() - endDate?: Date; + endDate?: Date | null; @Column() details?: string | null; @@ -139,4 +137,4 @@ export class UpdateSalary { isSpecial: boolean; } -// export type UpdateSalary = Partial ; \ No newline at end of file +// export type UpdateSalary = Partial ;