Thursday, 3 March 2022

Customer Aging Report in d365 F&O

 Added new fields to CustAgingReportTmp

public class DDDCustAgingReportController extends SrsReportRunController implements BatchRetryable

{

    protected str getReportName(CustAgingReportContract _contract)

    {

        str reportNameLocal;


        if (_contract.parmDetailed())

        {

            if (_contract.parmIncludeAmountCur())

            {

                reportNameLocal = ssrsReportStr(DDDCustAgingReport, DesignWithDetailAndWithTransactionCur);

            }

            else

            {

                reportNameLocal = ssrsReportStr(DDDCustAgingReport, DesignWithDetailAndNoTransactionCur);

            }

        }

        else

        {

            if (_contract.parmIncludeAmountCur())

            {

                reportNameLocal = ssrsReportStr(DDDCustAgingReport, DesignWithNoDetailAndWithTransactionCur);

            }

            else

            {

                reportNameLocal = ssrsReportStr(DDDCustAgingReport, DesignWithNoDetailAndNoTransactionCur);

            }

        }


        return reportNameLocal;

    }


    protected void prePromptModifyContract()

    {

        CustAgingReportContract contract = this.parmReportContract().parmRdpContract() as CustAgingReportContract;


        this.setRanges(this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey()), contract);

    }

  

    protected void preRunModifyContract()

    {

        CustAgingReportContract contract = this.parmReportContract().parmRdpContract() as CustAgingReportContract;

        this.parmReportContract().parmReportName(this.getReportName(contract));

        super();

    }

  

    protected container preRunValidate()

    {

        // Now that this report is a preprocess tempdb report, we no longer need

        // the limits that were required in the SYS version of the report.

        return super();

    }

    protected void queryChanged(str _key, Query _query)

    {

        super(_key, _query);

        SysOperationDataContractInfo queryInfo = this.getDataContractInfoObjectsRecursively().lookup(_key);

        SysOperationQueryDataContractInfo queryDataContractInfo = queryInfo as SysOperationQueryDataContractInfo;


        // checking to see if queryInfo is an object of SysOperationQueryDataContractInfo, if yes only then

        // check sorting information

        if (queryDataContractInfo != null)

        {

            int datasourceCount = _query.dataSourceCount();


            for (int i = 1; i <= datasourceCount; i+=1)

            {

                int sortFieldCount = _query.dataSourceNo(i).sortFieldCount();


                if (sortFieldCount)

                {

                    boolean found = false;

                    int j = 1;

                    QueryBuildDataSource qbds = _query.dataSourceNo(i);

                    str tableName = tableId2Name(qbds.table());


                    while (!found && j <= sortFieldCount)

                    {

                        found = (tableName == tableStr(CustTable)

                                    && qbds.sortField(j) != fieldNum(CustTable, AccountNum)

                                    && qbds.sortField(j) != fieldNum(CustTable, CustGroup))

                                || (tableName == tableStr(DirPartyTable) && qbds.sortField(j) != fieldNum(DirPartyTable, Name));


                        j++;

                    }

                    if (found)

                    {

                        info(strFmt("@AccountsReceivable:FieldsToSortInAgingReport", fieldPName(CustTable, AccountNum), fieldPName(DirPartyTable, Name), fieldPName(CustTable, CustGroup)));

                    }

                }

            }

        }

    }

   

    public void setRanges(Query _query, CustAgingReportContract _contract)

    {

        CustAgingReportTmp custAgingReportTmp;

        // Checking the current table number

        if (this.parmArgs() && this.parmArgs().record() && this.parmArgs().record().TableId == tableNum(CustAgingReportTmp))

        {

            custAgingReportTmp = this.parmArgs().record();

            // Modifying the query

            _query.dataSourceTable(tableNum(CustTable)).rangeField(fieldNum(CustTable, AccountNum)).value(custAgingReportTmp.AccountNum);


            // Setting the ranges

            _contract.parmDateTransactionDuedate(any2int(custAgingReportTmp.Balance01));

            _contract.parmAgingBuckets(custAgingReportTmp.Txt);

        }

    }

    public static void main(Args _args)

    {

        DDDCustAgingReportController controller = new DDDCustAgingReportController();

        controller.parmReportName(ssrsReportStr(DDDCustAgingReport, DesignWithNoDetailAndNoTransactionCur));

        controller.parmArgs(_args);

        controller.startOperation();

    }

    [Hookable(false)]

    final boolean isRetryable() 

    {

        return true;

    }

}

----------------------------------------------**************--------------------------------

[ExtensionOf(classStr(CustAgingReportDP))]

public final class DDDCustAgingReportDP_Extension

{

    protected CustAgingReportTmp insertCustAgingReportTmp(boolean _reverseAmountsAndHeadings)

    {

        CustTrans    custtrans;

        next insertCustAgingReportTmp(_reverseAmountsAndHeadings);

        CustAgingReportTmp   custAgingReportTmpLocal = this.custAgingReportTmp;

        update_recordset custAgingReportTmpLocal

            setting 

            DDDInvoiceAmount = custtrans.AmountCur,

            DDDTextRef = custtrans.TextRef

            join  custtrans

            where custtrans.Invoice  == custAgingReportTmpLocal.InvoiceId

            && custtrans.Invoice != "";


        return custAgingReportTmpLocal;

    }

}

No comments:

Post a Comment

Clean up jobs in D365FO

  https://anithasantosh.wordpress.com/2024/11/07/clean-up-jobs-in-d365fo/