hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Thursday, June 10, 2021

X++ code to get trade agreement price (sales ) based on price group in AX7/D365

     public Real GetPriceRetail(str itemNumber,str size, str color, str style, str channel)

    {

        PriceDisc               priceDisc;

        RetailStoreTable        storeTable;

        CustTable               custtable;

        InventTable             inventTable = InventTable::find(itemNumber);

        UnitOfMeasureSymbol     unitId  = inventTable.inventTableModuleInvent().UnitId;

        Price                   retPrice;

        InventDim               inventDim;

        select firstonly storeTable

            where storeTable.RetailChannelId == channel;

        custtable = CustTable::find(storeTable.DefaultCustAccount);

        InventDim.InventSizeId = size;

        InventDim.InventColorId = color;

        InventDim.InventStyleId = style;

        inventDim = InventDim::findOrCreate(inventDim);

        PriceDiscParameters parameters = PriceDiscParameters::construct();

        parameters.parmModuleType(ModuleInventPurchSales::Sales);

        parameters.parmItemId(itemNumber);

        parameters.parmInventDim(inventDim);

        parameters.parmUnitID(unitId);

        parameters.parmPriceDiscDate(systemDateGet());

        parameters.parmQty(1);

        parameters.parmAccountNum(custtable.AccountNum);

        parameters.parmCurrencyCode(custtable.Currency);

        priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);

        // From Trade agreement

        if (priceDisc.findPrice('Retail')) // clearance ,club price

        {

            retPrice = priceDisc.price();

        }

return retPrice ;

}


  public Price getRRPPrice(salesLine  salesLine)

    {

        PriceDiscTable  priceRetail;

        InventDim     inventDimRetail,inventDim;

        inventDim = InventDim::find(salesLine.InventDimId);

        select firstonly priceRetail

            join inventDimRetail

            where priceRetail.ItemCode == PriceDiscProductCodeType::Table

            && priceRetail.ItemRelation==salesLine.ItemId

            && (priceRetail.FromDate <= DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) || priceRetail.FromDate == Global::DateNull())

            && (priceRetail.ToDate >= DateTimeUtil::getToday(DateTimeUtil::getUserPreferredTimeZone()) || priceRetail.ToDate == Global::DateNull()) 

            && priceRetail.AccountCode == PriceDiscPartyCodeType::GroupId

            && priceRetail.AccountRelation ==  'Retail'

            && inventDimRetail.InventStyleId == inventDim.InventStyleId

            && inventDimRetail.InventColorId == inventDim.InventColorId

            && inventDimRetail.InventSizeId == inventDim.InventSizeId

            && priceRetail.InventDimId == inventDimRetail.inventDimId;


        return priceRetail.Amount;

    }

Wednesday, June 9, 2021

X++ code to get financial dimensions in AX7/D365


public void dimensions(defaultDimension)

{

VendParameters                          vendParameters = VendParameters::find();

DimensionAttribute                      attribute                = DimensionAttribute::findByName(vendParameters.DepartmentDim);

DimensionAttribute                      attributeProfitCentre    = DimensionAttribute::findByName(vendParameters.SiteDim);

MainAccountNum                          mainAccountNum;       

dimensionAttributeValueSetItemView.clear();

select DisplayValue from dimensionAttributeValueSetItemView

     where dimensionAttributeValueSetItemView.DimensionAttributeValueSet == DefaultDimension

        && dimensionAttributeValueSetItemView.DimensionAttribute    == attribute.RecId;

DimensionValue = dimensionAttributeValueSetItemView.DisplayValue;

dimensionAttributeValueSetItemView.clear();

select DisplayValue from dimensionAttributeValueSetItemView

      where dimensionAttributeValueSetItemView.DimensionAttributeValueSet == DefaultDimension

           && dimensionAttributeValueSetItemView.DimensionAttribute  ==  attributeProfitCentre.RecId;

DimensionValueprofitCentre = dimensionAttributeValueSetItemView.DisplayValue;

mainAccountNum = MainAccount::findByMainAccountId(LedgerDimensionFacade::getMainAccountIdFromLedgerDimension(paymode.InterCompanyLedgerDimension)).MainAccountId;

ledgerDim = CreateAndPostVendorJournal::getDimension(mainAccountNum,DimensionValue,DimensionValueprofitCentre);

}

//custom method

    public static RecId getDimension(str _ledgerAccount,DimensionValue _costCentre,DimensionValue _profitCentre)

    {

        //DimensionServiceProvider            DimensionServiceProvider    = new DimensionServiceProvider();

        LedgerAccountContract               LedgerAccountContract       = new LedgerAccountContract();

        DimensionAttributeValueContract     ValueContract;

        List                                ListValueContract = new List(Types::Class);

        dimensionAttributeValueCombination  dimensionAttributeValueCombination;

        DimensionStorage                    dimStorage;

        VendParameters salesParameters = VendParameters::find();

        if(_costCentre)

        {

            ValueContract = new DimensionAttributeValueContract();

            ValueContract.parmName(salesParameters.DepartmentDim);

            ValueContract.parmValue(_costCentre);

            ListValueContract.addEnd(ValueContract);

        }

        if(_profitCentre)

        {

            ValueContract = new DimensionAttributeValueContract();

            ValueContract.parmName(salesParameters.SiteDim);/\                              ValueContract.parmValue(_profitCentre);

            ListValueContract.addEnd(ValueContract);

        }

        LedgerAccountContract.parmMainAccount(_ledgerAccount);

        //LedgerAccountContract.parm

        LedgerAccountContract.parmValues(ListValueContract);

        dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);

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

        return dimensionAttributeValueCombination.RecId;

    }





 

Ledger settlements Automate through code in AX7/D365

 class ledgerSettlementService extends SysOperationServiceBase

{

    public void processOperation()

    {

        GeneralJournalAccountEntry     GeneralJournalAccountEntry,GeneralJournalAccountEntryLoc;

        GeneralJournalEntry            GeneralJournalEntry,GeneralJournalEntryLocal;

        LedgerTransSettlement          ledgerTransSettlement,ledgerTransSettlementloc,ledgerTransSettlementdata;

        LedgerEntryJournal             LedgerEntryJournal,LedgerEntryJournalLocal;

        real balance;

// Getting dimension from parameters

        RefRecId mainAccountRecId = MainAccount::findByMainAccountId(LedgerDimensionFacade::getMainAccountIdFromLedgerDimension(Parameters.WindcaveLedgerDimension)).RecId;


        while SELECT PaymentReference from GeneralJournalAccountEntry

            group by GeneralJournalAccountEntry.PaymentReference

                where GeneralJournalAccountEntry.MainAccount == mainAccountRecId

            JOIN  GeneralJournalEntry

                where  GeneralJournalAccountEntry.GeneralJournalEntry == GeneralJournalEntry.RecId 

                    && GeneralJournalEntry.Ledger == CompanyInfo::find().RecId

                    && GeneralJournalEntry.PostingLayer == CurrentOperationsTax::Current

            OUTER join  LedgerEntryJournal

                where generalJournalEntry.LedgerEntryJournal == LedgerEntryJournal.RecId

                NOTEXISTS join LedgerTransSettlement

                    WHERE GeneralJournalAccountEntry.RecId == LedgerTransSettlement.TransRecId

        {

          //  balance = 0;

            if(!this.balance(GeneralJournalAccountEntry,mainAccountRecId))

            {

                ledgerTransSettlementloc.SettleId = NumberSeq::newGetNum(CompanyInfo::numRefParmId()).num();


                while SELECT  * FROM GeneralJournalAccountEntryLoc

                    where GeneralJournalAccountEntryLoc.MainAccount == mainAccountRecId

                        && GeneralJournalAccountEntryLoc.PaymentReference == GeneralJournalAccountEntry.PaymentReference

                        JOIN  GeneralJournalEntryLocal

                    where  GeneralJournalAccountEntryLoc.GeneralJournalEntry == GeneralJournalEntryLocal.RecId &&

                        GeneralJournalEntryLocal.Ledger == CompanyInfo::find().RecId

                        && GeneralJournalEntryLocal.PostingLayer == 0

                        OUTER join  LedgerEntryJournalLocal

                    where GeneralJournalEntryLocal.LedgerEntryJournal == LedgerEntryJournalLocal.RecId

                        NOTEXISTS join ledgerTransSettlementdata

                    WHERE GeneralJournalAccountEntryLoc.RecId == ledgerTransSettlementdata.TransRecId

                //while select GeneralJournalEntryLoc

                //    where GeneralJournalEntryLoc.PaymentReference == GeneralJournalAccountEntry.PaymentReference

                //     && GeneralJournalEntryLoc.LedgerDimension == T07_TenderParameters::Find().WindcaveLedgerDimension

                {

                    ledgerTransSettlementloc.TransRecId = GeneralJournalAccountEntryLoc.RecId;

                    ledgerTransSettlementloc.insert();

                }

            }

        }


    }


    public real balance(GeneralJournalAccountEntry _generalJournalEntry,RefRecId   mainAccount)

    {

        GeneralJournalAccountEntry     GeneralJournalAccountEntry,GeneralJournalEntryLoc;

        GeneralJournalEntry            GeneralJournalEntry;

        LedgerTransSettlement ledgerTransSettlement,ledgerTransSettlementloc;

        RecordInsertList settlementCollection;

        LedgerEntryJournal LedgerEntryJournal;

        real balance = 0;


        while SELECT  GeneralJournalAccountEntry

                where GeneralJournalAccountEntry.MainAccount == mainAccount

             && GeneralJournalAccountEntry.PaymentReference == _generalJournalEntry.PaymentReference

            JOIN  GeneralJournalEntry

                where  GeneralJournalAccountEntry.GeneralJournalEntry == GeneralJournalEntry.RecId

                    && GeneralJournalEntry.Ledger == CompanyInfo::find().RecId

                    && GeneralJournalEntry.PostingLayer == CurrentOperationsTax::Current

            OUTER join  LedgerEntryJournal

                where generalJournalEntry.LedgerEntryJournal == LedgerEntryJournal.RecId

                NOTEXISTS join LedgerTransSettlement

                    WHERE GeneralJournalAccountEntry.RecId == LedgerTransSettlement.TransRecId

        //while select GeneralJournalEntryLocal

        //    where GeneralJournalEntryLocal.PaymentReference == GeneralJournalEntry.PaymentReference

              //  && GeneralJournalEntryLocal.LedgerDimension == T07_TenderParameters::Find().WindcaveLedgerDimension

        {

            balance += GeneralJournalAccountEntry.AccountingCurrencyAmount;

        }

        return balance;

    }


}