web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to create ledger vouchers in code including tax transactions to settle customer transactions

(0) ShareShare
ReportReport
Posted on by

Hi,

we're trying to create settlements in code in order to settle customer transactions that have some minor amount of balance left. Doing this with tax transactions seems to be difficult in code using the LedgerVoucher*-objects. Settling using journals works, but that's not practical for single transactions (aka. a unique journal for each transaction). 

Skipping journals aside, can you pass tax groups & tax item groups to LedgerVoucher objects, or do we have to use some Tax class and bind it to LedgerVoucher/LederPostingController in order to post tax transactions as well? E.g. a balance of 1,00e using a tax item group of 25 (25%) would do tax posts of 0,25e, 0,75e of sales and -1,00e balance.

Below is a snippet of the (part of) code to settle transactions without tax transactions and it works well in our case that doesn't include tax.

ledgerVoucher = LedgerVoucher::newLedgerPost(DetailSummary::Detail, SysModule::Cust, numberSequenceCode);

ledgerVoucherObject = LedgerVoucherObject::newVoucher(voucher, transDate, SysModule::Cust, LedgerTransType::Payment);
ledgerVoucher.AddVoucher(ledgerVoucherObject);

currencyExchangeHelper = currencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), ledgerVoucherObject.parmAccountingDate());

ledgerVoucherTransObject = LedgerVoucherTransObject::newTransactionAmountDefault(
ledgerVoucherObject
, LedgerPostingType::CustPayment
, ledgerDimension
, custTable.Currency
, _amountCur
, currencyExchangeHelper);

ledgerVoucher.addTrans(ledgerVoucherTransObject);


custVoucher = CustVendVoucher::construct(
SysModule::Cust
, custAccount
, _amountCur * -1
, custTable.Currency
, ledgerTransTxt::CustPaymentCust
, defaultDimension
, ''
, LedgerPostingType::CustPayment);


custVoucher.parmApprover(HcmWorker::userId2Worker(curUserId()));
custVoucher.parmApproved(NoYes::Yes);
custVoucher.parmTypeOfCreditmaxCheck(TypeOfCreditmaxCheck::None);
custVoucher.parmPaymMode(custTable.PaymMode);
custVoucher.parmPaymSpec(custTable.PaymSpec);
custVoucher.parmLanguageId(custTable.LanguageId());
custVoucher.parmPaymTermId(custTable.PaymTermId);
custVoucher.parmDueDate(systemDateGet());
custVoucher.parmExchRate(
ExchangeRateHelper::getExchangeRate1_Static(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), _custTrans.CurrencyCode, systemDateGet()));

custVoucher.parmExchRateSecondary(
ExchangeRateHelper::getExchangeRate2_Static(Ledger::primaryLedger(CompanyInfo::findDataArea(curext()).RecId), _custTrans.CurrencyCode, systemDateGet()));

custVoucher.parmTransRefType(CustTransRefType::Payment);
custVoucher.parmTransRefId(custTransTarget.Voucher);
custVoucher.parmThirdPartyBankAccountId(custTable.BankAccount);

custVoucher.post(ledgerVoucher, custTrans, NoYes::No, UnknownNoYes::No, NoYes::No, false );
ledgerVoucher.end();

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: How to create ledger vouchers in code including tax transactions to settle customer transactions

    Hi, rather than trying to code something, have you tried making use of the following standard feature? dynamicsax-fico.com/.../how-to-avoid-small-penny-differences-on-customer-accounts best regards, Ludwig

  • AB2014 Profile Picture
    on at
    RE: How to create ledger vouchers in code including tax transactions to settle customer transactions

    Hi,

    this actually covers more than just penny differences, it includes also credit loss transactions.

  • Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: How to create ledger vouchers in code including tax transactions to settle customer transactions

    Hi AB2014,

    How do you identify those credit loss transactions?

    Best regards,

    Ludwig

  • AB2014 Profile Picture
    on at
    RE: How to create ledger vouchers in code including tax transactions to settle customer transactions

    Hello,

    manually or through a query (e.g. get all transactions that are open and have balance less of x amount and have been open 2 years).

    The point being here is how do we make AX post these balances so that they're treated as gross and contain a certain amount of tax.

    Doing that via ledger journal is a quite a trivial task since you can define tax groups on the journal line and AX takes care of the rest. But if you have 150000 transactions that's impossible.

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: How to create ledger vouchers in code including tax transactions to settle customer transactions

    Hi AB2014,

    I am not giving up so easily because I believe that the standard application can do that :-)

    If you write off your balances through a vendor payment journal (described here under solution 2 dynamicsax-fico.com/.../cleansing-small-value-customer-balances-addendum) by making use of a payment proposal then you can apply advanced filters, such as the one shown here dynamicsaxfico.files.wordpress.com/.../en_99_0065.png or for date ranges shown at the end of the following site technet.microsoft.com/.../aa569937.aspx

    Once you have the transactions filtered you just have to ensure that you post it against a depreciation account. I have never posted a journal with >100000 lines but technically this should be ok if you post it in batch.

    Anyway, even if you do not like it, probably take a look at those links as they might give you some additional ideas for your code adjustment :-)

    Would be great if you could share your solution with the community once you found it and decided what and how to do.

    Many thanks and best regards,

    Ludwig

  • AB2014 Profile Picture
    on at
    RE: How to create ledger vouchers in code including tax transactions to settle customer transactions

    Hi,

    thanks for the tips.

    However, this whole thingy is supposed to work without the direct use of journals. Via journals this is a piece of cake, even in code, but since the base solutions was already implemented years ago (the one doing credit loss transactions without tax corrections), writing the entire modification from scratch using journals is the last option.

    I'd be a more happier camper to find out a way to include tax transaction posting in the existing solution.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Community Member Profile Picture

Community Member 2

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans