Thursday, January 10, 2013

Ax 2012 LedgerJournalPosting

 
static void hks_LedgerJournalPosting(Args _args)
{
    LedgerJournalName          ledgerJournalName;
    LedgerJournalTable         ledgerJournalTable;
    LedgerJournalTrans         ledgerJournalTrans;
    NumberSeq                  numberSeq;
    LedgerJournalCheckPost     ledgerJournalCheckPost; 
    container                  ledgerDim;
;


    select ledgerJournalName where ledgerJournalName.JournalType == 
    LedgerJournalType::Daily && ledgerJournalName.JournalName == "GenJrn"; 

    ledgerJournalTable.JournalName = ledgerJournalName.JournalName; 
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.insert(); 

    //NumberSequenceTable::find(ledgerJournalTable.NumberSequenceTable).NumberSequence
    numberSeq = numberSeq::newGetVoucherFromCode(NumberSequenceTable::find           
    (ledgerJournalName.NumberSequenceTable).NumberSequence, 
    NumberSeqScopeFactory::createDefaultScope(),true);

    ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum; 
    ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
    ledgerDim = ["Goodwill","1110000"];
    ledgerJournalTrans.LedgerDimension = AxdDimensionUtil::getLedgerAccountId(ledgerDim);
    ledgerJournalTrans.CurrencyCode = "USD";
    ledgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.CurrencyCode);
    ledgerJournalTrans.AmountCurDebit = 10;
    ledgerJournalTrans.TransDate = today();
    ledgerJournalTrans.Txt = "hks test";
    ledgerDim = ["Petty Cash","110180"];
    ledgerJournalTrans.OffsetLedgerDimension = AxdDimensionUtil::getLedgerAccountId
                                               (ledgerDim);
    ledgerJournalTrans.Voucher = numberSeq.voucher();
    ledgerJournalTrans.insert();
    numberSeq.used();

    info(ledgerJournalTable.JournalNum);

    ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable
                             (ledgerJournalTable,true);
    ledgerJournalCheckPost.run();

}