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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Need Auto Settlement Code

(0) ShareShare
ReportReport
Posted on by 3,333

Dear All

I have posted three invoices against a sales order and passed a collection journal with the customer. e.g.

INV001 = Rs. 5000, INV002 = Rs. 3000 and INV003 = Rs. 10000. My collection from the customer is Rs. 18000. Now I would settle this amount(18000) with these three invoices by code. I will be very greatefull if someone provides me this code. Its very urgent for me.

*This post is locked for comments

I have the same question (0)
  • MohammedRasheed Profile Picture
    1,405 on at

    Hi Rajdip,

    I wrote some quick (and dirty) code for you...

    hopefully it will give you a good indication on what needs to be done..

        AmountCur sumTransAmountCur;
        CustInvoiceSalesLink custInvoiceSalesLink;
       
        CustTable custTable;

        LedgerJournalTable ledgerJournalTable;
        LedgerJournalTrans ledgerJournalTrans;

        CustTrans custTrans;
        CustTransOpen custTransOpen;

        CustInvoiceJour custInvoiceJour;

        Specification_OffsetVoucher specOffsetVoucher;

        Num orderID; // = this will be your order id..


        ;

        // find the custTable record
        custTable = CustTable::find(this.getInvoiceAccount());

        // create a specification offset voucher for the current customer
        specOffsetVoucher =
            new Specification_OffsetVoucher(custTable.tableId, custTable.recID);

        // clear any marked transactions
        specOffsetVoucher.deleteSpecifications();

        while select RecID, AmountCur from custTransOpen
            join CurrencyCode from custTrans
            join Voucher from ledgerJournalTrans
            join JournalNum from ledgerJournalTable
            where ledgerJournalTrans.JournalNum == ledgerJournalTable.JournalNum
                  && custTrans.AccountNum == custTable.AccountNum
                  && custTrans.Voucher == ledgerJournalTrans.Voucher
                  && custTransOpen.RefRecId == custTrans.RecId
        {
            sumTransAmountCur += custTransOpen.AmountCur;

            specOffsetVoucher.create(custTransOpen.TableId,
                                     custTransOpen.RecId,
                                     custTransOpen.AmountCur,
                                     custTrans.CurrencyCode);
        }

        //Clear table buffers... being over cautious
        custTransOpen = null;
        custTrans = null;
        custInvoiceJour = null;

        // add open invoice transactions to the offset voucher
        while select RecID, AmountCur from custTransOpen
            join CurrencyCode from custTrans
            //join LedgerVoucher from custInvoiceJour
            join LedgerVoucher,salesid from CustInvoiceJour
            join salesID,origSalesID from custInvoiceSalesLink
            where custInvoiceSalesLink.origSalesId == orderID
                    &&  custInvoiceJour.SalesId == custInvoiceSalesLink.salesId
                    &&  custTrans.AccountNum == custTable.AccountNum
                    &&  custTrans.Voucher == custInvoiceJour.LedgerVoucher
                    &&  custTransOpen.RefRecId == custTrans.RecId
        {
            sumTransAmountCur += custTransOpen.AmountCur;

            specOffsetVoucher.create(custTransOpen.TableId,
                                     custTransOpen.RecId,
                                     custTransOpen.AmountCur,
                                     custTrans.CurrencyCode);
        }


        // only settle if:
        //  1) the transactions balance, or
        //  2) the full sales amount has been invoiced
        // or any other business logic
        if (// apply the logic explaind above) )
        {
            // settle the transactions
            custTrans::settleTransact(custTable);
        }
        else
        {
            specOffsetVoucher.deleteSpecifications();
        }

     

    let us know if you have any more questions.

    regards,

    Mohammed Rasheeed

    www.dynamic-ax.co.uk

  • COA Profile Picture
    15 on at

    How can I settle two transactions that don’t have same amount? I wont to do similar like Account Receivables -> Customer -> Function -> Open Transaction Editing to decrease balance on one transaction with another one.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans