Creating and posting Ledger Journal via code

static void InsertLedgerJournal(Args _args)
{
    LedgerJournalName           ledgerJournalName;
    LedgerJournalTable          ledgerJournalTable;
    LedgerJournalTrans          ledgerJournalTrans;
    LedgerJournalCheckPost      ledgerJournalCheckPost;
    NumberSeq                   numberSeq;
    ;
    ttsbegin;
    // Find LedgerJournalname Record
    select firstonly   ledgerJournalName where ledgerJournalname.JournalType == LedgerJournalType::Daily;
    //Create Ledger Journal Table
    ledgerJournalTable.JournalName      = ledgerJournalName.JournalName ;
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.Name             = "Daily Trans";
    ledgerJournalTable.insert();
    numberSeq                           = NumberSeq::newGetVoucherFromCode(ledgerJournalTable.VoucherSeries);
    ledgerJournalTrans.Voucher          = numberSeq.voucher();
    //Create Transaction Line
    ledgerJournalTrans.JournalNum       = ledgerjournalName.JournalName;
    ledgerJournalTrans.CurrencyCode     = 'EUR';
    ledgerJournalTrans.ExchRate         = Currency::exchRate(ledgerJournalTrans.CurrencyCode);
    ledgerJournalTrans.AccountNum       = '140567';
    ledgerJournalTrans.AccountType      = ledgerJournalACType::Ledger;
    ledgerJournalTrans.AmountCurDebit   = 102.00;
    ledgerJournalTrans.TransDate        = today();
    ledgerJournalTrans.Txt              = 'good Product';
    ledgerJournalTrans.OffsetAccount    = '140567';
    ledgerJournalTrans.insert();
    info(strfmt('Journal Id: %1',ledgerJournalTable.JournalNum));
    // Post Journal
    ledgerJournalCheckPost              = ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournaltable,Noyes::Yes);
    LedgerJournalCheckPost.run();
}

No comments:

Post a Comment