Thursday, 3 July 2025

Vendor payment advice remittance report in d365 FO X++

 Class:

[ExtensionOf(classStr(BankPaymAdviceReportGeneratorVend))]

public final class HTM_BankPaymAdviceReportGeneratorVend_C_Extension

{

    protected void populateBankPaymAdviceTempCommonInfo()

    {

        BankPaymAdviceVendTmp vendTmp = bankPaymAdviceTmp;

        next populateBankPaymAdviceTempCommonInfo();


        this.assignCompanyDetails(vendTmp);

    }


    public void assignCompanyDetails(BankPaymAdviceVendTmp _vendTmp)

    {

        BankPaymAdviceVendTmp vendTmpLocal = _vendTmp;


        companyInfo = CompanyInfo::find();

        vendTmpLocal.HTM_CompanyLogo = CompanyImage::findByRecord(companyInfo).Image;

        vendTmpLocal.CompanyPhone = this.getRemittancePhone(companyInfo);

        vendTmpLocal.HTM_CompanyEmail = this.getRemittanceEmail(companyInfo.recid);

    }


    public Phone getRemittancePhone(CompanyInfo _companyInfo)

    {

        CompanyInfo companyInfoLocal = _companyInfo;

        DirPartyLocation dirPartyLocation;

        LogisticsElectronicAddress logisticsElectronicAddress;

        LogisticsElectronicAddressRole logisticsElectronicAddressRole;

        LogisticsLocationRole logisticsLocationRole;

        const str RemitTo = 'Remittance';

        Phone remittancePhone;


        while select dirPartyLocation

            where dirPartyLocation.party == companyInfoLocal.RecId

        {

            while select logisticsElectronicAddress

                where logisticsElectronicAddress.Location == dirPartyLocation.Location

                    && logisticsElectronicAddress.Type == LogisticsElectronicAddressMethodType::Phone

            {

                while select logisticsElectronicAddressRole

                    where logisticsElectronicAddressRole.ElectronicAddress == logisticsElectronicAddress.RecId

                        join logisticsLocationRole

                        where logisticsLocationRole.RecId == logisticsElectronicAddressRole.LocationRole

                        && logisticsLocationRole.Name == RemitTo

                {

                    remittancePhone = logisticsElectronicAddress.Locator;

                }

            }

        }


        return remittancePhone;

    }


    public Email getRemittanceEmail(RefRecId _refRecid)

    {

        DirPartyLocation                dirPartyLocation;

        LogisticsElectronicAddress      logisticsElectronicAddress;

        LogisticsElectronicAddressRole  logisticsElectronicAddressRole;

        LogisticsLocationRole           logisticsLocationRole;

        const str RemitTo = 'Remittance';

        Email remittanceEmail;


        while select dirPartyLocation

            where dirPartyLocation.party == _refRecid

        {

            while select logisticsElectronicAddress

                where logisticsElectronicAddress.Location == dirPartyLocation.Location

                    && logisticsElectronicAddress.Type    == LogisticsElectronicAddressMethodType::Email

            {

                while select logisticsElectronicAddressRole

                    where logisticsElectronicAddressRole.ElectronicAddress == logisticsElectronicAddress.RecId

                        join logisticsLocationRole

                        where logisticsLocationRole.RecId == logisticsElectronicAddressRole.LocationRole

                        && logisticsLocationRole.Name == RemitTo

                {

                    remittanceEmail = logisticsElectronicAddress.Locator;

                }

            }

        }

        return remittanceEmail;

    }


    protected void populateBankPaymAdviceTempPaymentInfo()

    {

        BankPaymAdviceVendTmp vendTmp = bankPaymAdviceTmp;

        next populateBankPaymAdviceTempPaymentInfo();

        this.assignOtherDetails(vendTmp);

    }


    public void assignOtherDetails(BankPaymAdviceVendTmp _vendTmp)

    {

        BankPaymAdviceVendTmp vendTmpLocal = _vendTmp;

        VendBankAccount vendBankAccount = VendBankAccount::find(vendTable.AccountNum, ledgerJournalTrans.CustVendBankAccountId);


        if (vendBankAccount)

        {

            vendTmpLocal.HTM_RegistrationNum = vendBankAccount.RegistrationNum;

            vendTmpLocal.HTM_VendAccountNum = vendBankAccount.AccountNum;

        }

        vendTmpLocal.HTM_JournalBatchNum = ledgerJournalTrans.JournalNum;

        vendTmpLocal.HTM_Voucher = ledgerJournalTrans.Voucher;

        vendTmpLocal.HTM_VendAccountId = vendTable.AccountNum;

        LogisticsElectronicAddress electronicAddressPhone = DirParty::primaryElectronicAddress(vendTable.Party, LogisticsElectronicAddressMethodType::Phone);


        vendTmpLocal.HTM_VendorPhone   = electronicAddressPhone ? electronicAddressPhone.Locator : '';

        vendTmpLocal.HTM_VendorEmail   = this.getRemittanceEmail(vendTable.party);

    }


    protected void populateBankPaymAdviceTempInvoiceInfo()

    {

        BankPaymAdviceVendTmp vendTmp = bankPaymAdviceTmp;

        next populateBankPaymAdviceTempInvoiceInfo();

        VendInvoiceJour vendInvoiceJour;

        select crosscompany Description

            from vendInvoiceJour 

            where VendInvoiceJour.InvoiceId == vendTmp.Invoice && VendInvoiceJour.InvoiceAccount == vendTmp.AccountNum;

        vendTmp.HTM_InvoiceDescription = vendInvoiceJour.Description;

    }

}

------------------------

[ExtensionOf(classStr(BankPaymAdviceVendDPTransferQueryGenerator))]

public final class HTM_BankPaymAdviceVendDPTransferQueryGenerator_C_Extension

{

    protected void addInsertionFields(SysDaInsertObject _insertObject)

    {

        next addInsertionFields(_insertObject);

        

        _insertObject.fields()

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_VendAccountId))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_CompanyEmail))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_Voucher))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_JournalBatchNum))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_RegistrationNum))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_VendAccountNum))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_CompanyLogo))

            .add(fieldStr(BankPaymAdviceVendV2Tmp,HTM_InvoiceDescription))

            .add(fieldStr(BankPaymAdviceVendV2Tmp,HTM_VendorEmail))

            .add(fieldStr(BankPaymAdviceVendV2Tmp,HTM_VendorPhone));


    }


    protected void addProjectionFields(SysDaQueryObject _queryObject)

    {

        next addProjectionFields(_queryObject);


        _queryObject.projection()

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_VendAccountId))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_CompanyEmail))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_Voucher))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_JournalBatchNum))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_RegistrationNum))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_VendAccountNum))

            .add(fieldStr(BankPaymAdviceVendV2Tmp, HTM_CompanyLogo))

            .add(fieldStr(BankPaymAdviceVendV2Tmp,HTM_InvoiceDescription))

            .add(fieldStr(BankPaymAdviceVendV2Tmp,HTM_VendorEmail))

            .add(fieldStr(BankPaymAdviceVendV2Tmp,HTM_VendorPhone));

    }

}
---------------------------------------------------

public class HTM_PrintMgmtDocTypeHandler

{

    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]

    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)

    {

        switch(_docType)

        {

            case PrintMgmtDocumentType::VendPaymAdvice:

                _result.result(ssrsReportStr(HTM_BankPaymAdviceVendV2, Report));

                break;

        }

    }

}
---------------------------------

[ExtensionOf(classStr(SrsReportRunController))]

public final class HTM_SrsReportRunController_C_Extension

{

    protected void preRunModifyContract()

    {

        if (this.parmReportContract().parmRdpContract() is BankPaymAdviceContract)

        {

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

            if(LedgerJournalTrans::findRecId(contract.parmLedgerJournalTransRecId(), false).AccountType == LedgerJournalACType::Vend)

            {

                this.parmReportContract().parmReportName(ssrsReportStr(HTM_BankPaymAdviceVendV2, Report));

            }

        }

        next preRunModifyContract();

    }


    public LabelType parmDialogCaption(LabelType _dialogCaption)

    {

        LabelType reportDialogCaption;

        Name rdpName;

        reportDialogCaption = next parmDialogCaption(_dialogCaption);

        rdpName = this.getReportContract().parmRdpName();

        if (this.getReportContract().parmRdpName() == classStr(BankPaymAdviceVendDP))

        {

            reportDialogCaption = "@HTMships:HTM_RemAd"; // Set the file name

        }

        return reportDialogCaption;

    }

}

---------------------------------------------------
Reports: Duplicate standard report 

HTM_BankPaymAdviceVendV2
---------------------------------------------------
Table extension: Add fields in both tables

BankPaymAdviceVendTmp.HTMships
BankPaymAdviceVendV2Tmp.HTMships

No comments:

Post a Comment

Financial reporting DataMart reset in D365 FO X++

  https://community.dynamics.com/blogs/post/?postid=f866f228-4ca5-4013-b996-ec2fe9dde72e