Thursday, February 16, 2023

Sales invoice journal create and posting classes in D365FO

 Sales invoice journal create and posting classes in D365FO.

While creating:

[ExtensionOf(classstr(SalesInvoiceJournalCreateBase))]
final class SalesInvoiceJournalCreateBase_Extension
{
    public InvoiceId SalesInvoiceNum;

    protected void initJournalHeader()
    {       
        next initJournalHeader();

        if(CustParameters::find().ManualSalesInvoiceId == NoYes::Yes)
        {
            custInvoiceJour custInvoiceJourLocal;
            
            if(!SalesInvoiceNum)
            {            
                warning("Invoice number must be filled in.");
                throw error(strFmt("@SYS26498", custInvoiceJour.SalesId));          
            }
            select firstonly SalesId,InvoiceId from custInvoiceJourLocal
                where custInvoiceJourLocal.InvoiceId == SalesInvoiceNum;

            if(custInvoiceJourLocal.RecId != 0)
            {                
                warning(strFmt("Invoice number %1 already used for sales order %2",
                    SalesInvoiceNum,custInvoiceJourLocal.SalesId));
                throw error(strFmt("@SYS26498", custInvoiceJour.SalesId));
            }

            custInvoiceJour.InvoiceId = SalesInvoiceNum;
        }
    }

    protected container getNumAndVoucher()
    {
        container conLocal = next getNumAndVoucher();

        if(CustParameters::find().ManualSalesInvoiceId == NoYes::Yes)
        {
            SalesInvoiceNum = salesParmUpdate.InvoiceId;
            conLocal = conPoke(conLocal,1,SalesInvoiceNum);
        }

        return conLocal;
    }

}

While Posting:

[ExtensionOf(classstr(CustPostInvoice))]
final class CustPostInvoice_Extension
{
    public CustInvoiceId CustInvoiceId;

    protected container getInvoiceIdAndVoucher(CustInvoiceTable _custInvoiceTable, NumberSeq _numberSeq)
    {
        CustInvoiceTable custInvoiceTableLocal;

        container conLocal = next getInvoiceIdAndVoucher(_custInvoiceTable,_numberSeq);

        if(CustParameters::find().ManualSalesInvoiceId == NoYes::Yes)
        {
           CustInvoiceId = _custInvoiceTable.InvoiceId;

            if(!CustInvoiceId)
            {
                warning("Invoice number must be filled in.");
                throw error("Posting has been cancelled.");
            }
            select firstonly InvoiceId from custInvoiceTableLocal
                where custInvoiceTableLocal.InvoiceId == CustInvoiceId;

            if(custInvoiceTableLocal.RecId != 0)
            {
                warning(strFmt("Invoice number %1 has already been used.", CustInvoiceId));
                throw error("Posting has been cancelled.");
            }

            conLocal = conPoke(conLocal,1,CustInvoiceId);
        }


        return conLocal;
    }

}


Keep Daxing!!

No comments:

Post a Comment