Tuesday, November 27, 2012

Creating a general journal


1. In the AOT, create a new class named LedgerJournalTransData with the
following code:

class LedgerJournalTransData extends JournalTransData
{
}

public void create(boolean _doInsert = false, boolean _initVoucherList = true)
{
    lastLineNum++;
    journalTrans.LineNum = lastLineNum;
    if (journalTableData.journalVoucherNum())
    {
        this.initVoucher(lastVoucher, false, _initVoucherList);
    }
   
    this.addTotal(false, false);
    if (_doInsert)
    {
        journalTrans.doInsert();
    }
    else
    {
        journalTrans.insert();
    }

    if (journalTableData.journalVoucherNum())
    {
        lastVoucher = journalTrans.Voucher;
    }
}


2. Open the LedgerJournalStatic class, and replace its
newJournalTransData() method with the following code:

JournalTransData newJournalTransData(JournalTransMap _journalTrans,
JournalTableData _journalTableData)
{
    return new LedgerJournalTransData(_journalTrans, _journalTableData);
}

3. Double check that the getLedgerDimension() method exists on the
DimensionAttributeValueCombination table. If not, create it as described in the first
recipe in this chapter.

4. Create a new job named LedgerJournalCreate, with the following code:
static void LedgerJournalCreate(Args _args)
{
    LedgerJournalTable jourTable;
    LedgerJournalTrans jourTrans;
    LedgerJournalTableData jourTableData;
    LedgerJournalTransData jourTransData;
    LedgerJournalStatic jourStatic;
    DimensionDynamicAccount ledgerDim;
    DimensionDynamicAccount offsetLedgerDim;
    ttsBegin;
    ledgerDim = DimensionAttributeValueCombination::getLedgerDimension(
    '110180', ['Department', 'CostCenter', 'ExpensePurpose'], ['OU_2311', 'OU_3568', 'Training']);
    offsetLedgerDim = DimensionAttributeValueCombination::getLedgerDimension(
    '170150', ['Department', 'CostCenter', 'ExpensePurpose'], ['OU_2311', 'OU_3568', 'Training']);
    jourTableData = JournalTableData::newTable(jourTable);
    jourTable.JournalNum = jourTableData.nextJournalId();
    jourTable.JournalType = LedgerJournalType::Daily;
    jourTable.JournalName = 'GenJrn';
    jourTableData.initFromJournalName(LedgerJournalName::find(jourTable.JournalName));
    jourStatic = jourTableData.journalStatic();
    jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);
    jourTransData.initFromJournalTable();
    jourTrans.CurrencyCode = 'USD';
    jourTrans.initValue();
    jourTrans.TransDate = systemDateGet();
    jourTrans.LedgerDimension = ledgerDim;
    jourTrans.Txt = 'General journal demo';
    jourTrans.OffsetLedgerDimension = offsetLedgerDim;
    jourTrans.AmountCurDebit = 1000;
    jourTransData.create();
    jourTable.insert();
    ttsCommit;
    info(strFmt("Journal '%1' has been created", jourTable.JournalNum));
}

5. Run the job and check the results by opening General ledger | Journals |
General journal:


6. Click on the Lines button to open journal lines and notice the newly created line:




1 comment:

Unknown said...

Hello,

Will you please give the detail on point # 3 as well?

" Double check that the getLedgerDimension() method exists on the
DimensionAttributeValueCombination table. If not, create it as described in the first
recipe in this chapter."

Thanks,
Nitin