X++ Code To Create
Periodic Journal and also create and post new General journal entry for that
created periodic journal in ax 2012
static void
CON_PeriodicJournal(Args _args)
{
LedgerJournalTrans
ledgerJournalTrans,LedgerJournaltrans1;
LedgerJournalTable ledgerJournalTable;
ledgerJournalname
ledgerJournalname;
NumberSeq
numberSeq;
NumberSequenceTable
numSeqTable;
container
cont1,cont2,ledgerDimension,offSetAcctPattern;
DimensionDynamicAccount
ledgerDim, offsetledgerDim;
ledgerJournalCheckPost
ledgerJournalCheckPost;
int cnt;
DimensionDefault
DimensionDefault;
LedgerJournalPeriodicCopy
LedgerJournalPeriodicCopy;
CopyMove
CopyMove;
LedgerJournalId
periodicLedgerJournalId,genjourLedgerJournalId;
LedgerJournalACType
periodicACType,periodicOffSetACType;
DimensionDynamicAccount
periodicAccount,periodicoffsetAccount ;
AmountCurCredit
credit;
// find ledgerjournalname record
select firstonly ledgerjournalname where LedgerJournalName.JournalName =='PerJrn';
//create ledger journal table
ledgerjournaltable.journalname
= ledgerjournalname.journalname ;
ledgerjournaltable.initfromledgerjournalname();
ledgerjournaltable.name
= " May Periodic Journal";
ledgerJournalTable.insert(); // Creating
periodic journal header
//Creating periodic journal Lines
//ledgerJournalTable =
LedgerJournalTable::find("00553");
try
{
ttsbegin;
ledgerJournalTrans.clear();
ledgerJournalTrans.initValue();
ledgerJournalTrans.JournalNum =
ledgerJournalTable.JournalNum;
ledgerJournalTrans.TransDate = today();
ledgerJournalName =
ledgerJournalName::find(ledgerJournalTable.JournalName);
periodicLedgerJournalId = ledgerJournalTrans.JournalNum ;
select firstOnly
numSeqTable
where numSeqTable.RecId == ledgerJournalName.NumberSequenceTable;
if (numSeqTable)
{
numberseq =
numberseq::newGetVoucherFromCode(numSeqTable.NumberSequence);
ledgerJournalTrans.voucher = numberseq.voucher();
}
//ledgerJournalTrans.Voucher = voucher;
ledgerJournalTrans.AccountType
= LedgerJournalACType::Vend;
ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
// Main account dimensions
periodicACType = ledgerJournalTrans.AccountType;
periodicOffSetACType = ledgerJournalTrans.OffsetAccountType;
cont1=conNull();
cont2=conNull();
ledgerDimension =conNull();
cont2 += ['BusinessUnit','082','Department','023'];
cnt =2;
if(ledgerJournalTrans.AccountType == LedgerJournalACType::Ledger)
{
cont1+=['MainAccount','112100',2];
cont1+=cont2;
ledgerDim=AxdDimensionUtil::getLedgerAccountId(cont1);
if(ledgerDim==0)
{
offSetAcctPattern = ['112100','112100'];
ledgerDim =
AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern);
}
ledgerJournalTrans.LedgerDimension
= ledgerDim;
}
else //Except Ledger i.e Customer,Vendor,etc
{
// here it is Vendor
we used
ledgerDim = DimensionStorage::getDynamicAccount( '000021',ledgerJournalTrans.AccountType);
ledgerJournalTrans.LedgerDimension
= ledgerDim;
ledgerDimension +=cnt;
ledgerDimension +=cont2;
DimensionDefault =
AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
ledgerJournalTrans.DefaultDimension = DimensionDefault;
}
periodicAccount = ledgerDim;
cont1=conNull();
cont2=conNull();
ledgerDimension =conNull();
cont2 += ['BusinessUnit','082','Department','023'];
cnt =2;
if(ledgerJournalTrans.OffsetAccountType == LedgerJournalACType::Ledger)
{
cont1+=['MainAccount','112140',2];
cont1+=cont2;
offsetledgerDim=AxdDimensionUtil::getLedgerAccountId(cont1);
if(ledgerDim==0)
{
offSetAcctPattern = ['112140','112140'];
offsetledgerDim =
AxdDimensionUtil::getLedgerAccountId(offSetAcctPattern);
}
ledgerJournalTrans.OffsetLedgerDimension
= offsetledgerDim;
}
else
{
offsetledgerDim = DimensionStorage::getDynamicAccount( '000021',ledgerJournalTrans.AccountType);
ledgerJournalTrans.OffsetLedgerDimension = offsetledgerDim;
ledgerDimension +=cnt;
ledgerDimension +=cont2;
DimensionDefault =
AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);
ledgerJournalTrans.OffsetDefaultDimension = DimensionDefault;
}
periodicoffsetAccount = offsetledgerDim;
ledgerJournalTrans.CurrencyCode
= "USD";
ledgerJournalTrans.AmountCurCredit
= 6000;
ledgerJournalTrans.FreqCode
= PeriodUnit::Month;
ledgerJournalTrans.FreqValue
= 1;
credit = ledgerJournalTrans.AmountCurCredit;
if (ledgerJournalTrans.validateWrite())
{
ledgerJournalTrans.insert();
}
ttscommit;
}
catch(Exception::Error)
{
info(strFmt('Catched an error in row: %1',ledgerJournalTrans.OffsetDefaultDimension));
}
info(strFmt('Periodic
journal inserted %1',ledgerJournalTable.JournalNum));
// Up to here Periodic Journal is created Succesfully as below image
Periodic journal lines
Last date is updated here because it
is posted from general journal entry
//Creating General journal for above Periodic journal
ledgerJournalTable.clear();
//General Ledger create
select firstonly ledgerjournalname where LedgerJournalName.JournalName =='GenJrn';
//create ledger journal table
ledgerjournaltable.journalname
= ledgerjournalname.journalname ;
ledgerjournaltable.initfromledgerjournalname();
ledgerjournaltable.name
= " General Journal";
genjourLedgerJournalId= ledgerjournaltable.JournalNum;
ledgerJournalTable.insert();
info(strFmt("General
journal is %1",ledgerjournaltable.JournalNum));
// here finding the above created Periodic journal
ledgerJournalTrans =
ledgerJournalTrans::find(periodicLedgerJournalId,ledgerJournalTrans.Voucher,true);
ttsBegin;
ledgerJournalTrans1.initValue();
ledgerJournalTrans1.data(ledgerJournalTrans);
// inserting periodic journal values to general journal lines
ledgerJournalTrans1.JournalNum=ledgerjournaltable.JournalNum;
//ledgerJournalTrans1.initValue();
select firstOnly
numSeqTable
where numSeqTable.RecId == ledgerJournalName.NumberSequenceTable;
if (numSeqTable)
{
numberseq =
numberseq::newGetVoucherFromCode(numSeqTable.NumberSequence);
ledgerJournalTrans1.voucher = numberseq.voucher();
}
if(!ledgerJournalTrans1.validateWrite())
{
throw error("ERRor");
}
else
{
ledgerJournalTrans1.insert();
}
ttsCommit;
//Post Journal
ledgerJournalCheckPost
=
ledgerJournalCheckPost::newLedgerJournalTable(ledgerJournaltable,Noyes::Yes);
LedgerJournalCheckPost.run();
//Lastdate updated
ttsBegin;
ledgerJournalTrans.LastTransferred=today();
ledgerJournalTrans.update();
ttsCommit;
}
Info Message
(01:04:41 pm) Periodic journal inserted
00735
Info Message
(01:04:41 pm) General journal is 00736
Info Message
(01:04:41 pm) Number of vouchers posted to
the journal: 1
No comments:
Post a Comment