Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / Service class: for mar...
Finance forum
Unanswered

Service class: for marking invoice

editSubscribe (2) ShareShare
ReportReport
Posted on by 15
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./);
        }
    }
}
  • CU08050724-0 Profile Picture
    CU08050724-0 15 on at
    Service class: for marking invoice
    tender is table here,
     
  • Andre Arnaud de Calavon Profile Picture
    Andre Arnaud de Cal... 283,375 Super User on at
    Service class: for marking invoice
    Can you please answer all my questions? What is the current behavior? Do you get an error message? Do you get one of the info messages?
     
    I wonder what is being retrieved with the next line fo coding: 
       select firstonly RecId,SalesId from salesTable where salesTable.SalesId == '';
     
    There is no sales order number provided. I do expect this will not return any record. What is the xtsTender variable about?
  • CU08050724-0 Profile Picture
    CU08050724-0 15 on at
    Service class: for marking invoice
    ya, the code is marking settlements through the salesid (hardcoded value) but we want marking settlements through the tender.salesid.
     
  • CU08050724-0 Profile Picture
    CU08050724-0 15 on at
    Service class: for marking invoice
    tender is the partner solution here, 
    i have to start it with the tender salesid, 
    means whatever the tender created against the current salesid of the tender table 
     
    and if the custInvoiceJour.InvoiceAmount <= custTrans.AmountCur then it will find out the customer against the current sales id of the tendertable, and will check any invoice is remain to be marked againsst the customer, and will marked that invoice against customer
  • Andre Arnaud de Calavon Profile Picture
    Andre Arnaud de Cal... 283,375 Super User on at
    Service class: for marking invoice
    Hi,
     
    You provided some information and shared coding. What is the current behavior of the coding? Is one scenario not working? The Tender functionality is a customization or partner solution in your environment? Can you explain your exact question, please?

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,375 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans