Reputation: 1254
I am trying to create (and post) ledger journals from data received via AIF inbound service. The data is written in a custom staging table with all necessary fields.
Now, I need to create journals and journal trans records from this staging table. I am able to create LedgerJournalTable
record with multiple LedgerJournalTrans
records.
Here is a code snippet for creating LedgerJournalTrans
:
ledgerJournalTrans = this.initJournalTransFromStaging(ledgerJournalStaging);
ledgerJournalTrans.initValue();
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.Voucher = numberSeq.voucher();
if (ledgerJournalTrans.validateWrite())
{
ledgerJournalTrans.insert();
}
// After that comes voucher validation using JedgerJournalCheckPost, which issues error that the voucher does not balance
Where this.initJournalTransFromStaging
initializes some standard fields like AccountNum
, AmountCurDebit
and so on.
My problem is that OffsetAccount
is not populated from default settings (in my particular case, it should be defaulted from Ledger Journal Name, but it can also be taken from main account settings), that leads to error when validating voucher (does not balance).
It would be great make use of some standard functionality to correctly initialize offset account.
Thanks!
Upvotes: 0
Views: 2095
Reputation: 1254
I have found a solution:
ledgerJournalEngine = LedgerJournalEngine::construct(ledgerJournalTable.JournalType);
ledgerJournalEngine.newJournalActive(ledgerJournalTable);
ledgerJournalEngine.accountModified(ledgerJournalTrans);
This made the trick! It inits offset account from LedgerTable
or LedgerJournalName
, with LedgerTable
having higher priority.
Upvotes: 2
Reputation: 11544
You can init the offset account and offset dimension from a LedgerJournalName
record. Is there a reason you are not doing this or are you asking if there exists a more proper way to do this out of the box?
See my answer here about a very similar question: https://stackoverflow.com/a/27853468/1179573
Upvotes: 0