Hi,
I have a requirement to automatically post inventory journals but I must extract the line data from the journal at the time of posting. The map object I have defined and use in a next method takes an Enum (inicating the line is a credit or a debit) and a Int64 (the ledger dimension for that line). Currently, the code below works for when there is only one line in the journal, but when there is two (or more) the map starts mixing and matching values (for instance, the ledger dimension will be associated with a debit line but will read as a credit in the code). Additionally, the map gets updated and replaced when it is ran more than 2 times which happens when there is more than one line. Please refer to my code below:
public void reverseFinancialVouchers(JournalTransList _transList)
{
GeneralJournalAccountEntry reverseFinancialEntry;
GeneralJournalAccountEntry origAccountEntry;
GeneralJournalEntry origJournalEntry;
Map journalMap;
if (_transList.first())
{
do
{
JournalTransData transData = _transList.journalTransData();
Common record = transData.journalTrans();
journalMap = new Map(Types::Enum, Types::Int64);
if (record.TableId == tableNum(InventJournalTrans))
{
InventJournalTrans journalTrans = record as InventJournalTrans;
select firstonly origJournalEntry where
origJournalEntry.SubledgerVoucher == journalTrans.Voucher &&
origJournalEntry.SubledgerVoucherDataAreaId == journalTrans.DataAreaId;
//ts
itemIdForLookup = journalTrans.ItemId;
//ts
while select origAccountEntry where origAccountEntry.GeneralJournalEntry == origJournalEntry.RecId
{
reverseFinancialEntry.data(origAccountEntry);
reverseFinancialEntry.AccountingCurrencyAmount = -(origAccountEntry.AccountingCurrencyAmount);
reverseFinancialEntry.TransactionCurrencyAmount = -(origAccountEntry.TransactionCurrencyAmount);
reverseFinancialEntry.ReportingCurrencyAmount = -(origAccountEntry.ReportingCurrencyAmount);
if (origAccountEntry.IsCredit == NoYes::No)
{
reverseFinancialEntry.IsCredit = NoYes::Yes;
reverseFinancialEntry.PostingType = LedgerPostingType::InventProfit;
}
else
{
reverseFinancialEntry.IsCredit = NoYes::No;
reverseFinancialEntry.PostingType = LedgerPostingType::InventReceipt;
//ts
postingTypeForLookup = origAccountEntry.PostingType;
origMainAccount = origAccountEntry.MainAccount;
//JournalCheckPostLedger::fetchBudgetControlAccount();
//ts
}
reverseFinancialEntry.doinsert();
journalMap.add(origAccountEntry.IsCredit, origAccountEntry.LedgerDimension);
}
this.createAndPostFinancialJournal(journalTrans, journalMap);
}
}
while (_transList.next());
}
}