31 January 2012

Inventory Transfer Journal code in ax 2009 / create and post inventory Transfer journal

//following class to post the auto inventory journal posting create object to this class and //pass the record for required values
class ItemTransfer
{
ItemsRequest itemsRequest;
InventJournalTable inventJournalTable;
InventJournalTrans inventjournalTrans;
}
______________
void new(ItemsRequest localItemRequest)
{
FormDataSource fds;
;

fds = localItemRequest.dataSource();
// populates the inventJournalTable table
inventJournalTable = this.populateInventJournalTable();

itemsRequest = fds.getFirst();
while(itemsRequest)
{
// populates the inventJournalTrans table
inventjournalTrans = this.populateInventJournalTrans(inventJournalTable.JournalId);

itemsRequest = fds.getNext();
}
this.createAndPostJournal();// to post the journal
}
_______________
///
/// Populates the buffer of the InventJournalTable table data.
///

///
/// Buffer of the InventJournalTable table.
///

Public InventJournalTable populateInventJournalTable()
{
InventJournalTable journalTable;
InventJournalTableData journalTableData;

journalTable.clear();
journalTable.JournalNameId = ProjParameters::find().TransferJournal;
journalTableData = JournalTableData::newTable(journalTable);
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.Reservation = ItemReservation::Automatic;
journalTable.JournalType = InventJournalType::Transfer;
journalTableData.initFromJournalName(journalTableData.JournalStatic().findJournalName(journalTable.journalNameId));
//journalTable.Description = InventDescription.valueStr();
journalTable.insert();

return journalTable;
}
______________
public InventJournalTrans populateInventJournalTrans(InventJournalId _InventJournalId)
{
InventJournalTrans localInventJournalTrans;
InventSum inventSum;
InventQty inventQty;
InventDim fromInventDim,toInventDim;
InventJournalTransData journalTransData;
;

localInventJournalTrans.JournalId = _InventJournalId;
localInventJournalTrans.JournalType = InventJournalType::Transfer;
localInventJournalTrans.TransDate = itemsRequest.TransDate;//systemdateget();
localInventJournalTrans.ItemId = itemsRequest.ItemId;//inventSum.ItemId;
localInventJournalTrans.Qty = itemsRequest.Qty;//InventQty.realValue();

// Dimensions from which the transfer performs
fromInventDim.InventSiteId = itemsRequest.FromSite;
fromInventDim.InventLocationId = itemsRequest.FromWarehouse;

/*select firstonly inventSum where inventSum.Itemid == itemsRequest.itemid;
localInventJournalTrans.InventDimid = InventDim::find(inventSum.InventDimId).inventDimId;*/

localInventJournalTrans.InventDimid = InventDim::findOrCreate(fromInventDim).inventDimId;
localInventJournalTrans.initFromInventTable(InventTable::find(itemsRequest.ItemId), False, False);

// Dimensions To which the transfer performs
toInventDim.InventSiteId = itemsRequest.ToSite;
toInventDim.InventLocationId = itemsRequest.ToWarehouse;

toInventDim.inventSiteId = itemsRequest.ToSite;//InventSite.valueStr();
toInventDim.InventLocationId = itemsRequest.ToWarehouse;//InventWareHouse.valueStr();
localInventJournalTrans.ToInventDimId = InventDim::findOrCreate(toInventDim).inventDimId;
localInventJournalTrans.insert();

return localInventJournalTrans;
}
_______________
///
/// Creates and posts the Inventory Transfer Journal.
///

///
/// If there is any exception then the Inventory Journal data is deleted.
///

public void createAndPostJournal()
{

JournalCheckPost journalCheckPost;
;

/*ttsbegin;
//populates the inventJournalTable table
//inventJournalTable = this.populateInventJournalTable();
//populates the inventJournalTrans table
inventjournalTrans = this.populateInventJournalTrans(inventJournalTable.JournalId);
ttsCommit;*/

if (BOX::yesNo('Do you want to post the Journal ? ', DialogButton::Yes) == DialogButton::Yes)
{
// Call the static method to create the journal check post class
if(InventJournalCheckpost::newPostJournal(inventJournalTable).validate())
journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);

if(journalCheckPost.validate())
{
try
{
journalCheckPost.run();
}
catch
{
// Deletes the InventJournalTable table, the InventJournalTrans will auto delete because of the Delete actions.
InventJournalTable.delete();
}
}
}
}

__

2 comments:

  1. And in case someone wonders, here is a sample of how to post a transfer journal via AIF in 2012 R2: http://www.discipline.org.ua/eng/articles/Transfer_journal_posting_web_service_AIF_AX_2012R2.htm

    ReplyDelete
  2. Good one. Keep it up.

    This is axapta ERP blog for Technical and functional fields and includes Microsoft Dynamics Axapta tutorials and Dynamics Axapta Coverage. This blog also contains x++ code help for Ax developer and solution of technical and functional daily issues. This blog is specific for Microsoft dynamics programming. Enterprise portal, SharePoint services, business connectors and Enterprise Resource Planning applications and sql database.It will help to get Microsoft Business Solutions.


    axapta ERP blog

    ReplyDelete

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...