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)

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)
  • COA Profile Picture
    15 on at
    Re: Need Auto Settlement Code

    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.

  • MohammedRasheed Profile Picture
    1,405 on at
    Re: Need Auto Settlement Code

    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

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
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans