X++ code for Invent Marking in AX 2012 R3
public static void RBInventMarking(purchLine _purchLine)
{
RecId issueInventTransOriginId,receiptInventTransOriginId;
InventQty qtyToMark;
InventTrans issueInventTrans;
TmpInventTransMark tmpInventTransMask;
Map mapMarkNow;
container con;
real qty;
Map mapTmp;
MapEnumerator mapEnumerator;
PurchLine prePurchLine;
select firstOnly InventTransId from prePurchLine
where prePurchLine.PurchId == _purchLine.PurchId
&& prePurchLine.ItemId == _purchLine.ItemId;
if (_purchLine.PurchQty < 0 && _purchLine.PurchPrice > prePurchLine.PurchPrice)
{
issueInventTransOriginId =
InventTransOrigin::findByInventTransId(prePurchLine.InventTransId).RecId;
receiptInventTransOriginId =
InventTransOrigin::findByInventTransId(_purchLine.InventTransId).RecId;
qtyToMark = -1; // specify the qty as per your requirement
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