From b06247be0c51efcc5333813be000fdee7066496c Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 7 Mar 2025 17:11:22 +0700 Subject: [PATCH] test ws --- src/controllers/ReportController.ts | 1905 ++++++++++++++------------- 1 file changed, 973 insertions(+), 932 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 2c6b54b3..9e848514 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -32,7 +32,6 @@ import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; import { sendWebSocket } from "../services/webSocket"; -// import { sendWebSocket } from "../services/webSocket"; @Route("api/v1/org/report") @Tags("Report") @@ -1369,7 +1368,7 @@ export class ReportController extends Controller { } } } - + return new HttpSuccess({ template: "report1", reportName: "report1", data: { data } }); } @@ -1388,184 +1387,172 @@ export class ReportController extends Controller { // if (!orgRevision) { // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); // } + (async () => { + const orgRootData = await this.orgRootRepository.find({ + where: { + id: rootId, + // orgRevisionId: orgRevision.id, + }, + order: { orgRootOrder: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgRootData = await this.orgRootRepository.find({ - where: { - id: rootId, - // orgRevisionId: orgRevision.id, - }, - order: { orgRootOrder: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null; + const orgChild1Data = await this.child1Repository.find({ + where: { + orgRootId: In(orgRootIds), + }, + order: { orgChild1Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgRootIds = orgRootData.map((orgRoot) => orgRoot.id) || null; - const orgChild1Data = await this.child1Repository.find({ - where: { - orgRootId: In(orgRootIds), - }, - order: { orgChild1Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; + const orgChild2Data = await this.child2Repository.find({ + where: { + orgChild1: In(orgChild1Ids), + }, + order: { orgChild2Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgChild1Ids = orgChild1Data.map((orgChild1) => orgChild1.id) || null; - const orgChild2Data = await this.child2Repository.find({ - where: { - orgChild1: In(orgChild1Ids), - }, - order: { orgChild2Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; + const orgChild3Data = await this.child3Repository.find({ + where: { + orgChild2: In(orgChild2Ids), + }, + order: { orgChild3Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgChild2Ids = orgChild2Data.map((orgChild2) => orgChild2.id) || null; - const orgChild3Data = await this.child3Repository.find({ - where: { - orgChild2: In(orgChild2Ids), - }, - order: { orgChild3Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; + const orgChild4Data = await this.child4Repository.find({ + where: { + orgChild3: In(orgChild3Ids), + }, + order: { orgChild4Order: "ASC" }, + relations: [ + "posMasters", + "posMasters.orgRoot", + "posMasters.orgChild1", + "posMasters.orgChild2", + "posMasters.orgChild3", + "posMasters.orgChild4", + "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.profileSalary", + "posMasters.next_holder.profileEducations", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", + "posMasters.next_holder.current_holders.orgRoot", + "posMasters.next_holder.current_holders.orgChild1", + "posMasters.next_holder.current_holders.orgChild2", + "posMasters.next_holder.current_holders.orgChild3", + "posMasters.next_holder.current_holders.orgChild4", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - const orgChild3Ids = orgChild3Data.map((orgChild3) => orgChild3.id) || null; - const orgChild4Data = await this.child4Repository.find({ - where: { - orgChild3: In(orgChild3Ids), - }, - order: { orgChild4Order: "ASC" }, - relations: [ - "posMasters", - "posMasters.orgRoot", - "posMasters.orgChild1", - "posMasters.orgChild2", - "posMasters.orgChild3", - "posMasters.orgChild4", - "posMasters.next_holder", - "posMasters.next_holder.posLevel", - "posMasters.next_holder.posType", - "posMasters.next_holder.profileSalary", - "posMasters.next_holder.profileEducations", - "posMasters.next_holder.current_holders", - "posMasters.next_holder.current_holders.positions", - "posMasters.next_holder.current_holders.orgRoot", - "posMasters.next_holder.current_holders.orgChild1", - "posMasters.next_holder.current_holders.orgChild2", - "posMasters.next_holder.current_holders.orgChild3", - "posMasters.next_holder.current_holders.orgChild4", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); - - let orgRevisionActive: any = await this.orgRevisionRepository.findOne({ - where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, - relations: [ - "posMasters", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); - if (orgRevisionActive == null) { - const _orgRevisionActive = await this.orgRevisionRepository.find({ - order: { createdAt: "DESC" }, - skip: 1, + let orgRevisionActive: any = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false }, relations: [ "posMasters", "posMasters.positions", @@ -1574,392 +1561,30 @@ export class ReportController extends Controller { "posMasters.positions.posExecutive", ], }); - if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; - } + if (orgRevisionActive == null) { + const _orgRevisionActive = await this.orgRevisionRepository.find({ + order: { createdAt: "DESC" }, + skip: 1, + relations: [ + "posMasters", + "posMasters.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); + if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; + } - let data = new Array(); - let _node: any; - let no = 1; - for (let orgRoot of orgRootData) { - await Promise.all( - orgRoot.posMasters - .sort((a, b) => a.posMasterOrder - b.posMasterOrder) - .map(async (posMaster) => { - if (posMaster.orgChild1Id == null) { - const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; - const posType = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posType != null) - .map((x) => x.posType.posTypeName), - ), - ]; - const posLevel = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posLevel != null) - .map((x) => x.posLevel.posLevelName), - ), - ]; - const posExecutive = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posExecutive != null) - .map((x) => x.posExecutive.posExecutiveName), - ), - ]; - let positionMasterProfileOld: any = null; - if (posMaster.next_holder != null) { - positionMasterProfileOld = posMaster.next_holder.current_holders.find( - (x) => x.orgRevisionId == orgRevisionActive.id, - ); - } - - let positionMasterOld: any = null; - let profilePositionName: any = []; - let profilePosType: any = []; - let profilePosLevel: any = []; - let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { - positionMasterOld = orgRevisionActive.posMasters.find( - (x: any) => - x.orgRevisionId == orgRevisionActive.id && - x.ancestorDNA == posMaster.ancestorDNA, - ); - profilePositionName = [ - ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), - ]; - profilePosType = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posType != null) - .map((x: any) => x.posType.posTypeName), - ), - ]; - profilePosLevel = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posLevel != null) - .map((x: any) => x.posLevel.posLevelName), - ), - ]; - profilePosExecutive = [ - ...new Set( - positionMasterOld.positions - .filter((x: any) => x.posExecutive != null) - .map((x: any) => x.posExecutive.posExecutiveName), - ), - ]; - } - let education: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileEducations != null && - posMaster.next_holder.profileEducations.length > 0 - ) { - let _education: any = posMaster.next_holder.profileEducations.sort( - (a, b) => - (b.finishDate == null ? 0 : b.finishDate.getTime()) - - (a.finishDate == null ? 0 : a.finishDate.getTime()), - ); - if (_education.length > 0) { - education = _education[0]; - } - } - let salary: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileSalary != null && - posMaster.next_holder.profileSalary.length > 0 - ) { - let _salary: any = posMaster.next_holder.profileSalary.sort( - (a, b) => - (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - - (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), - ); - if (_salary.length > 0) { - salary = _salary[0]; - } - } - - let node = { - posMasterOrder: posMaster.posMasterOrder, // - isSit: posMaster.isSit, // - orgTreeName: orgRoot.orgRootName, - orgTreeShortName: orgRoot.orgRootShortName, - posMasterNo: posMaster.posMasterNo, - positionName: - posMaster.next_holder == null - ? positionName.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.positionName - : posMaster.next_holder.position, - posType: - posMaster.next_holder == null - ? posType.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posType - ?.posTypeName - : posMaster.next_holder.posType == null - ? "-" - : posMaster.next_holder.posType.posTypeName, - posLevel: - posMaster.next_holder == null - ? posLevel.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posLevel - ?.posLevelName - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - posExecutive: - posMaster.next_holder == null - ? posExecutive.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posExecutive?.posExecutiveName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.positions.find( - (x: any) => x.positionIsSelected == true, - )?.posExecutive?.posExecutiveName, - - profileOrgName: - posMaster.next_holder == null - ? orgRoot.orgRootName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4Name - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3Name - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2Name - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1Name - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootName - : "-", - profileOrgShortName: - posMaster.next_holder == null - ? orgRoot.orgRootShortName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4ShortName - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3ShortName - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2ShortName - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1ShortName - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootShortName - : "-", - profileFullname: - posMaster.next_holder == null - ? "- ว่าง -" - : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, - profilePosMasterNo: - posMaster.next_holder == null - ? positionMasterOld == null - ? "-" - : positionMasterOld.posMasterNo - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.posMasterNo, - profilePositionName: - posMaster.next_holder == null - ? positionMasterOld == null - ? positionName.join(" หรือ ") - : profilePositionName.join(" หรือ ") - : posMaster.next_holder.position, - profilePosType: - posMaster.next_holder == null - ? positionMasterOld == null - ? posType.join(" หรือ ") - : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null - ? "-" - : posMaster.next_holder.posType.posTypeName, - profilePosLevel: - posMaster.next_holder == null - ? positionMasterOld == null - ? posLevel.join(" หรือ ") - : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - profilePosExecutive: - posMaster.next_holder == null - ? positionMasterOld == null - ? posExecutive.join(" หรือ ") - : profilePosExecutive.join(" หรือ ") - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.positions.find( - (x: any) => x.positionIsSelected == true, - )?.posExecutive?.posExecutiveName, - education: education == "" ? "" : education.degree, - salary: salary == "" ? "" : salary.amount, - reason: posMaster.reason, - }; - if (_node == null) { - const head = { - posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), - posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber(node.profileOrgShortName.toString()), - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - reason: "", - }; - data.push(head); - const _head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", - reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName || - node.profileOrgShortName != _node.profileOrgShortName || - node.profileOrgName != _node.profileOrgName - ) { - const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName ? "" : node.orgTreeShortName, - profileFullname: - node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, - posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: - node.profileOrgShortName == _node.profileOrgShortName - ? "" - : node.profileOrgShortName, - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - reason: "", - }; - data.push(head); - _node == null; - } - const head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null ? "" : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null ? "" : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber(node.profilePosMasterNo.toString()), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null ? "" : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary ? Extension.ToThaiNumber(node.salary.toLocaleString()) : "", - reason: node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(head); - } - no += 1; - _node = node; - } - }), - ); - _node = null; - - for (let orgChild1 of orgChild1Data.filter( - (orgChild1) => orgChild1.orgRootId === orgRoot.id, - )) { + let data = new Array(); + let _node: any; + let no = 1; + for (let orgRoot of orgRootData) { await Promise.all( - orgChild1.posMasters + orgRoot.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild2Id == null) { + if (posMaster.orgChild1Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -2059,8 +1684,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild1.orgChild1Name, - orgTreeShortName: orgChild1.orgChild1ShortName, + orgTreeName: orgRoot.orgRootName, + orgTreeShortName: orgRoot.orgRootShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -2101,7 +1726,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild1.orgChild1Name + ? orgRoot.orgRootName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2117,7 +1742,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild1.orgChild1ShortName + ? orgRoot.orgRootShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2334,14 +1959,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild2 of orgChild2Data.filter( - (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, + for (let orgChild1 of orgChild1Data.filter( + (orgChild1) => orgChild1.orgRootId === orgRoot.id, )) { await Promise.all( - orgChild2.posMasters + orgChild1.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild3Id == null) { + if (posMaster.orgChild2Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -2441,8 +2066,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild2.orgChild2Name, - orgTreeShortName: orgChild2.orgChild2ShortName, + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -2483,7 +2108,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild2.orgChild2Name + ? orgChild1.orgChild1Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2499,7 +2124,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild2.orgChild2ShortName + ? orgChild1.orgChild1ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2730,14 +2355,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild3 of orgChild3Data.filter( - (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, + for (let orgChild2 of orgChild2Data.filter( + (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, )) { await Promise.all( - orgChild3.posMasters + orgChild2.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild4Id == null) { + if (posMaster.orgChild3Id == null) { const positionName = [ ...new Set(posMaster.positions.map((x) => x.positionName)), ]; @@ -2839,8 +2464,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild3.orgChild3Name, - orgTreeShortName: orgChild3.orgChild3ShortName, + orgTreeName: orgChild2.orgChild2Name, + orgTreeShortName: orgChild2.orgChild2ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -2881,7 +2506,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild3.orgChild3Name + ? orgChild2.orgChild2Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -2897,7 +2522,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild3.orgChild3ShortName + ? orgChild2.orgChild2ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -3133,333 +2758,246 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild4 of orgChild4Data.filter( - (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, + for (let orgChild3 of orgChild3Data.filter( + (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, )) { await Promise.all( - orgChild4.posMasters + orgChild3.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - const positionName = [ - ...new Set(posMaster.positions.map((x) => x.positionName)), - ]; - const posType = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posType != null) - .map((x) => x.posType.posTypeName), - ), - ]; - const posLevel = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posLevel != null) - .map((x) => x.posLevel.posLevelName), - ), - ]; - const posExecutive = [ - ...new Set( - posMaster.positions - .filter((x: any) => x.posExecutive != null) - .map((x) => x.posExecutive.posExecutiveName), - ), - ]; - let positionMasterProfileOld: any = null; - if (posMaster.next_holder != null) { - positionMasterProfileOld = posMaster.next_holder.current_holders.find( - (x) => x.orgRevisionId == orgRevisionActive.id, - ); - } - - let positionMasterOld: any = null; - let profilePositionName: any = []; - let profilePosType: any = []; - let profilePosLevel: any = []; - let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { - positionMasterOld = orgRevisionActive.posMasters.find( - (x: any) => - x.orgRevisionId == orgRevisionActive.id && - x.ancestorDNA == posMaster.ancestorDNA, - ); - profilePositionName = [ - ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), + if (posMaster.orgChild4Id == null) { + const positionName = [ + ...new Set(posMaster.positions.map((x) => x.positionName)), ]; - profilePosType = [ + const posType = [ ...new Set( - positionMasterOld.positions + posMaster.positions .filter((x: any) => x.posType != null) - .map((x: any) => x.posType.posTypeName), + .map((x) => x.posType.posTypeName), ), ]; - profilePosLevel = [ + const posLevel = [ ...new Set( - positionMasterOld.positions + posMaster.positions .filter((x: any) => x.posLevel != null) - .map((x: any) => x.posLevel.posLevelName), + .map((x) => x.posLevel.posLevelName), ), ]; - profilePosExecutive = [ + const posExecutive = [ ...new Set( - positionMasterOld.positions + posMaster.positions .filter((x: any) => x.posExecutive != null) - .map((x: any) => x.posExecutive.posExecutiveName), + .map((x) => x.posExecutive.posExecutiveName), ), ]; - } - let education: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileEducations != null && - posMaster.next_holder.profileEducations.length > 0 - ) { - let _education: any = posMaster.next_holder.profileEducations.sort( - (a, b) => - (b.finishDate == null ? 0 : b.finishDate.getTime()) - - (a.finishDate == null ? 0 : a.finishDate.getTime()), - ); - if (_education.length > 0) { - education = _education[0]; + let positionMasterProfileOld: any = null; + if (posMaster.next_holder != null) { + positionMasterProfileOld = posMaster.next_holder.current_holders.find( + (x) => x.orgRevisionId == orgRevisionActive.id, + ); } - } - let salary: any = ""; - if ( - posMaster.next_holder != null && - posMaster.next_holder.profileSalary != null && - posMaster.next_holder.profileSalary.length > 0 - ) { - let _salary: any = posMaster.next_holder.profileSalary.sort( - (a, b) => - (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - - (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), - ); - if (_salary.length > 0) { - salary = _salary[0]; - } - } - let node = { - posMasterOrder: posMaster.posMasterOrder, // - isSit: posMaster.isSit, // - orgTreeName: orgChild4.orgChild4Name, - orgTreeShortName: orgChild4.orgChild4ShortName, - posMasterNo: posMaster.posMasterNo, - positionName: - posMaster.next_holder == null - ? positionName.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.positionName + let positionMasterOld: any = null; + let profilePositionName: any = []; + let profilePosType: any = []; + let profilePosLevel: any = []; + let profilePosExecutive: any = []; + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { + positionMasterOld = orgRevisionActive.posMasters.find( + (x: any) => + x.orgRevisionId == orgRevisionActive.id && + x.ancestorDNA == posMaster.ancestorDNA, + ); + profilePositionName = [ + ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), + ]; + profilePosType = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posType != null) + .map((x: any) => x.posType.posTypeName), + ), + ]; + profilePosLevel = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posLevel != null) + .map((x: any) => x.posLevel.posLevelName), + ), + ]; + profilePosExecutive = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posExecutive != null) + .map((x: any) => x.posExecutive.posExecutiveName), + ), + ]; + } + let education: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileEducations != null && + posMaster.next_holder.profileEducations.length > 0 + ) { + let _education: any = posMaster.next_holder.profileEducations.sort( + (a, b) => + (b.finishDate == null ? 0 : b.finishDate.getTime()) - + (a.finishDate == null ? 0 : a.finishDate.getTime()), + ); + if (_education.length > 0) { + education = _education[0]; + } + } + let salary: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileSalary != null && + posMaster.next_holder.profileSalary.length > 0 + ) { + let _salary: any = posMaster.next_holder.profileSalary.sort( + (a, b) => + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), + ); + if (_salary.length > 0) { + salary = _salary[0]; + } + } + + let node = { + posMasterOrder: posMaster.posMasterOrder, // + isSit: posMaster.isSit, // + orgTreeName: orgChild3.orgChild3Name, + orgTreeShortName: orgChild3.orgChild3ShortName, + posMasterNo: posMaster.posMasterNo, + positionName: + posMaster.next_holder == null + ? positionName.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.positionName + : posMaster.next_holder.position, + posType: + posMaster.next_holder == null + ? posType.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posType?.posTypeName + : posMaster.next_holder.posType == null + ? "-" + : posMaster.next_holder.posType.posTypeName, + posLevel: + posMaster.next_holder == null + ? posLevel.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posLevel?.posLevelName + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + posExecutive: + posMaster.next_holder == null + ? posExecutive.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posExecutive?.posExecutiveName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posExecutive?.posExecutiveName, + + profileOrgName: + posMaster.next_holder == null + ? orgChild3.orgChild3Name + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4Name + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3Name + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2Name + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1Name + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootName + : "-", + profileOrgShortName: + posMaster.next_holder == null + ? orgChild3.orgChild3ShortName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4ShortName + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3ShortName + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2ShortName + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1ShortName + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootShortName + : "-", + profileFullname: + posMaster.next_holder == null + ? "- ว่าง -" + : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, + profilePosMasterNo: + posMaster.next_holder == null + ? positionMasterOld == null + ? "-" + : positionMasterOld.posMasterNo + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.posMasterNo, + profilePositionName: + posMaster.next_holder == null + ? positionMasterOld == null + ? positionName.join(" หรือ ") + : profilePositionName.join(" หรือ ") : posMaster.next_holder.position, - posType: - posMaster.next_holder == null - ? posType.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posType?.posTypeName + profilePosType: + posMaster.next_holder == null + ? positionMasterOld == null + ? posType.join(" หรือ ") + : profilePosType.join(" หรือ ") : posMaster.next_holder.posType == null ? "-" : posMaster.next_holder.posType.posTypeName, - posLevel: - posMaster.next_holder == null - ? posLevel.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posLevel?.posLevelName + profilePosLevel: + posMaster.next_holder == null + ? positionMasterOld == null + ? posLevel.join(" หรือ ") + : profilePosLevel.join(" หรือ ") : posMaster.next_holder.posLevel == null ? "-" : posMaster.next_holder.posLevel.posLevelName, - posExecutive: - posMaster.next_holder == null - ? posExecutive.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posExecutive?.posExecutiveName + profilePosExecutive: + posMaster.next_holder == null + ? positionMasterOld == null + ? posExecutive.join(" หรือ ") + : profilePosExecutive.join(" หรือ ") : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.positions.find( (x: any) => x.positionIsSelected == true, )?.posExecutive?.posExecutiveName, - - profileOrgName: - posMaster.next_holder == null - ? orgChild4.orgChild4Name - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4Name - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3Name - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2Name - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1Name - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootName - : "-", - profileOrgShortName: - posMaster.next_holder == null - ? orgChild4.orgChild4ShortName - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.orgChild4 != null - ? positionMasterProfileOld.orgChild4.orgChild4ShortName - : positionMasterProfileOld.orgChild3 != null - ? positionMasterProfileOld.orgChild3.orgChild3ShortName - : positionMasterProfileOld.orgChild2 != null - ? positionMasterProfileOld.orgChild2.orgChild2ShortName - : positionMasterProfileOld.orgChild1 != null - ? positionMasterProfileOld.orgChild1.orgChild1ShortName - : positionMasterProfileOld.orgRoot != null - ? positionMasterProfileOld.orgRoot.orgRootShortName - : "-", - profileFullname: - posMaster.next_holder == null - ? "- ว่าง -" - : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, - profilePosMasterNo: - posMaster.next_holder == null - ? positionMasterOld == null - ? "-" - : positionMasterOld.posMasterNo - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.posMasterNo, - profilePositionName: - posMaster.next_holder == null - ? positionMasterOld == null - ? positionName.join(" หรือ ") - : profilePositionName.join(" หรือ ") - : posMaster.next_holder.position, - profilePosType: - posMaster.next_holder == null - ? positionMasterOld == null - ? posType.join(" หรือ ") - : profilePosType.join(" หรือ ") - : posMaster.next_holder.posType == null - ? "-" - : posMaster.next_holder.posType.posTypeName, - profilePosLevel: - posMaster.next_holder == null - ? positionMasterOld == null - ? posLevel.join(" หรือ ") - : profilePosLevel.join(" หรือ ") - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - profilePosExecutive: - posMaster.next_holder == null - ? positionMasterOld == null - ? posExecutive.join(" หรือ ") - : profilePosExecutive.join(" หรือ ") - : positionMasterProfileOld == null - ? "-" - : positionMasterProfileOld.positions.find( - (x: any) => x.positionIsSelected == true, - )?.posExecutive?.posExecutiveName, - education: education == "" ? "" : education.degree, - salary: salary == "" ? "" : salary.amount, - reason: posMaster.reason, - }; - if (_node == null) { - const head = { - posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), - profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), - posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: Extension.ToThaiNumber( - node.profileOrgShortName.toString(), - ), - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - reason: "", + education: education == "" ? "" : education.degree, + salary: salary == "" ? "" : salary.amount, + reason: posMaster.reason, }; - data.push(head); - const _head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null - ? "" - : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null - ? "" - : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber( - node.profilePosMasterNo.toString(), - ), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null - ? "" - : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary - ? Extension.ToThaiNumber(node.salary.toLocaleString()) - : "", - reason: - node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName || - node.profileOrgShortName != _node.profileOrgShortName || - node.profileOrgName != _node.profileOrgName - ) { + if (_node == null) { const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName - ? "" - : node.orgTreeShortName, - profileFullname: - node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, - posExecutive: - node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), + profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), positionName: "", posType: "", posLevel: "", - profilePosMasterNo: - node.profileOrgShortName == _node.profileOrgShortName - ? "" - : node.profileOrgShortName, + profilePosMasterNo: Extension.ToThaiNumber( + node.profileOrgShortName.toString(), + ), profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -3469,80 +3007,583 @@ export class ReportController extends Controller { reason: "", }; data.push(head); - _node == null; + const _head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null + ? "" + : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null + ? "" + : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber( + node.profilePosMasterNo.toString(), + ), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null + ? "" + : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary + ? Extension.ToThaiNumber(node.salary.toLocaleString()) + : "", + reason: + node.reason == null + ? "" + : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName || + node.profileOrgShortName != _node.profileOrgShortName || + node.profileOrgName != _node.profileOrgName + ) { + const head = { + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName + ? "" + : node.orgTreeShortName, + profileFullname: + node.profileOrgName == _node.profileOrgName + ? "" + : node.profileOrgName, + posExecutive: + node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + reason: "", + }; + data.push(head); + _node == null; + } + const head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null + ? "" + : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null + ? "" + : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber( + node.profilePosMasterNo.toString(), + ), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null + ? "" + : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary + ? Extension.ToThaiNumber(node.salary.toLocaleString()) + : "", + reason: + node.reason == null + ? "" + : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(head); } - const head = { - no: Extension.ToThaiNumber(no.toString()), - posMasterNo: - node.posMasterNo == null - ? "" - : Extension.ToThaiNumber(node.posMasterNo.toString()), - profileFullname: - node.profileFullname == null - ? "" - : Extension.ToThaiNumber(node.profileFullname.toString()), - posExecutive: - node.posExecutive == null - ? "" - : Extension.ToThaiNumber(node.posExecutive.toString()), - positionName: - node.positionName == null - ? "" - : Extension.ToThaiNumber(node.positionName.toString()), - posType: - node.posType == null - ? "" - : Extension.ToThaiNumber(node.posType.toString()), - posLevel: - node.posLevel == null - ? "" - : Extension.ToThaiNumber(node.posLevel.toString()), - profilePosMasterNo: Extension.ToThaiNumber( - node.profilePosMasterNo.toString(), - ), - profilePosExecutive: - node.profilePosExecutive == null - ? "" - : Extension.ToThaiNumber(node.profilePosExecutive.toString()), - profilePositionName: - node.profilePositionName == null - ? "" - : Extension.ToThaiNumber(node.profilePositionName.toString()), - profilePosType: - node.profilePosType == null - ? "" - : Extension.ToThaiNumber(node.profilePosType.toString()), - profilePosLevel: - node.profilePosLevel == null - ? "" - : Extension.ToThaiNumber(node.profilePosLevel.toString()), - education: - node.education == null - ? "" - : Extension.ToThaiNumber(node.education.toString()), - salary: node.salary - ? Extension.ToThaiNumber(node.salary.toLocaleString()) - : "", - reason: - node.reason == null ? "" : Extension.ToThaiNumber(node.reason.toString()), - }; - data.push(head); + no += 1; + _node = node; } - no += 1; - _node = node; }), ); _node = null; + + for (let orgChild4 of orgChild4Data.filter( + (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, + )) { + await Promise.all( + orgChild4.posMasters + .sort((a, b) => a.posMasterOrder - b.posMasterOrder) + .map(async (posMaster) => { + const positionName = [ + ...new Set(posMaster.positions.map((x) => x.positionName)), + ]; + const posType = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posType != null) + .map((x) => x.posType.posTypeName), + ), + ]; + const posLevel = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posLevel != null) + .map((x) => x.posLevel.posLevelName), + ), + ]; + const posExecutive = [ + ...new Set( + posMaster.positions + .filter((x: any) => x.posExecutive != null) + .map((x) => x.posExecutive.posExecutiveName), + ), + ]; + let positionMasterProfileOld: any = null; + if (posMaster.next_holder != null) { + positionMasterProfileOld = posMaster.next_holder.current_holders.find( + (x) => x.orgRevisionId == orgRevisionActive.id, + ); + } + + let positionMasterOld: any = null; + let profilePositionName: any = []; + let profilePosType: any = []; + let profilePosLevel: any = []; + let profilePosExecutive: any = []; + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { + positionMasterOld = orgRevisionActive.posMasters.find( + (x: any) => + x.orgRevisionId == orgRevisionActive.id && + x.ancestorDNA == posMaster.ancestorDNA, + ); + profilePositionName = [ + ...new Set(positionMasterOld.positions.map((x: any) => x.positionName)), + ]; + profilePosType = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posType != null) + .map((x: any) => x.posType.posTypeName), + ), + ]; + profilePosLevel = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posLevel != null) + .map((x: any) => x.posLevel.posLevelName), + ), + ]; + profilePosExecutive = [ + ...new Set( + positionMasterOld.positions + .filter((x: any) => x.posExecutive != null) + .map((x: any) => x.posExecutive.posExecutiveName), + ), + ]; + } + let education: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileEducations != null && + posMaster.next_holder.profileEducations.length > 0 + ) { + let _education: any = posMaster.next_holder.profileEducations.sort( + (a, b) => + (b.finishDate == null ? 0 : b.finishDate.getTime()) - + (a.finishDate == null ? 0 : a.finishDate.getTime()), + ); + if (_education.length > 0) { + education = _education[0]; + } + } + let salary: any = ""; + if ( + posMaster.next_holder != null && + posMaster.next_holder.profileSalary != null && + posMaster.next_holder.profileSalary.length > 0 + ) { + let _salary: any = posMaster.next_holder.profileSalary.sort( + (a, b) => + (b.commandDateAffect == null ? 0 : b.commandDateAffect.getTime()) - + (a.commandDateAffect == null ? 0 : a.commandDateAffect.getTime()), + ); + if (_salary.length > 0) { + salary = _salary[0]; + } + } + + let node = { + posMasterOrder: posMaster.posMasterOrder, // + isSit: posMaster.isSit, // + orgTreeName: orgChild4.orgChild4Name, + orgTreeShortName: orgChild4.orgChild4ShortName, + posMasterNo: posMaster.posMasterNo, + positionName: + posMaster.next_holder == null + ? positionName.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.positionName + : posMaster.next_holder.position, + posType: + posMaster.next_holder == null + ? posType.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posType?.posTypeName + : posMaster.next_holder.posType == null + ? "-" + : posMaster.next_holder.posType.posTypeName, + posLevel: + posMaster.next_holder == null + ? posLevel.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posLevel?.posLevelName + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + posExecutive: + posMaster.next_holder == null + ? posExecutive.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.posExecutive?.posExecutiveName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posExecutive?.posExecutiveName, + + profileOrgName: + posMaster.next_holder == null + ? orgChild4.orgChild4Name + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4Name + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3Name + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2Name + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1Name + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootName + : "-", + profileOrgShortName: + posMaster.next_holder == null + ? orgChild4.orgChild4ShortName + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.orgChild4 != null + ? positionMasterProfileOld.orgChild4.orgChild4ShortName + : positionMasterProfileOld.orgChild3 != null + ? positionMasterProfileOld.orgChild3.orgChild3ShortName + : positionMasterProfileOld.orgChild2 != null + ? positionMasterProfileOld.orgChild2.orgChild2ShortName + : positionMasterProfileOld.orgChild1 != null + ? positionMasterProfileOld.orgChild1.orgChild1ShortName + : positionMasterProfileOld.orgRoot != null + ? positionMasterProfileOld.orgRoot.orgRootShortName + : "-", + profileFullname: + posMaster.next_holder == null + ? "- ว่าง -" + : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, + profilePosMasterNo: + posMaster.next_holder == null + ? positionMasterOld == null + ? "-" + : positionMasterOld.posMasterNo + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.posMasterNo, + profilePositionName: + posMaster.next_holder == null + ? positionMasterOld == null + ? positionName.join(" หรือ ") + : profilePositionName.join(" หรือ ") + : posMaster.next_holder.position, + profilePosType: + posMaster.next_holder == null + ? positionMasterOld == null + ? posType.join(" หรือ ") + : profilePosType.join(" หรือ ") + : posMaster.next_holder.posType == null + ? "-" + : posMaster.next_holder.posType.posTypeName, + profilePosLevel: + posMaster.next_holder == null + ? positionMasterOld == null + ? posLevel.join(" หรือ ") + : profilePosLevel.join(" หรือ ") + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + profilePosExecutive: + posMaster.next_holder == null + ? positionMasterOld == null + ? posExecutive.join(" หรือ ") + : profilePosExecutive.join(" หรือ ") + : positionMasterProfileOld == null + ? "-" + : positionMasterProfileOld.positions.find( + (x: any) => x.positionIsSelected == true, + )?.posExecutive?.posExecutiveName, + education: education == "" ? "" : education.degree, + salary: salary == "" ? "" : salary.amount, + reason: posMaster.reason, + }; + if (_node == null) { + const head = { + posMasterNo: Extension.ToThaiNumber(node.orgTreeShortName.toString()), + profileFullname: Extension.ToThaiNumber(node.profileOrgName.toString()), + posExecutive: Extension.ToThaiNumber(node.orgTreeName.toString()), + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: Extension.ToThaiNumber( + node.profileOrgShortName.toString(), + ), + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + reason: "", + }; + data.push(head); + const _head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null + ? "" + : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null + ? "" + : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber( + node.profilePosMasterNo.toString(), + ), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null + ? "" + : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary + ? Extension.ToThaiNumber(node.salary.toLocaleString()) + : "", + reason: + node.reason == null + ? "" + : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName || + node.profileOrgShortName != _node.profileOrgShortName || + node.profileOrgName != _node.profileOrgName + ) { + const head = { + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName + ? "" + : node.orgTreeShortName, + profileFullname: + node.profileOrgName == _node.profileOrgName + ? "" + : node.profileOrgName, + posExecutive: + node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + reason: "", + }; + data.push(head); + _node == null; + } + const head = { + no: Extension.ToThaiNumber(no.toString()), + posMasterNo: + node.posMasterNo == null + ? "" + : Extension.ToThaiNumber(node.posMasterNo.toString()), + profileFullname: + node.profileFullname == null + ? "" + : Extension.ToThaiNumber(node.profileFullname.toString()), + posExecutive: + node.posExecutive == null + ? "" + : Extension.ToThaiNumber(node.posExecutive.toString()), + positionName: + node.positionName == null + ? "" + : Extension.ToThaiNumber(node.positionName.toString()), + posType: + node.posType == null + ? "" + : Extension.ToThaiNumber(node.posType.toString()), + posLevel: + node.posLevel == null + ? "" + : Extension.ToThaiNumber(node.posLevel.toString()), + profilePosMasterNo: Extension.ToThaiNumber( + node.profilePosMasterNo.toString(), + ), + profilePosExecutive: + node.profilePosExecutive == null + ? "" + : Extension.ToThaiNumber(node.profilePosExecutive.toString()), + profilePositionName: + node.profilePositionName == null + ? "" + : Extension.ToThaiNumber(node.profilePositionName.toString()), + profilePosType: + node.profilePosType == null + ? "" + : Extension.ToThaiNumber(node.profilePosType.toString()), + profilePosLevel: + node.profilePosLevel == null + ? "" + : Extension.ToThaiNumber(node.profilePosLevel.toString()), + education: + node.education == null + ? "" + : Extension.ToThaiNumber(node.education.toString()), + salary: node.salary + ? Extension.ToThaiNumber(node.salary.toLocaleString()) + : "", + reason: + node.reason == null + ? "" + : Extension.ToThaiNumber(node.reason.toString()), + }; + data.push(head); + } + no += 1; + _node = node; + }), + ); + _node = null; + } } } } } - } - const metaData = { template: "report2", reportName: "report2", data: { data } }; - sendWebSocket(metaData) - - return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + const metaData = { template: "report2", reportName: "report2", data: { data } }; + sendWebSocket(metaData); + })(); + + // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /**