From 190a5d665a51d93af3f00738917e664dbbefeb16 Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Tue, 28 Apr 2026 16:53:15 +0700 Subject: [PATCH] fixed add isGovernment & commandDateAffect --- src/controllers/ImportDataController.ts | 32 +++---------------- src/controllers/ProfileSalaryController.ts | 22 +++++++++++++ .../ProfileSalaryEmployeeController.ts | 21 ++++++++++++ .../ProfileSalaryTempController.ts | 25 ++++++++++++--- 4 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 3d7a083a..b424edbb 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -7053,24 +7053,12 @@ export class ImportDataController extends Controller { salaryTemp.lastUpdateFullName = req.user?.name || "System Administrator"; // 12,15,16 isGovernment = false & dateGovernment = salaryTemp.commandDateAffect - if ( - salaryTemp.commandCode === "12" || - salaryTemp.commandCode === "15" || - salaryTemp.commandCode === "16" - ) { + if (["12", "15", "16"].includes(salaryTemp.commandCode ?? "")) { salaryTemp.isGovernment = false; salaryTemp.dateGovernment = salaryTemp.commandDateAffect; } // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = salaryTemp.commandDateAffect - else if ( - salaryTemp.commandCode === "1" || - salaryTemp.commandCode === "2" || - salaryTemp.commandCode === "3" || - salaryTemp.commandCode === "4" || - salaryTemp.commandCode === "10" || - salaryTemp.commandCode === "11" || - salaryTemp.commandCode === "20" - ) { + else if (["1", "2", "3", "4", "10", "11", "20"].includes(salaryTemp.commandCode ?? "")) { salaryTemp.isGovernment = true; salaryTemp.dateGovernment = salaryTemp.commandDateAffect; } @@ -7325,24 +7313,12 @@ export class ImportDataController extends Controller { salaryTemp.lastUpdateFullName = req.user?.name || "System Administrator"; // 12,15,16 isGovernment = false & dateGovernment = salaryTemp.commandDateAffect - if ( - salaryTemp.commandCode === "12" || - salaryTemp.commandCode === "15" || - salaryTemp.commandCode === "16" - ) { + if (["12", "15", "16"].includes(salaryTemp.commandCode ?? "")) { salaryTemp.isGovernment = false; salaryTemp.dateGovernment = salaryTemp.commandDateAffect; } // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = salaryTemp.commandDateAffect - else if ( - salaryTemp.commandCode === "1" || - salaryTemp.commandCode === "2" || - salaryTemp.commandCode === "3" || - salaryTemp.commandCode === "4" || - salaryTemp.commandCode === "10" || - salaryTemp.commandCode === "11" || - salaryTemp.commandCode === "20" - ) { + else if (["1", "2", "3", "4", "10", "11", "20"].includes(salaryTemp.commandCode ?? "")) { salaryTemp.isGovernment = true; salaryTemp.dateGovernment = salaryTemp.commandDateAffect; } diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 4e3e9e3b..814f5e89 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -919,6 +919,17 @@ export class ProfileSalaryController extends Controller { else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง"; } Object.assign(data, { ...body, ...meta }); + // 12,15,16 isGovernment = false & dateGovernment = commandDateAffect + if (["12", "15", "16"].includes(body.commandCode ?? "")) { + data.isGovernment = false; + if (body.commandDateAffect) data.dateGovernment = body.commandDateAffect; + } + // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = commandDateAffect + else if (["1", "2", "3", "4", "10", "11", "20"].includes(body.commandCode ?? "")) { + data.isGovernment = true; + if (body.commandDateAffect) data.dateGovernment = body.commandDateAffect; + } + const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); await this.salaryRepo.save(data, { data: req }); @@ -1043,6 +1054,17 @@ export class ProfileSalaryController extends Controller { else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง"; } Object.assign(record, body); + // 12,15,16 isGovernment = false & dateGovernment = commandDateAffect + if (["12", "15", "16"].includes(body.commandCode ?? "")) { + record.isGovernment = false; + if (body.commandDateAffect) record.dateGovernment = body.commandDateAffect; + } + // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = commandDateAffect + else if (["1", "2", "3", "4", "10", "11", "20"].includes(body.commandCode ?? "")) { + record.isGovernment = true; + if (body.commandDateAffect) record.dateGovernment = body.commandDateAffect; + } + Object.assign(history, { ...record, id: undefined }); history.profileSalaryId = salaryId; diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index 7428e913..44b93a5d 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -403,6 +403,17 @@ export class ProfileSalaryEmployeeController extends Controller { else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง"; } Object.assign(data, { ...body, ...meta }); + // 12,15,16 isGovernment = false & dateGovernment = commandDateAffect + if (["12", "15", "16"].includes(body.commandCode ?? "")) { + data.isGovernment = false; + if (body.commandDateAffect) data.dateGovernment = body.commandDateAffect; + } + // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = commandDateAffect + else if (["1", "2", "3", "4", "10", "11", "20"].includes(body.commandCode ?? "")) { + data.isGovernment = true; + if (body.commandDateAffect) data.dateGovernment = body.commandDateAffect; + } + const history = new ProfileSalaryHistory(); Object.assign(history, { ...data, id: undefined }); const _null: any = null; @@ -537,6 +548,16 @@ export class ProfileSalaryEmployeeController extends Controller { else if (body.commandCode == "19") body.commandName = "ไม่ได้เลื่อนเงินเดือน/ค่าจ้าง"; } Object.assign(record, body); + // 12,15,16 isGovernment = false & dateGovernment = commandDateAffect + if (["12", "15", "16"].includes(body.commandCode ?? "")) { + record.isGovernment = false; + if (body.commandDateAffect) record.dateGovernment = body.commandDateAffect ?? null; + } + // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = commandDateAffect + else if (["1", "2", "3", "4", "10", "11", "20"].includes(body.commandCode ?? "")) { + record.isGovernment = true; + if (body.commandDateAffect) record.dateGovernment = body.commandDateAffect ?? null; + } Object.assign(history, { ...record, id: undefined }); history.profileSalaryId = salaryId; diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 49c757dc..42cffe41 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -133,8 +133,8 @@ export class ProfileSalaryTempController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - // : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` - : `current_holders.orgChild1Id is null` + : // : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` + `current_holders.orgChild1Id is null` : "1=1", { child1: _data.child1, @@ -545,8 +545,8 @@ export class ProfileSalaryTempController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `current_holders.orgChild1Id IN (:...child1)` - // : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` - : `current_holders.orgChild1Id is null` + : // : `current_holders.orgChild1Id is ${_data.privilege == "PARENT" ? "not null" : "null"}` + `current_holders.orgChild1Id is null` : "1=1", { child1: _data.child1, @@ -1233,6 +1233,13 @@ export class ProfileSalaryTempController extends Controller { isDelete: false, }; Object.assign(data, { ...body, ...meta }); + if (["12", "15", "16"].includes(body.commandCode ?? "")) { + data.isGovernment = false; + if (body.commandDateAffect) data.dateGovernment = body.commandDateAffect; + } else if (["1", "2", "3", "4", "10", "11", "20"].includes(body.commandCode ?? "")) { + data.isGovernment = true; + if (body.commandDateAffect) data.dateGovernment = body.commandDateAffect; + } await this.salaryRepo.save(data, { data: req }); setLogDataDiff(req, { before, after: data }); @@ -1509,6 +1516,16 @@ export class ProfileSalaryTempController extends Controller { const before = structuredClone(record); Object.assign(record, body); + // 12,15,16 isGovernment = false & dateGovernment = commandDateAffect + if (["12", "15", "16"].includes(body.commandCode ?? "")) { + record.isGovernment = false; + if (body.commandDateAffect) record.dateGovernment = body.commandDateAffect; + } + // 1,2,3,4,10,11,20 isGovernment = true & dateGovernment = commandDateAffect + else if (["1", "2", "3", "4", "10", "11", "20"].includes(body.commandCode ?? "")) { + record.isGovernment = true; + if (body.commandDateAffect) record.dateGovernment = body.commandDateAffect; + } record.isEdit = true; record.lastUpdateUserId = req.user.sub;