Create and Post GL journal - with Settlement marking

Hi,

The below code is used to create and post the GL journal and also do the marking for the settlement.

static void CreateGLJournalPost_withSettlement(Args _args)
{

AxLedgerJournalTable journalTable; // class
AxLedgerJournalTrans journalTrans; // class
container acctPattern;
container offSetAcctPattern;
LedgerJournalTable ledgerJournalTable; // table
ledgerJournalCheckPost ledgerJournalCheckPost;// table

void markSettlement(ledgerJournalTrans _ledgerJournalTrans,
                    RefRecId _vendInvoiceJourRecId) //settlement voucher's recId
{
CustVendOpenTransManager manager;
VendTransOpen vendTransOpen;
ExchangeRateHelper exchangeRateHelper;
AmountCur totalSettleAmount;
RefRecId vendTransRecid;
;

vendTransRecid = vendInvoiceJour::findRecId(_vendInvoiceJourRecId).vendTrans().RecId;  vendTransOpen = vendTransOpen::findRefId(vendTransRecid); //settlement voucher line -> i.e PO inv voucher's Vendor trans

manager = CustVendOpenTransManager::construct(_ledgerJournalTrans);
manager.updateTransMarked(vendTransOpen, true);


exchangeRateHelper = exchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(_ledgerJournalTrans.Company).RecId),
_ledgerJournalTrans.CurrencyCode);
       

totalSettleAmount = SpecTransManager::getTotalSettleAmountForSpecReference(
_ledgerJournalTrans.Company(),
_ledgerJournalTrans.TableId,
_ledgerJournalTrans.RecId,
_ledgerJournalTrans.CurrencyCode,
_ledgerJournalTrans.Company,
_ledgerJournalTrans.TransDate,
exchangeRateHelper.prepareExchangeRateForStorage(_ledgerJournalTrans.crossrate()));

ttsBegin;
_ledgerJournalTrans.selectForUpdate(true);
_ledgerJournalTrans.AmountCurDebit = abs(totalSettleAmount);
_ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
_ledgerJournalTrans.update();

ttsCommit;

}
; 
journalTable = new AxLedgerJournalTable();
journalTrans = new AxLedgerJournalTrans();

//Journal Name
journalTable.parmJournalName("GenJrn");
journalTable.save();
//Debit line
journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(systemDateGet());
journalTrans.parmCurrencyCode("AED");
journalTrans.parmAmountCurDebit(1200); 

/*journalTrans.parmAccountType(LedgerJournalACType::Ledger); 
acctPattern = ["1101001-Disp","1101001", 1, "Worker","000005"];
journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(acctPattern));*/
journalTrans.parmAccountType(LedgerJournalACType::Vend);
journalTrans.parmLedgerDimension(DimensionStorage::getDynamicAccount("9877",LedgerJournalACType::Vend));
journalTrans.save();


//marking the journal line against PO invoice voucher
markSettlement(journalTrans.ledgerJournalTrans(),
5637176212); // Vend invoice jour recid / settlement voucher



//credit line 1
journalTrans = new AxLedgerJournalTrans();
journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(systemDateGet());
journalTrans.parmCurrencyCode("AED");
journalTrans.parmAmountCurCredit(1200);

journalTrans.parmAccountType(LedgerJournalACType:: Ledger );
acctPattern = ["1121002-Disp","1121002", 1, "Worker","000038"];
journalTrans.parmLedgerDimension(AxdDimensionUtil::getLedgerAccountId(acctPattern));
journalTrans.save();


//Post
ledgerJournalCheckPost = ledgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
ledgerJournalCheckPost.run();


info(strFmt("Journal No. %1.", journalTable.ledgerJournalTable().JournalNum));

} 

Comments

  1. Please give detailed comments so that beginners can understand it.

    ReplyDelete

Post a Comment

Popular posts from this blog

x++ code to Generate cheque for vendor payment journal

Import Procurement Hierarchy / Categories with out code in ax 2012

Copy favorites From one user to another user - Ax 2012