From e6639e8e721d327627b3c50c2474cae3ed424396 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 1 May 2025 13:22:51 +0700 Subject: [PATCH] update --- src/controllers/SalaryPeriodController.ts | 78 +++++++++++++---------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/src/controllers/SalaryPeriodController.ts b/src/controllers/SalaryPeriodController.ts index 12bdf80..f27d482 100644 --- a/src/controllers/SalaryPeriodController.ts +++ b/src/controllers/SalaryPeriodController.ts @@ -2528,6 +2528,7 @@ export class SalaryPeriodController extends Controller { salaryPeriodId: string, @Request() request: RequestWithUser, ) { + try { snapshot = snapshot.toLocaleUpperCase(); const salaryPeriod = await this.salaryPeriodRepository.findOne({ where: { id: salaryPeriodId }, @@ -2554,18 +2555,18 @@ export class SalaryPeriodController extends Controller { await this.salaryProfileEmployeeRepository.remove(salaryProfileEmployee, { data: request }); await this.salaryOrgEmployeeRepository.remove(salaryOrgEmployee, { data: request }); let orgs = await new CallAPI().GetData(request, "/org/unauthorize/active/root/id"); + //snap บางสำนัก - orgs = orgs.filter((x: any) => - x.rootId.includes([ - "d7e98989-b5ce-47d6-93c3-ab63ed486348", - "e0545eca-5d0a-4a1c-8bbd-e3e25c2521db", - "7ff1fbf2-cc9e-4f53-b83c-334967c27967", - "26989ffa-d5ab-4bbd-ac97-130646cd1da6", - "6f9b30e1-757a-40d5-b053-61eb1b91c0f0", - "eaf65f33-25e9-4956-9dba-5d909f5eb595", - ]), - ); - + const targetRootIds = [ + "d7e98989-b5ce-47d6-93c3-ab63ed486348", + "e0545eca-5d0a-4a1c-8bbd-e3e25c2521db", + "7ff1fbf2-cc9e-4f53-b83c-334967c27967", + "26989ffa-d5ab-4bbd-ac97-130646cd1da6", + "6f9b30e1-757a-40d5-b053-61eb1b91c0f0", + "eaf65f33-25e9-4956-9dba-5d909f5eb595", + ]; + + orgs = orgs.filter((x: any) => targetRootIds.includes(x.rootId)); let total = 1000; // let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/salary/gen", { let _orgProfiles = await new CallAPI().PostData(request, "/org/unauthorize/new-salary/gen", { @@ -2577,6 +2578,8 @@ export class SalaryPeriodController extends Controller { }); let orgProfiles = _orgProfiles.data; total = _orgProfiles.total; + console.log(`total: ${total}`); + if (total > 1000) { const page = Math.ceil(total / 1000); for (let index = 2; index <= page; index++) { @@ -2610,6 +2613,7 @@ export class SalaryPeriodController extends Controller { ); orgProfileEmployees = _orgProfileEmployees.data; total = _orgProfileEmployees.total; + console.log(`totalEmp: ${total}`); if (total > 1000) { const page = Math.ceil(total / 1000); for (let index = 2; index <= page; index++) { @@ -2627,6 +2631,7 @@ export class SalaryPeriodController extends Controller { }); } } + let revisionId = await new CallAPI().GetData(request, "/org/unauthorize/revision/latest"); let _null: any = null; const beforeSalaryPeriod = structuredClone(salaryPeriod); @@ -2742,25 +2747,31 @@ export class SalaryPeriodController extends Controller { if (snapshot == "SNAP2") { console.log(`step5`); - const salaryOrgOld = await this.salaryOrgRepository.find({ - where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" }, - }); - const salaryOld = await this.salaryProfileRepository.findOne({ - where: { - citizenId: salaryProfileNew.citizenId, - salaryOrgId: In(salaryOrgOld.map((x) => x.id)), - }, - }); - salaryProfileNew.type = salaryOld == null ? "PENDING" : salaryOld.type; - salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount; - salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial; - salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse; - salaryProfileNew.positionSalaryAmount = - salaryOld == null ? 0 : salaryOld.positionSalaryAmount; - salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext; - salaryProfileNew.isSpecial = salaryOld == null ? false : salaryOld.isSpecial; - salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve; - salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired; + try{ + const salaryOrgOld = await this.salaryOrgRepository.find({ + where: { salaryPeriodId: salaryPeriod.id, snapshot: "SNAP1" }, + }); + console.log(`ก่อนหา salaryOld`); + const salaryOld = await this.salaryProfileRepository.findOne({ + where: { + citizenId: salaryProfileNew.citizenId, + salaryOrgId: In(salaryOrgOld.map((x) => x.id)), + }, + }); + + salaryProfileNew.type = salaryOld == null ? "PENDING" : salaryOld.type; + salaryProfileNew.amount = salaryOld == null ? 0 : salaryOld.amount; + salaryProfileNew.amountSpecial = salaryOld == null ? 0 : salaryOld.amountSpecial; + salaryProfileNew.amountUse = salaryOld == null ? 0 : salaryOld.amountUse; + salaryProfileNew.positionSalaryAmount = + salaryOld == null ? 0 : salaryOld.positionSalaryAmount; + salaryProfileNew.isNext = salaryOld == null ? false : salaryOld.isNext; + salaryProfileNew.isSpecial = salaryOld == null ? false : salaryOld.isSpecial; + salaryProfileNew.isReserve = salaryOld == null ? false : salaryOld.isReserve; + salaryProfileNew.isRetired = salaryOld == null ? false : salaryOld.isRetired; + } catch (err) { + console.error(`❌ error processing employee:`, err); + } } console.log(`step6`); await this.salaryProfileRepository.save(salaryProfileNew, { data: request }); @@ -2776,7 +2787,6 @@ export class SalaryPeriodController extends Controller { console.log("mlength", orgProfileEmployees.length); await Promise.all( orgProfileEmployees.map(async (profile: any) => { - try { const salaryOrgNew = await this.salaryOrgEmployeeRepository.findOne({ where: { salaryPeriodId: salaryPeriod.id, @@ -2840,9 +2850,6 @@ export class SalaryPeriodController extends Controller { `⚠️ [SNAP: ${snapshot}] ไม่พบ salaryOrgEmployee สำหรับ rootId: ${profile.rootId}`, ); } - } catch (err) { - console.error(`❌ error processing employee: ${profile.citizenId}`, err); - } }), ); } @@ -3078,6 +3085,9 @@ export class SalaryPeriodController extends Controller { } return new HttpSuccess(); + } catch (err) { + console.error(`❌ error processing employee:`, err); + } } /**