From 70003ef6091f0233ba2f65dc4b156b8ad311485e Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 20 Feb 2025 09:54:13 +0700 Subject: [PATCH] fix transfer command & registry report --- src/controllers/CommandController.ts | 1 + src/controllers/ReportController.ts | 131 +++++++++++++++++++-------- 2 files changed, 94 insertions(+), 38 deletions(-) diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index a42342f5..7163b44a 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -3140,6 +3140,7 @@ export class CommandController extends Controller { profile.isActive = false; } } + profile.isLeave = item.isLeave; profile.leaveCommandId = item.commandId ?? _null; profile.leaveCommandNo = item.refCommandNo ?? _null; profile.leaveRemark = clearProfile.leaveRemark ?? _null; diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 48e50e24..5bd4eadd 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -312,16 +312,44 @@ export class ReportController extends Controller { ) .orderBy(`registryOfficer.${sortBy}`, sort) .getManyAndCount(); - + const mapData = lists.map(x => ({ + profileId: x.profileId, + citizenId: x.citizenId, + prefix: x.prefix, + firstName: x.firstName, + lastName: x.lastName, + isProbation: x.isProbation, + isLeave: x.isLeave, + isRetirement: x.isRetirement, + leaveType: x.leaveType, + posMasterNo: x.posMasterNo, + orgRootId: x.orgRootId, + orgChild1Id: x.orgChild1Id, + orgChild2Id: x.orgChild2Id, + orgChild3Id: x.orgChild3Id, + orgChild4Id: x.orgChild4Id, + orgRootName: x.orgRootName, + orgChild1Name: x.orgChild1Name, + orgChild2Name: x.orgChild2Name, + orgChild3Name: x.orgChild3Name, + orgChild4Name: x.orgChild4Name, + org: x.org, + searchShortName: x.searchShortName, + posExecutiveName: x.posExecutiveName, + position: x.position, + posTypeName: x.posTypeName, + posLevelName: x.posLevelName, + gender: x.gender, + relationship: x.relationship, + dateAppoint: x.dateAppoint, + birthdate: x.birthdate, + degree: x.degree, + age: x.age, + currentPosition: null, + lengthPosition: null, + })); return new HttpSuccess({ - // template: "registry-officer", - // reportName: "xlsx-report", - // data: { - // date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), - // data: lists, - // total: total - // }, - data: lists, + data: mapData, total: total }); } @@ -477,49 +505,49 @@ export class ReportController extends Controller { let nodeCondition = "1=1"; if (node === 0 && nodeId) { - nodeCondition = "registryOfficer.orgRootId = :nodeId"; + nodeCondition = "registryEmployee.orgRootId = :nodeId"; } else if (node === 1 && nodeId) { - nodeCondition = "registryOfficer.orgChild1Id = :nodeId"; + nodeCondition = "registryEmployee.orgChild1Id = :nodeId"; } else if (node === 2 && nodeId) { - nodeCondition = "registryOfficer.orgChild2Id = :nodeId"; + nodeCondition = "registryEmployee.orgChild2Id = :nodeId"; } else if (node === 3 && nodeId) { - nodeCondition = "registryOfficer.orgChild3Id = :nodeId"; + nodeCondition = "registryEmployee.orgChild3Id = :nodeId"; } else if (node === 4 && nodeId) { - nodeCondition = "registryOfficer.orgChild4Id = :nodeId"; + nodeCondition = "registryEmployee.orgChild4Id = :nodeId"; } let dateAppointCondition = "1=1"; if (startDateAppoint && endDateAppoint) { - dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint AND DATE(registryOfficer.dateAppoint) <= :endDateAppoint"; + dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint AND DATE(registryEmployee.dateAppoint) <= :endDateAppoint"; } else if (startDateAppoint) { - dateAppointCondition = "DATE(registryOfficer.dateAppoint) >= :startDateAppoint"; + dateAppointCondition = "DATE(registryEmployee.dateAppoint) >= :startDateAppoint"; } else if (endDateAppoint) { - dateAppointCondition = "DATE(registryOfficer.dateAppoint) <= :endDateAppoint"; + dateAppointCondition = "DATE(registryEmployee.dateAppoint) <= :endDateAppoint"; } - const IsLeavecondition = ["registryOfficer.isLeave = :isLeave"]; + const IsLeavecondition = ["registryEmployee.isLeave = :isLeave"]; const parameters: any = { isLeave: isRetire }; if (retireType && retireType.trim() !== "") { - IsLeavecondition.push("registryOfficer.leaveType = :retireType"); + IsLeavecondition.push("registryEmployee.leaveType = :retireType"); parameters.retireType = retireType; } const [lists, total] = await AppDataSource.getRepository(viewRegistryEmployee) - .createQueryBuilder("registryOfficer") + .createQueryBuilder("registryEmployee") .where(nodeCondition, { nodeId: nodeId }) - .andWhere("registryOfficer.age BETWEEN :ageMin AND :ageMax", { + .andWhere("registryEmployee.age BETWEEN :ageMin AND :ageMax", { ageMin, ageMax }) .andWhere(dateAppointCondition, { startDateAppoint: startDateAppoint?.toISOString().split("T")[0], endDateAppoint: endDateAppoint?.toISOString().split("T")[0] }) - .andWhere("registryOfficer.isProbation = :isProbation", { + .andWhere("registryEmployee.isProbation = :isProbation", { isProbation: isProbation, }) .andWhere(IsLeavecondition.join(" AND "), parameters) @@ -527,7 +555,7 @@ export class ReportController extends Controller { new Brackets((qb) => { qb.orWhere( posTypeName != null && posTypeName != "" - ? "registryOfficer.posTypeName LIKE :posTypeName" + ? "registryEmployee.posTypeName LIKE :posTypeName" : "1=1", { posTypeName: `%${posTypeName}%`, @@ -535,7 +563,7 @@ export class ReportController extends Controller { ) qb.orWhere( posLevelName != null && posLevelName != "" - ? "registryOfficer.posLevelName LIKE :posLevelName" + ? "registryEmployee.posLevelName LIKE :posLevelName" : "1=1", { posLevelName: `%${posLevelName}%`, @@ -543,7 +571,7 @@ export class ReportController extends Controller { ) qb.orWhere( position != null && position != "" - ? "registryOfficer.position LIKE :position" + ? "registryEmployee.position LIKE :position" : "1=1", { position: `%${position}%`, @@ -551,7 +579,7 @@ export class ReportController extends Controller { ) qb.orWhere( gender != null && gender != "" - ? "registryOfficer.gender LIKE :gender" + ? "registryEmployee.gender LIKE :gender" : "1=1", { gender: `%${gender}%`, @@ -559,7 +587,7 @@ export class ReportController extends Controller { ) qb.orWhere( relationship != null && relationship != "" - ? "registryOfficer.relationship LIKE :relationship" + ? "registryEmployee.relationship LIKE :relationship" : "1=1", { relationship: `%${relationship}%`, @@ -567,7 +595,7 @@ export class ReportController extends Controller { ) qb.orWhere( degree != null && degree != "" - ? "registryOfficer.degree LIKE :degree" + ? "registryEmployee.degree LIKE :degree" : "1=1", { degree: `%${degree}%`, @@ -575,18 +603,45 @@ export class ReportController extends Controller { ) }), ) - .orderBy(`registryOfficer.${sortBy}`, sort) + .orderBy(`registryEmployee.${sortBy}`, sort) .getManyAndCount(); - + const mapData = lists.map(x => ({ + profileId: x.profileEmployeeId, + citizenId: x.citizenId, + prefix: x.prefix, + firstName: x.firstName, + lastName: x.lastName, + isProbation: x.isProbation, + isLeave: x.isLeave, + isRetirement: x.isRetirement, + leaveType: x.leaveType, + posMasterNo: x.posMasterNo, + orgRootId: x.orgRootId, + orgChild1Id: x.orgChild1Id, + orgChild2Id: x.orgChild2Id, + orgChild3Id: x.orgChild3Id, + orgChild4Id: x.orgChild4Id, + orgRootName: x.orgRootName, + orgChild1Name: x.orgChild1Name, + orgChild2Name: x.orgChild2Name, + orgChild3Name: x.orgChild3Name, + orgChild4Name: x.orgChild4Name, + org: x.org, + searchShortName: x.searchShortName, + position: x.position, + posTypeName: x.posTypeName, + posLevelName: x.posLevelName, + gender: x.gender, + relationship: x.relationship, + dateAppoint: x.dateAppoint, + birthdate: x.birthdate, + degree: x.degree, + age: x.age, + currentPosition: null, + lengthPosition: null, + })); return new HttpSuccess({ - // template: "registry-officer", - // reportName: "xlsx-report", - // data: { - // date: Extension.ToThaiNumber(Extension.ToThaiShortDate(new Date())), - // data: lists, - // total: total - // }, - data: lists, + data: mapData, total: total }); }