Tuesday, March 17, 2009

Posting a ledger journal

Here is the adapted example for posting a ledger journal line. Simply replace values between #s (#value#):

static void ExampleLedgerJournal(Args _args)
{
    LedgerJournalTable      ledgerJournalTable;
    LedgerJournalTrans      ledgerJournalTrans;
    LedgerJournalCheckPost  ledgerJournalCheckPost;
    NumberSeq               numberSeq;
    ;

    ttsbegin;

    // Journal name
    ledgerJournalTable.JournalName = "#JOURNALNAME#"; // ex. Daily, daytrans, etc.
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.Name = "#DESCRIPTION#";  // description for this journal
    ledgerJournalTable.insert();

    // Voucher
    numberSeq = NumberSeq::newGetVoucherFromCode(LedgerJournalName::find(ledgerJournalTable.JournalName).VoucherSeries);
    ledgerJournalTrans.Voucher = numberSeq.voucher();

    // Lines
    ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
    ledgerJournalTrans.CurrencyCode = CompanyInfo::standardCurrency();
    ledgerJournalTrans.ExchRate = Currency::exchRate(ledgerJournalTrans.CurrencyCode);
    ledgerJournalTrans.AccountNum = "#ACCOUNT#";
    ledgerJournalTrans.AccountType = LedgerJournalACType::Ledger;
    ledgerJournalTrans.AmountCurDebit = #VALUE#;
    ledgerJournalTrans.TransDate = systemDateGet(); //Avoid the Today function
    ledgerJournalTrans.OffsetAccount = "#OFFSET ACCOUNT#";
    ledgerJournalTrans.Txt = "#TXT#";
    ledgerJournalTrans.insert();

    //Posting the Journal
    ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, NoYes::Yes);
    ledgerJournalCheckPost.run();
    
    ttscommit;
}


Note: you can expand to include more than one line. Enjoy!

8 comments:

Anonymous said...

shouldn't you use the AxLedgerJourTrans Class to create a journal.

Oscar Londono said...

Sure, if you are planning to import data, these kind of classes (AIF classes) can be very helpful for preserve integrity.

GCS Master said...

Hi, there's something that I was doing since 3 years ago, more or less.
Well, I hope you have the answer.
It's about the MyExtRichTextBox
the REOBJECT has a mistake, when I try to get poleobj it retrieves a wrong pointer.

For example I insert a PictureBox this value is 8808..84, just to say
But when I try to get it I use:

...
for(int i=0; i<...ObjectCount(); i++)
{
//I make a reobject just like UpdateObject method
and when I try to get the poleobj
it retrieves 8808..48
-> see the last two numbers

Please this is very clear, there's a mistake with the length of the REOBJECT

I tried another example where this procedure works perfectly,
This nigth I'll try making all again

}

Thanks.

GCS Master said...

Ok, it doesn't matter, I found the solution, well, it was an accident to find it; but I must say that the "guid" that I used was the COM guid, not the control's guid. So it works perfectly.
Thanks, I hope this little information has helped somebody else.
walter_apaza@hotmail.com for more information.

Oscar Londono said...

Sorry GCS Master, very busy on this summer, but good to know that you finally found the solution!

Regards

Alberto said...

Hi, in code how would you post the ledger journal related to a specific invoice.

Thomas Lund said...

Hi,
I REALLY need a good example of controlling the voucher number when importing a csv file to a journal using the AXLedgerJournalTrans class.

lets say that the import job will not use the offset account but one transaction will count two ledgerjournaltrans records. If my csv file has 4 lines (2 transactions) then I would like ledgerJournalTrans line 1 and 2 to share voucher number and 3 and 4 should share voucher number

I cant figure out how to do this. Anyone?

Oscar Londono said...

Try sharing the source Engine

axledgerJournalTrans_2 = AxLedgerJournalTrans::construct();
axledgerJournalTrans_2.ledgerJournalEngine(axledgerJournalTrans_1.ledgerJournalEngine());
axledgerJournalTrans_2.numberSeqFormHandlerLedgerJournal(axledgerJournalTrans_1.numberSeqFormHandlerLedgerJournal());


View My Stats