Step 5: Add code to distribute and journalize source document amounts
There might be a need to create new monetary amounts but that is optional and you may find existing monetary amounts sufficient. It depends if existing monetary amounts are a good fit for your document and have appropriate names to display on accounting distributions form. Either new or existing MonetaryAmount enum values will be used in your code creating distributions.
a) Create a class extending AccountingPolicy. Using framework naming standards name this class AccPolicyMyBusinessEvent .
Decorate it with SourceDocumentExtensionAttribute:
[SourceDocumentExtensionAttribute(enumNum(BusinessEvent_MyDocument), BusinessEvent_MyDocument::MyBusinessEvent)]
b) (Optional) Add an additional value (MyValue) to MonetaryAmount enum. This will be used later to identify your specific amount when you add code to calculate all amounts that need to be distributed for your document in calculateSourceDocumentAmountMap method on your source document line classes.
c) (Optional) In case you added your value to MonetaryAmount enum – update SourceDocumentMonetaryAmountModel class. Methods initMonetaryAmountChildMap() and optionally initMonetaryAmountParentMap() will need to be updated.
d) (Optional) In case you added your value to MonetaryAmount enum – you may need to update SourceDocumentAmountFormTreeBuildHelper.initMonetaryAmountTreePostionMap() if you have specific requirements about sequencing of monetary amounts in the accounting distribution form.
e) Create a class extending AccountingDistributionRule. Using framework naming standards name this class AccDistRuleMyDesiredAction where “MyDesiredAction” describes the business event associated with the rule (e.g. AccDistRuleSaleOfProductTax). Decorate it with SourceDocumentExtensionAttribute:
[SourceDocumentExtensionAttribute(enumNum(BusinessEvent_MyDocument), BusinessEvent_ MyDocument::MyBusinessEvent, MonetaryAmount::MyValue)]
MyValue could be either an existing value or a newly created value (see optional steps 5 b-d).
Implement abstract methods parmSide() and parmLedgerPostingType().
f) Revisit your classes extending SourceDocumentLine which have monetary amounts to distribute. On each of them override method calculateSourceDocumentAmountMap() to return map of all source document amounts which need to be distributed.
g) (Optional) Create your own account dimension list provider. To do that, you need to first add a value to MainAccountDimensionListProviderType enum identifying the provider (let’s call it MyType). Next create a class that extends MainAccountDimensionListProvider. Decorate the class with SourceDocumentExtensionAttribute:
[SourceDocumentExtensionAttribute(enumNum(MainAccountDimensionListProviderType), MainAccountDimensionListProviderType::MyType)]
h) (Optional) Create an interface to abstract out usage of your provider and get required data for SourceDocumentLineItem classes that will implement this interface. Name it after the new enum value: SourceDocumentIMyType.
i) (Optional) Revisit your source document class (MyDocumentSourceDocument) and implement the SourceDocumentIMyType interface on it.
j) (Optional) Create provider class inheriting from MainAccountDimensionListProvider. Using framework naming standards name it MyTypeMainAccountDimensionListProvider. Decorate it with SourceDocumentExtensionAttribute:
[SourceDocumentExtensionAttribute(enumNum(MainAccountDimensionListProviderType), MainAccountDimensionListProviderType::MyType)]
Implement populateMainAccountDimensionList() method to return the list containing the appropriate main account.
k) (Optional) Modify AccountingRule class adding method canUseMyTypeMainAccountDimensionListProvider() which determines under which conditions your provider should be used. It will usually be determined by source document extension class implementing correct interface, but could be other condition as well:
public boolean canUseMyTypeMainAccDimListProvider()
{
Object sourceDocument = sourceDocumentLineItem.parmSourceDocument();
return (sourceDocument is SourceDocumentIMyType);
}
l) (Optional) Modify MainAccountDerivationDistributionRule and/or MainAccountDerivationJournalizingRule to initialize the account list based on new provider. Code will be added in populateMainAccountList() method.
The distributions part should be working now and you should be able to see distributions on your document’s form clicking on distributions buttons which you added earlier.
Now you need to add necessary code for proper journalization of your document.
Usually you will just want to put the balancing amount into certain account (like Vendor Balance). If you need just that, do the following:
m) Create a class extending AccountingJournalizingRule. Using framework naming standards name this class AccJourRuleMyDesiredAction where “MyDesiredAction” describes the action you are performing which affects your distributions (e.g. AccJourRuleSaleRevenue). Decorate it with SourceDocumentExtensionAttribute:
[SourceDocumentExtensionAttribute(enumNum(BusinessEvent_MyDocument), BusinessEvent_ MyDocument::MyBusinessEvent, MonetaryAmount::MyValue)]
MyValue could be either newly created value or an existing one.
Implement abstract methods parmSide() and parmLedgerPostingType().
n) Go back to your source document class and inherit the right source document interface on it (for example SourceDocumentIParty for vendor balance) - it will tell the MainAccountDerivationJournalizingRule class (through canUse<ProviderType> method) to use the specific DimensionListProvider during journalization (see code inside MainAccountDerivationJournalizingRule.populateMainAccountList() for more info).
Rarely, your document will have more demanding journalization requirements than just putting a balance amount into a balance account. If that is the case you may need to implement journalization rules with steps analogous to implementing distribution generation described above.
After this step the button which you added earlier on your document’s form which invokes menu item SubledgerJournalAccountEntries should display all subledger account entries for your document allowing you to test distribution and journalization rules.
Next - Step 6: Implement confirmation/posting of your document
Comments
- Anonymous
May 06, 2014
I have been reading your blog with interest, as I have been tasked with doing customization to the source documents / accounting for purchase orders.My customer can achieve bonus with their vendors when making a purchase, and I need to post vendor bonus sometimes on seperate accounts and sometimes as additional general ledger postings in the opposite side to effectively lower the net value of the voucher.Is there any way I can get in contact with you directly ?I have been reading your blog - Anonymous
March 02, 2015
See existing implementations of source documents in AX 2012 for examples of more complex scenarios. - Anonymous
December 02, 2015
Jacob, Did you get any solution for your scenario? Even I have same requirement. I need to post additional entries during PO invoice.