Excel export Vendor invoice journal excel template from the form.

 Today we have a requirement to create a custom excel export from the form :- 


using Microsoft.Dynamics.Platform.Integration.Office;


/// <summary>

/// The <c>VendInvoiceJournalExcelTemplate</c> is the supporting class for the Vendor invoice journal excel template.

/// </summary>

public class AVAVendInvoiceJournalExcelTemplate extends DocuTemplateRegistrationBase implements LedgerIJournalExcelTemplate

{

    private const DocuTemplateName ExcelTemplateName = resourceStr(WGVendInvoiceJournalTemplate);

    private const DataEntityName LineEntityName = tableStr(VendInvoiceJournalLineEntity);

    private const FieldName LineEntityJournalNum = fieldStr(VendInvoiceJournalLineEntity, JournalBatchNumber);

    private const FieldName LineEntityDataAreaId = fieldStr(VendInvoiceJournalLineEntity, dataAreaId);

    private const DataEntityName HeaderEntityName = tableStr(VendInvoiceJournalHeaderEntity);

    private const FieldName HeaderEntityJournalNum = fieldStr(VendInvoiceJournalHeaderEntity, JournalBatchNumber);

    private const FieldName HeaderEntityDataAreaId = fieldStr(VendInvoiceJournalHeaderEntity, dataAreaId);


    public boolean isJournalTypeSupported(LedgerJournalType _ledgerJournalType)

    {

        return _ledgerJournalType == LedgerJournalType::VendInvoiceRegister;

    }


    public DocuTemplateName documentTemplateName()

    {

        return ExcelTemplateName;

    }


    public void applyCustomTrimming(Excel.IWorkbookManager _templateManager, Excel.WorkbookSettingsManager _settingsManager, LedgerJournalTable _ledgerJournalTable)

    {

    }


    public Set supportedAccountTypes()

    {

        Set accountTypeSet = new Set(Types::Integer);


        accountTypeSet.add(LedgerJournalACType::FixedAssets);

        accountTypeSet.add(LedgerJournalACType::Ledger);

        accountTypeSet.add(LedgerJournalACType::Project);

        accountTypeSet.add(LedgerJournalACType::Vend);


        return accountTypeSet;

    }


    public Set supportedOffsetAccountTypes()

    {

        Set offsetAccountTypeSet = new Set(Types::Integer);


        offsetAccountTypeSet.add(LedgerJournalACType::FixedAssets);

        offsetAccountTypeSet.add(LedgerJournalACType::Ledger);

        offsetAccountTypeSet.add(LedgerJournalACType::Project);

        offsetAccountTypeSet.add(LedgerJournalACType::Vend);


        return offsetAccountTypeSet;

    }


    public Set supportedAssetTransTypes()

    {

        Set assetTransTypeSet = new Set(Types::Integer);


        assetTransTypeSet.add(AssetTransTypePurch::Acquisition);

        assetTransTypeSet.add(AssetTransTypePurch::AcquisitionAdj);


        return assetTransTypeSet;

    }


    public boolean validateJournalForTemplate(LedgerJournalTable _ledgerJournalTable)

    {

        return LedgerJournalExcelTemplate::validateJournalForTemplate(_ledgerJournalTable, this);

    }


    public void registerTemplates()

    {

        this.addTemplate(

            OfficeAppApplicationType::Excel,

            ExcelTemplateName,

            ExcelTemplateName,

            literalStr("@AccountsPayable:VendInvoiceJournalTemplateDescription"),

            literalStr("@AVAExtension:VendInvoiceJpurnalTemplate"),

            NoYes::No,

            NoYes::No);

    }


    public DataEntityName headerEntityName()

    {

        return HeaderEntityName;

    }


    public DataEntityName lineEntityName()

    {

        return LineEntityName;

    }


    public FieldName headerJournalBatchNumberFieldName()

    {

        return HeaderEntityJournalNum;

    }


    public FieldName headerDataAreaFieldName()

    {

        return HeaderEntityDataAreaId;

    }


    public FieldName lineJournalBatchNumberFieldName()

    {

        return LineEntityJournalNum;

    }


    public FieldName lineDataAreaFieldName()

    {

        return LineEntityDataAreaId;

    }


    public FilterCollectionNode appendHeaderEntityFilters(FilterCollectionNode _headerFilter, ExportToExcelFilterTreeBuilder _headerFilterBuilder)

    {

        return _headerFilter;

    }


    public FilterCollectionNode appendLineEntityFilters(FilterCollectionNode _lineFilter, ExportToExcelFilterTreeBuilder _lineFilterBuilder)

    {

        FilterCollectionNode accountTypeFilter = _lineFilterBuilder.or(

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, AccountType), LedgerJournalACType::Vend),

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, AccountType), LedgerJournalACType::Ledger));


        accountTypeFilter = _lineFilterBuilder.or(accountTypeFilter,

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, AccountType), LedgerJournalACType::FixedAssets));


        accountTypeFilter = _lineFilterBuilder.or(accountTypeFilter,

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, AccountType), LedgerJournalACType::Project));


        FilterCollectionNode offsetAccountTypeFilter = _lineFilterBuilder.or(

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, OffsetAccountType), LedgerJournalACType::Ledger),

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, OffsetAccountType), LedgerJournalACType::FixedAssets));


        offsetAccountTypeFilter = _lineFilterBuilder.or(offsetAccountTypeFilter,

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, OffsetAccountType), LedgerJournalACType::Project));


        offsetAccountTypeFilter = _lineFilterBuilder.or(offsetAccountTypeFilter,

            _lineFilterBuilder.areEqual(fieldStr(VendInvoiceJournalLineEntity, OffsetAccountType), LedgerJournalACType::Vend));


        FilterCollectionNode accountAndOffsetAccountTypeFilter = _lineFilterBuilder.and(accountTypeFilter, offsetAccountTypeFilter);


        return _lineFilterBuilder.and(_lineFilter, accountAndOffsetAccountTypeFilter);

    }


}

====================================================================

 

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++