Wednesday, July 15, 2015

Inventory Marking Functionality x++ Batch in Ax 2012

// Inventory Marking Functionality in X++ for All Transaction:

 Create New Batch Class , Extends RunBaseBatch

public void InventAutoMarkingRec()
{
    //InventTransOrigin InventTransOrigin,InventTransOriginL;
    InventTrans InventTrans,InventTransL;
    InventTransOriginId receiptInventTransOriginId;
    CostAmountValue CostAmountValue1,CostAmountValue2;

   while select forupdate InventTransOrigin
                    where InventTransOrigin.ReferenceId == ‘Reference Id’
            join InventTrans where InventTransOrigin.RecId == InventTrans.InventTransOrigin
                     && InventTransOrigin.ReferenceCategory == inventtranstype::InventTransaction
                            && InventTrans.StatusReceipt ==StatusReceipt::Purchased
                                //&& (InventTransOrigin.itemid == '9696'||InventTransOrigin.itemid == '9697')
    {
        //qtyToMark = InventTrans.Qty;
       // inventDim        = InventTrans.inventDim();
      while  select forupdate InventTransOriginL
                                where InventTransOriginL.ReferenceId == ‘Reference Id’

                    join InventTransL where InventTransOriginL.RecId == InventTransL.InventTransOrigin
                                && InventTransOriginL.ReferenceCategory == inventtranstype::InventTransaction
                                    && InventTransL.StatusIssue == StatusIssue::Sold
                                        && InventTransL.Qty * -1 == InventTrans.Qty
                                            // && InventTransOrigin.itemid ==InventTransOriginL.itemid
                                            //&& InventTrans.CostAmountPosted == InventTransL.CostAmountPosted *-1
                                            //&& InventTransOrigin.itemid =='1004'
            {
                CostAmountValue1=  InventTrans.CostAmountPosted;
                CostAmountValue2=  InventTransL.CostAmountPosted * -1;
                if(CostAmountValue1 == CostAmountValue2)
                {

                    this.AdremTek_San_InvMarkAuto(InventTransOriginL.InventTransId,InventTransOrigin.InventTransId,InventTrans.Qty);
                    info(strFmt("%1 -Lot Id %2 - Ref Lot %3",InventTransOrigin.ItemId,InventTransOriginL.InventTransId,InventTransOrigin.InventTransId));
                }
            }
     }
}


void Adt_San_InvMarkAuto(InventTransId _issueInventTransId,InventTransId _receiveInventTransId,InventQty _qty)
{
    InventTrans issueInventTrans;
    TmpInventTransMark tmpInventTransMask;
    Map mapMarkNow;
    container con;
    real qty;
    Map mapTmp;
    MapEnumerator mapEnumerator;

    //for Issue Lot Id
    InventTransOriginId issueInventTransOriginId =
        InventTransOrigin::findByInventTransId(_issueInventTransId).RecId;
    //For ReceiptL  Lot Id
    InventTransOriginId receiptInventTransOriginId =
        InventTransOrigin::findByInventTransId(_receiveInventTransId).RecId;
    InventQty qtyToMark = _qty; // Qty Need to Mark

    ttsBegin;

    issueInventTrans = InventTrans::findByInventTransOrigin(issueInventTransOriginId);

    [con, qty] = TmpInventTransMark::packTmpMark(InventTransOrigin::find(issueInventTransOriginId),issueInventTrans.inventDim(),issueInventTrans.Qty);

    mapTmp = Map::create(con);
    mapEnumerator = mapTmp.getEnumerator();
    while (mapEnumerator.moveNext())
    {
        tmpInventTransMask = mapEnumerator.currentValue();

        if (tmpInventTransMask.InventTransOrigin == receiptInventTransOriginId)
        {
            tmpInventTransMask.QtyMarkNow = qtyToMark;
            tmpInventTransMask.QtyRemain -= tmpInventTransMask.QtyMarkNow;
            mapMarkNow = new Map(Types::Int64, Types::Record);
            mapMarkNow.insert(tmpInventTransMask.RecId, tmpInventTransMask);

            TmpInventTransMark::updateTmpMark(
                issueInventTransOriginId,
                issueInventTrans.inventDim(),
                -qtyToMark,
                mapMarkNow.pack());

            break;
        }
    }

    ttsCommit;
}


No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...