Tuesday, April 13, 2021

How to use RecordInsertList in AX

/// <summary>
/// The <c>BankCheckStubDP</c> class declares the variables and tables that are required for the
/// <c>BankCheckStub</c> report.
/// </summary>
[
    SRSReportParameterAttribute(classStr(BankCheckStubContract))
]
public class BankCheckStubDP extends SRSReportDataProviderBase
{
    BankCheckStubTmp  BankCheckStubTmp;
    /// <summary>
    ///    Fetches the <c>BankCheckStubTmp</c> temporary table.
    /// </summary>
    /// <returns>
    ///    The <c>BankCheckStubTmp</c> temporary table.
    /// </returns>
    [
        SRSReportDataSetAttribute(tablestr(BankCheckStubTmp))
    ]
    public BankCheckStubTmp getBankCheckStubTmp()
    {
        select  BankCheckStubTmp;
    
        return  BankCheckStubTmp;
    }

    /// <summary>
    ///    Fetches the required data for the <c>BankCheckStub</c> report.
    /// </summary>
    public void processReport()
    {
        RecordInsertList            tmpTableRecordList;
        BankTrans             BankTrans;
        BankChequeTable             bankChequeTable;
        CompanyBankAccountId        curBankAccountIdGroup;
        BankChequeNum               curChequeNumGroup;
        int                         lineNumInCheck;
        RefRecId                    SSNType;
        HcmIdentificationNumber     BankSSN;
    
        BankCheckStubContract contract        = this.parmDataContract() as BankCheckStubContract;
        BankChequeNum               chequeNum       = contract.parmChequeNum();
        TransDate                   transDate       = contract.parmChequeDate();
        CompanyBankAccountId        bankAccountId   = contract.parmBankAccountId();
        ShowSSN                  showSSN         = contract.parmShowSSN();
    
        tmpTableRecordList = new RecordInsertList(tableNum(BankCheckStubTmp), true, true, true, false, true, BankCheckStubTmp);
    
        SSNType = BankAccountingParameters::find().SSNIdentificationType;
        if (!Global::hasTableAccess(tableNum(HcmPersonIdentificationNumber))
        ||  !Global::hasFieldAccess(tableNum(HcmPersonIdentificationNumber), fieldNum(HcmPersonIdentificationNumber, IdentificationNumber)))
        {
            showSSN = false;
        }
    
        while select BankTrans order by BankAccountId, BankChequeNum
            where (BankTrans.JournalEntryType == JournalEntryType::Refund
              ||   BankTrans.JournalEntryType == JournalEntryType::Stipend
              ||   BankTrans.JournalEntryType == JournalEntryType::SubsidiaryRefund)
              &&   BankTrans.SISPaymentType   == SISPaymentType::Check
              &&   BankTrans.BankChequeNum
              &&  (!chequeNum     || (chequeNum     && BankTrans.BankChequeNum  == chequeNum))
              &&  (!bankAccountId || (bankAccountId && BankTrans.BankAccountId  == bankAccountId))
            join TransDate from bankChequeTable
                where bankChequeTable.AccountID     == BankTrans.BankAccountId
                  &&  bankChequeTable.ChequeNum     == BankTrans.BankChequeNum
                  && (!transDate  || (transDate     && bankChequeTable.TransDate == transDate))
        {
            if (curBankAccountIdGroup != BankTrans.BankAccountId || curChequeNumGroup != BankTrans.BankChequeNum)
            {
                curBankAccountIdGroup = BankTrans.BankAccountId;
                curChequeNumGroup     = BankTrans.BankChequeNum;
                lineNumInCheck        = 1;
            }
    
            BankSSN  = "";
            if (showSSN)
            {
                BankSSN  = HcmPersonIdentificationNumber::findByPersonAndType(Bank::find(BankTrans.Bank).Person, SSNType).IdentificationNumber;
            }
    
            BankCheckStubTmp.BankAccountId   = BankTrans.BankAccountId;
            BankCheckStubTmp.ChequeNum       = BankTrans.BankChequeNum;
            BankCheckStubTmp.ChequeDate      = bankChequeTable.TransDate;
            BankCheckStubTmp.LineNum         = strFmt('%1', lineNumInCheck);
            BankCheckStubTmp.BankId       = strFmt('%1', BankTrans.BankIdInSIS);
            BankCheckStubTmp.BankName     = BankTrans.BankName();
            BankCheckStubTmp.BankSSN      = BankSSN;
            BankCheckStubTmp.FundSource      = FundSource::findByRecId(BankTrans.FundSource).Description;
            BankCheckStubTmp.Amount          = BankTrans.AmountCur;
    
            tmpTableRecordList.add(BankCheckStubTmp);
            lineNumInCheck++;
        }
    
        tmpTableRecordList.insertDatabase();
    }
}

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8