Sunday, May 28, 2017

Get Sales Agreement Price Without standard method in AX

Public Price GetSalesAgreementPrice(ItemId          itemRelation,
                                    CustAccount     accountRelation,
                                    InventdimId     dimId = "",
                                    PriceType       relation =  PriceType::PriceSales
                                    )
{
    PriceDiscTable      priceDiscTable;
    ;
    if(!dimId)
    {
        priceDiscTable.clear();
        select * from  priceDiscTable
                    where priceDiscTable.Relation  == relation               
                            && priceDiscTable.ItemCode == TableGroupAll::Table
                                && priceDiscTable.ItemRelation       == itemRelation
                                    && priceDiscTable.AccountCode ==  TableGroupAll::All;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation          == relation
                    && priceDiscTable.AccountCode        == TableGroupAll::Table 
                        && priceDiscTable.AccountRelation    == accountRelation
                            &&  priceDiscTable.ItemCode           == TableGroupAll::Table
                                && priceDiscTable.ItemRelation       == itemRelation;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::All
                        && priceDiscTable.AccountCode ==  TableGroupAll::Table
                            && priceDiscTable.AccountRelation    == accountRelation ;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::Table
                        && priceDiscTable.AccountRelation    == CustTable::find(accountRelation).CustGroup
                            && priceDiscTable.AccountCode ==  TableGroupAll::GroupId
                                && priceDiscTable.ItemRelation       == itemRelation;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::All
                        && priceDiscTable.AccountRelation    == CustTable::find(accountRelation).CustGroup
                            && priceDiscTable.AccountCode ==  TableGroupAll::GroupId ;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::GroupId
                        && priceDiscTable.AccountRelation    == CustTable::find(accountRelation).CustGroup
                            && priceDiscTable.AccountCode ==  TableGroupAll::GroupId
                                && priceDiscTable.ItemRelation       == InventTable::find(itemRelation).itemGroupId();
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }

    }
    else
    {
        priceDiscTable.clear();
        select * from  priceDiscTable
                    where priceDiscTable.Relation  == relation               
                            && priceDiscTable.ItemCode == TableGroupAll::Table
                                && priceDiscTable.ItemRelation       == itemRelation
                                    && priceDiscTable.AccountCode ==  TableGroupAll::All
                                        && priceDiscTable.InventDimId == dimId;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation          == relation
                    && priceDiscTable.AccountCode        == TableGroupAll::Table 
                        && priceDiscTable.AccountRelation    == accountRelation
                            &&  priceDiscTable.ItemCode           == TableGroupAll::Table
                                && priceDiscTable.ItemRelation       == itemRelation
                                    && priceDiscTable.InventDimId == dimId;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::All
                        && priceDiscTable.AccountCode ==  TableGroupAll::Table
                            && priceDiscTable.AccountRelation    == accountRelation
                                && priceDiscTable.InventDimId == dimId;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::Table
                        && priceDiscTable.AccountRelation    == CustTable::find(accountRelation).CustGroup
                            && priceDiscTable.AccountCode ==  TableGroupAll::GroupId
                                && priceDiscTable.ItemRelation       == itemRelation
                                    && priceDiscTable.InventDimId == dimId;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::All
                        && priceDiscTable.AccountRelation    == CustTable::find(accountRelation).CustGroup
                            && priceDiscTable.AccountCode ==  TableGroupAll::GroupId
                                && priceDiscTable.InventDimId == dimId;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
        priceDiscTable.clear();
        select * from  priceDiscTable
                where priceDiscTable.Relation           == relation
                    && priceDiscTable.ItemCode           == TableGroupAll::GroupId
                        && priceDiscTable.AccountRelation    == CustTable::find(accountRelation).CustGroup
                            && priceDiscTable.AccountCode ==  TableGroupAll::GroupId
                                && priceDiscTable.ItemRelation       == InventTable::find(itemRelation).itemGroupId()
                                    && priceDiscTable.InventDimId == dimId;
        if (priceDiscTable)
        {
            return priceDiscTable.Amount;
        }
    }
    return 0;
}

No comments:

Post a Comment

Copy Markup charges while posting purchase invoice using X++

 Copy Markup charges while posting purchase invoice using X++ Class: Important: Code logic is just for Reference.  New class => Duplicate...