Create Paym Journal in ax 2012 X++
Journal contents of voucher or number of voucher so you can create General Journal using the code like in below
static void VendPaympkJournalCreate(Args _args)
{
LedgerJournalTable jourTable;
LedgerJournalTrans jourTrans;
LedgerJournalTableData jourTableData;
//LedgerJournalTransData jourTransData;
LedgerJournalStatic jourStatic;
DimensionDynamicAccount ledgerDim;
DimensionDynamicAccount offsetLedgerDim;
ttsBegin;
ledgerDim = DimensionStorage::getDynamicAccount(
'1001',
LedgerJournalACType::Vend);
offsetLedgerDim = DimensionStorage::getDynamicAccount(
'USA OPER',
LedgerJournalACType::Bank);
jourTableData = JournalTableData::newTable(jourTable);
jourTable.JournalNum = jourTableData.nextJournalId();
jourTable.JournalType = LedgerJournalType::Payment;
jourTable.JournalName = 'APPay';
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.AccountType = LedgerJournalACType::Vend;
jourTrans.LedgerDimension = ledgerDim;
jourTrans.Txt = 'Vendor payment journal demo';
jourTrans.OffsetAccountType = LedgerJournalACType::Bank;
jourTrans.OffsetLedgerDimension = offsetLedgerDim;
jourTrans.AmountCurDebit = 1000;
//jourTransData.create();
jourTable.insert();
ttsCommit;
info(strFmt(
"Journal '%1' has been created", jourTable.JournalNum));
}
-> then you should make your post via this code
static void LedgerJournalPost(Args _args)
{
LedgerJournalCheckPost jourPost;
LedgerJournalTable jourTable;
jourTable = LedgerJournalTable::find('000420_010');
jourPost = LedgerJournalCheckPost::newLedgerJournalTable(
jourTable,
NoYes::Yes);
jourPost.run();
}
{
LedgerJournalCheckPost jourPost;
LedgerJournalTable jourTable;
jourTable = LedgerJournalTable::find('000420_010');
jourPost = LedgerJournalCheckPost::newLedgerJournalTable(
jourTable,
NoYes::Yes);
jourPost.run();
}
you can change type of journal depend on your business needs
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:
What if we need the journal to have multiple lines?
ReplyDelete