Add Total Quantity and Total Net amount in while Posting Invoice OR Delivery Note in sales order invoice/delivery note form in D365

Hi,


Request: Add Total Quantity and Total Net amount in while Posting Invoice OR Delivery Note in sales order invoice/delivery note form.





Solution:

Step 1: Above two fields are belong to Table SalesParmLine so Add new extension class for SalesParmLine Table and below display methods

[ExtensionOf(TableStr(SalesParmLine))]
public final class SalesParmLineTable_Extension
{

    /// <summary>
    ///
    /// </summary>
    PUBLIC static  display real  dispDeliver(SalesParmLine _salesParmLine)
    {
        // SalesParmLine_DS.observe();
        SalesParmLine _salesParmLine1 ;
        real DeliverNowSum=0;

        while select DeliverNow from _salesParmLine1 where _salesParmLine1.ParmId == _salesParmLine.ParmId &&
                _salesParmLine1.TableRefId == _salesParmLine.TableRefId &&
               _salesParmLine1.OrigSalesId == _salesParmLine.OrigSalesId
        {
            DeliverNowSum = DeliverNowSum + _salesParmLine1.DeliverNow;
        }

        return DeliverNowSum;
    }

    PUBLIC static  display real  dispNetAmount(SalesParmLine _salesParmLine2)
    {
        // SalesParmLine_DS.observe();
        SalesParmLine _salesParmLine3 ;
        real LineAmountSum=0;

        while select LineAmount  from _salesParmLine3 where _salesParmLine3.ParmId == _salesParmLine2.ParmId &&
                _salesParmLine3.TableRefId == _salesParmLine2.TableRefId &&
               _salesParmLine3.OrigSalesId == _salesParmLine2.OrigSalesId
        {
            LineAmountSum = LineAmountSum + _salesParmLine3.LineAmount;
        }

        return LineAmountSum;
    }

}



Step 2: Extend the form SalesEditLines and add new real control and assign the display method as below.




Reference


IF You want to validate anything like we have default invoice validation while posting DN and Invoice for all Sales Orders.

You can use below code for that.

[ExtensionOf(TableStr(SalesParmLine))]
public final class V_SalesParmLineTable_Extension
{

 public boolean  validateWrite()
    {
        boolean ret1;
        ret1= next validateWrite();

        if (this.InvoiceAccount != 'V.000004')
        {
           ret1 = checkfailed(strFmt("Invoice account %1 is invalid. Please change invoice account from %2 to V.000004 (Default Invoice account)." ,this.InvoiceAccount,this.InvoiceAccount));
        }

        return ret1;
    }

}

Validation msg




Comments