Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Auto settlement for Cu...
Finance forum
Unanswered

Auto settlement for Customer payment journal using x++

Posted on by 25
Hi,
 
I am working on creating a Customer Payment Journal for all unsettled invoices for a specific customer using a batch job (Parameter: customer account),
However, I've encountered an issue where the total amount for the settlements selected is not being updated in the LedgerJournalTrans table's AmountCurCredit (Credit) field and for the MarkedInvoice (Invoice) field.
 
while checking the settle trans, the lines are selected but the amount is not updated in the LedgerJournalTrans

this is my code for select the settlement against the customer:
 
public void settleCustomerInvoices(LedgerJournalTable  _LedgerJournalTable, CustAccount _custAccount)
    {
        CustTable custTable;
        CustTransOpen custTransOpen;
        CustTrans custTrans;
        SpecTrans spectrans,_specTrans;
        LedgerJournalTrans _LedgerJournalTrans;
        LedgerJournalCheckPost ledgerJournalCheckpost;
        custvendopentransmanager manager;
        AmountCur amountCur;
        select forupdate _LedgerJournalTrans where _LedgerJournalTrans.JournalNum == _LedgerJournalTable.JournalNum;
        
        manager = custvendopentransmanager::construct(_LedgerJournalTrans);
        
        if(manager.getSpecTransCount() == 0)
        {
            custTable = CustTable::find(_custAccount); //:findByLedgerDimension(_LedgerJournalTrans.LedgerDimension);
            
            while select custTransOpen where custTransOpen.AccountNum == custTable.AccountNum && custTransOpen.AmountCur > 0
                join custTrans where custTrans.RecId == custTransOpen.RefRecId && custTrans.AccountNum == custTransOpen.AccountNum
                notexists join specTrans where specTrans.RefRecId == custTransOpen.RecId
            {
                manager.updateTransMarked(custTransOpen,true);
                manager.updateSettleAmount(custTransOpen, custTransOpen.AmountCur);
            }
            
            ttsBegin;
            _LedgerJournalTrans.selectForUpdate(true);
            _LedgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
            _LedgerJournalTrans.update();
            ttsCommit;
            
            try
            {
                ledgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(_LedgerJournalTable,NoYes::No);
                ledgerJournalCheckPost.run();
            }
            catch(Exception::Error)
            {
                error("Autosettlement Exception");
                if(manager.getSpecTransCount() > 0)
                {
                    manager.resetMarkedTrans();
                }
            }
        }
    }

I would appreciate guidance on ensuring the "AmountCurCredit" and "MarkedInvoice" field updates correctly.
  • Auto settlement for Customer payment journal using x++
    Have you tried tracing how the standard application works?
     
    I don't remember exactly how the code works behind the scenes, but when I'm uncertain about how something functions, I use the trace parser tool to analyze the code path of the standard application and see when something gets updated.
     

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,537 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,520 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans