From 0732071da06c27f813f0af57b2921fbe601b3055 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 29 Apr 2025 16:07:24 +0700 Subject: [PATCH 1/3] =?UTF-8?q?[Bug=20=E0=B8=AD=E0=B8=B1=E0=B8=95=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=81=E0=B8=B3=E0=B8=A5=E0=B8=B1=E0=B8=87=E0=B8=A5?= =?UTF-8?q?=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=88=E0=B8=B3]=201=20=E0=B8=84=E0=B8=99?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=B7=E0=B8=AD=E0=B8=81=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=AD=E0=B8=87=E0=B9=84=E0=B8=94=E0=B9=89=201=20=E0=B8=95?= =?UTF-8?q?=E0=B8=B3=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87=20#116?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileEmployeeController.ts | 34 +++++++++++++++---- .../ProfileEmployeeTempController.ts | 33 ++++++++++++++---- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index a807c638..0a87094c 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -2590,7 +2590,7 @@ export class ProfileEmployeeController extends Controller { } const [profiles, total] = await this.profileRepo .createQueryBuilder("profileEmployee") - .leftJoinAndSelect("profileEmployee.next_holders", "next_holders") + .leftJoinAndSelect("profileEmployee.current_holders", "current_holders") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") .where( @@ -2606,12 +2606,29 @@ export class ProfileEmployeeController extends Controller { new Brackets((qb) => { qb.where( requestBody.keyword != null && requestBody.keyword != "" - ? `CONCAT(profileEmployee.prefix, profileEmployee.firstName," ",profileEmployee.lastName) LIKE :keyword` + ? "profileEmployee.prefix LIKE :keyword" : "1=1", { keyword: `%${requestBody.keyword}%`, }, - ).orWhere( + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( requestBody.keyword != null && requestBody.keyword != "" ? "profileEmployee.citizenId LIKE :keyword" : "1=1", @@ -2642,19 +2659,22 @@ export class ProfileEmployeeController extends Controller { qb.where("profileEmployee.id NOT IN (:...ids)", { ids: orgRevision.employeePosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId).length == 0 + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId).length == 0 ? ["zxc"] : orgRevision.employeePosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId), + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId), }); }), ) .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "PERM" }) .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) + .orderBy("posType.posTypeRank", "ASC") + .addOrderBy("posLevel.posLevelRank", "ASC") .getManyAndCount(); + const data = profiles.map((_data) => ({ id: _data.id, prefix: _data.prefix, diff --git a/src/controllers/ProfileEmployeeTempController.ts b/src/controllers/ProfileEmployeeTempController.ts index a3e7734b..78a7e665 100644 --- a/src/controllers/ProfileEmployeeTempController.ts +++ b/src/controllers/ProfileEmployeeTempController.ts @@ -1704,7 +1704,7 @@ export class ProfileEmployeeTempController extends Controller { } const [profiles, total] = await this.profileRepo .createQueryBuilder("profileEmployee") - .leftJoinAndSelect("profileEmployee.next_holderTemps", "next_holderTemps") + .leftJoinAndSelect("profileEmployee.current_holderTemps", "current_holderTemps") .leftJoinAndSelect("profileEmployee.posLevel", "posLevel") .leftJoinAndSelect("profileEmployee.posType", "posType") .where( @@ -1720,12 +1720,29 @@ export class ProfileEmployeeTempController extends Controller { new Brackets((qb) => { qb.where( requestBody.keyword != null && requestBody.keyword != "" - ? `CONCAT(profileEmployee.prefix, profileEmployee.firstName," ",profileEmployee.lastName) LIKE :keyword` + ? "profileEmployee.prefix LIKE :keyword" : "1=1", { keyword: `%${requestBody.keyword}%`, }, - ).orWhere( + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.firstName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( + requestBody.keyword != null && requestBody.keyword != "" + ? "profileEmployee.lastName LIKE :keyword" + : "1=1", + { + keyword: `%${requestBody.keyword}%`, + }, + ) + .orWhere( requestBody.keyword != null && requestBody.keyword != "" ? "profileEmployee.citizenId LIKE :keyword" : "1=1", @@ -1780,18 +1797,20 @@ export class ProfileEmployeeTempController extends Controller { qb.where("profileEmployee.id NOT IN (:...ids)", { ids: orgRevision.employeeTempPosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId).length == 0 + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId).length == 0 ? ["zxc"] : orgRevision.employeeTempPosMasters - .filter((x) => x.next_holderId != null) - .map((x) => x.next_holderId), + .filter((x) => x.current_holderId != null) + .map((x) => x.current_holderId), }); }), ) .andWhere("profileEmployee.employeeClass = :employeeClass", { employeeClass: "TEMP" }) .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) + .orderBy("posType.posTypeRank", "ASC") + .addOrderBy("posLevel.posLevelRank", "ASC") .getManyAndCount(); const data = profiles.map((_data) => ({ id: _data.id, From d9799e642fb852901f9693ac24a8e2996dcdc6ce Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Tue, 29 Apr 2025 16:58:20 +0700 Subject: [PATCH 2/3] fix commandCode --- .../ProfileSalaryEmployeeController.ts | 116 ++++++++++++------ 1 file changed, 81 insertions(+), 35 deletions(-) diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index ab172166..9ad2b02c 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -24,7 +24,7 @@ import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; import { Profile } from "../entities/Profile"; -import { In, LessThan, MoreThan } from "typeorm"; +import { In, LessThan, IsNull, MoreThan } from "typeorm"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; import { Command } from "../entities/Command"; @@ -47,7 +47,7 @@ export class ProfileSalaryEmployeeController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profile.id }, + where: { profileEmployeeId: profile.id, commandCode: In(["5", "6", "7"]) }, order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -60,7 +60,28 @@ export class ProfileSalaryEmployeeController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profile.id }, + where: [ + { + profileEmployeeId: profile.id, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + { profileEmployeeId: profile.id, commandCode: IsNull() }, + ], order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -87,7 +108,28 @@ export class ProfileSalaryEmployeeController extends Controller { if (_workflow == false) await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileId); const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profileId }, + where: [ + { + profileEmployeeId: profileId, + commandCode: In([ + "0", + "9", + "1", + "2", + "3", + "4", + "8", + "10", + "11", + "12", + "13", + "14", + "15", + "16", + ]), + }, + { profileEmployeeId: profileId, commandCode: IsNull() }, + ], order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -131,7 +173,9 @@ export class ProfileSalaryEmployeeController extends Controller { [] as { name: string; days: number; year: number; month: number; day: number }[], ); - const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [profile.id]); + const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [ + profile.id, + ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = _posLevel.length > 1 @@ -204,7 +248,9 @@ export class ProfileSalaryEmployeeController extends Controller { [] as { name: string; days: number; year: number; month: number; day: number }[], ); - const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [profileId]); + const posLevel = await AppDataSource.query("CALL GetProfileEmployeeSalaryLevel(?)", [ + profileId, + ]); const _posLevel = posLevel.length > 0 ? posLevel[0] : []; const mapPosLevel = _posLevel.length > 1 @@ -248,7 +294,7 @@ export class ProfileSalaryEmployeeController extends Controller { let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE"); if (_workflow == false) await new permission().PermissionGet(req, "SYS_WAGE"); const record = await this.salaryRepo.find({ - where: { profileEmployeeId: profileId }, + where: { profileEmployeeId: profileId, commandCode: In(["5", "6", "7"]) }, order: { order: "ASC" }, }); return new HttpSuccess(record); @@ -318,9 +364,9 @@ export class ProfileSalaryEmployeeController extends Controller { lastUpdatedAt: new Date(), }; if (body.commandCode && !body.commandName) { - if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" - else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" - else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" + if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"; + else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"; } Object.assign(data, { ...body, ...meta }); const history = new ProfileSalaryHistory(); @@ -359,10 +405,10 @@ export class ProfileSalaryEmployeeController extends Controller { order: { order: "DESC" }, }); const before = null; - let _posNumCodeSit: string = "" - let _posNumCodeSitAbb: string = "" + let _posNumCodeSit: string = ""; + let _posNumCodeSitAbb: string = ""; const _command = await this.commandRepository.findOne({ - where: { id: body.commandId ?? "" } + where: { id: body.commandId ?? "" }, }); if (_command) { if (_command?.isBangkok?.toLocaleUpperCase() == "OFFICE") { @@ -371,35 +417,35 @@ export class ProfileSalaryEmployeeController extends Controller { isDeputy: true, orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } + orgRevisionIsDraft: false, + }, }, - relations: ["orgRevision"] - }) + relations: ["orgRevision"], + }); _posNumCodeSit = orgRootDeputy ? orgRootDeputy?.orgRootName : "สำนักปลัดกรุงเทพมหานคร"; _posNumCodeSitAbb = orgRootDeputy ? orgRootDeputy?.orgRootShortName : "สนป."; - } - else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { - _posNumCodeSit = "กรุงเทพมหานคร" - _posNumCodeSitAbb = "กทม." - } - else { + } else if (_command?.isBangkok?.toLocaleUpperCase() == "BANGKOK") { + _posNumCodeSit = "กรุงเทพมหานคร"; + _posNumCodeSitAbb = "กทม."; + } else { let _profileAdmin = await this.profileGovementRepo.findOne({ - where: { + where: { keycloak: _command?.createdUserId.toString(), current_holders: { orgRevision: { orgRevisionIsCurrent: true, - orgRevisionIsDraft: false - } - } + orgRevisionIsDraft: false, + }, + }, }, - relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"] + relations: ["current_holders", "current_holders.orgRevision", "current_holders.orgRoot"], }); - _posNumCodeSit = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? "" - _posNumCodeSitAbb = _profileAdmin?.current_holders - .find(x => x.orgRoot.orgRootShortName)?.orgRoot.orgRootShortName ?? "" + _posNumCodeSit = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootName)?.orgRoot.orgRootName ?? + ""; + _posNumCodeSitAbb = + _profileAdmin?.current_holders.find((x) => x.orgRoot.orgRootShortName)?.orgRoot + .orgRootShortName ?? ""; } } const data = new ProfileSalary(); @@ -451,9 +497,9 @@ export class ProfileSalaryEmployeeController extends Controller { const before = structuredClone(record); const history = new ProfileSalaryHistory(); if (body.commandCode && !body.commandName) { - if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ" - else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ" - else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ" + if (body.commandCode == "7") body.commandName = "เงินพิเศษอื่น ๆ"; + else if (body.commandCode == "6") body.commandName = "เลื่อนเงินเดือนกรณีอื่น ๆ"; + else if (body.commandCode == "5") body.commandName = "เลื่อนเงินเดือนตามปกติ"; } Object.assign(record, body); Object.assign(history, { ...record, id: undefined }); From f790fa72cba0e75a984a596c509e8288715c094c Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 29 Apr 2025 17:15:35 +0700 Subject: [PATCH 3/3] =?UTF-8?q?[Bug=20=E0=B8=AD=E0=B8=B1=E0=B8=95=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B8=81=E0=B8=B3=E0=B8=A5=E0=B8=B1=E0=B8=87=E0=B8=A5?= =?UTF-8?q?=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87]=20?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1=E0=B8=95=E0=B8=B3?= =?UTF-8?q?=E0=B9=81=E0=B8=AB=E0=B8=99=E0=B9=88=E0=B8=87=20#117?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/EmployeePositionController.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/controllers/EmployeePositionController.ts b/src/controllers/EmployeePositionController.ts index 4b6ef89f..861a9247 100644 --- a/src/controllers/EmployeePositionController.ts +++ b/src/controllers/EmployeePositionController.ts @@ -572,7 +572,7 @@ export class EmployeePositionController extends Controller { const chk_SName0 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgRoot: { orgRootShortName: SName }, + orgRoot: { orgRootShortName: SName, id: requestBody.orgRootId ?? "" }, orgChild1Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -588,7 +588,7 @@ export class EmployeePositionController extends Controller { const chk_SName1 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild1: { orgChild1ShortName: SName }, + orgChild1: { orgChild1ShortName: SName, id: requestBody.orgChild1Id ?? "" }, orgChild2Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -604,7 +604,7 @@ export class EmployeePositionController extends Controller { const chk_SName2 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild2: { orgChild2ShortName: SName }, + orgChild2: { orgChild2ShortName: SName, id: requestBody.orgChild2Id ?? "" }, orgChild3Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -620,7 +620,7 @@ export class EmployeePositionController extends Controller { const chk_SName3 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild3: { orgChild3ShortName: SName }, + orgChild3: { orgChild3ShortName: SName, id: requestBody.orgChild3Id ?? "" }, orgChild4Id: IsNull(), posMasterNo: requestBody.posMasterNo, }, @@ -636,7 +636,7 @@ export class EmployeePositionController extends Controller { const chk_SName4 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild4: { orgChild4ShortName: SName }, + orgChild4: { orgChild4ShortName: SName, id: requestBody.orgChild4Id ?? "" }, posMasterNo: requestBody.posMasterNo, }, relations: ["orgChild4"], @@ -780,7 +780,7 @@ export class EmployeePositionController extends Controller { const chk_SName0 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgRoot: { orgRootShortName: SName }, + orgRoot: { orgRootShortName: SName, id: requestBody.orgRootId ?? "" }, orgChild1Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -797,7 +797,7 @@ export class EmployeePositionController extends Controller { const chk_SName1 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild1: { orgChild1ShortName: SName }, + orgChild1: { orgChild1ShortName: SName, id: requestBody.orgChild1Id ?? "" }, orgChild2Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -814,7 +814,7 @@ export class EmployeePositionController extends Controller { const chk_SName2 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild2: { orgChild2ShortName: SName }, + orgChild2: { orgChild2ShortName: SName, id: requestBody.orgChild2Id ?? "" }, orgChild3Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -831,7 +831,7 @@ export class EmployeePositionController extends Controller { const chk_SName3 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild3: { orgChild3ShortName: SName }, + orgChild3: { orgChild3ShortName: SName, id: requestBody.orgChild3Id ?? "" }, orgChild4Id: IsNull(), posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), @@ -848,7 +848,7 @@ export class EmployeePositionController extends Controller { const chk_SName4 = await this.employeePosMasterRepository.findOne({ where: { orgRevisionId: posMaster.orgRevisionId, - orgChild4: { orgChild4ShortName: SName }, + orgChild4: { orgChild4ShortName: SName, id: requestBody.orgChild4Id ?? "" }, posMasterNo: requestBody.posMasterNo, id: Not(posMaster.id), },