diff --git a/src/controllers/PosMasterActController.ts b/src/controllers/PosMasterActController.ts index 68d5d8ec..4d449d21 100644 --- a/src/controllers/PosMasterActController.ts +++ b/src/controllers/PosMasterActController.ts @@ -433,6 +433,11 @@ export class PosMasterActController extends Controller { .leftJoinAndSelect("positions.posLevel", "posLevel") .leftJoinAndSelect("posMasterAct.posMaster", "posMaster") .leftJoinAndSelect("posMaster.positions", "positionActs") + .leftJoinAndSelect("posMaster.orgRoot", "orgRootAct") + .leftJoinAndSelect("posMaster.orgChild1", "orgChild1Act") + .leftJoinAndSelect("posMaster.orgChild2", "orgChild2Act") + .leftJoinAndSelect("posMaster.orgChild3", "orgChild3Act") + .leftJoinAndSelect("posMaster.orgChild4", "orgChild4Act") .leftJoinAndSelect("positionActs.posType", "posTypeAct") .leftJoinAndSelect("positionActs.posLevel", "posLevelAct") .leftJoinAndSelect("posMasterChild.orgRevision", "orgRevision") @@ -447,8 +452,8 @@ export class PosMasterActController extends Controller { .andWhere("orgRevision.orgRevisionIsDraft = :orgRevisionIsDraft", { orgRevisionIsDraft: false, }) - // .andWhere("positions.positionIsSelected = :isSelected", { isSelected: true }) - .andWhere("positionActs.positionIsSelected = :isSelected", { isSelected: true }) + .andWhere("positions.positionIsSelected = :isSelected", { isSelected: true }) + // .andWhere("positionActs.positionIsSelected = :isSelected", { isSelected: true }) .andWhere( new Brackets((qb) => { qb.andWhere(conditionGroup); @@ -467,6 +472,12 @@ export class PosMasterActController extends Controller { "orgChild2.orgChild2ShortName", "orgChild3.orgChild3ShortName", "orgChild4.orgChild4ShortName", + "posMaster.posMasterNo", + "orgRootAct.orgRootShortName", + "orgChild1Act.orgChild1ShortName", + "orgChild2Act.orgChild2ShortName", + "orgChild3Act.orgChild3ShortName", + "orgChild4Act.orgChild4ShortName", "current_holder.prefix", "current_holder.firstName", "current_holder.lastName", @@ -476,17 +487,33 @@ export class PosMasterActController extends Controller { .getMany(); const _posMaster = posMaster.map((x) => { const posMasterNo = - x.posMasterChild.orgChild4 != null - ? `${x.posMasterChild.orgChild4.orgChild4ShortName} ${x.posMasterChild.posMasterNo}` - : x.posMasterChild != null && x?.posMasterChild?.orgChild3 != null - ? `${x.posMasterChild.orgChild3.orgChild3ShortName} ${x.posMasterChild.posMasterNo}` - : x.posMasterChild != null && x?.posMasterChild?.orgChild2 != null - ? `${x.posMasterChild.orgChild2.orgChild2ShortName} ${x.posMasterChild.posMasterNo}` - : x.posMasterChild != null && x?.posMasterChild?.orgChild1 != null - ? `${x.posMasterChild.orgChild1.orgChild1ShortName} ${x.posMasterChild.posMasterNo}` - : x.posMasterChild != null && x?.posMasterChild?.orgRoot != null - ? `${x.posMasterChild.orgRoot.orgRootShortName} ${x.posMasterChild.posMasterNo}` - : null; + [ + x.posMasterChild?.orgChild4?.orgChild4ShortName, + x.posMasterChild?.orgChild3?.orgChild3ShortName, + x.posMasterChild?.orgChild2?.orgChild2ShortName, + x.posMasterChild?.orgChild1?.orgChild1ShortName, + x.posMasterChild?.orgRoot?.orgRootShortName, + ].find((name) => !!name) && x.posMasterChild?.posMasterNo + ? `${[ + x.posMasterChild?.orgChild4?.orgChild4ShortName, + x.posMasterChild?.orgChild3?.orgChild3ShortName, + x.posMasterChild?.orgChild2?.orgChild2ShortName, + x.posMasterChild?.orgChild1?.orgChild1ShortName, + x.posMasterChild?.orgRoot?.orgRootShortName, + ].find((name) => !!name)} ${x.posMasterChild.posMasterNo}` + : x.posMasterChild?.posMasterNo || null; + const orgShortNameAct = + [ + x.posMaster?.orgChild4?.orgChild4ShortName, + x.posMaster?.orgChild3?.orgChild3ShortName, + x.posMaster?.orgChild2?.orgChild2ShortName, + x.posMaster?.orgChild1?.orgChild1ShortName, + x.posMaster?.orgRoot?.orgRootShortName, + ].find((name) => !!name) || ""; + const posMasterNoAct = + orgShortNameAct && x.posMaster?.posMasterNo + ? `${orgShortNameAct} ${x.posMaster.posMasterNo}` + : x.posMaster?.posMasterNo || null; const position = x.posMasterChild.positions.filter((x) => x.positionIsSelected == true).length > 0 ? x.posMasterChild.positions.filter((x) => x.positionIsSelected == true)[0] @@ -494,6 +521,7 @@ export class PosMasterActController extends Controller { return { id: x.id, posMasterNo: posMasterNo, + posMasterNoAct: posMasterNoAct, positionName: position?.positionName || null, posType: position?.posType?.posTypeName || null, posLevel: position?.posLevel?.posLevelName || null,