AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 07.03.2022, 23:19   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
How to populate custom fields in GeneralJournalAccountEntry from LedgerJournalTrans for Ledger, Customer, Vendor, and Bank account type
Источник: http://alexvoy.blogspot.com/2022/03/...fields-in.html
==============

Say, we need to add a new field EOGUniqueId to LedgerJournalTrans and then have it populated in GeneralJournalAccountEntry, once a General journal posted.







In other words the field value must be transferred from a general journal line to a related voucher transaction.



Generally speaking there are two different ways how GL transactions created in D365FO: via Source document framework and via LedgerVoucherObject. Moreover, one transaction may be a result of summarization of multiple documents. So, this approach works for this particular scenario, when GL transactions come from a general journal. The proposed solution covers Ledger, Customer, Vendor, and Bank types. You can elaborate it for Project, Fixed Asset, etc. Check their appropriate classes.

LedgerJournalCheckPost class creates one transaction per a line of Ledger type, two if the latter has an offset info.



When it comes to other transaction type, first, a transaction in CustTrans, VendTrans, BankTrans etc is created, and then based on the latter a new transaction is added.











So, we creates the following extensions.

Tables.






Classes.









Below, you can find code snippets for each of them.

EOGBankVoucher_Extension

///
/// Extension of BankVoucher class to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
[ExtensionOf(classStr(BankVoucher))]
final class EOGBankVoucher_Extension
{
public EOGUniqueId eogUniqueId;

///
/// Gets or sets the transaction EOGUniqueId.
///
/// EOGUniqueId
/// EOGUniqueId
public EOGUniqueId EOGParmUniqueId(EOGUniqueId _parm = eogUniqueId)
{
eogUniqueId = _parm;

return eogUniqueId;
}

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
///
/// An instance of LedgerVoucherObject class.
///
///
/// An instance of CurrencyExchangeHelper class.
///
///
/// The initialized LedgerVoucherTransObject object.
///
protected LedgerVoucherTransObject initializeLedgerVoucherTransObjectForPosting(LedgerVoucherObject _ledgerVoucherObject, CurrencyExchangeHelper _exchangeRateHelper)
{
LedgerVoucherTransObject ledgerVoucherTransObject = next initializeLedgerVoucherTransObjectForPosting(_ledgerVoucherObject, _exchangeRateHelper);

ledgerVoucherTransObject.EOGParmUniqueId(_ledgerVoucherObject.EOGParmUniqueId());

return ledgerVoucherTransObject;
}

}

EOGCustVendVoucher_Extension

///
/// Extension of CustVendorVoucher class to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
[ExtensionOf(classStr(CustVendVoucher))]
final class EOGCustVendVoucher_Extension
{
public EOGUniqueId eogUniqueId;

///
/// Gets or sets the transaction EOGUniqueId.
///
/// EOGUniqueId
/// EOGUniqueId
public EOGUniqueId EOGParmUniqueId(EOGUniqueId _parm = eogUniqueId)
{
eogUniqueId = _parm;

return eogUniqueId;
}

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
/// A Boolean value that indicates whether the SubLedger is being used.
/// The LedgerDimensionAccount ledger account record.
/// The LedgerJournalTrans record.
/// The ledger posting journal to use for ledger posting.
/// The Map object that contains the value of vendor transaction or customer transaction.
/// The instance of LedgerVoucherTransObject class.
protected LedgerVoucherTransObject createLedgerVoucherTransObject(boolean _useSubLedger,
LedgerDimensionAccount _ledgerDimensionMerged,
LedgerJournalTrans _ledgerJournalTrans,
LedgerVoucher _ledgerPostingJournal,
CustVendTrans _custVendTrans)
{
LedgerVoucherTransObject ledgerVoucherTransObject = next createLedgerVoucherTransObject( _useSubLedger, _ledgerDimensionMerged, _ledgerJournalTrans, _ledgerPostingJournal, _custVendTrans);

ledgerVoucherTransObject.EOGParmUniqueId(eogUniqueId);

return ledgerVoucherTransObject;
}

}

EOGLedgerJournalCheckPost_Extension

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
[ExtensionOf(classStr(LedgerJournalCheckPost))]
final class EOGLedgerJournalCheckPost_Extension
{

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
///
/// The LedgerJournalTrans record.
///
///
/// A SysModule enumeration value.
///
///
/// The created LedgerVoucherObject reference.
///
protected LedgerVoucherObject createPostingReference(LedgerJournalTrans _ledgerJournalTrans, SysModule _sysModule)
{
LedgerVoucherObject newVoucher = next createPostingReference(_ledgerJournalTrans, _sysModule);

newVoucher.EOGParmUniqueId(_ledgerJournalTrans.EOGUniqueId);

return newVoucher;
}

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
///
/// The LedgerVoucherObject instance.
///
///
/// The LedgerJournalTrans record.
///
///
/// A SysModule enumeration value.
///
///
/// The updated LedgerVoucherObject reference.
///
protected LedgerVoucherObject updatePostingReference(LedgerVoucherObject _postingReference, LedgerJournalTrans _ledgerJournalTrans, SysModule _sysModule)
{
next updatePostingReference(_postingReference, _ledgerJournalTrans, _sysModule);

_postingReference.EOGParmUniqueId(_ledgerJournalTrans.EOGUniqueId);

return _postingReference;
}

}

EOGLedgerJournalTransUpdateBank_Extension

///
/// Extension of LedgerJournalTransUpdateBank class to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
[ExtensionOf(classStr(LedgerJournalTransUpdateBank))]
final class EOGLedgerJournalTransUpdateBank_Extension
{

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
///
/// The LedgerJournalTrans record to pass the transaction data.
///
///
/// The tax amount.
///
///
/// The tax withhold amount.
///
///
/// The default dimension.
///
///
/// The journal type..
///
///
/// The flag skip Dimension Validation.
///
///
/// The new BankVoucher class instance.
///
protected BankVoucher initBankVoucher( LedgerJournalTrans _ledgerJournalTrans,
TaxAmount _taxAmount,
real _taxWithholdAmount,
DimensionDefault _defaultDimension,
LedgerJournalType _ledgerJournalType,
boolean _skipDimensionValidation)
{
BankVoucher bankVoucher = next initBankVoucher(_ledgerJournalTrans, _taxAmount, _taxWithholdAmount, _defaultDimension, _ledgerJournalType, _skipDimensionValidation);

bankVoucher.EOGParmUniqueId(_ledgerJournalTrans.EOGUniqueId);

return bankVoucher;
}

}

EOGLedgerVoucherObject_Extension

///
/// Extension of LedgerVoucherOject class to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
[ExtensionOf(classStr(LedgerVoucherObject))]
final class EOGLedgerVoucherObject_Extension
{
public EOGUniqueId eogUniqueId;

///
/// Gets or sets the transaction EOGUniqueId.
///
/// EOGUniqueId
/// EOGUniqueId
public EOGUniqueId EOGParmUniqueId(EOGUniqueId _parm = eogUniqueId)
{
eogUniqueId = _parm;

return eogUniqueId;
}

}

EOGLedgerVoucherTransObject_Extension

///
/// Extension of LedgerVoucherTransObject class to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
[ExtensionOf(classStr(LedgerVoucherTransObject))]
final class EOGLedgerVoucherTransObject_Extension
{
public EOGUniqueId eogUniqueId;

///
/// Gets or sets the transaction EOGUniqueId.
///
/// EOGUniqueId
/// EOGUniqueId
public EOGUniqueId EOGParmUniqueId(EOGUniqueId _parm = eogUniqueId)
{
generalJournalAccountEntry.EOGUniqueId = _parm;
return generalJournalAccountEntry.EOGUniqueId;
}

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
///
///
/// A LedgerJournalTrans record buffer.
///
///
/// The tax amount; optional. Defaults to 0. Will be deducted from the regular amount of the LedgerJournalTrans record buffer.
///
///
/// true if the transation will be bridged; otherwise, false. optional.
///
///
/// A container that holds the RecIds of LedgerJournalTrans records that are for intercompany accounts.
///
///
/// true if reversals may exist for this LedgerJournalTrans record; otherwise, false. Optional.
///
///
/// true if the provided LedgerJournalTrans exchange rates should be used for accounting and reporting amount
/// calculations; otherwise, false. Optional.
///
///
/// A new LedgerVoucherTransObject object.
///
public static LedgerVoucherTransObject newTransLedgerJournal(
LedgerJournalTrans _ledgerJournalTrans,
TaxAmount _taxAmount,
boolean _bridging,
container _intercompanyRecIds,
boolean _reversalsMayExist,
boolean _forcedExchangeRate)
{
LedgerVoucherTransObject ledgerVoucherTransObject = next newTransLedgerJournal(_ledgerJournalTrans, _taxAmount, _bridging, _intercompanyRecIds, _reversalsMayExist, _forcedExchangeRate);

ledgerVoucherTransObject.EOGParmUniqueId(_ledgerJournalTrans.EOGUniqueId);

return ledgerVoucherTransObject;
}

///
/// Gets the LedgerPostingTransactionTmp record for the current object.
///
///
/// The LedgerPostingTransactionTmp record.
///
public LedgerPostingTransactionTmp getLedgerPostingTransaction()
{
LedgerPostingTransactionTmp ledgerPostingTransaction = next getLedgerPostingTransaction();

ledgerPostingTransaction.EOGUniqueId = generalJournalAccountEntry.EOGUniqueId;

return ledgerPostingTransaction;
}

///
/// Chain of comand method to populate the Unique Id
///
///
///
public void initFromLedgerPostingTransaction(LedgerPostingTransactionTmp _ledgerPostingTransaction,LedgerPostingTransactionProjectTmp _projectPostingTransaction)
{
next initFromLedgerPostingTransaction(_ledgerPostingTransaction,_projectPostingTransaction);

generalJournalAccountEntry.EOGUniqueId = _ledgerPostingTransaction.EOGUniqueId;
}

///
/// to populate EOGUniqueId field in GeneralJournalAccountEntry from LedgerJournalTrans
/// amount, an accounting currency amount, and a ledger posting reference for defaulting.
///
///
/// The ledger posting reference used for defaulting.
///
///
/// The posting type of the general journal entry.
///
///
/// The dimension attribute value combination of the general journal entry.
///
///
/// The currency code of the general journal entry.
///
///
/// The amount in the transaction currency.
///
///
/// The amount in the accounting currency.
///
///
/// An CurrencyExchangeHelper object initialized for the current LedgerVoucherTransObject.
///
///
/// A new instance of the LedgerVoucherTransObject class.
///
///
/// The default ledger posting reference is used to set the transaction type.
///
public static LedgerVoucherTransObject newTransactionAccountingAmountsDefault(
LedgerVoucherObject _defaultLedgerPostingReference,
LedgerPostingType _postingType,
RecId _ledgerDimensionId,
CurrencyCode _transactionCurrencyCode,
Money _transactionCurrencyAmount,
MoneyMST _accountingCurrencyAmount,
CurrencyExchangeHelper _currencyExchangeHelper)
{
LedgerVoucherTransObject postingTrans;

postingTrans = next newTransactionAccountingAmountsDefault(_defaultLedgerPostingReference, _postingType, _ledgerDimensionId, _transactionCurrencyCode, _transactionCurrencyAmount, _accountingCurrencyAmount, _currencyExchangeHelper);

postingTrans.EOGParmUniqueId(_defaultLedgerPostingReference.EOGParmUniqueId());

return postingTrans;
}

}

I wish to credit the following articles I used:

заполнение новых полей в GeneralJournalAccountEntry

https://allaboutdynamic.com/2018/06/...ng-of-journal/

http://axwiki.blogspot.com/2017/01/c...altabletr.html



Источник: http://alexvoy.blogspot.com/2022/03/...fields-in.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 11:09.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.