Project Item Journal D365FO using X++
Project item journal is used to
do 2 things in a single step:
1. remove quantity of an item from inventory (just
like a movement journal does)
2. Record the cost of the item into a project (so
create and post a project transaction)
The GL impact of that journal
is:
credit: inventory balance
debit: project item expense (as defined in the
project module, Ledger Posting Setup)
Using below code you can create the
project item journal.
public void createProjectItemJournal()
{
InventDim inventDim;
InventJournalName InventJournalName;
InventJournalTable inventJournalTable;
ProjectJournalContract _projectJournal;
InventJournalTableData journalTableData
= JournalTableData::newTable(inventJournalTable);
InventTable inventTable;
ProjTable projTable;
AWCFieldServIntegrtionMainAccount ServiceOffsetAccount=this.findServiceMainAccount(AWCFieldServiceIntegrationType::ProjectItem);
ProjectJournalTransContract journalTransContract;
if(_projectJournal.getProjectJournalTransCount()==0)
{
return;
}
journalTransContract
= _projectJournal.getProjectJournalTrans(0);
select projTable
where projTable.ProjId==journalTransContract.ProjectId;
select inventTable
where inventTable.itemId==journalTransContract.ItemId;
select InventJournalName
where InventJournalName.JournalType==InventJournalType::project
&&
InventJournalName.isFSJournal==NoYes::Yes;
inventJournalTable.JournalId
= journalTableData.nextJournalId();
inventJournalTable.JournalType=InventJournalType::project;
journalTableData.initFromJournalName(InventJournalName);
inventJournalTable.insert();
InventJournalTrans inventJournalTrans;
InventJournalTransData journalTransData
= journalTableData.journalStatic().newJournalTransData(inventJournalTrans,
journalTableData);
journalTransData.initFromJournalTable();
inventJournalTrans.TransDate =
today();
inventJournalTrans.ProjId =journalTransContract.ProjectId;
inventJournalTrans.ProjCategoryId =
journalTransContract.ProjectCateId;
inventJournalTrans.initFromProjTable(projTable);
inventJournalTrans.initFromInventTable(inventTable);
inventJournalTrans.Qty =
journalTransContract.QtyUsed;
inventJournalTrans.PriceUnit =
journalTransContract.CostPrice;
inventJournalTrans.ProjUnitID =
journalTransContract.Unit;
inventJournalTrans.Worker = HcmWorkerLookup::currentWorker();
inventJournalTrans.LedgerDimension = LedgerDefaultAccountHelper::getDefaultAccountFromMainAccountRecId(MainAccount::findByMainAccountId(ServiceOffsetAccount.MainAccountId).RecId);
inventJournalTrans.activityNumberModified();
inventDim.clear();
inventDim.InventSiteId =
journalTransContract.Site;
inventDim.InventLocationId
=journalTransContract.Location;
inventDim.wMSLocationId
= journalTransContract.Warehouse;
inventJournalTrans.InventDimId
= inventDim::findOrCreate(inventDim).inventDimId;
//other fields
journalTransData.create();
}
Comments
Post a Comment