Bank cheque report customization in D365

 Customize bank cheque payment report in D365


Lets say, we need to add a column Description in SlipText field on the report that is generated dynamically from code. In order to customize the field we need to make COC of few methods of class CustVendChequeSlipTextCalculator.



class CustVendChequeSlipTextCalculator is responsible for calculating slip text area required during printing of cheque and adding dynamic columns and values in the field.

Note: Cheque layout is sensitive to the area of printing. We need to be careful in order to modify a design while customizing as each and every field added to the report contains limited area of printing which is a risk to disturb as it can effect the size and length of report. Slip text is also calculated according to the size of the cheque in millimeters.

We need to create COC of following methods to add a new column in SlipText field. 

We have to add header and then value. 

Before creating COC for SlipText we need to first add Description field in table BankChequePaymTrans. 

Note: We need to create extension of the table and add Description field in BankChequePaymTrans.

After that we need to create a COC of method InitBankChequePaymentTransFromVendTrans of class CustVendCheque to fill description field as this field has to be populated from ledger transaction of vendor payment. 

[ExtensionOf(classStr(CustVendCheque))]

internal final class CustVendCheque_Extension

{

    Protected BankChequePaymTrans 
    initBankChequePaymentTransFromVendTrans
   (SpecTrans _specTrans, CustVendPaym _custVendPaym, AmountCur    
   _paymAmount)

    {
        BankChequePaymTrans bankChequePaymTrans;
        
        bankChequePaymTrans = next     
        initBankChequePaymentTransFromVendTrans(_specTrans, 
        _custVendPaym,     _paymAmount);

        bankChequePaymTrans.Description = 
        _custVendPaym.ledgerJournalTrans().Txt;
        
        return bankChequePaymTrans;
    }

Now we need to use this description field of BankChequePaymTrans in SlipText value.

1)  For Header column we need to create COC of method determineSlipTextTitleAndEndLinesAdjustmentForColumnHeaders.

[ExtensionOf(classStr(CustVendChequeSlipTextCalculator))]

internal final class CustVendChequeSlipTextCalculator_Extension

{

      public container 
      determineSlipTextTitleAndEndLinesAdjustmentForColumnHeaders
     (BankChequeTable _bankChequeTable, ChequeFormType,
      _chequeFormType)
     {
        ChequeSlipTxt chequeSlipText;
        Counter endLines;

        [chequeSlipText, endLines] = next 
        determineSlipTextTitleAndEndLinesAdjustmentForColumnHeaders
        (_bankChequeTable, _chequeFormType);

        switch (_chequeFormType)
        {
            case ChequeFormType::USStyle:  
            //we can modify cheque slip text here
                chequeSlipText = strFmt(
                    '\n\n\n%1       %2    %3   %4 %5\n\n',
                    "@SYS14204", "@SYS80056", "@SYS41042",      
                    "@SYS11818", "@SYS1943");
                endLines = -2;
                break;
        }
        return [chequeSlipText, endLines];
    }

2) Now adding column value in slip text. We need to create COC of method determinSlipTextAndEndLinesAdjustmentForBankChequePaymTrans.

    protected container   
    determineSlipTextAndEndLinesAdjustmentForBankChequePaymTrans
   (BankChequePaymTrans bankChequePaymTrans)
    {
        ChequeSlipTxt chequeSlipText;
        Counter endLines;

        [chequeSlipText, endLines] = next
        determineSlipTextAndEndLinesAdjustmentForBankChequePaymTrans
        (bankChequePaymTrans);

        FromDate invoiceDate = bankChequePaymTrans.InvoiceDate;

        //we can modify values here for slip text
        chequeSlipText = strFmt(
        '%1  %2  %3  %4  %5\n',
        strLFix(bankChequePaymTrans.InvoiceId, 12),
        strLFix(date2StrUsr(invoiceDate), 10),
        strLFix(bankChequePaymTrans.Description, 36),
        strRFix(num2str(-
        bankChequePaymTrans.InvoiceAmountCur, 0, 2, -1, -1), 12),
        strRFix(num2str(-
        bankChequePaymTrans.PaymentAmountCur, 0, 2, -1, -1), 14));

        endLines = -1;
        return [chequeSlipText, endLines];
    }

Also, if we need to move a value we can use strLFix and strRFix.
strLFix moves value from left side
strRFix moves value from right side


I need to move total amount of SlipText to a bit of right side to adjust accordingly, so we need to create another COC of method determineSlipTextTitleAndEndLinesForSubTotalOrTotal of same class above,
that is responsible for adjusting total amount of slipText. 


Note: I changed strLFix(_args.chequeSlipTxtLabel, 66) to trLFix(_args.chequeSlipTxtLabel, 75) in below method. 


 protected CustVendChequeSlipTextCalcDeterminSlipTextForTotalReturn 
 determineSlipTextTitleAndEndLinesForSubTotalOrTotal(CustVendChequeSl
 ipTextCalcDeterminSlipTextForTotalParameters _args)
 {
    CustVendChequeSlipTextCalcDeterminSlipTextForTotalReturn 
    totalReturn = 
    CustVendChequeSlipTextCalcDeterminSlipTextForTotalReturn
    ::construct();

    totalReturn = next 
    determineSlipTextTitleAndEndLinesForSubTotalOrTotal(_args);

    totalReturn.chequeSlipTxt = strFmt('\n%1 %2', 
    strLFix(_args.chequeSlipTxtLabel, 75)
    num2str(_args.TotalAmountCur, 16, 2, -1, -1));
    
    totalReturn.endLines = -1;

    return totalReturn;
 }

Output:










Comments

Popular posts from this blog

Cross Company queries - X++

Create multi select company lookup in report dialogue using X++

Positive pay file in D365