从贸易协议更新购买行中的购买价格

时间:2016-10-24 15:59:29

标签: microsoft-dynamics dynamics-ax-2012 x++ dynamics-ax-2012-r3

我必须更新过去创建的采购订单。要求是通过应用在创建采购订单后在系统中创建的新贸易协议来更新采购价格。我写了一段代码,但贸易协议中的组合是无穷无尽的。

有没有更快的方法来获得组合活跃的价格?

谢谢

public static PriceDiscTable checkPriceDiscTable(PriceDiscAccountRelation    _accountRelation,
                                                 PriceDiscItemRelation       _itemRelation,
                                                 InventLocationId            _inventLocationId)
{
    RecId              priceDiscTableRec;
    PriceDiscTable      priceDiscTable;
    TableGroupAll               accountCode, ItemCode;
    PriceDiscAccountRelation    accountRelation;
    PriceDiscItemRelation       itemRelation;

    int     totalcases = 3;
    int     prioritycase = 0;

    while(prioritycase < totalcases)
    {
        switch (priorityCase)
        {
            case 0:
                accountCode         = TableGroupAll::Table;
                accountRelation     = _accountRelation;
                itemCode            = TableGroupAll::Table;
                itemRelation        = _itemRelation;

                priceDiscTableRec = DAL_PriceFromAgrement::findPriceDiscTable(accountCode, accountRelation,
                                                                                itemCode, itemRelation, _inventLocationId);
                priceDiscTable = PriceDiscTable::findRecId(priceDiscTableRec);
                if(priceDiscTable.recId)
                {
                    return priceDiscTable;
                }
                break;

            case 1:
                accountCode         = TableGroupAll::GroupId;
                accountRelation     = _accountRelation;
                itemCode            = TableGroupAll::Table;
                itemRelation        = _itemRelation;

                priceDiscTableRec = DAL_PriceFromAgrement::findPriceDiscTable(accountCode, accountRelation,
                                                                                itemCode, itemRelation, _inventLocationId);
                if(priceDiscTable.recId)
                {
                    return priceDiscTable;
                }
                break;

            case 2:
                accountCode         = TableGroupAll::All;
                accountRelation     = "";
                itemCode            = TableGroupAll::Table;
                itemRelation        = _itemRelation;

                priceDiscTableRec = DAL_PriceFromAgrement::findPriceDiscTable(accountCode, accountRelation,
                                                                                itemCode, itemRelation, _inventLocationId);
                if(priceDiscTable.recId)
                {
                    return priceDiscTable;
                }
                break;
        }
        prioritycase++;
    }

    return priceDiscTable;
}

1 个答案:

答案 0 :(得分:0)

助手类已经为你做了这个。

班级名称为PriceDisc

查看purchPriceAgreement上的InventTable方法。

...
vendTable= VendTable::find(_accountNum);

priceDisc = new PriceDisc(ModuleInventPurchSales::Purch,
                              this.ItemId,
                              _inventDim,
                              inventTableModule.UnitId,
                              _priceDate,
                              _qty,
                              vendTable.AccountNum,
                              _currencyCode);

    if (!priceDisc.findPrice(vendTable.PriceGroup, false))

...

price       = priceDisc.price();
priceMarkup = priceDisc.markup();
priceUnit   = priceDisc.priceUnit();
...
etc