diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 18465656..9f0df140 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -6418,6 +6418,18 @@ export class OrganizationController extends Controller { // const formattedData = orgRootData.map((orgRoot) => { const formattedData = await Promise.all( orgRootData.map(async (orgRoot) => { + const sum0 = await this.posMasterRepository.find({ + where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id }, + select: [ + "current_holderId", + "next_holderId", + "orgRootId", + "orgChild1Id", + "orgChild2Id", + "orgChild3Id", + "orgChild4Id", + ], + }); return { orgTreeId: orgRoot.id, orgTreeDnaId: orgRoot.ancestorDNA, @@ -6442,539 +6454,341 @@ export class OrganizationController extends Controller { responsibility: orgRoot.responsibility, labelName: orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName, - totalPosition: await this.posMasterRepository.count({ - where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id }, - }), - totalPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - current_holderId: IsNull() || "", - }, - }), - totalPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - next_holderId: IsNull() || "", - }, - }), - totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: IsNull() || "", - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - }, - }), - totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: IsNull() || "", - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: IsNull() || "", - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - current_holderId: IsNull() || "", - }, - }), - totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: IsNull() || "", - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: IsNull() || "", - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - next_holderId: IsNull() || "", - }, - }), + totalPosition: sum0.length + 1, + totalPositionCurrentUse: + sum0.filter((x) => x.current_holderId != null && x.current_holderId != "").length + 1, + totalPositionCurrentVacant: + sum0.filter((x) => x.current_holderId == null || x.current_holderId == "").length + 1, + totalPositionNextUse: + sum0.filter((x) => x.next_holderId != null && x.next_holderId != "").length + 1, + totalPositionNextVacant: + sum0.filter((x) => x.next_holderId == null || x.next_holderId == "").length + 1, + totalRootPosition: + sum0.filter( + (x) => + (x.orgChild1Id == null || x.orgChild1Id == "") && + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == ""), + ).length + 1, + totalRootPositionCurrentUse: + sum0.filter( + (x) => + (x.orgChild1Id == null || x.orgChild1Id == "") && + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.current_holderId != null && + x.current_holderId != "", + ).length + 1, + totalRootPositionCurrentVacant: + sum0.filter( + (x) => + (x.orgChild1Id == null || x.orgChild1Id == "") && + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.current_holderId == null || x.current_holderId == ""), + ).length + 1, + totalRootPositionNextUse: + sum0.filter( + (x) => + (x.orgChild1Id == null || x.orgChild1Id == "") && + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.next_holderId != null && + x.next_holderId != "", + ).length + 1, + totalRootPositionNextVacant: + sum0.filter( + (x) => + (x.orgChild1Id == null || x.orgChild1Id == "") && + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.next_holderId == null || x.next_holderId == ""), + ).length + 1, children: await Promise.all( orgChild1Data .filter((orgChild1) => orgChild1.orgRootId === orgRoot.id) - .map(async (orgChild1) => ({ - orgTreeId: orgChild1.id, - orgTreeDnaId: orgChild1.ancestorDNA, - orgRootId: orgRoot.id, - orgRootDnaId: orgRoot.ancestorDNA, - orgLevel: 1, - orgName: `${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, - orgTreeName: orgChild1.orgChild1Name, - orgTreeShortName: orgChild1.orgChild1ShortName, - orgTreeCode: orgChild1.orgChild1Code, - orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code, - orgTreeRank: orgChild1.orgChild1Rank, - orgTreeRankSub: orgChild1.orgChild1RankSub, - DEPARTMENT_CODE: orgChild1.DEPARTMENT_CODE, - DIVISION_CODE: orgChild1.DIVISION_CODE, - SECTION_CODE: orgChild1.SECTION_CODE, - JOB_CODE: orgChild1.JOB_CODE, - orgTreeOrder: orgChild1.orgChild1Order, - orgRootCode: orgRoot.orgRootCode, - orgTreePhoneEx: orgChild1.orgChild1PhoneEx, - orgTreePhoneIn: orgChild1.orgChild1PhoneIn, - orgTreeFax: orgChild1.orgChild1Fax, - orgRevisionId: orgRoot.orgRevisionId, - orgRootName: orgRoot.orgRootName, - responsibility: orgChild1.responsibility, - labelName: - orgChild1.orgChild1Name + - " " + - orgRoot.orgRootCode + - orgChild1.orgChild1Code + - " " + - orgChild1.orgChild1ShortName + - "/" + - orgRoot.orgRootName + - " " + - orgRoot.orgRootCode + - "00" + - " " + - orgRoot.orgRootShortName, - totalPosition: await this.posMasterRepository.count({ - where: { orgRevisionId: orgRoot.orgRevisionId, orgChild1Id: orgChild1.id }, - }), - totalPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild1Id: orgChild1.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild1Id: orgChild1.id, - current_holderId: IsNull() || "", - }, - }), - totalPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild1Id: orgChild1.id, - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild1Id: orgChild1.id, - next_holderId: IsNull() || "", - }, - }), - totalRootPosition: await this.posMasterRepository.count({ + .map(async (orgChild1) => { + const sum1 = await this.posMasterRepository.find({ where: { orgRevisionId: orgRoot.orgRevisionId, orgRootId: orgRoot.id, orgChild1Id: orgChild1.id, - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", }, - }), - totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - current_holderId: IsNull() || "", - }, - }), - totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: IsNull() || "", - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - next_holderId: IsNull() || "", - }, - }), + select: [ + "current_holderId", + "next_holderId", + "orgRootId", + "orgChild1Id", + "orgChild2Id", + "orgChild3Id", + "orgChild4Id", + ], + }); + return { + orgTreeId: orgChild1.id, + orgTreeDnaId: orgChild1.ancestorDNA, + orgRootId: orgRoot.id, + orgRootDnaId: orgRoot.ancestorDNA, + orgLevel: 1, + orgName: `${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, + orgTreeName: orgChild1.orgChild1Name, + orgTreeShortName: orgChild1.orgChild1ShortName, + orgTreeCode: orgChild1.orgChild1Code, + orgCode: orgRoot.orgRootCode + orgChild1.orgChild1Code, + orgTreeRank: orgChild1.orgChild1Rank, + orgTreeRankSub: orgChild1.orgChild1RankSub, + DEPARTMENT_CODE: orgChild1.DEPARTMENT_CODE, + DIVISION_CODE: orgChild1.DIVISION_CODE, + SECTION_CODE: orgChild1.SECTION_CODE, + JOB_CODE: orgChild1.JOB_CODE, + orgTreeOrder: orgChild1.orgChild1Order, + orgRootCode: orgRoot.orgRootCode, + orgTreePhoneEx: orgChild1.orgChild1PhoneEx, + orgTreePhoneIn: orgChild1.orgChild1PhoneIn, + orgTreeFax: orgChild1.orgChild1Fax, + orgRevisionId: orgRoot.orgRevisionId, + orgRootName: orgRoot.orgRootName, + responsibility: orgChild1.responsibility, + labelName: + orgChild1.orgChild1Name + + " " + + orgRoot.orgRootCode + + orgChild1.orgChild1Code + + " " + + orgChild1.orgChild1ShortName + + "/" + + orgRoot.orgRootName + + " " + + orgRoot.orgRootCode + + "00" + + " " + + orgRoot.orgRootShortName, + totalPosition: sum1.length + 1, + totalPositionCurrentUse: + sum1.filter((x) => x.current_holderId != null && x.current_holderId != "") + .length + 1, + totalPositionCurrentVacant: + sum1.filter((x) => x.current_holderId == null || x.current_holderId == "") + .length + 1, + totalPositionNextUse: + sum1.filter((x) => x.next_holderId != null && x.next_holderId != "").length + 1, + totalPositionNextVacant: + sum1.filter((x) => x.next_holderId == null || x.next_holderId == "").length + 1, + totalRootPosition: + sum1.filter( + (x) => + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == ""), + ).length + 1, + totalRootPositionCurrentUse: + sum1.filter( + (x) => + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.current_holderId != null && + x.current_holderId != "", + ).length + 1, + totalRootPositionCurrentVacant: + sum1.filter( + (x) => + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.current_holderId == null || x.current_holderId == ""), + ).length + 1, + totalRootPositionNextUse: + sum1.filter( + (x) => + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.next_holderId != null && + x.next_holderId != "", + ).length + 1, + totalRootPositionNextVacant: + sum1.filter( + (x) => + (x.orgChild2Id == null || x.orgChild2Id == "") && + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.next_holderId == null || x.next_holderId == ""), + ).length + 1, - children: await Promise.all( - orgChild2Data - .filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id) - .map(async (orgChild2) => ({ - orgTreeId: orgChild2.id, - orgTreeDnaId: orgChild2.ancestorDNA, - orgRootId: orgChild1.id, - orgRootDnaId: orgChild1.ancestorDNA, - orgLevel: 2, - orgName: `${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, - orgTreeName: orgChild2.orgChild2Name, - orgTreeShortName: orgChild2.orgChild2ShortName, - orgTreeCode: orgChild2.orgChild2Code, - orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code, - orgTreeRank: orgChild2.orgChild2Rank, - orgTreeRankSub: orgChild2.orgChild2RankSub, - DEPARTMENT_CODE: orgChild2.DEPARTMENT_CODE, - DIVISION_CODE: orgChild2.DIVISION_CODE, - SECTION_CODE: orgChild2.SECTION_CODE, - JOB_CODE: orgChild2.JOB_CODE, - orgTreeOrder: orgChild2.orgChild2Order, - orgRootCode: orgRoot.orgRootCode, - orgTreePhoneEx: orgChild2.orgChild2PhoneEx, - orgTreePhoneIn: orgChild2.orgChild2PhoneIn, - orgTreeFax: orgChild2.orgChild2Fax, - orgRevisionId: orgRoot.orgRevisionId, - orgRootName: orgRoot.orgRootName, - responsibility: orgChild2.responsibility, - labelName: - orgChild2.orgChild2Name + - " " + - orgRoot.orgRootCode + - orgChild2.orgChild2Code + - " " + - orgChild2.orgChild2ShortName + - "/" + - orgChild1.orgChild1Name + - " " + - orgRoot.orgRootCode + - orgChild1.orgChild1Code + - " " + - orgChild1.orgChild1ShortName + - "/" + - orgRoot.orgRootName + - " " + - orgRoot.orgRootCode + - "00" + - " " + - orgRoot.orgRootShortName, - totalPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild2Id: orgChild2.id, - }, - }), - totalPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild2Id: orgChild2.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild2Id: orgChild2.id, - current_holderId: IsNull() || "", - }, - }), - totalPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild2Id: orgChild2.id, - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild2Id: orgChild2.id, - next_holderId: IsNull() || "", - }, - }), - totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - }, - }), - totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - current_holderId: IsNull() || "", - }, - }), - totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: IsNull() || "", - orgChild4Id: IsNull() || "", - next_holderId: IsNull() || "", - }, - }), - - children: await Promise.all( - orgChild3Data - .filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id) - .map(async (orgChild3) => ({ - orgTreeId: orgChild3.id, - orgTreeDnaId: orgChild3.ancestorDNA, - orgRootId: orgChild2.id, - orgRootDnaId: orgChild2.ancestorDNA, - orgLevel: 3, - orgName: `${orgChild3.orgChild3Name} ${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, - orgTreeName: orgChild3.orgChild3Name, - orgTreeShortName: orgChild3.orgChild3ShortName, - orgTreeCode: orgChild3.orgChild3Code, - orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code, - orgTreeRank: orgChild3.orgChild3Rank, - orgTreeRankSub: orgChild3.orgChild3RankSub, - DEPARTMENT_CODE: orgChild3.DEPARTMENT_CODE, - DIVISION_CODE: orgChild3.DIVISION_CODE, - SECTION_CODE: orgChild3.SECTION_CODE, - JOB_CODE: orgChild3.JOB_CODE, - orgTreeOrder: orgChild3.orgChild3Order, - orgRootCode: orgRoot.orgRootCode, - orgTreePhoneEx: orgChild3.orgChild3PhoneEx, - orgTreePhoneIn: orgChild3.orgChild3PhoneIn, - orgTreeFax: orgChild3.orgChild3Fax, + children: await Promise.all( + orgChild2Data + .filter((orgChild2) => orgChild2.orgChild1Id === orgChild1.id) + .map(async (orgChild2) => { + const sum2 = await this.posMasterRepository.find({ + where: { orgRevisionId: orgRoot.orgRevisionId, - orgRootName: orgRoot.orgRootName, - responsibility: orgChild3.responsibility, - labelName: - orgChild3.orgChild3Name + - " " + - orgRoot.orgRootCode + - orgChild3.orgChild3Code + - " " + - orgChild3.orgChild3ShortName + - "/" + - orgChild2.orgChild2Name + - " " + - orgRoot.orgRootCode + - orgChild2.orgChild2Code + - " " + - orgChild2.orgChild2ShortName + - "/" + - orgChild1.orgChild1Name + - " " + - orgRoot.orgRootCode + - orgChild1.orgChild1Code + - " " + - orgChild1.orgChild1ShortName + - "/" + - orgRoot.orgRootName + - " " + - orgRoot.orgRootCode + - "00" + - " " + - orgRoot.orgRootShortName, - totalPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild3Id: orgChild3.id, - }, - }), - totalPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild3Id: orgChild3.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild3Id: orgChild3.id, - current_holderId: IsNull() || "", - }, - }), - totalPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild3Id: orgChild3.id, - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild3Id: orgChild3.id, - next_holderId: IsNull() || "", - }, - }), - totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: IsNull() || "", - }, - }), - totalRootPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: IsNull() || "", - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: IsNull() || "", - current_holderId: IsNull() || "", - }, - }), - totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: IsNull() || "", - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: IsNull() || "", - next_holderId: IsNull() || "", - }, - }), + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + }, + select: [ + "current_holderId", + "next_holderId", + "orgRootId", + "orgChild1Id", + "orgChild2Id", + "orgChild3Id", + "orgChild4Id", + ], + }); + return { + orgTreeId: orgChild2.id, + orgTreeDnaId: orgChild2.ancestorDNA, + orgRootId: orgChild1.id, + orgRootDnaId: orgChild1.ancestorDNA, + orgLevel: 2, + orgName: `${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, + orgTreeName: orgChild2.orgChild2Name, + orgTreeShortName: orgChild2.orgChild2ShortName, + orgTreeCode: orgChild2.orgChild2Code, + orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code, + orgTreeRank: orgChild2.orgChild2Rank, + orgTreeRankSub: orgChild2.orgChild2RankSub, + DEPARTMENT_CODE: orgChild2.DEPARTMENT_CODE, + DIVISION_CODE: orgChild2.DIVISION_CODE, + SECTION_CODE: orgChild2.SECTION_CODE, + JOB_CODE: orgChild2.JOB_CODE, + orgTreeOrder: orgChild2.orgChild2Order, + orgRootCode: orgRoot.orgRootCode, + orgTreePhoneEx: orgChild2.orgChild2PhoneEx, + orgTreePhoneIn: orgChild2.orgChild2PhoneIn, + orgTreeFax: orgChild2.orgChild2Fax, + orgRevisionId: orgRoot.orgRevisionId, + orgRootName: orgRoot.orgRootName, + responsibility: orgChild2.responsibility, + labelName: + orgChild2.orgChild2Name + + " " + + orgRoot.orgRootCode + + orgChild2.orgChild2Code + + " " + + orgChild2.orgChild2ShortName + + "/" + + orgChild1.orgChild1Name + + " " + + orgRoot.orgRootCode + + orgChild1.orgChild1Code + + " " + + orgChild1.orgChild1ShortName + + "/" + + orgRoot.orgRootName + + " " + + orgRoot.orgRootCode + + "00" + + " " + + orgRoot.orgRootShortName, + totalPosition: sum2.length + 1, + totalPositionCurrentUse: + sum2.filter( + (x) => x.current_holderId != null && x.current_holderId != "", + ).length + 1, + totalPositionCurrentVacant: + sum2.filter( + (x) => x.current_holderId == null || x.current_holderId == "", + ).length + 1, + totalPositionNextUse: + sum2.filter((x) => x.next_holderId != null && x.next_holderId != "") + .length + 1, + totalPositionNextVacant: + sum2.filter((x) => x.next_holderId == null || x.next_holderId == "") + .length + 1, + totalRootPosition: + sum2.filter( + (x) => + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == ""), + ).length + 1, + totalRootPositionCurrentUse: + sum2.filter( + (x) => + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.current_holderId != null && + x.current_holderId != "", + ).length + 1, + totalRootPositionCurrentVacant: + sum2.filter( + (x) => + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.current_holderId == null || x.current_holderId == ""), + ).length + 1, + totalRootPositionNextUse: + sum2.filter( + (x) => + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.next_holderId != null && + x.next_holderId != "", + ).length + 1, + totalRootPositionNextVacant: + sum2.filter( + (x) => + (x.orgChild3Id == null || x.orgChild3Id == "") && + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.next_holderId == null || x.next_holderId == ""), + ).length + 1, - children: await Promise.all( - orgChild4Data - .filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id) - .map(async (orgChild4) => ({ - orgTreeId: orgChild4.id, - orgTreeDnaId: orgChild4.ancestorDNA, - orgRootId: orgChild3.id, - orgRootDnaId: orgChild3.ancestorDNA, - orgLevel: 4, - orgName: `${orgChild4.orgChild4Name} ${orgChild3.orgChild3Name} ${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, - orgTreeName: orgChild4.orgChild4Name, - orgTreeShortName: orgChild4.orgChild4ShortName, - orgTreeCode: orgChild4.orgChild4Code, - orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code, - orgTreeRank: orgChild4.orgChild4Rank, - orgTreeRankSub: orgChild4.orgChild4RankSub, - DEPARTMENT_CODE: orgChild4.DEPARTMENT_CODE, - DIVISION_CODE: orgChild4.DIVISION_CODE, - SECTION_CODE: orgChild4.SECTION_CODE, - JOB_CODE: orgChild4.JOB_CODE, - orgTreeOrder: orgChild4.orgChild4Order, + children: await Promise.all( + orgChild3Data + .filter((orgChild3) => orgChild3.orgChild2Id === orgChild2.id) + .map(async (orgChild3) => { + const sum3 = await this.posMasterRepository.find({ + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + }, + select: [ + "current_holderId", + "next_holderId", + "orgRootId", + "orgChild1Id", + "orgChild2Id", + "orgChild3Id", + "orgChild4Id", + ], + }); + return { + orgTreeId: orgChild3.id, + orgTreeDnaId: orgChild3.ancestorDNA, + orgRootId: orgChild2.id, + orgRootDnaId: orgChild2.ancestorDNA, + orgLevel: 3, + orgName: `${orgChild3.orgChild3Name} ${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, + orgTreeName: orgChild3.orgChild3Name, + orgTreeShortName: orgChild3.orgChild3ShortName, + orgTreeCode: orgChild3.orgChild3Code, + orgCode: orgRoot.orgRootCode + orgChild3.orgChild3Code, + orgTreeRank: orgChild3.orgChild3Rank, + orgTreeRankSub: orgChild3.orgChild3RankSub, + DEPARTMENT_CODE: orgChild3.DEPARTMENT_CODE, + DIVISION_CODE: orgChild3.DIVISION_CODE, + SECTION_CODE: orgChild3.SECTION_CODE, + JOB_CODE: orgChild3.JOB_CODE, + orgTreeOrder: orgChild3.orgChild3Order, orgRootCode: orgRoot.orgRootCode, - orgTreePhoneEx: orgChild4.orgChild4PhoneEx, - orgTreePhoneIn: orgChild4.orgChild4PhoneIn, - orgTreeFax: orgChild4.orgChild4Fax, + orgTreePhoneEx: orgChild3.orgChild3PhoneEx, + orgTreePhoneIn: orgChild3.orgChild3PhoneIn, + orgTreeFax: orgChild3.orgChild3Fax, orgRevisionId: orgRoot.orgRevisionId, orgRootName: orgRoot.orgRootName, - responsibility: orgChild4.responsibility, + responsibility: orgChild3.responsibility, labelName: - orgChild4.orgChild4Name + - " " + - orgRoot.orgRootCode + - orgChild4.orgChild4Code + - " " + - orgChild4.orgChild4ShortName + - "/" + orgChild3.orgChild3Name + " " + orgRoot.orgRootCode + @@ -7002,106 +6816,193 @@ export class OrganizationController extends Controller { "00" + " " + orgRoot.orgRootShortName, - totalPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild4Id: orgChild4.id, - }, - }), - totalPositionCurrentUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild4Id: orgChild4.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionCurrentVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), - totalPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild4Id: orgChild4.id, - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalPositionNextVacant: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }), - totalRootPosition: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - }, - }), - totalRootPositionCurrentUse: await this.posMasterRepository.count( - { - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - current_holderId: Not(IsNull()) || Not(""), - }, - }, - ), + totalPosition: sum3.length + 1, + totalPositionCurrentUse: + sum3.filter( + (x) => x.current_holderId != null && x.current_holderId != "", + ).length + 1, + totalPositionCurrentVacant: + sum3.filter( + (x) => x.current_holderId == null || x.current_holderId == "", + ).length + 1, + totalPositionNextUse: + sum3.filter( + (x) => x.next_holderId != null && x.next_holderId != "", + ).length + 1, + totalPositionNextVacant: + sum3.filter( + (x) => x.next_holderId == null || x.next_holderId == "", + ).length + 1, + totalRootPosition: + sum3.filter((x) => x.orgChild4Id == null || x.orgChild4Id == "") + .length + 1, + totalRootPositionCurrentUse: + sum3.filter( + (x) => + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.current_holderId != null && + x.current_holderId != "", + ).length + 1, totalRootPositionCurrentVacant: - await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - current_holderId: IsNull() || "", - }, - }), - totalRootPositionNextUse: await this.posMasterRepository.count({ - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - next_holderId: Not(IsNull()) || Not(""), - }, - }), - totalRootPositionNextVacant: await this.posMasterRepository.count( - { - where: { - orgRevisionId: orgRoot.orgRevisionId, - orgRootId: orgRoot.id, - orgChild1Id: orgChild1.id, - orgChild2Id: orgChild2.id, - orgChild3Id: orgChild3.id, - orgChild4Id: orgChild4.id, - next_holderId: IsNull() || "", - }, - }, + sum3.filter( + (x) => + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.current_holderId == null || x.current_holderId == ""), + ).length + 1, + totalRootPositionNextUse: + sum3.filter( + (x) => + (x.orgChild4Id == null || x.orgChild4Id == "") && + x.next_holderId != null && + x.next_holderId != "", + ).length + 1, + totalRootPositionNextVacant: + sum3.filter( + (x) => + (x.orgChild4Id == null || x.orgChild4Id == "") && + (x.next_holderId == null || x.next_holderId == ""), + ).length + 1, + + children: await Promise.all( + orgChild4Data + .filter((orgChild4) => orgChild4.orgChild3Id === orgChild3.id) + .map(async (orgChild4) => { + const sum4 = await this.posMasterRepository.find({ + where: { + orgRevisionId: orgRoot.orgRevisionId, + orgRootId: orgRoot.id, + orgChild1Id: orgChild1.id, + orgChild2Id: orgChild2.id, + orgChild3Id: orgChild3.id, + orgChild4Id: orgChild4.id, + }, + select: [ + "current_holderId", + "next_holderId", + "orgRootId", + "orgChild1Id", + "orgChild2Id", + "orgChild3Id", + "orgChild4Id", + ], + }); + return { + orgTreeId: orgChild4.id, + orgTreeDnaId: orgChild4.ancestorDNA, + orgRootId: orgChild3.id, + orgRootDnaId: orgChild3.ancestorDNA, + orgLevel: 4, + orgName: `${orgChild4.orgChild4Name} ${orgChild3.orgChild3Name} ${orgChild2.orgChild2Name} ${orgChild1.orgChild1Name} ${orgRoot.orgRootName}`, + orgTreeName: orgChild4.orgChild4Name, + orgTreeShortName: orgChild4.orgChild4ShortName, + orgTreeCode: orgChild4.orgChild4Code, + orgCode: orgRoot.orgRootCode + orgChild4.orgChild4Code, + orgTreeRank: orgChild4.orgChild4Rank, + orgTreeRankSub: orgChild4.orgChild4RankSub, + DEPARTMENT_CODE: orgChild4.DEPARTMENT_CODE, + DIVISION_CODE: orgChild4.DIVISION_CODE, + SECTION_CODE: orgChild4.SECTION_CODE, + JOB_CODE: orgChild4.JOB_CODE, + orgTreeOrder: orgChild4.orgChild4Order, + orgRootCode: orgRoot.orgRootCode, + orgTreePhoneEx: orgChild4.orgChild4PhoneEx, + orgTreePhoneIn: orgChild4.orgChild4PhoneIn, + orgTreeFax: orgChild4.orgChild4Fax, + orgRevisionId: orgRoot.orgRevisionId, + orgRootName: orgRoot.orgRootName, + responsibility: orgChild4.responsibility, + labelName: + orgChild4.orgChild4Name + + " " + + orgRoot.orgRootCode + + orgChild4.orgChild4Code + + " " + + orgChild4.orgChild4ShortName + + "/" + + orgChild3.orgChild3Name + + " " + + orgRoot.orgRootCode + + orgChild3.orgChild3Code + + " " + + orgChild3.orgChild3ShortName + + "/" + + orgChild2.orgChild2Name + + " " + + orgRoot.orgRootCode + + orgChild2.orgChild2Code + + " " + + orgChild2.orgChild2ShortName + + "/" + + orgChild1.orgChild1Name + + " " + + orgRoot.orgRootCode + + orgChild1.orgChild1Code + + " " + + orgChild1.orgChild1ShortName + + "/" + + orgRoot.orgRootName + + " " + + orgRoot.orgRootCode + + "00" + + " " + + orgRoot.orgRootShortName, + totalPosition: sum4.length + 1, + totalPositionCurrentUse: + sum4.filter( + (x) => + x.current_holderId != null && + x.current_holderId != "", + ).length + 1, + totalPositionCurrentVacant: + sum4.filter( + (x) => + x.current_holderId == null || + x.current_holderId == "", + ).length + 1, + totalPositionNextUse: + sum4.filter( + (x) => + x.next_holderId != null && x.next_holderId != "", + ).length + 1, + totalPositionNextVacant: + sum4.filter( + (x) => + x.next_holderId == null || x.next_holderId == "", + ).length + 1, + totalRootPosition: sum4.length + 1, + totalRootPositionCurrentUse: + sum4.filter( + (x) => + x.current_holderId != null && + x.current_holderId != "", + ).length + 1, + totalRootPositionCurrentVacant: + sum4.filter( + (x) => + x.current_holderId == null || + x.current_holderId == "", + ).length + 1, + totalRootPositionNextUse: + sum4.filter( + (x) => + x.next_holderId != null && x.next_holderId != "", + ).length + 1, + totalRootPositionNextVacant: + sum4.filter( + (x) => + x.next_holderId == null || x.next_holderId == "", + ).length + 1, + }; + }), ), - })), - ), - })), - ), - })), - ), - })), + }; + }), + ), + }; + }), + ), + }; + }), ), }; }), diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index 5eb7f126..3db102f2 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -1474,7 +1474,7 @@ export class ProfileSalaryTempController extends Controller { const profiles = await this.profileRepo.find(); let num = 1; for await (const item of profiles) { - let salaryOld = await this.salaryRepo.find({ + let salaryOld = await this.salaryOldRepo.find({ where: { profileId: item.id }, order: { commandDateAffect: "ASC", order: "ASC" }, }); @@ -1484,7 +1484,7 @@ export class ProfileSalaryTempController extends Controller { }); num = num + 1; console.log(num); - await this.salaryRepo.save(salaryOld); + await this.salaryOldRepo.save(salaryOld); } return new HttpSuccess();