08 July 2019

Credit limit check on Sales Quotation based on the customer credit limit in D365 FO of AX7


class TRG_SalesQuotationTableWriteEventHandler
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(SalesQuotationTable, SalesQuotationLine), FormDataSourceEventType::Written)]
    public static void SalesQuotationLine_OnWriting(FormDataSource sender, FormDataSourceEventArgs e)
    {
        SalesQuotationTable salesQuotationTable;
        SalesQuotationLine  salesQuotationLine,salesQuotationLineLoc;
        CustTransOpenSum    custTransOpenSum;

        salesQuotationLineLoc = sender.cursor();
        salesQuotationTable = salesQuotationTable::find(salesQuotationLineLoc.QuotationId);

        if(smmParametersTable::find().CheckCreditLimitOnQuotation == NoYes::Yes)
        {
            Amount creditLimit  = CustTable::find(salesQuotationLineLoc.CustAccount).CreditMax;
            select sum(LineAmount) from salesQuotationLine
                group by QuotationId
                where salesQuotationLine.QuotationId == salesQuotationTable.QuotationId;
           
            select AccountNum,AmountMST from custTransOpenSum
                where custTransOpenSum.AccountNum == salesQuotationTable.CustAccount;

            Amount newBalance = custTransOpenSum.AmountMST + salesQuotationLine.LineAmount;
            Amount creditExcess = newBalance - creditLimit;
            if(newBalance  > creditLimit)
            {
                warning(strFmt("Quotation:%1 Creit limit exedded Opening balance %2 Current order:%3 New balance:%4 Credit limit:%5 Credit excess:%6 ",
                    salesQuotationLineLoc.QuotationId,
                    custTransOpenSum.AmountMST,
                    salesQuotationLine.LineAmount,
                    newBalance,
                    creditLimit,
                    creditExcess));
            }
        }
    }

}

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...