Thursday, 3 July 2025

Free Text invoice report in d365 FO X++

https://community.dynamics.com/blogs/post/?postid=19c6056b-956f-4325-bf2a-25b9c0ea9e12

Class:

class HTM_FreeTextInvoiceController extends FreeTextInvoiceController

{

    public static HTM_FreeTextInvoiceController construct()

    {

        return new HTM_FreeTextInvoiceController();

    }

    public static void main(Args _args)

    {

        SrsReportRunController formLetterController = HTM_FreeTextInvoiceController::construct();

        HTM_FreeTextInvoiceController controller = formLetterController;

        controller.parmReportName(ssrsReportStr(HTM_FreeTextInvoice, Report));

        controller.parmArgs(_args);

        controller.startOperation();

    }



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

[ExtensionOf(classStr(FreeTextInvoiceDP))]

public final class HTM_FreeTextInvoiceDP_C_Extension

{

    protected void populateFreeTextInvoiceHeaderFooterTmp(CustInvoiceJour _custInvoiceJour, CompanyInfo _companyInfo)

    {

        next populateFreeTextInvoiceHeaderFooterTmp(_custInvoiceJour, _companyInfo);

        LogisticsElectronicAddress electronicAddressPhone = DirParty::primaryElectronicAddress(CustTable::find(_custInvoiceJour.InvoiceAccount).Party, LogisticsElectronicAddressMethodType::Phone);


        freeTextInvoiceHeaderFooterTmp.HTM_CustPhone        = electronicAddressPhone ? electronicAddressPhone.Locator : '';

        freeTextInvoiceHeaderFooterTmp.HTM_CustEmail        = this.getinvoiceEmail(CustTable::find(_custInvoiceJour.InvoiceAccount).party);

        freeTextInvoiceHeaderFooterTmp.HTM_Notes            = SalesTable::find(_custInvoiceJour.SalesId).HTMInvoiceNotes;

        freeTextInvoiceHeaderFooterTmp.HTM_Project          = this.getDimensionDisplayValue(_custInvoiceJour.DefaultDimension, 'A7Project');

        freeTextInvoiceHeaderFooterTmp.HTM_Vessel           = SalesTable::find(_custInvoiceJour.SalesId).HTMVessel;

        freeTextInvoiceHeaderFooterTmp.HTM_PaymentReference = _custInvoiceJour.payment;

        freeTextInvoiceHeaderFooterTmp.CompanyBankAccount   = BankAccountTable::find(_companyInfo.Bank).AccountNum;

        freeTextInvoiceHeaderFooterTmp.CompanyBankName      = BankAccountTable::find(_companyInfo.Bank).Name;

        freeTextInvoiceHeaderFooterTmp.CompanyRegNum        = BankAccountTable::find(_companyInfo.Bank).RegistrationNum;

        freeTextInvoiceHeaderFooterTmp.SwiftNumber          = BankAccountTable::find(_companyInfo.Bank).swiftNo;

        freeTextInvoiceHeaderFooterTmp.HTM_FooterText       = CustFormletterParameters::find().HTM_FooterText;

        freeTextInvoiceHeaderFooterTmp.CompanyEmail         = _companyInfo.email();

    }


    /// <summary>

    /// Get Invoice Advice Email

    /// </summary>

    /// <param name = "_refRecid">RefRecid Information</param>

    /// <returns>Invoice Email Address</returns>

    public Email getInvoiceEmail(RefRecId _refRecid)

    {

        DirPartyLocation                dirPartyLocation;

        LogisticsElectronicAddress      logisticsElectronicAddress;

        LogisticsElectronicAddressRole  logisticsElectronicAddressRole;

        LogisticsLocationRole           logisticsLocationRole;

        const str invoiceTo = 'Invoice';

        Email invoiceEmail;


        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 == invoiceTo

                {

                    invoiceEmail = logisticsElectronicAddress.Locator;

                }

            }

        }


        return invoiceEmail;

    }


    public str getDimensionDisplayValue(RecId defaultDimension, Name dimName)

    {

        DimensionAttributeValueSetStorage dimStorage;

        dimStorage = DimensionAttributeValueSetStorage::find(defaultDimension);

        return dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName(dimName).RecId);

    }

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

public class HTM_PrintMgmtDocTypeHandler

{

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

    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)

    {

        switch(_docType)

        {

            case PrintMgmtDocumentType::SalesFreeTextInvoice:

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

                break;

        }

    }

}
-----------------------------------------------------
Output Menu Item Extensions:
FreeTextInvoiceCopy.HTMship
FreeTextInvoiceOriginal.HTMship

----------------------------------------------------
Report: Duplicate the standard report and do the required changes
HTM_FreeTextInvoice

---------------------------------------------------
Table Extensions:
FreeTextInvoiceHeaderFooterTmp.HTMship

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