diff --git a/src/controllers/ProfileAddressController.ts b/src/controllers/ProfileAddressController.ts index fc9ff880..782fcd37 100644 --- a/src/controllers/ProfileAddressController.ts +++ b/src/controllers/ProfileAddressController.ts @@ -91,8 +91,8 @@ export class ProfileAddressController extends Controller { "currentDistrictId", "currentSubDistrictId", "currentZipCode", - "createdFullName", - "createdAt", + "lastUpdateFullName", + "lastUpdatedAt", ], }); if (!record) { diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index abd79a4e..b7785d20 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -84,7 +84,15 @@ export class ProfileChangeNameController extends Controller { public async changeNameHistory(@Path() changeNameId: string) { const record = await this.changeNameHistoryRepository.find({ where: { profileChangeNameId: changeNameId }, - select: ["id", "prefix", "firstName", "lastName", "status", "createdFullName", "createdAt"], + select: [ + "id", + "prefix", + "firstName", + "lastName", + "status", + "lastUpdateFullName", + "lastUpdatedAt", + ], order: { createdAt: "DESC" }, }); return new HttpSuccess(record); diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index a690883b..d2c0ba92 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -97,6 +97,8 @@ export class ProfileDutyController extends Controller { "detail", "refCommandNo", "refCommandDate", + "lastUpdateFullName", + "lastUpdatedAt", ], order: { createdAt: "DESC" }, }); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 9a40db6c..2eee2a3f 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -51,98 +51,194 @@ export class ReportController extends Controller { */ @Get("report1") async findReport1() { - const orgRevision = await this.orgRevisionRepository.findOne({ - where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, - relations: ["orgRoots"], - }); - if (!orgRevision) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } + const orgRevision = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, + relations: ["orgRoots"], + }); + if (!orgRevision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } - const orgRootData = await this.orgRootRepository.find({ - where: { - orgRevisionId: orgRevision.id, - }, - order: { orgRootOrder: "ASC" }, - relations: [ - "posMasters", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); + const orgRootData = await this.orgRootRepository.find({ + where: { + orgRevisionId: orgRevision.id, + }, + order: { orgRootOrder: "ASC" }, + relations: [ + "posMasters", + "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.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.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.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.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.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.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.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.positions", + "posMasters.positions.posLevel", + "posMasters.positions.posType", + "posMasters.positions.posExecutive", + ], + }); - let data = new Array(); - let _node: any; - let no = 1; - for (let orgRoot of orgRootData) { + let data = new Array(); + let _node: any; + let no = 1; + for (let orgRoot of orgRootData) { + await Promise.all( + orgRoot.posMasters + .filter((x) => x.orgChild1Id == null) + .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 node = { + orgTreeName: orgRoot.orgRootName, + orgTreeShortName: orgRoot.orgRootShortName, + posMasterNo: posMaster.posMasterNo, + positionName: positionName.join(" หรือ "), + posType: posType.join(" หรือ "), + posLevel: posLevel.join(" หรือ "), + posExecutive: posExecutive.join(" หรือ "), + }; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + posExecutive: node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + reason: "", + }; + data.push(head); + const _head = { + no: no, + posMasterNo: node.posMasterNo, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + reason: "", + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName + ) { + const head = { + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName ? "" : node.orgTreeShortName, + posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + reason: "", + }; + data.push(head); + _node == null; + } + const head = { + no: no, + posMasterNo: node.posMasterNo, + posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + reason: "", + }; + data.push(head); + } + no += 1; + _node = node; + } + }), + ); + _node = null; + + for (let orgChild1 of orgChild1Data.filter( + (orgChild1) => orgChild1.orgRootId === orgRoot.id, + )) { await Promise.all( - orgRoot.posMasters - .filter((x) => x.orgChild1Id == null) + orgChild1.posMasters + .filter((x) => x.orgChild2Id == null) .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild1Id == null) { + if (posMaster.orgChild2Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -167,13 +263,14 @@ export class ReportController extends Controller { ]; let node = { - orgTreeName: orgRoot.orgRootName, - orgTreeShortName: orgRoot.orgRootShortName, + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, posMasterNo: posMaster.posMasterNo, positionName: positionName.join(" หรือ "), posType: posType.join(" หรือ "), posLevel: posLevel.join(" หรือ "), posExecutive: posExecutive.join(" หรือ "), + reason: "", }; if (_node == null) { const head = { @@ -232,15 +329,15 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild1 of orgChild1Data.filter( - (orgChild1) => orgChild1.orgRootId === orgRoot.id, + for (let orgChild2 of orgChild2Data.filter( + (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, )) { await Promise.all( - orgChild1.posMasters - .filter((x) => x.orgChild2Id == null) + orgChild2.posMasters + .filter((x) => x.orgChild3Id == null) .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild2Id == null) { + if (posMaster.orgChild3Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -265,13 +362,13 @@ export class ReportController extends Controller { ]; let node = { - orgTreeName: orgChild1.orgChild1Name, - orgTreeShortName: orgChild1.orgChild1ShortName, + orgTreeName: orgChild2.orgChild2Name, + orgTreeShortName: orgChild2.orgChild2ShortName, posMasterNo: posMaster.posMasterNo, + posExecutive: posExecutive.join(" หรือ "), positionName: positionName.join(" หรือ "), posType: posType.join(" หรือ "), posLevel: posLevel.join(" หรือ "), - posExecutive: posExecutive.join(" หรือ "), reason: "", }; if (_node == null) { @@ -332,15 +429,15 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild2 of orgChild2Data.filter( - (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, + for (let orgChild3 of orgChild3Data.filter( + (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, )) { await Promise.all( - orgChild2.posMasters - .filter((x) => x.orgChild3Id == null) + orgChild3.posMasters + .filter((x) => x.orgChild4Id == null) .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild3Id == null) { + if (posMaster.orgChild4Id == null) { const positionName = [ ...new Set(posMaster.positions.map((x) => x.positionName)), ]; @@ -367,13 +464,13 @@ export class ReportController extends Controller { ]; let node = { - orgTreeName: orgChild2.orgChild2Name, - orgTreeShortName: orgChild2.orgChild2ShortName, + orgTreeName: orgChild3.orgChild3Name, + orgTreeShortName: orgChild3.orgChild3ShortName, posMasterNo: posMaster.posMasterNo, - posExecutive: posExecutive.join(" หรือ "), positionName: positionName.join(" หรือ "), posType: posType.join(" หรือ "), posLevel: posLevel.join(" หรือ "), + posExecutive: posExecutive.join(" หรือ "), reason: "", }; if (_node == null) { @@ -435,215 +532,111 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild3 of orgChild3Data.filter( - (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, + for (let orgChild4 of orgChild4Data.filter( + (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, )) { await Promise.all( - orgChild3.posMasters - .filter((x) => x.orgChild4Id == null) + orgChild4.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild4Id == 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), - ), - ]; + 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 node = { - orgTreeName: orgChild3.orgChild3Name, - orgTreeShortName: orgChild3.orgChild3ShortName, - posMasterNo: posMaster.posMasterNo, - positionName: positionName.join(" หรือ "), - posType: posType.join(" หรือ "), - posLevel: posLevel.join(" หรือ "), - posExecutive: posExecutive.join(" หรือ "), + let node = { + orgTreeName: orgChild4.orgChild4Name, + orgTreeShortName: orgChild4.orgChild4ShortName, + posMasterNo: posMaster.posMasterNo, + positionName: positionName.join(" หรือ "), + posType: posType.join(" หรือ "), + posLevel: posLevel.join(" หรือ "), + posExecutive: posExecutive.join(" หรือ "), + reason: "", + }; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + posExecutive: node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", reason: "", }; - if (_node == null) { + data.push(head); + const _head = { + no: no, + posMasterNo: node.posMasterNo, + posExecutive: node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + reason: "", + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName + ) { const head = { - posMasterNo: node.orgTreeShortName, - posExecutive: node.orgTreeName, + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName + ? "" + : node.orgTreeShortName, + posExecutive: + node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, positionName: "", posType: "", posLevel: "", reason: "", }; data.push(head); - const _head = { - no: no, - posMasterNo: node.posMasterNo, - posExecutive: node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - reason: "", - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName - ) { - const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName - ? "" - : node.orgTreeShortName, - posExecutive: - node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - reason: "", - }; - data.push(head); - _node == null; - } - const head = { - no: no, - posMasterNo: node.posMasterNo, - posExecutive: - node.posExecutive == _node.posExecutive ? "" : node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - reason: "", - }; - data.push(head); + _node == null; } - no += 1; - _node = node; + const head = { + no: no, + posMasterNo: node.posMasterNo, + posExecutive: + node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + reason: "", + }; + data.push(head); } + 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 node = { - orgTreeName: orgChild4.orgChild4Name, - orgTreeShortName: orgChild4.orgChild4ShortName, - posMasterNo: posMaster.posMasterNo, - positionName: positionName.join(" หรือ "), - posType: posType.join(" หรือ "), - posLevel: posLevel.join(" หรือ "), - posExecutive: posExecutive.join(" หรือ "), - reason: "", - }; - if (_node == null) { - const head = { - posMasterNo: node.orgTreeShortName, - posExecutive: node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - reason: "", - }; - data.push(head); - const _head = { - no: no, - posMasterNo: node.posMasterNo, - posExecutive: node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - reason: "", - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName - ) { - const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName - ? "" - : node.orgTreeShortName, - posExecutive: - node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - reason: "", - }; - data.push(head); - _node == null; - } - const head = { - no: no, - posMasterNo: node.posMasterNo, - posExecutive: - node.posExecutive == _node.posExecutive ? "" : node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - reason: "", - }; - data.push(head); - } - no += 1; - _node = node; - }), - ); - _node = null; - } } } } } - return new HttpSuccess({ template: "report1", reportName: "report1", data: { data } }); - + } + return new HttpSuccess({ template: "report1", reportName: "report1", data: { data } }); } /** @@ -654,167 +647,179 @@ export class ReportController extends Controller { */ @Get("report2") async findReport2() { - const orgRevision = await this.orgRevisionRepository.findOne({ - where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, - relations: ["orgRoots"], - }); - if (!orgRevision) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } + const orgRevision = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, + relations: ["orgRoots"], + }); + if (!orgRevision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } - const orgRootData = await this.orgRootRepository.find({ - where: { - 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.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: { + 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.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.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.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.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.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.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.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.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.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 }, + 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: { orgRevisionCreatedAt: "DESC" }, + skip: 1, relations: [ "posMasters", "posMasters.positions", @@ -823,30 +828,306 @@ export class ReportController extends Controller { "posMasters.positions.posExecutive", ], }); - if (orgRevisionActive == null) { - const _orgRevisionActive = await this.orgRevisionRepository.find({ - order: { orgRevisionCreatedAt: "DESC" }, - skip: 1, - relations: [ - "posMasters", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); - if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; - } + if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; + } - let data = new Array(); - let _node: any; - let no = 1; - for (let orgRoot of orgRootData) { + 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 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: "", + salary: "", + }; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.profileOrgName, + posExecutive: node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", + education: "", + salary: "", + }; + data.push(head); + const _head = { + no: no, + 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, + education: "", + salary: "", + }; + 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: "", + }; + data.push(head); + _node == null; + } + const head = { + no: no, + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + education: "", + salary: "", + }; + data.push(head); + } + no += 1; + _node = node; + } + }), + ); + _node = null; + + for (let orgChild1 of orgChild1Data.filter( + (orgChild1) => orgChild1.orgRootId === orgRoot.id, + )) { await Promise.all( - orgRoot.posMasters + orgChild1.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild1Id == null) { + if (posMaster.orgChild2Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -881,7 +1162,7 @@ export class ReportController extends Controller { let profilePosType: any = []; let profilePosLevel: any = []; let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null) { + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { positionMasterOld = orgRevisionActive.posMasters.find( (x: any) => x.orgRevisionId == orgRevisionActive.id && @@ -916,8 +1197,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgRoot.orgRootName, - orgTreeShortName: orgRoot.orgRootShortName, + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -958,7 +1239,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgRoot.orgRootName + ? orgChild1.orgChild1Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -974,7 +1255,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgRoot.orgRootShortName + ? orgChild1.orgChild1ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1129,14 +1410,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild1 of orgChild1Data.filter( - (orgChild1) => orgChild1.orgRootId === orgRoot.id, + for (let orgChild2 of orgChild2Data.filter( + (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, )) { await Promise.all( - orgChild1.posMasters + orgChild2.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild2Id == null) { + if (posMaster.orgChild3Id == null) { const positionName = [...new Set(posMaster.positions.map((x) => x.positionName))]; const posType = [ ...new Set( @@ -1171,7 +1452,7 @@ export class ReportController extends Controller { let profilePosType: any = []; let profilePosLevel: any = []; let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null) { + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { positionMasterOld = orgRevisionActive.posMasters.find( (x: any) => x.orgRevisionId == orgRevisionActive.id && @@ -1206,8 +1487,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild1.orgChild1Name, - orgTreeShortName: orgChild1.orgChild1ShortName, + orgTreeName: orgChild2.orgChild2Name, + orgTreeShortName: orgChild2.orgChild2ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -1248,7 +1529,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild1.orgChild1Name + ? orgChild2.orgChild2Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1264,7 +1545,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild1.orgChild1ShortName + ? orgChild2.orgChild2ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1420,14 +1701,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild2 of orgChild2Data.filter( - (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, + for (let orgChild3 of orgChild3Data.filter( + (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, )) { await Promise.all( - orgChild2.posMasters + orgChild3.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild3Id == null) { + if (posMaster.orgChild4Id == null) { const positionName = [ ...new Set(posMaster.positions.map((x) => x.positionName)), ]; @@ -1464,7 +1745,7 @@ export class ReportController extends Controller { let profilePosType: any = []; let profilePosLevel: any = []; let profilePosExecutive: any = []; - if (posMaster.ancestorDNA != null) { + if (posMaster.ancestorDNA != null && posMaster.ancestorDNA != "") { positionMasterOld = orgRevisionActive.posMasters.find( (x: any) => x.orgRevisionId == orgRevisionActive.id && @@ -1499,8 +1780,8 @@ export class ReportController extends Controller { let node = { posMasterOrder: posMaster.posMasterOrder, // isSit: posMaster.isSit, // - orgTreeName: orgChild2.orgChild2Name, - orgTreeShortName: orgChild2.orgChild2ShortName, + orgTreeName: orgChild3.orgChild3Name, + orgTreeShortName: orgChild3.orgChild3ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.next_holder == null @@ -1541,7 +1822,7 @@ export class ReportController extends Controller { profileOrgName: posMaster.next_holder == null - ? orgChild2.orgChild2Name + ? orgChild3.orgChild3Name : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1557,7 +1838,7 @@ export class ReportController extends Controller { : "-", profileOrgShortName: posMaster.next_holder == null - ? orgChild2.orgChild2ShortName + ? orgChild3.orgChild3ShortName : positionMasterProfileOld == null ? "-" : positionMasterProfileOld.orgChild4 != null @@ -1714,213 +1995,260 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild3 of orgChild3Data.filter( - (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, + for (let orgChild4 of orgChild4Data.filter( + (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, )) { await Promise.all( - orgChild3.posMasters + orgChild4.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild4Id == null) { - const positionName = [ - ...new Set(posMaster.positions.map((x) => x.positionName)), + 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)), ]; - const posType = [ + profilePosType = [ ...new Set( - posMaster.positions + positionMasterOld.positions .filter((x: any) => x.posType != null) - .map((x) => x.posType.posTypeName), + .map((x: any) => x.posType.posTypeName), ), ]; - const posLevel = [ + profilePosLevel = [ ...new Set( - posMaster.positions + positionMasterOld.positions .filter((x: any) => x.posLevel != null) - .map((x) => x.posLevel.posLevelName), + .map((x: any) => x.posLevel.posLevelName), ), ]; - const posExecutive = [ + profilePosExecutive = [ ...new Set( - posMaster.positions + positionMasterOld.positions .filter((x: any) => x.posExecutive != null) - .map((x) => x.posExecutive.posExecutiveName), + .map((x: any) => 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 - .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 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(" หรือ ") + 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, - profilePosType: - posMaster.next_holder == null - ? positionMasterOld == null - ? posType.join(" หรือ ") - : profilePosType.join(" หรือ ") + 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, - profilePosLevel: - posMaster.next_holder == null - ? positionMasterOld == null - ? posLevel.join(" หรือ ") - : profilePosLevel.join(" หรือ ") + 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, - profilePosExecutive: - posMaster.next_holder == null - ? positionMasterOld == null - ? posExecutive.join(" หรือ ") - : profilePosExecutive.join(" หรือ ") + 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: "", + salary: "", + }; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: node.profileOrgName, + posExecutive: node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + profilePosMasterNo: node.profileOrgShortName, + profilePosExecutive: "", + profilePositionName: "", + profilePosType: "", + profilePosLevel: "", education: "", salary: "", }; - if (_node == null) { + data.push(head); + const _head = { + no: no, + 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, + education: "", + salary: "", + }; + 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, - profileFullname: node.profileOrgName, - posExecutive: node.orgTreeName, + 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, + profilePosMasterNo: + node.profileOrgShortName == _node.profileOrgShortName + ? "" + : node.profileOrgShortName, profilePosExecutive: "", profilePositionName: "", profilePosType: "", @@ -1929,387 +2257,41 @@ export class ReportController extends Controller { salary: "", }; data.push(head); - const _head = { - no: no, - 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, - education: "", - salary: "", - }; - 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: "", - }; - data.push(head); - _node == null; - } - const head = { - no: no, - posMasterNo: node.posMasterNo, - profileFullname: node.profileFullname, - posExecutive: - node.posExecutive == _node.posExecutive ? "" : node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - profilePosMasterNo: node.profilePosMasterNo, - profilePosExecutive: - node.profilePosExecutive == _node.profilePosExecutive - ? "" - : node.profilePosExecutive, - profilePositionName: node.profilePositionName, - profilePosType: node.profilePosType, - profilePosLevel: node.profilePosLevel, - education: "", - salary: "", - }; - data.push(head); + _node == null; } - no += 1; - _node = node; + const head = { + no: no, + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: + node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + profilePosMasterNo: node.profilePosMasterNo, + profilePosExecutive: + node.profilePosExecutive == _node.profilePosExecutive + ? "" + : node.profilePosExecutive, + profilePositionName: node.profilePositionName, + profilePosType: node.profilePosType, + profilePosLevel: node.profilePosLevel, + education: "", + salary: "", + }; + data.push(head); } + 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) { - 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 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: "", - salary: "", - }; - if (_node == null) { - const head = { - posMasterNo: node.orgTreeShortName, - profileFullname: node.profileOrgName, - posExecutive: node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - profilePosMasterNo: node.profileOrgShortName, - profilePosExecutive: "", - profilePositionName: "", - profilePosType: "", - profilePosLevel: "", - education: "", - salary: "", - }; - data.push(head); - const _head = { - no: no, - 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, - education: "", - salary: "", - }; - 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: "", - }; - data.push(head); - _node == null; - } - const head = { - no: no, - posMasterNo: node.posMasterNo, - profileFullname: node.profileFullname, - posExecutive: - node.posExecutive == _node.posExecutive ? "" : node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - profilePosMasterNo: node.profilePosMasterNo, - profilePosExecutive: - node.profilePosExecutive == _node.profilePosExecutive - ? "" - : node.profilePosExecutive, - profilePositionName: node.profilePositionName, - profilePosType: node.profilePosType, - profilePosLevel: node.profilePosLevel, - education: "", - salary: "", - }; - data.push(head); - } - no += 1; - _node = node; - }), - ); - _node = null; - } } } } } - return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); - + } + return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /** @@ -2320,167 +2302,179 @@ export class ReportController extends Controller { */ @Get("report3") async findReport3() { - const orgRevision = await this.orgRevisionRepository.findOne({ - where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, - relations: ["orgRoots"], - }); - if (!orgRevision) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - } + const orgRevision = await this.orgRevisionRepository.findOne({ + where: { orgRevisionIsDraft: true, orgRevisionIsCurrent: false }, + relations: ["orgRoots"], + }); + if (!orgRevision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } - const orgRootData = await this.orgRootRepository.find({ - where: { - 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.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: { + 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.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.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.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.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.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.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.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.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.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 }, + 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: { orgRevisionCreatedAt: "DESC" }, + skip: 1, relations: [ "posMasters", "posMasters.positions", @@ -2489,30 +2483,148 @@ export class ReportController extends Controller { "posMasters.positions.posExecutive", ], }); - if (orgRevisionActive == null) { - const _orgRevisionActive = await this.orgRevisionRepository.find({ - order: { orgRevisionCreatedAt: "DESC" }, - skip: 1, - relations: [ - "posMasters", - "posMasters.positions", - "posMasters.positions.posLevel", - "posMasters.positions.posType", - "posMasters.positions.posExecutive", - ], - }); - if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; - } + if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; + } - let data = new Array(); - let _node: any; - let no = 1; - for (let orgRoot of orgRootData) { + 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 && posMaster.next_holder != null) { + let positionMasterProfileOld: any = null; + if (posMaster.next_holder != null) { + positionMasterProfileOld = posMaster.next_holder.current_holders.find( + (x) => x.orgRevisionId == orgRevisionActive.id, + ); + } + + let node = { + orgTreeName: orgRoot.orgRootName, + orgTreeShortName: orgRoot.orgRootShortName, + posMasterNo: posMaster.posMasterNo, + positionName: + posMaster.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true) + ?.positionName + : posMaster.next_holder.position, + posType: + 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.isSit == false + ? posMaster.positions.find((x: any) => x.positionIsSelected == true)?.posLevel + ?.posLevelName + : posMaster.next_holder.posLevel == null + ? "-" + : posMaster.next_holder.posLevel.posLevelName, + posExecutive: + 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, + + profileFullname: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, + education: "", + salary: "", + positionSalaryAmount: "", + mouthSalaryAmount: "", + reason: "", + }; + if (_node == null) { + const head = { + posMasterNo: node.orgTreeShortName, + profileFullname: "", + posExecutive: node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + education: "", + salary: "", + positionSalaryAmount: "", + mouthSalaryAmount: "", + reason: "", + }; + data.push(head); + const _head = { + no: no, + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive == undefined ? "" : node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + education: "", + salary: "", + positionSalaryAmount: "", + mouthSalaryAmount: "", + reason: "", + }; + data.push(_head); + } else { + if ( + node.orgTreeShortName != _node.orgTreeShortName || + node.orgTreeName != _node.orgTreeName + ) { + const head = { + posMasterNo: + node.orgTreeShortName == _node.orgTreeShortName ? "" : node.orgTreeShortName, + profileFullname: "", + posExecutive: node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, + positionName: "", + posType: "", + posLevel: "", + education: "", + salary: "", + positionSalaryAmount: "", + mouthSalaryAmount: "", + reason: "", + }; + data.push(head); + _node == null; + } + const head = { + no: no, + posMasterNo: node.posMasterNo, + profileFullname: node.profileFullname, + posExecutive: node.posExecutive == _node.posExecutive ? "" : node.posExecutive, + positionName: node.positionName, + posType: node.posType, + posLevel: node.posLevel, + education: "", + salary: "", + positionSalaryAmount: "", + mouthSalaryAmount: "", + reason: "", + }; + data.push(head); + } + no += 1; + _node = node; + } + }), + ); + _node = null; + + for (let orgChild1 of orgChild1Data.filter( + (orgChild1) => orgChild1.orgRootId === orgRoot.id, + )) { await Promise.all( - orgRoot.posMasters + orgChild1.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild1Id == null && posMaster.next_holder != null) { + if (posMaster.orgChild2Id == null && posMaster.next_holder != null) { let positionMasterProfileOld: any = null; if (posMaster.next_holder != null) { positionMasterProfileOld = posMaster.next_holder.current_holders.find( @@ -2521,8 +2633,8 @@ export class ReportController extends Controller { } let node = { - orgTreeName: orgRoot.orgRootName, - orgTreeShortName: orgRoot.orgRootShortName, + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.isSit == false @@ -2579,7 +2691,7 @@ export class ReportController extends Controller { no: no, posMasterNo: node.posMasterNo, profileFullname: node.profileFullname, - posExecutive: node.posExecutive == undefined ? "" : node.posExecutive, + posExecutive: node.posExecutive, positionName: node.positionName, posType: node.posType, posLevel: node.posLevel, @@ -2637,14 +2749,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild1 of orgChild1Data.filter( - (orgChild1) => orgChild1.orgRootId === orgRoot.id, + for (let orgChild2 of orgChild2Data.filter( + (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, )) { await Promise.all( - orgChild1.posMasters + orgChild2.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild2Id == null && posMaster.next_holder != null) { + if (posMaster.orgChild3Id == null && posMaster.next_holder != null) { let positionMasterProfileOld: any = null; if (posMaster.next_holder != null) { positionMasterProfileOld = posMaster.next_holder.current_holders.find( @@ -2653,8 +2765,8 @@ export class ReportController extends Controller { } let node = { - orgTreeName: orgChild1.orgChild1Name, - orgTreeShortName: orgChild1.orgChild1ShortName, + orgTreeName: orgChild2.orgChild2Name, + orgTreeShortName: orgChild2.orgChild2ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.isSit == false @@ -2684,7 +2796,6 @@ export class ReportController extends Controller { : positionMasterProfileOld.positions.find( (x: any) => x.positionIsSelected == true, )?.posExecutive?.posExecutiveName, - profileFullname: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, education: "", salary: "", @@ -2770,14 +2881,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild2 of orgChild2Data.filter( - (orgChild2) => orgChild2.orgChild1Id === orgChild1.id, + for (let orgChild3 of orgChild3Data.filter( + (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, )) { await Promise.all( - orgChild2.posMasters + orgChild3.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild3Id == null && posMaster.next_holder != null) { + if (posMaster.orgChild4Id == null && posMaster.next_holder != null) { let positionMasterProfileOld: any = null; if (posMaster.next_holder != null) { positionMasterProfileOld = posMaster.next_holder.current_holders.find( @@ -2786,8 +2897,8 @@ export class ReportController extends Controller { } let node = { - orgTreeName: orgChild2.orgChild2Name, - orgTreeShortName: orgChild2.orgChild2ShortName, + orgTreeName: orgChild3.orgChild3Name, + orgTreeShortName: orgChild3.orgChild3ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.isSit == false @@ -2903,14 +3014,14 @@ export class ReportController extends Controller { ); _node = null; - for (let orgChild3 of orgChild3Data.filter( - (orgChild3) => orgChild3.orgChild2Id === orgChild2.id, + for (let orgChild4 of orgChild4Data.filter( + (orgChild4) => orgChild4.orgChild3Id === orgChild3.id, )) { await Promise.all( - orgChild3.posMasters + orgChild4.posMasters .sort((a, b) => a.posMasterOrder - b.posMasterOrder) .map(async (posMaster) => { - if (posMaster.orgChild4Id == null && posMaster.next_holder != null) { + if (posMaster.next_holder != null) { let positionMasterProfileOld: any = null; if (posMaster.next_holder != null) { positionMasterProfileOld = posMaster.next_holder.current_holders.find( @@ -2919,8 +3030,8 @@ export class ReportController extends Controller { } let node = { - orgTreeName: orgChild3.orgChild3Name, - orgTreeShortName: orgChild3.orgChild3ShortName, + orgTreeName: orgChild4.orgChild4Name, + orgTreeShortName: orgChild4.orgChild4ShortName, posMasterNo: posMaster.posMasterNo, positionName: posMaster.isSit == false @@ -3035,145 +3146,11 @@ export class ReportController extends Controller { }), ); _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) => { - if (posMaster.next_holder != null) { - let positionMasterProfileOld: any = null; - if (posMaster.next_holder != null) { - positionMasterProfileOld = posMaster.next_holder.current_holders.find( - (x) => x.orgRevisionId == orgRevisionActive.id, - ); - } - - let node = { - orgTreeName: orgChild4.orgChild4Name, - orgTreeShortName: orgChild4.orgChild4ShortName, - posMasterNo: posMaster.posMasterNo, - positionName: - posMaster.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.positionName - : posMaster.next_holder.position, - posType: - 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.isSit == false - ? posMaster.positions.find((x: any) => x.positionIsSelected == true) - ?.posLevel?.posLevelName - : posMaster.next_holder.posLevel == null - ? "-" - : posMaster.next_holder.posLevel.posLevelName, - posExecutive: - 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, - profileFullname: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, - education: "", - salary: "", - positionSalaryAmount: "", - mouthSalaryAmount: "", - reason: "", - }; - if (_node == null) { - const head = { - posMasterNo: node.orgTreeShortName, - profileFullname: "", - posExecutive: node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - education: "", - salary: "", - positionSalaryAmount: "", - mouthSalaryAmount: "", - reason: "", - }; - data.push(head); - const _head = { - no: no, - posMasterNo: node.posMasterNo, - profileFullname: node.profileFullname, - posExecutive: node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - education: "", - salary: "", - positionSalaryAmount: "", - mouthSalaryAmount: "", - reason: "", - }; - data.push(_head); - } else { - if ( - node.orgTreeShortName != _node.orgTreeShortName || - node.orgTreeName != _node.orgTreeName - ) { - const head = { - posMasterNo: - node.orgTreeShortName == _node.orgTreeShortName - ? "" - : node.orgTreeShortName, - profileFullname: "", - posExecutive: - node.orgTreeName == _node.orgTreeName ? "" : node.orgTreeName, - positionName: "", - posType: "", - posLevel: "", - education: "", - salary: "", - positionSalaryAmount: "", - mouthSalaryAmount: "", - reason: "", - }; - data.push(head); - _node == null; - } - const head = { - no: no, - posMasterNo: node.posMasterNo, - profileFullname: node.profileFullname, - posExecutive: - node.posExecutive == _node.posExecutive ? "" : node.posExecutive, - positionName: node.positionName, - posType: node.posType, - posLevel: node.posLevel, - education: "", - salary: "", - positionSalaryAmount: "", - mouthSalaryAmount: "", - reason: "", - }; - data.push(head); - } - no += 1; - _node = node; - } - }), - ); - _node = null; - } } } } } - return new HttpSuccess({ template: "report3", reportName: "report3", data: { data } }); - + } + return new HttpSuccess({ template: "report3", reportName: "report3", data: { data } }); } }