Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Service class: for mar...
Finance forum
Under review by Community Managers

Under review

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

Service class: for marking invoice

Posted on by
i am going to create a service class, which will mark invoice, 
firstly ,
How much amount of invoice is pending with us, we have to find out any order against the customer.
What is left to invoice customers' remaining sales orders 
And decide the transactions as per date/second, find out whether any invoice of our customer is unmarked, and if unmarked then it has to be marked.
how to write it in MarkOpenTransaction().
i want while loop which will pick tender lines.
 
suppose we created sales order of 1000 invoice amount, then we will create tender of 500 check, 300 cash, 200 upi,
But now this will create a journal of 1000 invoice amount of invoice, in a tender amount 300+200 will get marked through invoice but what about that 500 by check?
 
public class TenderMarkingServiceClass extends SysOperationServiceBase
{
        public void checkRecordMarked(InvoiceId   _invoice, LedgerJournalTrans _ledgerJournalTrans,AccountNum _accountNum)
    {
        custvendopentransmanager            manager;
        CustTransOpen                       custTransOpen;
        CustTrans                           custTrans;
       
        //To mark particular invoice based on Acc num
        select custTransOpen where custTransOpen.AccountNum ==_accountNum
                join custTrans where custTrans.Invoice == _invoice
                     && custTrans.RecId == custTransOpen.RefRecId
                    && custTrans.AccountNum == custTransOpen.AccountNum;
   
        if(custTransOpen)
        {
            //To check transaction line which we want to settle
            manager = custvendopentransmanager::construct(_ledgerJournalTrans);
            manager.updateTransMarked(custTransOpen,true);
   
            Info(/Marked/);
        }
    }
    public void  settlementnew()
    {
        tender Tender;
        Ledgerjournaltrans  ledgerjournaltrans;
        Custinvoicejour custinvoicejour;
 
        select firstonly RecId, AccountNum, PaymentJournalNum, SalesId from Tender where  Tender.SalesId == '' &&  Tender.PaymentJournalNum != '';
        select firstonly InvoiceId from custinvoicejour where custinvoicejour.SalesId == Tender.Salesid;
        if (xtsTender)
        {
            While select * from Ledgerjournaltrans where ledgerjournaltrans.JournalNum == Tender.PaymentJournalNum
            {
                this.checkRecordMarked(custinvoicejour.InvoiceId, Ledgerjournaltrans, Tender.AccountNum);
            }
        }
        else
        {
            info(/Payment journal is not created for the sales order./);
        }
     }
    ///////////////////////****************///////////////
    public void MarkOpenTransaction()
    {
        SalesTable salesTable;
        CustTable custTable;
        CustInvoiceJour custInvoiceJour;
        CustTransOpen custTransOpen;
        CustTrans   custTrans;
        Tender sTender;
        LedgerJournalTrans ledgerJournalTrans;
       
//select firstOnly RecId, SalesId from salesTable order by salesTable.SalesId desc;
        //select firstonly RecId, CustAccount, SalesId from salesTable join Tender
        //            where salesTable.SalesId == Tender.SalesId && Tender.SalesId == '';
        select firstonly RecId,SalesId from salesTable where salesTable.SalesId == '';
        if (salesTable)
        {
            select firstonly RecId, InvoiceId, InvoiceDate, InvoiceAmount 
                from custInvoiceJour
            order by custInvoiceJour.InvoiceDate desc
                where custInvoiceJour.SalesId ==  salesTable.SalesId;
            if (custInvoiceJour)
            {
                select count(RecId) from custTransOpen
                where custTransOpen.RefRecId == custInvoiceJour.RecId;
                if (custTransOpen)
                {
                    select firstonly custTable
                    where custTable.AccountNum == salesTable.CustAccount;
                    if(custTable)
                    {
                        select firstonly custTrans
                            where custTrans.Invoice == custInvoiceJour.InvoiceId
                                && custTrans.AccountNum == custTable.AccountNum;
                        if (custTrans && custInvoiceJour.InvoiceAmount <= custTrans.AmountCur)
                        {
                            while select Tender
                        where Tender.SalesId == salesTable.SalesId
                            {
                                while select ledgerJournalTrans
                                where ledgerJournalTrans.JournalNum == Tender.PaymentJournalNum
                                {
                                    //info(strFmt(/Checking records for InvoiceId: %1, JournalNum: %2, AccountNum: %3/,
                                    //    custInvoiceJour.InvoiceId, ledgerJournalTrans.JournalNum, Tender.AccountNum));
                                    this.checkRecordMarked(custInvoiceJour.InvoiceId, ledgerJournalTrans, Tender.AccountNum);
                                }
                            }
                        }
                    }
                }
           }
        }
        else
        {
            info(/No invoice found for the specified SalesId./);
        }
    }
}

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,459 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,066 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans