From 64f9cd942161e67156b51348d515f3203db638ed Mon Sep 17 00:00:00 2001 From: Kittapath Date: Mon, 18 Mar 2024 16:17:05 +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=99=E0=B8=97=E0=B8=B6=E0=B8=81step=E0=B9=80=E0=B8=87?= =?UTF-8?q?=E0=B8=B4=E0=B8=99=E0=B9=80=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 | 33 +++++++++------ .../SalaryPeriodEmployeeController.ts | 41 +++++++++++-------- 2 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 220b65d..2649496 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -185,7 +185,8 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryProfile.salaryOrg.spentAmount; - salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryProfile.salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); } @@ -414,7 +415,8 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryProfile.salaryOrg.spentAmount; - salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryProfile.salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); } @@ -476,7 +478,8 @@ export class SalaryPeriodController extends Controller { .getRawOne(); const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; - salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryOrg); } @@ -734,7 +737,8 @@ export class SalaryPeriodController extends Controller { salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryProfile.salaryOrg.spentAmount; - salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryProfile.salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile.salaryOrg); } @@ -1122,7 +1126,8 @@ export class SalaryPeriodController extends Controller { .getRawOne(); const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; - _salaryOrg.useAmount = sumAmountUse.totalAmount; + _salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; _salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(_salaryOrg); } @@ -2360,10 +2365,12 @@ export class SalaryPeriodController extends Controller { if (!salaryPeriod) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); await Promise.all( - salaryPeriod.salaryOrgs.map(async (x) => { - x.status = "WAITHEAD1"; - await this.salaryPeriodRepository.save(salaryPeriod); - }), + salaryPeriod.salaryOrgs + .filter((x) => x.rootId == rootId) + .map(async (x) => { + x.status = "WAITHEAD1"; + await this.salaryOrgRepository.save(x); + }), ); return new HttpSuccess(); } @@ -2389,7 +2396,7 @@ export class SalaryPeriodController extends Controller { .filter((x) => x.rootId == rootId) .map(async (x) => { x.status = "WAITOWNER1"; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); @@ -2416,7 +2423,7 @@ export class SalaryPeriodController extends Controller { .filter((x) => x.rootId == rootId) .map(async (x) => { x.status = "REPORT"; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); @@ -2451,7 +2458,7 @@ export class SalaryPeriodController extends Controller { .map(async (x) => { x.status = "WAITHEAD2"; x.ownerRecommend = body.titleRecommend; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); @@ -2486,7 +2493,7 @@ export class SalaryPeriodController extends Controller { .map(async (x) => { x.status = "REPORT"; x.ownerRecommend = body.titleRecommend; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index 1ef6fc9..3116797 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -184,7 +184,8 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryProfile.salaryOrg.spentAmount; - salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryProfile.salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); } @@ -415,7 +416,8 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryProfile.salaryOrg.spentAmount; - salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryProfile.salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile?.salaryOrg); } @@ -477,7 +479,8 @@ export class SalaryPeriodEmployeeController extends Controller { .getRawOne(); const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; - salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryOrg); } @@ -737,7 +740,8 @@ export class SalaryPeriodEmployeeController extends Controller { salaryProfile.salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryProfile.salaryOrg.spentAmount; - salaryProfile.salaryOrg.useAmount = sumAmountUse.totalAmount; + salaryProfile.salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; salaryProfile.salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(salaryProfile.salaryOrg); } @@ -1125,7 +1129,8 @@ export class SalaryPeriodEmployeeController extends Controller { .getRawOne(); const calRemainAmount = salaryOrg.sixPercentAmount - sumAmountUse.totalAmount - salaryOrg.spentAmount; - _salaryOrg.useAmount = sumAmountUse.totalAmount; + _salaryOrg.useAmount = + sumAmountUse == null || sumAmountUse.totalAmount == null ? 0 : sumAmountUse.totalAmount; _salaryOrg.remainingAmount = calRemainAmount; await this.salaryOrgRepository.save(_salaryOrg); } @@ -1461,10 +1466,12 @@ export class SalaryPeriodEmployeeController extends Controller { if (!salaryPeriod) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบผังเงินเดือนนี้"); await Promise.all( - salaryPeriod.salaryOrgs.map(async (x) => { - x.status = "WAITHEAD1"; - await this.salaryPeriodRepository.save(salaryPeriod); - }), + salaryPeriod.salaryOrgs + .filter((x) => x.rootId == rootId) + .map(async (x: any) => { + x.status = "WAITHEAD1"; + await this.salaryOrgRepository.save(x); + }), ); return new HttpSuccess(); } @@ -1488,9 +1495,9 @@ export class SalaryPeriodEmployeeController extends Controller { await Promise.all( salaryPeriod.salaryOrgs .filter((x) => x.rootId == rootId) - .map(async (x) => { + .map(async (x: any) => { x.status = "WAITOWNER1"; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); @@ -1515,9 +1522,9 @@ export class SalaryPeriodEmployeeController extends Controller { await Promise.all( salaryPeriod.salaryOrgs .filter((x) => x.rootId == rootId) - .map(async (x) => { + .map(async (x: any) => { x.status = "REPORT"; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); @@ -1549,10 +1556,10 @@ export class SalaryPeriodEmployeeController extends Controller { await Promise.all( salaryPeriod.salaryOrgs .filter((x) => x.rootId == rootId) - .map(async (x) => { + .map(async (x: any) => { x.status = "WAITHEAD2"; x.ownerRecommend = body.titleRecommend; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess(); @@ -1584,10 +1591,10 @@ export class SalaryPeriodEmployeeController extends Controller { await Promise.all( salaryPeriod.salaryOrgs .filter((x) => x.rootId == rootId) - .map(async (x) => { + .map(async (x: any) => { x.status = "REPORT"; x.ownerRecommend = body.titleRecommend; - await this.salaryPeriodRepository.save(salaryPeriod); + await this.salaryOrgRepository.save(x); }), ); return new HttpSuccess();