Wednesday, 2 March 2022

Create cheque report in single page in D365 F&O

[ExtensionOf(classStr(ChequeController))]

final class DDDChequeController_Extension

{

    protected str determineReportMenuOutput(ChequeFormType _chequeFormType, BankChequeLayout _bankChequeLayout)

    {

        chequeReport = next determineReportMenuOutput( _chequeFormType,  _bankChequeLayout);

        switch (_chequeFormType)

        {

            case ChequeFormType::USStyle:

                chequeReport = ssrsReportStr(DDDCheque_US, Report);

                break;

        }

        return chequeReport;

    }

}

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

[ExtensionOf (classStr(ChequeDP))]

final class DDDChequeDP_Extension

{

    protected void populateChequeTmp()

    {

        #Define.Company('DDD')

        #Define.DefaultDDDCompany('XX000')

        #Define.EmptySpace(' ')

        #Define.BarCodeSplit('BARCODESPLIT')

        #Define.SlipText('\n\n\n\t                      SEE ENCLOSED FOR DETAILS OF INVOICES PAID.')

        #Define.EmptyLine('\n')


        next populateChequeTmp();


        bankChequeTable  bankChequeTable;

        int64            returnCount = 0, emptyLine = 0;


        if (BankChequeLayout::find(tmpChequePrintout.AccountId).chequeFormType == ChequeFormType::USStyle)

        {

            select firstonly bankChequeTable

            where bankChequeTable.AccountID == tmpChequePrintout.AccountID

            && bankChequeTable.ChequeNum == tmpChequePrintout.ChequeNum;

            if (bankChequeTable.RecId && !tmpChequePrintout.DDDVendorCompanyName)

            {

                ttsbegin;

                tmpChequePrintout.selectforupdate(true);

                tmpChequePrintout.DDDVendorCompanyName  = CompanyInfo::findByCompany_IN(bankChequeTable.RecipientCompany).Name;

                tmpChequePrintout.DDDVendorID           = bankChequeTable.RecipientAccountNum;

                tmpChequePrintout.DDDVendorCompanyID    = bankChequeTable.RecipientCompany;


                if (BankChequeLayout::find(tmpChequePrintout.AccountId).chequeFormType == ChequeFormType::USStyle)

                {

                    tmpChequePrintout.AmountTxt = strFmt('***%1', tmpChequePrintout.AmountTxt);

                }

                tmpChequePrintout.update();

                ttscommit;

            }


            BarcodeCode39 barcode, barCodeSplit;

            barcode      = Barcode::construct(BarcodeType::Code39);

            barCodeSplit = Barcode::construct(BarcodeType::Code39);


            barcode.string(true, (tmpChequePrintout.DDDVendorCompanyID == #Company? #DefaultDDDCompany: tmpChequePrintout.DDDVendorCompanyID)

                            +#EmptySpace+ tmpChequePrintout.DDDVendorID +#EmptySpace+ chequeTmp.ChequeNum);

            barcode.encode();


            barCodeSplit.string(true, #BarCodeSplit);

            barCodeSplit.encode();


            chequeTmp.DDDBarCode            = barcode.barcodeStr();

            chequeTmp.DDDBarCodeStatic      = barCodeSplit.barcodeStr();

            chequeTmp.DDDVendorCompanyName  = tmpChequePrintout.DDDVendorCompanyName;

            chequeTmp.DDDVendorID           = tmpChequePrintout.DDDVendorID;

        

            if (bankChequeLayout.DDDRegionsCheck == NoYes::No)

            {

                chequeTmp.Amount            = strRem(strFmt('**$%1**',chequeTmp.amountCur),',');

            }

        

            int64  invoiceCount = BankChequePaymTrans::getInvoiceCount(chequeTmp.ChequeNum, chequeTmp.AccountId);

            if (invoiceCount > bankChequeLayout.DDDMaxSlipLines)

            {

                chequeTmp.SlipTxt = #SlipText;


                if (bankChequeLayout.DDDMaxSlipLines >4)

                {

                    returnCount     = bankChequeLayout.DDDMaxSlipLines - 4;

                

                    while (emptyLine <= returnCount)

                    {

                        chequeTmp.SlipTxt = chequeTmp.SlipTxt + #EmptyLine;

                        emptyLine++;

                    }

                }

            }

            else 

            {

                returnCount = (invoiceCount < 5) ? 5-invoiceCount : returnCount;


                if (bankChequeLayout.DDDMaxSlipLines > returnCount)

                {

                    while (invoiceCount < bankChequeLayout.DDDMaxSlipLines-returnCount)

                    {

                        chequeTmp.SlipTxt = chequeTmp.SlipTxt + #EmptyLine;

                        invoiceCount++;

                    }

                }

            }

        }

    }


}

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

[ExtensionOf(classStr(CustVendCheque))]

final class DDDCustVendCheque_Extension

{

    public CompanyBankAccountId parmCompanyBankAccountId()

    {

        return accountId;

    }

    protected ChequeSlipTxt formatSlipText(LedgerJournalTrans _ledgerJournalTrans)

    {

        #define.NullValue('')


        _ledgerJournalTrans.PaymentNotes =  next formatSlipText(_ledgerJournalTrans);

        _ledgerJournalTrans.PaymentNotes = #NullValue;

        

        return _ledgerJournalTrans.PaymentNotes;

    }

    protected boolean shouldPrintPaymentNotes(LedgerJournalTrans _ledgerJournalTrans, Counter _bankChequePaymTransLines, Counter _totalBankChequePaymTransLines)

    {

        boolean             ret;

        ledgerJournalTrans  ledgerJournalTrans = _ledgerJournalTrans;

        ledgerJournalTrans = null;

        ret  =   next shouldprintpaymentNotes(ledgerJournalTrans,_bankChequePaymTransLines,_totalBankChequePaymTransLines);

        return ret;

    }

    protected int getRemainingTotalBankChequePaymentTransLines(int _totalBankChequePaymTransLines)

    {

        int totalBankChequePaymTransLines = next getRemainingTotalBankChequePaymentTransLines(_totalBankChequePaymTransLines);

        CompanyBankAccountId  accId = this.parmCompanyBankAccountId();

        if (totalBankChequePaymTransLines > BankChequeLayout::find(accId).DDDMaxSlipLines)

        {

            totalBankChequePaymTransLines = -1;

        }

        return totalBankChequePaymTransLines;

    }

    public void output(CustVendPaym _custVendPaym)

    {

        vendTable          vendTable;

        LedgerJournalTrans ledgerJournalTrans = _custVendPaym.ledgerJournalTrans();

        next output(_custVendPaym);

        if (ledgerJournalTrans.AccountType == LedgerJournalACType::Vend && ledgerJournalTrans.Company &&

            BankChequeLayout::find(tmpChequePrintout.AccountId).chequeFormType == ChequeFormType::USStyle)

        {

            vendTable = VendTable::findByLedgerDimension(ledgerJournalTrans.parmLedgerDimension());


            ttsbegin;

            tmpChequePrintout.selectforupdate(true);

            tmpChequePrintout.DDDVendorCompanyName  = CompanyInfo::findByCompany_IN(ledgerJournalTrans.Company).Name;

            tmpChequePrintout.DDDVendorID           = vendTable.AccountNum;

            tmpChequePrintout.DDDVendorCompanyID    = ledgerJournalTrans.Company;


            if (BankChequeLayout::find(tmpChequePrintout.AccountId).chequeFormType == ChequeFormType::USStyle)

            {

                tmpChequePrintout.AmountTxt = strFmt('***%1', tmpChequePrintout.AmountTxt);

            }

            tmpChequePrintout.update();

            ttscommit;

        }

     }

}

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

[ExtensionOf(classStr(CustVendChequeSlipTextCalculator))]

final class DDDCustVendChequeSlipTextCalculator_Extension

{

    #define.NullValue('')

    BankChequeLayout parmbankChequeLayout()

    {

        return bankChequeLayout;

    }


    public container determineSlipTextTitleAndEndLinesAdjustmentForChequeFormType(

    BankChequeTable _bankChequeTable,

    ChequeFormType _chequeFormType)

    {

        ChequeSlipTxt   chequeSlipText;

        Counter         endLines;

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

        switch (_chequeFormType)

        {

            case ChequeFormType::USStyle,

                ChequeFormType::ESStyle,

                ChequeFormType::MXStyle,

                ChequeFormType::CAStyle:

                chequeSlipText = #NullValue;

                endLines = 0;

                break;

        }

        return [chequeSlipText, endLines];

    }


    public container determineSlipTextTitleAndEndLinesAdjustmentForChequeRecipientType(

        BankChequeTable _bankChequeTable,

        ChequeFormType _chequeFormType)

    {

        ChequeSlipTxt chequeSlipText;

        Counter endLines;

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

        switch (_bankChequeTable.RecipientType)

        {

            case BankChequeRecipientType::Vend:

                VendTable vendTable = VendTable::findByCompany(_bankChequeTable.RecipientCompany, _bankChequeTable.RecipientAccountNum);

                if (vendTable)

                {

                    chequeSlipText = #NullValue;

                    endLines = 0;

                }

                break;

        }

        return [chequeSlipText, endLines];

    }


    public container determineSlipTextTitleAndEndLinesAdjustmentForColumnHeaders(

        BankChequeTable _bankChequeTable,

        ChequeFormType _chequeFormType)

    {

        ChequeSlipTxt   chequeSlipText;

        Counter         endLines;

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

        switch (_chequeFormType)

        {

            case ChequeFormType::USStyle,

                ChequeFormType::ESStyle,

                ChequeFormType::MXStyle,

                ChequeFormType::CAStyle,

                ChequeFormType::DEStyle,

                ChequeFormType::UKStyle:

                chequeSlipText = #NullValue;

                //chequeSlipText += strFmt(

                //    '%1         %2    %3             %4      %5   %6\n\n',

                //    "@SYS339127", "@SYS4726", "@SYS35300", "@SYS53072", "@SYS77949", "@SYS6901");

                endLines = -2;

                break;

        }

        return [chequeSlipText, endLines];

    }


    Protected CustVendChequeSlipTextCalcDeterminSlipTextForTotalReturn determineSlipTextTitleAndEndLinesForSubTotalOrTotal(CustVendChequeSlipTextCalcDeterminSlipTextForTotalParameters _args)

    {

        CustVendChequeSlipTextCalcDeterminSlipTextForTotalReturn totalReturn = CustVendChequeSlipTextCalcDeterminSlipTextForTotalReturn::construct();

        BankChequeLayout bankChequeLayoutValue = this.parmbankChequeLayout();

        totalReturn = next determineSlipTextTitleAndEndLinesForSubTotalOrTotal(_args);

        totalReturn.chequeSlipTxt = '';

        totalReturn.endLines      = -(bankChequeLayoutValue.DDDMaxSlipLines);

        return totalReturn;

    }

    protected boolean shouldPrintSubTotal(Counter _endLines, Counter _bankChequePaymTransLines, Counter _totalBankChequePaymTransLines, ChequeFormType _chequeFormType)

    {

        boolean shouldPrintSubTotal = next shouldPrintSubTotal(_endLines, _bankChequePaymTransLines, _totalBankChequePaymTransLines, _chequeFormType);

        if (_chequeFormType == ChequeFormType::USStyle)

        {

            shouldPrintSubTotal = false;

        }

        return shouldPrintSubTotal;

    }

    protected container determineSlipTextAndEndLinesAdjustmentForBankChequePaymTrans(BankChequePaymTrans bankChequePaymTrans)

    {

        ChequeSlipTxt   chequeSlipText;

        VendTrans       vendTrans;

        Counter         endLines;

        BankChequeTable bankChequeTable;

        FromDate        invoiceDate     = bankChequePaymTrans.InvoiceDate;

        CashDiscAmount  cashDiscAmount  = bankChequePaymTrans.CashDiscAmountCur;

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

         bankChequeTable = bankChequeTable::find(bankChequePaymTrans.AccountId, bankChequePaymTrans.ChequeNum);

        switch (bankChequeTable.RecipientType)

        {

            case BankChequeRecipientType::Vend:

                select firstonly Txt from vendTrans

                    where vendTrans.Invoice == bankChequePaymTrans.InvoiceId;

                chequeSlipText = #NullValue;

                chequeSlipText += strFmt('%1 %2 %3 %4 %5 %6\n',

                                strLFix(date2StrUsr(invoiceDate), 12),

                                strLFix(bankChequePaymTrans.InvoiceId, 14),

                                strLFix(vendTrans.Txt, 20),

                                strRFix(num2str(-bankChequePaymTrans.InvoiceAmountCur, 0, 2, -1, -1), 12),

                                strRFix(num2str(cashDiscAmount, 0, 2, -1, -1), 13),

                                strRFix(num2str(-bankChequePaymTrans.PaymentAmountCur, 0, 2, -1, -1), 14));


                endLines = -1;

                break;

        }

        return [chequeSlipText, endLines];

    }

}


No comments:

Post a Comment

DefaultDimension in d365 FO X++

 Navigate to PurchTable methods you can find with DefaultDimension this.DefaultDimension = this.mergeDimension(this.getDefaultDimension(),th...