web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

PDF Report for trial balance

(0) ShareShare
ReportReport
Posted on by 72

Hello everyone, I'd like to export the result of trial balance calculation to pdf file. To do so, modified the existing classes LedgerTrialBalanceContract and LedgerTrialBalanceDP and added controller class but i'am getting "Object reference not set to an instance of an object."

TrialBalanceError.JPG

class HmcTrialBalancePdfController extends SrsReportRunController
{
    
    /// 
    ///
    /// 
    
    protected void prePromptModifyContract()
    {
        HmcTrialBalancePdfContract contract = this.parmReportContract().parmRdpContract() as HmcTrialBalancePdfContract;
        if (this.parmArgs().dataset() == tableNum(LedgerTrialBalanceTmp))
        {
            LedgerTrialBalanceTmp ledgerTrialBalanceTmp = this.parmArgs().record() as LedgerTrialBalanceTmp ;
           contract.parmPrimaryDimensionFocus();
           contract.parmFromDate();
           contract.parmToDate();
           contract.parmIncludeOpening();
           contract.parmIncludeClosingAdjustments();
           contract.parmIncludeClosingTransactions();
           contract.parmPostingLayers();
          
           
            
            
            
        }
    }

    public static void main(Args _args)
    {
        HmcTrialBalancePdfController controller = new HmcTrialBalancePdfController();
        controller.parmReportName(ssrsReportStr(HmcTrialBalncePdfReport, PrecisionDesign1));
        controller.parmArgs(_args);
        controller.parmShowDialog(false);
        
        controller.startOperation();
    }

}

[SRSReportParameterAttribute(classStr(HmcTrialBalancePdfContract))]
class HmcTrialBalancePdfDP extends SRSReportDataProviderBase
{
    LedgerTrialBalanceTmp ledgerTrialBalanceTmp;
    HmcTrialBalancePdfContract contract;
    /*
    public HmcTrialBalancePdfContract parmDataContract(HmcTrialBalancePdfContract _contract = contract)
    {
        contract = _contract;
        return contract;
    }
    */
    public void setTrialBalanceTmpTable(LedgerTrialBalanceTmp _ledgerTrialBalanceTmp)
    {
        ledgerTrialBalanceTmp.linkPhysicalTableInstance(_ledgerTrialBalanceTmp);
    }

    private void calculateSummaryClosingTransactions(LedgerTrialBalanceTmp _ledgerTrialBalanceTmp, boolean _includeClosingAdjustments, boolean _includeClosingTransactions)
    {
        LedgerTrialBalanceTmpAccumulated    tmpAccumulated;
        FiscalPeriodType                    operating = FiscalPeriodType::Operating;
        LedgerTrialBalanceTmp        ledgerTrialBalanceTmpReference;

        ledgerTrialBalanceTmpReference.linkPhysicalTableInstance(_ledgerTrialBalanceTmp);

        if (_includeClosingAdjustments || _includeClosingTransactions)
        {
            // Sum closing transactions as necessary by first summing
            // into accumulated since update_recordset doesn't support summation
            insert_recordset tmpAccumulated
                (AccumulatedDebit, AccumulatedCredit, ReportingAccumulatedDebit, ReportingAccumulatedCredit, PrimaryFocus, LedgerDimension, IsClosingTransaction)
            select sum(AmountDebit), sum(AmountCredit), sum(ReportingAmountDebit), sum(ReportingAmountCredit), PrimaryFocus, LedgerDimension, IsClosingTransaction from _ledgerTrialBalanceTmp
                    group by _ledgerTrialBalanceTmp.PrimaryFocus, _ledgerTrialBalanceTmp.LedgerDimension, _ledgerTrialBalanceTmp.IsClosingTransaction
                where _ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Closing;

            // Insert new operating rows for accumulated closing transactions with no operating activity
            insert_recordset _ledgerTrialBalanceTmp
                (PrimaryFocus, LedgerDimension, TransactionType)
            select PrimaryFocus, LedgerDimension, operating from tmpAccumulated
                group by tmpAccumulated.PrimaryFocus, tmpAccumulated.LedgerDimension
            notexists join ledgerTrialBalanceTmpReference
                where ledgerTrialBalanceTmpReference.PrimaryFocus == tmpAccumulated.PrimaryFocus
                    && ledgerTrialBalanceTmpReference.TransactionType == FiscalPeriodType::Operating;

            if (_includeClosingAdjustments)
            {
                // Update the closing adjustment amounts from tmpAccumulated
                update_recordSet _ledgerTrialBalanceTmp
                    setting ClosingAdjustments = tmpAccumulated.AccumulatedDebit - tmpAccumulated.AccumulatedCredit,
                        ReportingClosingAdjustments = tmpAccumulated.ReportingAccumulatedDebit - tmpAccumulated.ReportingAccumulatedCredit
                        where _ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Operating
                join tmpAccumulated
                    where tmpAccumulated.PrimaryFocus == _ledgerTrialBalanceTmp.PrimaryFocus
                        && tmpAccumulated.IsClosingTransaction == NoYes::No;
            }

            if (_includeClosingTransactions)
            {
                // Update the closing transactions amounts from tmpAccumulated
                update_recordSet _ledgerTrialBalanceTmp
                    setting ClosingTransactions = tmpAccumulated.AccumulatedDebit - tmpAccumulated.AccumulatedCredit,
                        ReportingClosingTransactions = tmpAccumulated.ReportingAccumulatedDebit - tmpAccumulated.ReportingAccumulatedCredit
                        where _ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Operating
                join tmpAccumulated
                    where tmpAccumulated.PrimaryFocus == _ledgerTrialBalanceTmp.PrimaryFocus
                        && tmpAccumulated.IsClosingTransaction == NoYes::Yes;
            }
        }

        // Remove those closing amounts that were summed and so they are not printed individually
        delete_from _ledgerTrialBalanceTmp
            where _ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Closing;
    }

    private void calculateSummaryOpeningBalances(LedgerTrialBalanceTmp _ledgerTrialBalanceTmp, boolean _includeOpeningInDetail, TransDate _startDate, TransDate _periodStartDate)
    {
        LedgerTrialBalanceTmpAccumulated    tmpAccumulated;
        FiscalPeriodType                    operating = FiscalPeriodType::Operating;
        LedgerTrialBalanceTmp        ledgerTrialBalanceTmpReference;

        ledgerTrialBalanceTmpReference.linkPhysicalTableInstance(_ledgerTrialBalanceTmp);

        // Adjust opening transactions as necessary by first summing
        // into accumulated since update_recordset doesn't support summation
        insert_recordset tmpAccumulated
            (AccumulatedDebit, AccumulatedCredit, ReportingAccumulatedDebit, ReportingAccumulatedCredit, PrimaryFocus, LedgerDimension)
            select sum(AmountDebit), sum(AmountCredit), sum(ReportingAmountDebit), sum(ReportingAmountCredit), PrimaryFocus, LedgerDimension from _ledgerTrialBalanceTmp
                group by _ledgerTrialBalanceTmp.PrimaryFocus, _ledgerTrialBalanceTmp.LedgerDimension
                where (_ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Opening // Include opening transactions *unless* opening in detail is specified
                    && (!_includeOpeningInDetail || (_startDate > _periodStartDate)) ||
                        (_ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Operating // Include operating transactions prior to start date in opening balance
                    && _ledgerTrialBalanceTmp.AccountingDate < _startDate));

        // Insert new operating rows for accumulated opening values with no activity
        insert_recordset _ledgerTrialBalanceTmp
            (PrimaryFocus, LedgerDimension, TransactionType, AccountingDate)
            select PrimaryFocus, LedgerDimension, operating, _startDate from tmpAccumulated
                notexists join ledgerTrialBalanceTmpReference
                    where ledgerTrialBalanceTmpReference.PrimaryFocus == tmpAccumulated.PrimaryFocus
                        && ledgerTrialBalanceTmpReference.TransactionType == FiscalPeriodType::Operating;

        // Update the opening amounts from tmpAccumulated
        update_recordSet _ledgerTrialBalanceTmp setting
            OpeningBalance = tmpAccumulated.AccumulatedDebit - tmpAccumulated.AccumulatedCredit,
            ReportingOpeningBalance = tmpAccumulated.ReportingAccumulatedDebit - tmpAccumulated.ReportingAccumulatedCredit
            where _ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Operating
            join tmpAccumulated
                where tmpAccumulated.PrimaryFocus == _ledgerTrialBalanceTmp.PrimaryFocus;

        // Remove those opening transactions that were summed and so they are not printed
        delete_from _ledgerTrialBalanceTmp
            where _ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Opening
                && (_ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Opening
                && (!_includeOpeningInDetail || (_startDate > _periodStartDate)) ||
                   (_ledgerTrialBalanceTmp.TransactionType == FiscalPeriodType::Operating
                    && _ledgerTrialBalanceTmp.AccountingDate < _startDate));
    }

    /// 
    ///    Gets the data for the report from the temporary table.
    /// 
    /// 
    ///    The LedgerTrialBalanceTmp temporary table.
    /// 
    /// 
    [SRSReportDataSetAttribute(tableStr('LedgerTrialBalanceTmp'))]
    public LedgerTrialBalanceTmp getLedgerTrialBalanceTmp()
    {
        select * from ledgerTrialBalanceTmp;
        return ledgerTrialBalanceTmp;
    }

    /// 
    /// Initializes the data provider.
    /// 
    public void initialize()
    {
        // Ensure that the balances used by this run are up to date by
        // running this prior to starting the transaction scope for the report.
        // This must be done outside of the report transaction scope since
        // pre-processing reports are done on a different transactional scope
        // and therefore won't pick up balance updates that aren't committed prior
        // to the transaction start.
        DimensionFocusUpdateBalance::updateBalance(
            DimensionHierarchy::findByTypeAndName(
                DimensionHierarchyType::Focus,
                contract.parmPrimaryDimensionFocus()));
    }

    private void populateTmpTransSummary(
        LedgerTrialBalanceTmp _ledgerTrialBalanceTmp,
        DimensionHierarchy _primaryDimensionSet,
        Map _dimensionRangeMap,
        TransDate _startDate,
        TransDate _endDate,
        boolean _includeOpeningInDetail,
        boolean _includeClosingAdjustments,
        boolean _includeClosingTransactions,
        List _postingLayers)
    {
        LedgerTransAccountTmp               ledgerTransAccountTmp;
        DimensionAttributeValueCombination  dimensionAttributeValueCombination;
        FiscalPeriodType                    opening = FiscalPeriodType::Opening;
        FiscalPeriodType                    operating = FiscalPeriodType::Operating;
        FiscalPeriodType                    closing = FiscalPeriodType::Closing;
        DimensionFocusBalance               dimensionFocusBalance;
        NoYes                               yes = NoYes::Yes;

        date periodStartDate = LedgerFiscalCalendar::findOpeningStartDateByDate(Ledger::fiscalCalendar(CompanyInfo::current()), _startDate);

        CreatedTransactionId createdTransId = appl.curTransactionId(true);

        boolean wasDimCriteriaCreated = LedgerTransAccountTmp::fillFromDimSetBalWithDimRanges(null, _primaryDimensionSet, _dimensionRangeMap, _startDate, _endDate);

        // Build a temporary table containing all the posting layers we are reporting on which can be joined into the query that populates the transactions
        LedgerPostingLayerTmp postingLayersTmp;

        if (_postingLayers)
        {
            ListEnumerator postingLayerLE = _postingLayers.getEnumerator();

            while (postingLayerLE.moveNext())
            {
                postingLayersTmp.PostingLayer = postingLayerLE.current();
                postingLayersTmp.insert();
            }
        }

        if (wasDimCriteriaCreated)
        {
            // Insert all operating trans records
            insert_recordset _ledgerTrialBalanceTmp
                (AccountingDate,
                LedgerDimension,
                AmountDebit,
                AmountCredit,
                ReportingAmountDebit,
                ReportingAmountCredit,
                TransactionType,
                PrimaryFocus)
            select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                    operating from dimensionFocusBalance
                    group by dimensionFocusBalance.FocusLedgerDimension, dimensionAttributeValueCombination.DisplayValue
                where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                    dimensionFocusBalance.Ledger == Ledger::current() &&
                    dimensionFocusBalance.AccountingDate >= _startDate &&
                    dimensionFocusBalance.AccountingDate <= _endDate &&
                    ( dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Operating
                        || (dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Opening && _includeOpeningInDetail) )
                
            join DisplayValue from dimensionAttributeValueCombination
                where dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
            exists join postingLayersTmp
                where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer
            exists join ledgerTransAccountTmp
                where ledgerTransAccountTmp.LedgerDimension == dimensionFocusBalance.FocusLedgerDimension
                    && ledgerTransAccountTmp.createdTransactionId == createdTransId;
        }
        else
        {
            // Insert all operating trans records
            insert_recordset _ledgerTrialBalanceTmp
                (AccountingDate,
                LedgerDimension,
                AmountDebit,
                AmountCredit,
                ReportingAmountDebit,
                ReportingAmountCredit,
                TransactionType,
                PrimaryFocus)
            select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                operating from dimensionFocusBalance
                    group by dimensionFocusBalance.FocusLedgerDimension, dimensionAttributeValueCombination.DisplayValue
                where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                    dimensionFocusBalance.Ledger == Ledger::current() &&
                    dimensionFocusBalance.AccountingDate >= _startDate &&
                    dimensionFocusBalance.AccountingDate <= _endDate &&
                    ( dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Operating
                        || (dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Opening && _includeOpeningInDetail) )
            join DisplayValue from dimensionAttributeValueCombination
                where dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
            exists join postingLayersTmp
                where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer;
        }

        // Insert all closing transaction and adjustment records
        if (_includeClosingAdjustments || _includeClosingTransactions)
        {
            if (wasDimCriteriaCreated)
            {
                insert_recordset _ledgerTrialBalanceTmp
                    (AccountingDate,
                    LedgerDimension,
                    AmountDebit,
                    AmountCredit,
                    ReportingAmountDebit,
                    ReportingAmountCredit,
                    IsClosingTransaction,
                    TransactionType,
                    PrimaryFocus)
                select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                    IsSystemGeneratedUltimo, closing from dimensionFocusBalance
                        group by dimensionFocusBalance.FocusLedgerDimension,
                            dimensionAttributeValueCombination.DisplayValue,
                            dimensionFocusBalance.IsSystemGeneratedUltimo
                    where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                        dimensionFocusBalance.Ledger == Ledger::current() &&
                        dimensionFocusBalance.AccountingDate >= _startDate &&
                        dimensionFocusBalance.AccountingDate <= _endDate &&
                        dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Closing
                join DisplayValue from dimensionAttributeValueCombination
                    where dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
                exists join postingLayersTmp
                    where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer
                exists join ledgerTransAccountTmp
                    where ledgerTransAccountTmp.LedgerDimension == dimensionFocusBalance.FocusLedgerDimension
                        && ledgerTransAccountTmp.createdTransactionId == createdTransId;
            }
            else
            {
                insert_recordset _ledgerTrialBalanceTmp
                    (AccountingDate,
                    LedgerDimension,
                    AmountDebit,
                    AmountCredit,
                    ReportingAmountDebit,
                    ReportingAmountCredit,
                    IsClosingTransaction,
                    TransactionType,
                    PrimaryFocus)
                select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                    IsSystemGeneratedUltimo, closing from dimensionFocusBalance
                        group by dimensionFocusBalance.FocusLedgerDimension,
                            dimensionAttributeValueCombination.DisplayValue,
                            dimensionFocusBalance.IsSystemGeneratedUltimo
                    where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                        dimensionFocusBalance.Ledger == Ledger::current() &&
                        dimensionFocusBalance.AccountingDate >= _startDate &&
                        dimensionFocusBalance.AccountingDate <= _endDate &&
                        dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Closing
                join DisplayValue from dimensionAttributeValueCombination
                    where dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
                exists join postingLayersTmp
                    where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer;
            }
        }

        if (wasDimCriteriaCreated)
        {
            // Insert transactions prior to the start date as opening transactions
            insert_recordset _ledgerTrialBalanceTmp
                (AccountingDate,
                LedgerDimension,
                AmountDebit,
                AmountCredit,
                ReportingAmountDebit,
                ReportingAmountCredit,
                TransactionType,
                PrimaryFocus)
            select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                opening from dimensionFocusBalance
                    group by dimensionFocusBalance.FocusLedgerDimension, dimensionAttributeValueCombination.DisplayValue
                where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                    dimensionFocusBalance.Ledger == Ledger::current() &&
                    dimensionFocusBalance.AccountingDate >= periodStartDate &&
                    dimensionFocusBalance.AccountingDate < _startDate &&
                    dimensionFocusBalance.FiscalCalendarPeriodType != FiscalPeriodType::Closing
            join DisplayValue from dimensionAttributeValueCombination where
                dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
            exists join postingLayersTmp
                where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer
            exists join ledgerTransAccountTmp
                where ledgerTransAccountTmp.LedgerDimension == dimensionFocusBalance.FocusLedgerDimension
                    && ledgerTransAccountTmp.createdTransactionId == createdTransId;

            if (!_includeOpeningInDetail)
            {
                insert_recordset _ledgerTrialBalanceTmp
                    (AccountingDate,
                    LedgerDimension,
                    AmountDebit,
                    AmountCredit,
                    ReportingAmountDebit,
                    ReportingAmountCredit,
                    TransactionType,
                    PrimaryFocus)
                select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                    opening from dimensionFocusBalance
                        group by dimensionFocusBalance.FocusLedgerDimension, dimensionAttributeValueCombination.DisplayValue
                    where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                        dimensionFocusBalance.Ledger == Ledger::current() &&
                        dimensionFocusBalance.AccountingDate >= _startDate &&
                        dimensionFocusBalance.AccountingDate <= _endDate &&
                        dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Opening
                join DisplayValue from dimensionAttributeValueCombination where
                    dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
                exists join postingLayersTmp
                    where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer
                exists join ledgerTransAccountTmp
                    where ledgerTransAccountTmp.LedgerDimension == dimensionFocusBalance.FocusLedgerDimension
                        && ledgerTransAccountTmp.createdTransactionId == createdTransId;
            }
        }
        else
        {
            // Insert transactions prior to the start date as opening transactions
            insert_recordset _ledgerTrialBalanceTmp
                (AccountingDate,
                LedgerDimension,
                AmountDebit,
                AmountCredit,
                ReportingAmountDebit,
                ReportingAmountCredit,
                TransactionType,
                PrimaryFocus)
            select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                opening from dimensionFocusBalance
                    group by dimensionFocusBalance.FocusLedgerDimension, dimensionAttributeValueCombination.DisplayValue
                where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                    dimensionFocusBalance.Ledger == Ledger::current() &&
                    dimensionFocusBalance.AccountingDate >= periodStartDate &&
                    dimensionFocusBalance.AccountingDate < _startDate &&
                    dimensionFocusBalance.FiscalCalendarPeriodType != FiscalPeriodType::Closing
            join DisplayValue from dimensionAttributeValueCombination
                where dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
            exists join postingLayersTmp
                where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer;

            if (!_includeOpeningInDetail)
            {
                insert_recordset _ledgerTrialBalanceTmp
                    (AccountingDate,
                    LedgerDimension,
                    AmountDebit,
                    AmountCredit,
                    ReportingAmountDebit,
                    ReportingAmountCredit,
                    TransactionType,
                    PrimaryFocus)
                select minOf(AccountingDate), FocusLedgerDimension, sum(DebitAccountingCurrencyAmount), sum(CreditAccountingCurrencyAmount), sum(DebitReportingCurrencyAmount), sum(CreditReportingCurrencyAmount),
                    opening from dimensionFocusBalance
                        group by dimensionFocusBalance.FocusLedgerDimension, dimensionAttributeValueCombination.DisplayValue
                    where dimensionFocusBalance.FocusDimensionHierarchy == _primaryDimensionSet.RecId &&
                        dimensionFocusBalance.Ledger == Ledger::current() &&
                        dimensionFocusBalance.AccountingDate >= _startDate &&
                        dimensionFocusBalance.AccountingDate <= _endDate &&
                        dimensionFocusBalance.FiscalCalendarPeriodType == FiscalPeriodType::Opening
                join DisplayValue from dimensionAttributeValueCombination where
                    dimensionAttributeValueCombination.RecId == dimensionFocusBalance.FocusLedgerDimension
                exists join postingLayersTmp
                    where dimensionFocusBalance.PostingLayer == postingLayersTmp.PostingLayer;
            }
        }

        // Reverse the sign on the credit amounts since they are stored as a negative value in the focus table
        update_recordSet _ledgerTrialBalanceTmp
            setting AmountCredit = -_ledgerTrialBalanceTmp.AmountCredit,
            ReportingAmountCredit = -_ledgerTrialBalanceTmp.ReportingAmountCredit;
    }

    /// 
    /// Retrieves records that are based on the parameters that were entered.
    /// 
    public void processReport()
    {
        DimensionHierarchy primaryDimensionSet;
        DimensionHierarchy secondaryDimensionSet;
        Query query;
        QueryBuildDataSource dsDetail;

        primaryDimensionSet = DimensionHierarchy::findByTypeAndName(DimensionHierarchyType::Focus, contract.parmPrimaryDimensionFocus());

        this.processReportSummary(ledgerTrialBalanceTmp, primaryDimensionSet);
    }

    private void processReportSummary(LedgerTrialBalanceTmp _ledgerTrialBalanceTmp, DimensionHierarchy _primaryDimensionSet)
    {
        // Get contract info
        TransDate startDate = contract.parmFromDate();
        TransDate endDate = contract.parmToDate();
        boolean includeOpening = contract.parmIncludeOpening();
        boolean includeClosingAdjustments = contract.parmIncludeClosingAdjustments();
        boolean includeClosingTransactions = contract.parmIncludeClosingTransactions();
        List postingLayers = contract.parmPostingLayers();
        Map dimensionRangeMap = contract.parmDimensionRangeMap();

        TransDate periodStartDate = LedgerFiscalCalendar::findOpeningStartDateByDate(Ledger::fiscalCalendar(CompanyInfo::current()), startDate);
                    
        if (AggregateDimensionCombinationsByDimensionFocusFeature::isEnabled())
        {
            LedgerTrialBalanceTmp ledgerTrialBalanceTmpReference;
            this.populateTmpTransSummary(ledgerTrialBalanceTmpReference, _primaryDimensionSet, dimensionRangeMap, startDate, endDate, includeOpening, includeClosingAdjustments, includeClosingTransactions, postingLayers);

            this.aggregateDimensionCombinationsByDimensionFocus(ledgerTrialBalanceTmpReference, _ledgerTrialBalanceTmp);
        }
        else
        {
            this.populateTmpTransSummary(_ledgerTrialBalanceTmp, _primaryDimensionSet, dimensionRangeMap, startDate, endDate, includeOpening, includeClosingAdjustments, includeClosingTransactions, postingLayers);
        }

        this.calculateSummaryOpeningBalances(_ledgerTrialBalanceTmp, includeOpening, startDate, periodStartDate);

        this.calculateSummaryClosingTransactions(_ledgerTrialBalanceTmp, includeClosingAdjustments, includeClosingTransactions);

        this.updateSummaryMainFocusDescriptions(_ledgerTrialBalanceTmp, _primaryDimensionSet.Name);

        update_recordSet _ledgerTrialBalanceTmp
            setting
                NetChange = _ledgerTrialBalanceTmp.AmountDebit - _ledgerTrialBalanceTmp.AmountCredit,
                EndingBalance = (_ledgerTrialBalanceTmp.OpeningBalance
                      _ledgerTrialBalanceTmp.AmountDebit
                    - _ledgerTrialBalanceTmp.AmountCredit
                      _ledgerTrialBalanceTmp.ClosingAdjustments
                      _ledgerTrialBalanceTmp.ClosingTransactions),
                ReportingEndingBalance = (_ledgerTrialBalanceTmp.ReportingOpeningBalance
                      _ledgerTrialBalanceTmp.ReportingAmountDebit
                    - _ledgerTrialBalanceTmp.ReportingAmountCredit
                      _ledgerTrialBalanceTmp.ReportingClosingAdjustments
                      _ledgerTrialBalanceTmp.ReportingClosingTransactions);
    }

    private void aggregateDimensionCombinationsByDimensionFocus(LedgerTrialBalanceTmp _sourceLedgerTrialBalanceTmp, LedgerTrialBalanceTmp _destinationLedgerTrialBalanceTmp)
    {
        insert_recordset _destinationLedgerTrialBalanceTmp
            (LedgerDimension,
            DimensionValues,
            PrimaryFocus,
            PrimaryFocusDescription,
            AccountingDate,
            PostingLayer,
            TransactionType,
            IsClosingTransaction,
            AmountCredit,
            AmountCreditTrans,
            AmountDebit,
            AmountDebitTrans,
            ClosingAdjustments,
            ClosingTransactions,
            ReportingAmountCredit,
            ReportingAmountDebit,
            ReportingClosingAdjustments,
            ReportingClosingTransactions)
        select
            minof(LedgerDimension),
            DimensionValues,
            PrimaryFocus,
            PrimaryFocusDescription,
            minof(AccountingDate),
            PostingLayer,
            TransactionType,
            IsClosingTransaction,
            sum(AmountCredit),
            sum(AmountCreditTrans),
            sum(AmountDebit),
            sum(AmountDebitTrans),
            sum(ClosingAdjustments),
            sum(ClosingTransactions),
            sum(ReportingAmountCredit),
            sum(ReportingAmountDebit),
            sum(ReportingClosingAdjustments),
            sum(ReportingClosingTransactions)
        from _sourceLedgerTrialBalanceTmp
            group by _sourceLedgerTrialBalanceTmp.DimensionValues,
            _sourceLedgerTrialBalanceTmp.PrimaryFocus,
            _sourceLedgerTrialBalanceTmp.PrimaryFocusDescription,
            _sourceLedgerTrialBalanceTmp.PostingLayer,
            _sourceLedgerTrialBalanceTmp.TransactionType,
            _sourceLedgerTrialBalanceTmp.IsClosingTransaction;

        DimensionDataIntegrityLogCopy integrityLog;
        RefTableId sourceTableId = tablenum(DimensionAttributeValueCombination);
        TableNameShort sourceTableName = tableStr(DimensionAttributeValueCombination);
        DimensionDataIntegrityIssueType issueType = DimensionDataIntegrityIssueType::DuplicationInTrialBalance;

        insert_recordset integrityLog
        (
            SourceTableId,
            SourceTableName,
            SourceRecId,
            IssueType
        )
        select sourceTableId,
            sourceTableName,
            LedgerDimension,
            issueType
        from _sourceLedgerTrialBalanceTmp
        notexists join _destinationLedgerTrialBalanceTmp
            where _destinationLedgerTrialBalanceTmp.LedgerDimension == _sourceLedgerTrialBalanceTmp.LedgerDimension;

        int affectedRows = int642int(integrityLog.RowCount());
        if (affectedRows > 0)
        {
            GeneralLedgerInstrumentationCopy::logInformation(classStr(LedgerTrialBalanceDP), strFmt('%1 duplicate records found in trial balance.', affectedRows));
        }

    }

    private void updateSummaryMainFocusDescriptions(LedgerTrialBalanceTmp _ledgerTrialBalanceTmp, Name _primaryFocusName)
    {
        DimensionFocusNameTmp dimNameTmpDesc;

        insert_recordset dimNameTmpDesc (LedgerDimension)
            select LedgerDimension from _ledgerTrialBalanceTmp
                group by _ledgerTrialBalanceTmp.LedgerDimension;

        DimensionFocusNameTmp::generateFocusDescriptions(dimNameTmpDesc, _primaryFocusName, new Connection());

        // Update _ledgerTrialBalanceTmp with the main focus descriptions
        update_recordset _ledgerTrialBalanceTmp setting
            PrimaryFocusDescription = dimNameTmpDesc.FocusValue,
            DimensionValues[1] = dimNameTmpDesc.DimValue1,
            DimensionValues[2] = dimNameTmpDesc.DimValue2,
            DimensionValues[3] = dimNameTmpDesc.DimValue3,
            DimensionValues[4] = dimNameTmpDesc.DimValue4,
            DimensionValues[5] = dimNameTmpDesc.DimValue5,
            DimensionValues[6] = dimNameTmpDesc.DimValue6,
            DimensionValues[7] = dimNameTmpDesc.DimValue7,
            DimensionValues[8] = dimNameTmpDesc.DimValue8,
            DimensionValues[9] = dimNameTmpDesc.DimValue9,
            DimensionValues[10] = dimNameTmpDesc.DimValue10,
            DimensionValues[11] = dimNameTmpDesc.DimValue11
            join dimNameTmpDesc
                where dimNameTmpDesc.LedgerDimension == _ledgerTrialBalanceTmp.LedgerDimension;
    }

}

[DataConTractAttribute]
class HmcTrialBalancePdfContract
{
    
    FromDate fromDate;
    ToDate toDate;
    boolean includeOpening;
    boolean includeClosingTransactions;
    boolean includeClosingAdjustments;
    Name primaryDimensionFocus;
    List postingLayers;

    // string value of range
    SerializedDimensionRange    serializedDimensionRanges;
    FreeText                    dimensionRange;

    [DataMemberAttribute("FreeText")]
    public FreeText parmDimensionRange(FreeText _dimensionRange = dimensionRange)
    {
        dimensionRange = _dimensionRange;
        return dimensionRange;
    }

    public Map parmDimensionRangeMap(Map _dimensionRangeMap = null)
    {
        XmlDocument xDoc;
        Map dimRangeMap;

        if (prmisDefault(_dimensionRangeMap))
        {
            if (serializedDimensionRanges)
            {
                xDoc = new XmlDocument();
                xDoc.loadXml(serializedDimensionRanges);

                dimRangeMap = Map::createFromXML(xDoc.root() as XmlNode);
            }
            else
            {
                dimRangeMap = new Map(Types::Int64, Types::String);
            }
        }
        else
        {
            if (_dimensionRangeMap == null)
            {
                _dimensionRangeMap = new Map(Types::Int64, Types::String);
            }
            else
            {
                this.parmSerializedDimensionRanges(_dimensionRangeMap.xml());
            }
            dimRangeMap = _dimensionRangeMap;
        }
        return dimRangeMap;
    }

    [DataMemberAttribute("SerializedDimensionRange")]
    public SerializedDimensionRange parmSerializedDimensionRanges(SerializedDimensionRange _serializedDimensionRanges = serializedDimensionRanges)
    {
        serializedDimensionRanges = _serializedDimensionRanges;
        return serializedDimensionRanges;
    }

    [DataMemberAttribute("FromDate")]
    public FromDate parmFromDate(FromDate _fromDate = fromDate)
    {
        fromDate = _fromDate;
        return fromDate;
    }

    // The parmIncludeClosing parameter is left for backwards compatibility, and will set both the
    // parmIncludeClosingAdjustments and parmIncludeClosingTransactions values. Please consider using
    // the individual methods instead.
    public void parmIncludeClosing(boolean _includeClosing)
    {
        this.parmIncludeClosingAdjustments(_includeClosing);
        this.parmIncludeClosingTransactions(_includeClosing);
    }

    [DataMemberAttribute("IncludeClosingAdjustments")]
    public boolean parmIncludeClosingAdjustments(boolean _includeClosingAdjustments = includeClosingAdjustments)
    {
        includeClosingAdjustments = _includeClosingAdjustments;
        return includeClosingAdjustments;
    }

    [DataMemberAttribute("IncludeClosingTransactions")]
    public boolean parmIncludeClosingTransactions(boolean _includeClosingTransactions = includeClosingTransactions)
    {
        includeClosingTransactions = _includeClosingTransactions;
        return includeClosingTransactions;
    }

    [DataMemberAttribute("IncludeOpening")]
    public boolean parmIncludeOpening(boolean _includeOpening = includeOpening)
    {
        includeOpening = _includeOpening;
        return includeOpening;
    }

    public List parmPostingLayers(List _postingLayers = postingLayers)
    {
        postingLayers = _postingLayers;
        return postingLayers;
    }

    /*
    [SysObsolete('This method is no longer used; use parmPostingLayers() instead.', true, 25\06\2020)]
    public OperationsTax parmOperationsTax(OperationsTax _operationsTax = OperationsTax::Current)
    {
        throw error(Error::wrongUseOfFunction(funcName()));
    }
    */

    [DataMemberAttribute("PrimaryDimensionFocus")]
    public Name parmPrimaryDimensionFocus(Name _primaryDimensionFocus = primaryDimensionFocus)
    {
        primaryDimensionFocus = _primaryDimensionFocus;
        return primaryDimensionFocus;
    }

    [DataMemberAttribute("ToDate")]
    public ToDate parmToDate(ToDate _toDate = toDate)
    {
        toDate = _toDate;
        return toDate;
    }

}

So, how do I fix my classes and force the PDF export via code?

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi wassim,

    What changes you have done to existing trail balance ssrs report?

    Thanks,

    Girish S.

  • wassim.77 Profile Picture
    72 on at

    I made no changes to any reports. I simply created my own report and used the form's Data provider class.

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    So you want to change the report view to pdf instead of screen right?

    If yes then you need to duplicate only the controller class and set the print destination settings to pdf format. Refer to below code.

    On the main method of the duplicated controller class add the below code before calling start Operation method.

    controller.printDestinationSettings().printMediumType(SRSPrintMediumType::File);

    controller.printDestinationSettings().fileFormat(SRSReportFileFormat::PDF);

    After that you can extend the output menu item and map your newly created controller class to it.

    Thanks,

    Girish S.

  • wassim.77 Profile Picture
    72 on at

    Hello, Girish.

    How do I get to the report view from the form?

    and which controller class should I duplicate?

    thanks.

  • GirishS Profile Picture
    27,827 Moderator on at

    You already have a controller class it seems where you have pasted in the starting of the thread.

    In the same controller class you add the code which I have given in my previous thread. No need to create contract or dp class as you don't want changes in the report.

    It seems there is no controller class for standard report. So forgot about extending output menu items.

    Just create new output menu item and map your controller class to it.

    Thanks,

    Girish S

  • wassim.77 Profile Picture
    72 on at

    I got it, but the report I made isn't working; it says "Object reference not set to an instance of an object."

    So, which standard report should I use in my controller class?

    thank you Girish.

  • GirishS Profile Picture
    27,827 Moderator on at

    It seems you have duplicated all the reports which Is not needed for your scenario.

    I guess standard report name for trail balance report is HcmTrailBalanceReport. You need to mention that report name in parmReportName method. Refer to line number 32 in controller class - You need to replace that with the standard report HcmTrialBalanceReport.

    Hope its clear now!!!

    Thanks,

    Girish S.

  • wassim.77 Profile Picture
    72 on at

    Girish, thank you It's obvious, but there isn't a standard report called HcmTrialBalanceReport.

    The only report I could find was LedgerTRialBalanceReport_CN, but it did not meet my requirements.

  • GirishS Profile Picture
    27,827 Moderator on at

    Oh sorry it seems I have wrongly understood your question.

    Okay then, have you debugged the code?

    Debug the code and find out exactly at what point this error is throwing.

    Add a debugger in dp, contract and controller class to identify the errors.

    Thanks,

    Girish S

  • wassim.77 Profile Picture
    72 on at

    It's alright, Girish.

    I have a VM issue that prevents me from debugging my code.

    I altered my strategy and adopted yours.

    I utilised the DP and Contract default classes.

    I'm getting this error.

    "This report requires a default or user-defined value for the report parameter

    'LedgerTrialBalanceDP FreeText'. To run or subscribe to this report,

    you must provide a parameter value."

    because I'm not passing the Controller Class's required parameters.

    Therefore, my concern is where I can obtain the parameters from and how to pass them on to the controller.

    I hope I haven't confused you in any way.

    in the image below are the paramters

    pastedimage1669650111016v1.jpeg

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans