diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 362be804..38cf4a99 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -216,195 +216,7 @@ export class ReportController extends Controller { orgRoot.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.map((x) => x.posType.posTypeName))]; - const posLevel = [ - ...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)), - ]; - const posExecutive = [ - ...new Set(posMaster.positions.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) { - 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.map((x: any) => x.posType.posTypeName)), - ]; - profilePosLevel = [ - ...new Set(positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName)), - ]; - profilePosExecutive = [ - ...new Set( - positionMasterOld.positions.map((x: any) => x.posExecutive.posExecutiveName), - ), - ]; - } - - 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.isSit = true))?.positionName - : posMaster.next_holder.position, - posType: - posMaster.next_holder == null - ? posType.join(" หรือ ") - : posMaster.isSit == false - ? posMaster.positions.find((x: any) => (x.isSit = 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.isSit = 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.isSit = true))?.posExecutive - ?.posExecutiveName - : positionMasterProfileOld == null - ? "" - : positionMasterProfileOld.positions.find((x: any) => (x.isSit = 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, - }; - if (_node != null) { - if (node.orgTreeName == _node.orgTreeName) node.orgTreeName = ""; - if (node.orgTreeShortName == _node.orgTreeShortName) node.orgTreeShortName = ""; - if (node.profileOrgName == _node.profileOrgName) node.profileOrgName = ""; - if (node.profileOrgShortName == _node.profileOrgShortName) - node.profileOrgShortName = ""; - if (node.positionName == _node.positionName) node.positionName = ""; - if (node.posType == _node.posType) node.posType = ""; - if (node.posLevel == _node.posLevel) node.posLevel = ""; - if (node.posExecutive == _node.posExecutive) node.posExecutive = ""; - if (node.profilePositionName == _node.profilePositionName) - node.profilePositionName = ""; - if (node.profilePosType == _node.profilePosType) node.profilePosType = ""; - if (node.profilePosLevel == _node.profilePosLevel) node.profilePosLevel = ""; - if (node.profilePosExecutive == _node.profilePosExecutive) - node.profilePosExecutive = ""; - } - _node = node; - data.push(node); - }), - ); - _node = null; - - for (let orgChild1 of orgChild1Data.filter( - (orgChild1) => orgChild1.orgRootId === orgRoot.id, - )) { - await Promise.all( - orgChild1.posMasters - .sort((a, b) => a.posMasterOrder - b.posMasterOrder) - .map(async (posMaster) => { + if (posMaster.orgChild1 == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [...new Set(posMaster.positions.map((x) => x.posType.posTypeName))]; const posLevel = [ @@ -452,8 +264,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 @@ -492,7 +304,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild1.orgChild1Name + ? orgRoot.orgRootName : positionMasterProfileOld == null ? "" : positionMasterProfileOld.orgChild4 != null @@ -508,7 +320,7 @@ export class ReportController extends Controller { : "", profileOrgShortName: posMaster.next_holder == null - ? orgChild1.orgChild1ShortName + ? orgRoot.orgRootShortName : positionMasterProfileOld == null ? "" : positionMasterProfileOld.orgChild4 != null @@ -567,25 +379,364 @@ export class ReportController extends Controller { (x: any) => (x.positionIsSelected = true), )?.posExecutive?.posExecutiveName, }; - if (_node != null) { - if (node.orgTreeName == _node.orgTreeName) node.orgTreeName = ""; - if (node.orgTreeShortName == _node.orgTreeShortName) node.orgTreeShortName = ""; - if (node.profileOrgName == _node.profileOrgName) node.profileOrgName = ""; - if (node.profileOrgShortName == _node.profileOrgShortName) - node.profileOrgShortName = ""; - if (node.positionName == _node.positionName) node.positionName = ""; - if (node.posType == _node.posType) node.posType = ""; - if (node.posLevel == _node.posLevel) node.posLevel = ""; - if (node.posExecutive == _node.posExecutive) node.posExecutive = ""; - if (node.profilePositionName == _node.profilePositionName) - node.profilePositionName = ""; - if (node.profilePosType == _node.profilePosType) node.profilePosType = ""; - if (node.profilePosLevel == _node.profilePosLevel) node.profilePosLevel = ""; - if (node.profilePosExecutive == _node.profilePosExecutive) - node.profilePosExecutive = ""; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + const _head = { + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + }; + 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.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: + node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + _node == null; + } + const head = { + posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: node.positionName == _node.positionName ? "" : node.positionName, + posType: node.posType == _node.posType ? "" : node.posType, + posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel, + profilePosMasterNo: + node.profilePosMasterNo == _node.profilePosMasterNo + ? "" + : node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: + node.profilePositionName == _node.profilePositionName + ? "" + : node.profilePositionName, + profilePosType: + node.profilePosType == _node.profilePosType ? "" : node.profilePosType, + profilePosLevel: + node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel, + }; + data.push(head); } _node = node; - data.push(node); + } + }), + ); + _node = null; + + for (let orgChild1 of orgChild1Data.filter( + (orgChild1) => orgChild1.orgRootId === orgRoot.id, + )) { + await Promise.all( + orgChild1.posMasters + .sort((a, b) => a.posMasterOrder - b.posMasterOrder) + .map(async (posMaster) => { + if (posMaster.orgChild2Id == null) { + const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; + const posType = [ + ...new Set(posMaster.positions.map((x) => x.posType.posTypeName)), + ]; + const posLevel = [ + ...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)), + ]; + const posExecutive = [ + ...new Set(posMaster.positions.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) { + 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.map((x: any) => x.posType.posTypeName), + ), + ]; + profilePosLevel = [ + ...new Set( + positionMasterOld.positions.map((x: any) => x.posLevel.posLevelName), + ), + ]; + profilePosExecutive = [ + ...new Set( + positionMasterOld.positions.map( + (x: any) => x.posExecutive.posExecutiveName, + ), + ), + ]; + } + + let node = { + posMasterOrder: posMaster.posMasterOrder, // + isSit: posMaster.isSit, // + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, + posMasterNo: posMaster.posMasterNo, + positionName: + posMaster.next_holder == null + ? positionName.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => (x.isSit = true))?.positionName + : posMaster.next_holder.position, + posType: + posMaster.next_holder == null + ? posType.join(" หรือ ") + : posMaster.isSit == false + ? posMaster.positions.find((x: any) => (x.isSit = 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.isSit = 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.isSit = true))?.posExecutive + ?.posExecutiveName + : positionMasterProfileOld == null + ? "" + : positionMasterProfileOld.positions.find((x: any) => (x.isSit = true)) + ?.posExecutive?.posExecutiveName, + + profileOrgName: + posMaster.next_holder == null + ? orgChild1.orgChild1Name + : 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 + ? orgChild1.orgChild1ShortName + : 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, + }; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + const _head = { + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + }; + 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.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: + node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + _node == null; + } + const head = { + posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: + node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: + node.positionName == _node.positionName ? "" : node.positionName, + posType: node.posType == _node.posType ? "" : node.posType, + posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel, + profilePosMasterNo: + node.profilePosMasterNo == _node.profilePosMasterNo + ? "" + : node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: + node.profilePositionName == _node.profilePositionName + ? "" + : node.profilePositionName, + profilePosType: + node.profilePosType == _node.profilePosType ? "" : node.profilePosType, + profilePosLevel: + node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel, + }; + data.push(head); + } + _node = node; + } }), ); _node = null; @@ -765,25 +916,95 @@ export class ReportController extends Controller { (x: any) => (x.positionIsSelected = true), )?.posExecutive?.posExecutiveName, }; - if (_node != null) { - if (node.orgTreeName == _node.orgTreeName) node.orgTreeName = ""; - if (node.orgTreeShortName == _node.orgTreeShortName) node.orgTreeShortName = ""; - if (node.profileOrgName == _node.profileOrgName) node.profileOrgName = ""; - if (node.profileOrgShortName == _node.profileOrgShortName) - node.profileOrgShortName = ""; - if (node.positionName == _node.positionName) node.positionName = ""; - if (node.posType == _node.posType) node.posType = ""; - if (node.posLevel == _node.posLevel) node.posLevel = ""; - if (node.posExecutive == _node.posExecutive) node.posExecutive = ""; - if (node.profilePositionName == _node.profilePositionName) - node.profilePositionName = ""; - if (node.profilePosType == _node.profilePosType) node.profilePosType = ""; - if (node.profilePosLevel == _node.profilePosLevel) node.profilePosLevel = ""; - if (node.profilePosExecutive == _node.profilePosExecutive) - node.profilePosExecutive = ""; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + const _head = { + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + }; + 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.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: + node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + _node == null; + } + const head = { + posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: + node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: + node.positionName == _node.positionName ? "" : node.positionName, + posType: node.posType == _node.posType ? "" : node.posType, + posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel, + profilePosMasterNo: + node.profilePosMasterNo == _node.profilePosMasterNo + ? "" + : node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: + node.profilePositionName == _node.profilePositionName + ? "" + : node.profilePositionName, + profilePosType: + node.profilePosType == _node.profilePosType ? "" : node.profilePosType, + profilePosLevel: + node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel, + }; + data.push(head); } _node = node; - data.push(node); }), ); _node = null; @@ -966,26 +1187,95 @@ export class ReportController extends Controller { (x: any) => (x.positionIsSelected = true), )?.posExecutive?.posExecutiveName, }; - if (_node != null) { - if (node.orgTreeName == _node.orgTreeName) node.orgTreeName = ""; - if (node.orgTreeShortName == _node.orgTreeShortName) - node.orgTreeShortName = ""; - if (node.profileOrgName == _node.profileOrgName) node.profileOrgName = ""; - if (node.profileOrgShortName == _node.profileOrgShortName) - node.profileOrgShortName = ""; - if (node.positionName == _node.positionName) node.positionName = ""; - if (node.posType == _node.posType) node.posType = ""; - if (node.posLevel == _node.posLevel) node.posLevel = ""; - if (node.posExecutive == _node.posExecutive) node.posExecutive = ""; - if (node.profilePositionName == _node.profilePositionName) - node.profilePositionName = ""; - if (node.profilePosType == _node.profilePosType) node.profilePosType = ""; - if (node.profilePosLevel == _node.profilePosLevel) node.profilePosLevel = ""; - if (node.profilePosExecutive == _node.profilePosExecutive) - node.profilePosExecutive = ""; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + const _head = { + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + }; + 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.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: + node.profileOrgName == _node.profileOrgName ? "" : node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + _node == null; + } + const head = { + posMasterNo: node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: + node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: + node.positionName == _node.positionName ? "" : node.positionName, + posType: node.posType == _node.posType ? "" : node.posType, + posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel, + profilePosMasterNo: + node.profilePosMasterNo == _node.profilePosMasterNo + ? "" + : node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: + node.profilePositionName == _node.profilePositionName + ? "" + : node.profilePositionName, + profilePosType: + node.profilePosType == _node.profilePosType ? "" : node.profilePosType, + profilePosLevel: + node.profilePosLevel == _node.profilePosLevel ? "" : node.profilePosLevel, + }; + data.push(head); } _node = node; - data.push(node); }), ); _node = null; @@ -1168,27 +1458,100 @@ export class ReportController extends Controller { (x: any) => (x.positionIsSelected = true), )?.posExecutive?.posExecutiveName, }; - if (_node != null) { - if (node.orgTreeName == _node.orgTreeName) node.orgTreeName = ""; - if (node.orgTreeShortName == _node.orgTreeShortName) - node.orgTreeShortName = ""; - if (node.profileOrgName == _node.profileOrgName) node.profileOrgName = ""; - if (node.profileOrgShortName == _node.profileOrgShortName) - node.profileOrgShortName = ""; - if (node.positionName == _node.positionName) node.positionName = ""; - if (node.posType == _node.posType) node.posType = ""; - if (node.posLevel == _node.posLevel) node.posLevel = ""; - if (node.posExecutive == _node.posExecutive) node.posExecutive = ""; - if (node.profilePositionName == _node.profilePositionName) - node.profilePositionName = ""; - if (node.profilePosType == _node.profilePosType) node.profilePosType = ""; - if (node.profilePosLevel == _node.profilePosLevel) - node.profilePosLevel = ""; - if (node.profilePosExecutive == _node.profilePosExecutive) - node.profilePosExecutive = ""; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + const _head = { + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + }; + 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.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + posExecutive: "", + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, + profilePosExecutive: + node.profileOrgName == _node.profileOrgName + ? "" + : node.profileOrgName, + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + }; + data.push(head); + _node == null; + } + const head = { + posMasterNo: + node.posMasterNo == _node.posMasterNo ? "" : node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: + node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: + node.positionName == _node.positionName ? "" : node.positionName, + posType: node.posType == _node.posType ? "" : node.posType, + posLevel: node.posLevel == _node.posLevel ? "" : node.posLevel, + profilePosMasterNo: + node.profilePosMasterNo == _node.profilePosMasterNo + ? "" + : node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: + node.profilePositionName == _node.profilePositionName + ? "" + : node.profilePositionName, + profilePosType: + node.profilePosType == _node.profilePosType ? "" : node.profilePosType, + profilePosLevel: + node.profilePosLevel == _node.profilePosLevel + ? "" + : node.profilePosLevel, + }; + data.push(head); } _node = node; - data.push(node); }), ); _node = null;