Tuesday, November 11, 2025

Ledger dimension

  public void mapEntityToDataSource(DataEntityRuntimeContext entityCtxDataEntityDataSourceRuntimeContext dataSourceCtx) 

    { 

        HcmWorker       hcmWorker; 

        MainAccountNum  mainAccountId; 

        container con; 

        LedgerJournalTrans  journalTrans; 

        str Sector,SubSector1,SubSector2; 

  

        select hcmWorker where hcmWorker.PersonnelNumber == this.Approver ; 

        

        this.EY_Approver = hcmWorker.RecId; 

  

        if (entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert 

            || entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Update) 

        { 

            // When editing through the entity, always delay tax calculation to avoid 

            // a O(n^2) tax calculation while importing multiple lines. The journal will 

            // automatically calculate taxes later at posting time or when necessary. 

            this.DelayTaxCalculation = NoYes::Yes; 

  

            switch (dataSourceCtx.name()) 

            { 

                case dataEntityDataSourceStr(EY_LedgerJournalEntityLedgerJournalTable): 

                    dataSourceCtx.setBuffer(EY_LedgerJournalEntityBase::findOrCreateLedgerJournalHeader(this)); 

  

                    break; 

            } 

  

            super(entityCtxdataSourceCtx); 

            if (entityCtx.getDatabaseOperation() == DataEntityDatabaseOperation::Insert) 

            { 

                mainAccountId = this.AccountDisplayValue; 

                if (dataSourceCtx.name() ==dataEntityDataSourceStr(EY_LedgerJournalEntity,LedgerJournalTrans) ) 

                { 

                    journalTrans = dataSourceCtx.getBuffer(); 

                    journalTrans.LedgerDimension = this.getLedgerDimensionStructure(this.AccountDisplayValue); 

                if(this.OffsetAccountDisplayValue) 

                { 

                    journalTrans.OffsetLedgerDimension = this.getLedgerDimensionStructure(this.OffsetAccountDisplayValue); 

  

                } 

                else 

                { 

                    this.OffsetAccountDisplayValue = ""; 

                } 

                } 

  

  

            } 

        } 

    } 

 

 

 

 

public RecId getLedgerDimensionStructure(MainAccountNum    _mainAccount) 

    { 

        container displayValues; 

  

        DimensionAttributeValueSetStorage dimStorage; 

        Counter i; 

        str dimensionValue; 

        RefRecId defaultdim; 

        DirPartyName dimensionValue1; 

        str Sector,SubSector1,SubSector2; 

         

        dimStorage = DimensionAttributeValueSetStorage::find(LedgerJournalName::find(this.JournalName).DefaultDimension); 

  

        for (i=1 ; i<= dimStorage.elements() ; i++) 

        { 

                 

                //str name = dimStorage.getAttributeByIndex(i); 

                if (DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name =="Sector") 

                { 

  

                    Sector = dimStorage.getDisplayValueByIndex(i); 

                     

                } 

                if (DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name =="SubSector1") 

                { 

  

                    SubSector1 = dimStorage.getDisplayValueByIndex(i); 

                     

                } 

                if (DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name =="SubSector2") 

                { 

  

                    SubSector2 = dimStorage.getDisplayValueByIndex(i); 

                     

                } 

             

        } 

         

        RecId ledger = this.getLedgerAccount(Sector,SubSector1,SubSector2,_mainAccount); 

        return ledger; 

  

    } 

 

  public RecId getLedgerAccount( str _sector, str _subsector1,str _subsector2, MainAccountNum _mainAccount ) 

    { 

        RecId ledgerAccount ; 

  

        container                                                conData; 

        int                                                      hierarchyCount; 

        int                                                      hierarchyIdx; 

        LedgerRecId                                              ledgerRecId; 

        MainAccount                                              mainAccount; 

        RefRecId                                                 recordvalue; 

        DimensionAttribute                                       dimensionAttribute; 

        DimensionAttributeValue                                  dimensionAttributeValue; 

        DimensionSetSegmentName                                  DimensionSet; 

        DimensionStorage                                         dimStorage; 

        DimensionAttributeValueContract                          ValueContract; 

        LedgerAccountContract                                    LedgerAccountContract; 

        DimensionAttributeValueCombination                       dimensionAttributeValueCombination; 

        List                                                     valueContracts; 

  

        #define.MainAccount('MainAccount') 

        #define.Sector('Sector') 

        #define.SubSector1('SubSector1') 

        #define.SubSector2('SubSector2') 

        #define.Intercompany('Intercompany') 

        #define.Customer('Customer') 

        #define.Language('en-gb') 

  

  

        LedgerAccountContract   = new LedgerAccountContract(); 

        valueContracts          = new List(Types::Class); 

  

        conData =[_mainAccount]; 

  

  

        mainAccount     =   MainAccount::findByMainAccountId(_mainAccount); 

        recordvalue     =   DimensionHierarchy::getAccountStructure(mainAccount.RecId,Ledger::current()); 

        hierarchyCount  =   DimensionHierarchy::getLevelCount(recordvalue); 

        DimensionSet    =   DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue); 

  

        if (recordvalue) 

        { 

            for(hierarchyIdx = 1;hierarchyIdx<=hierarchyCount;hierarchyIdx++) 

            { 

  

                if(hierarchyIdx == 1) 

            continue; 

  

                dimensionAttribute = DimensionAttribute::findByLocalizedName(DimensionSet[hierarchyIdx],false,#Language); 

  

                

                

                if (dimensionAttribute.Name == "Sector") 

                { 

                    conData += [_sector]; 

                } 

                if (dimensionAttribute.Name == "SubSector1") 

                { 

                    conData += [_subsector1]; 

                } 

                if (dimensionAttribute.Name == "SubSector2") 

                { 

                    conData += [_subsector2]; 

                } 

  

                if(dimensionAttribute) 

                { 

                    dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(conData,hierarchyIdx)); 

  

                    if(dimensionAttributeValue) 

                    { 

  

                        ValueContract = new DimensionAttributeValueContract(); 

                        ValueContract.parmName(dimensionAttribute.Name) ; 

                        ValueContract.parmValue(dimensionAttributeValue.CachedDisplayValue); 

                        valueContracts.addEnd(ValueContract); 

                    } 

                } 

  

            } 

  

            LedgerAccountContract.parmMainAccount(_mainAccount); 

            LedgerAccountContract.parmValues(valueContracts); 

  

            dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract); 

            dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save()); 

            ledgerAccount = dimensionAttributeValueCombination.RecId; 

        } 

        

  

  

        return  ledgerAccount; 

  

         

    } 

 

No comments:

Post a Comment