From 87670fb5b456821cac11343f4af5ef5e581c85d7 Mon Sep 17 00:00:00 2001 From: moss <> Date: Mon, 21 Apr 2025 16:04:50 +0700 Subject: [PATCH] isclose --- src/controllers/SalaryPeriodController.ts | 78 ++++++++++++------- .../SalaryPeriodEmployeeController.ts | 25 +++--- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 3cde762..b575394 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -67,59 +67,66 @@ export class SalaryPeriodController extends Controller { if (!salaryPeriod) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบรอบการขึ้นเงินเดือน"); } - const data = { group1id: - salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + : salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), )?.id, group1IsClose: - salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + : salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), )?.isClose, group2id: - salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + : salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), )?.id, group2IsClose: - salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + : salaryPeriod.salaryOrgs && + salaryPeriod.salaryOrgs.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && @@ -1576,12 +1583,12 @@ export class SalaryPeriodController extends Controller { // : `profile.isRetired = false` // : "1=1", body.isRetire == null - ? `profile.isRetired = false` - : body.isRetire == "1" - ? `profile.isRetired = true` - : body.isRetire == "0" - ? `profile.isRetired = false` - : "1=1", + ? `profile.isRetired = false` + : body.isRetire == "1" + ? `profile.isRetired = true` + : body.isRetire == "0" + ? `profile.isRetired = false` + : "1=1", ) .andWhere({ salaryOrgId: salaryOrg.id, @@ -2630,7 +2637,7 @@ export class SalaryPeriodController extends Controller { }), ); if (salaryPeriod.period != "SPECIAL") { - console.log(`step1`) + console.log(`step1`); await Promise.all( orgProfiles.map(async (profile: any) => { let group = "GROUP1"; @@ -2644,7 +2651,7 @@ export class SalaryPeriodController extends Controller { ) { group = "GROUP2"; } - console.log(`step2`) + console.log(`step2`); const salaryOrgNew = await this.salaryOrgRepository.findOne({ where: { salaryPeriodId: salaryPeriod.id, @@ -2653,9 +2660,9 @@ export class SalaryPeriodController extends Controller { group: group, }, }); - console.log(`step3`) + console.log(`step3`); if (salaryOrgNew != null) { - console.log(`step4`) + console.log(`step4`); let salaryProfileNew = Object.assign(new SalaryProfile(), profile); delete salaryProfileNew.id; @@ -2671,7 +2678,7 @@ export class SalaryPeriodController extends Controller { salaryProfileNew.lastUpdatedAt = new Date(); if (snapshot == "SNAP2") { - console.log(`step5`) + console.log(`step5`); const salaryOrgOld = await this.salaryOrgRepository.find({ where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" }, }); @@ -2692,11 +2699,13 @@ export class SalaryPeriodController extends Controller { salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve; salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired; } - console.log(`step6`) + console.log(`step6`); await this.salaryProfileRepository.save(salaryProfileNew, { data: request }); setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew }); - console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`); - }else{ + console.log( + `✅ [SNAP: ${snapshot}] บันทึก SalaryProfile: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`, + ); + } else { console.warn(`⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrg สำหรับ rootId: ${profile.rootId}`); } }), @@ -2737,7 +2746,10 @@ export class SalaryPeriodController extends Controller { }, }); salaryProfileNew.type = salaryOld == null ? 0 : salaryOld.type; - salaryProfileNew.salaryLevel = salaryOld && salaryOld.salaryLevelNew ? salaryOld.salaryLevelNew : salaryOld?.salaryLevel; + salaryProfileNew.salaryLevel = + salaryOld && salaryOld.salaryLevelNew + ? salaryOld.salaryLevelNew + : salaryOld?.salaryLevel; salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount; salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial; salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse; @@ -2750,9 +2762,13 @@ export class SalaryPeriodController extends Controller { } await this.salaryProfileEmployeeRepository.save(salaryProfileNew, { data: request }); setLogDataDiff(request, { before: beforeSalaryProfileNew, after: salaryProfileNew }); - console.log(`✅ [SNAP: ${snapshot}] บันทึก SalaryProfileEmployee: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`); - }else{ - console.warn(`⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrgEmployee สำหรับ rootId: ${profile.rootId}`); + console.log( + `✅ [SNAP: ${snapshot}] บันทึก SalaryProfileEmployee: ${salaryProfileNew.citizenId} (${salaryProfileNew.fullName ?? "-"})`, + ); + } else { + console.warn( + `⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrgEmployee สำหรับ rootId: ${profile.rootId}`, + ); } }), ); @@ -3750,6 +3766,14 @@ export class SalaryPeriodController extends Controller { item.isClose = body.isClose; await this.salaryOrgRepository.save(item); } + const salaryPeriodEmp = await this.salaryOrgEmployeeRepository.find({ + where: { salaryPeriodId: salaryPeriodId, snapshot: snapShot }, + }); + + for await (const item of salaryPeriodEmp) { + item.isClose = body.isClose; + await this.salaryOrgEmployeeRepository.save(item); + } return new HttpSuccess(); } } diff --git a/src/controllers/SalaryPeriodEmployeeController.ts b/src/controllers/SalaryPeriodEmployeeController.ts index 68f7a70..96340d0 100644 --- a/src/controllers/SalaryPeriodEmployeeController.ts +++ b/src/controllers/SalaryPeriodEmployeeController.ts @@ -69,56 +69,64 @@ export class SalaryPeriodEmployeeController extends Controller { } const data = { group1id: - salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find( + salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find( + : salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), )?.id, group1IsClose: - salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + : salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP1" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), )?.isClose, group2id: - salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find( + salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgEmployees && salaryPeriod.salaryOrgEmployees.find( + : salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), )?.id, group2IsClose: - salaryPeriod.salaryOrgs &&salaryPeriod.salaryOrgs.find( + salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && x.snapshot == body.snapshot.toLocaleUpperCase(), ) == null ? null - : salaryPeriod.salaryOrgs && salaryPeriod.salaryOrgs.find( + : salaryPeriod.salaryOrgEmployees && + salaryPeriod.salaryOrgEmployees.find( (x) => x.group == "GROUP2" && x.rootId == body.rootId && @@ -128,7 +136,6 @@ export class SalaryPeriodEmployeeController extends Controller { period: salaryPeriod.period, }; - return new HttpSuccess(data); }