Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Auto settlement for Customer payment journal using x++

(1) ShareShare
ReportReport
Posted on by 39
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.
  • Anton Venter Profile Picture
    Anton Venter 18,788 Super User 2024 Season 2 on at
    Auto settlement for Customer payment journal using x++
    Has your question been answered? If so, mark the post as answered to help others in the future.
  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 18,788 Super User 2024 Season 2 on at
    Auto settlement for Customer payment journal using x++
    Add your code to the forum post using the "Insert Code Snippet" button, it makes it easier to read :-).
     
    There are many examples in the standard application. How do you find examples? In case you don't know, in the Visual Studio Application Explorer, right click the MarkedInvoice field on the LedgerJournalTrans table and select Find References.
     
    To update the LedgerJournalTrans line amount, keep a running total of each transaction that will be settled and update the LedgerJournalTrans line amount. Or as others have already mentioned, take a look how the standard application does it.
     
    
    ledgerJournalTrans.MarkedInvoice = custTrans.Invoice;
    ledgerJournalTrans.MarkedInvoiceCompany = custTrans.company();
    ledgerJournalTrans.MarkedInvoiceRecId = custTransOpen.RecId;
    ledgerJournalTrans.SettleVoucher = SettlementType::SelectedTransact;
     
  • Suggested answer
    Bill Ngo Profile Picture
    Bill Ngo 370 on at
    Auto settlement for Customer payment journal using x++
    Hi Saran,
     
    There is a standard function like your custom function. It is very powerful. Why don't you use it? 
     
    You can check it in the All customers > Collect > Settle > Settle transactions.
     
     
    For the system automatically settles, you can read a introduction and activate a feature of "Settle customer payment deductions using the matching invoice" in the Feature management for your enhancement and practice. 

    "This feature adds an option that lets you choose to settle customer payment deductions using the invoice selected for each deduction. When you use this option, the system automatically settles deduction transactions using the matching invoice provided an open balance exists for that invoice; otherwise the deduction won't be settled automatically. Without this option, the system instead settles deduction transactions using the open amount for payment invoices, which was the standard behavior in Supply Chain Management version 10.0.24 and earlier."

    Regards,
    Bill
  • 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,419 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,492 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans