Create Inventory Adjustment Journal d365fo x++
Create Inventory Adjustment Journal d365fo x++
Code:
public void processOperation(JSInvADJJournalCreationContract _contract)
{
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
GroupType GroupType = _contract.paramGroupType();
InventLocationId Warehouse = _contract.paramInventLocationId();
// Create journal table
inventJournalTable = JSInvADJJournalCreationService::createJournalTable();
if(inventJournalTable)
{
// Initialize journal trans
inventJournalTrans = JSInvADJJournalCreationService::createLines(GroupType, Warehouse, inventJournalTable);
info(strFmt("INV Adjustment JOURNAL CREATED %1", INVENTJOURNALTABLE.JournalId));
// Post Inventory journal
JSInvADJJournalCreationService::postInventTableJournal(inventJournalTable);
}
}private static InventJournalTable createJournalTable()
{
INVENTJOURNALTABLE INVENTJOURNALTABLE;
InventJournalNameId inventJournalName;
// Create INV JOURNAL HEADER
ttsbegin;
INVENTJOURNALTABLE.clear();
inventJournalName = InventJournalName::standardJournalName(InventJournalType::LossProfit);
inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName));
INVENTJOURNALTABLE.Description = "Inventory Adjustment Journal";
INVENTJOURNALTABLE.SystemBlocked = true;
INVENTJOURNALTABLE.insert();
ttscommit;
return inventJournalTable;
}private static InventJournalTrans createLines(GroupType GroupType, InventLocationId Warehouse, InventJournalTable inventJournalTable) { InventJournalTrans InventJournalTrans; InventSum InventSum; InventDim InventDim; InventTable InventTable; InventItemGroupItem InventItemGroupItem; InventItemGroup InventItemGroup; while SELECT * from InventSum JOIN InventDim WHERE InventSum.InventDimId == InventDim.inventDimId JOIN InventTable WHERE InventSum.ItemId == InventTable.ItemId join InventItemGroupItem WHERE InventItemGroupItem.ItemDataAreaId == InventTable.dataAreaId && InventItemGroupItem.ItemId == InventTable.ItemId join InventItemGroup WHERE InventItemGroupItem.ItemGroupDataAreaId == InventItemGroup.dataAreaId && InventItemGroupItem.ItemGroupId == InventItemGroup.ItemGroupId && InventSum.PhysicalInvent != 0 &&InventSum.Closed == 0 && InventItemGroup.groupType == GroupType && InventDim.InventLocationId == Warehouse { ttsbegin; inventJournalTrans.clear(); inventJournalTrans.initFromInventJournalTable(inventJournalTable); inventJournalTrans.initFromInventTable(InventTable::find(InventSum.ItemId)); InventJournalTrans.JournalType = InventJournalType::LossProfit; inventJournalTrans.Qty = -InventSum.PhysicalInvent; inventJournalTrans.TransDate = SystemDateget(); inventJournalTrans.InventDimId = InventDim::findOrCreate(InventDim).inventDimId; inventJournalTrans.insert(); ttscommit; } return InventJournalTrans; }public static void postInventTableJournal(InventJournalTable _inventJournalTable) { JournalCheckPost journalCheckPost; journalCheckPost = inventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Post ,_inventJournalTable); journalCheckPost.parmThrowCheckFailed(true); journalCheckPost.parmShowInfoResult(true); journalCheckPost.run(); }
Comments
Post a Comment