class TaskJuggler::AccountListRE

This specialization of TableReport implements a task listing. It generates a list of tasks that can optionally have the allocated resources nested underneath each task line.

Public Class Methods

new(report) click to toggle source

Create a new object and set some default values.

Calls superclass method
# File lib/taskjuggler/reports/AccountListRE.rb, line 27
def initialize(report)
  super
  @table = ReportTable.new
  @table.selfcontained = report.get('selfcontained')
  @table.auxDir = report.get('auxdir')
end

Public Instance Methods

generateIntermediateFormat() click to toggle source

Generate the table in the intermediate format.

Calls superclass method
# File lib/taskjuggler/reports/AccountListRE.rb, line 35
def generateIntermediateFormat
  super

  # Prepare the account list.
  accountList = PropertyList.new(@project.accounts)
  accountList.setSorting(@report.get('sortAccounts'))
  accountList.query = @report.project.reportContexts.last.query
  accountList = filterAccountList(accountList,
                                  @report.get('hideAccount'),
                                  @report.get('rollupAccount'),
                                  @report.get('openNodes'))
  accountList.sort!

  # Generate the table header.
  @report.get('columns').each do |columnDescr|
    adjustColumnPeriod(columnDescr)
    generateHeaderCell(columnDescr)
  end

  if (costAccount = @report.get('costaccount')) &&
     (revenueAccount = @report.get('revenueaccount'))
    # We are in balance mode. First show the cost and then the revenue
    # accounts and then the total balance.
    costAccountList = PropertyList.new(@project.accounts)
    costAccountList.clear
    costAccountList.setSorting(@report.get('sortAccounts'))
    costAccountList.query = @report.project.reportContexts.last.query

    revenueAccountList = PropertyList.new(@project.accounts)
    revenueAccountList.clear
    revenueAccountList.setSorting(@report.get('sortAccounts'))
    revenueAccountList.query = @report.project.reportContexts.last.query

    # Split the account list into a cost and a revenue account list.
    accountList.each do |account|
      if account.isChildOf?(costAccount) || account == costAccount
        costAccountList << account
      elsif account.isChildOf?(revenueAccount) || account == revenueAccount
        revenueAccountList << account
      end
    end

    # Make sure that the top-level cost and revenue accounts are always
    # included in the lists.
    unless costAccountList.include?(costAccount)
      costAccountList << costAccount
    end
    unless revenueAccountList.include?(revenueAccount)
      revenueAccountList << revenueAccount
    end

    generateAccountList(costAccountList, 0, nil)
    generateAccountList(revenueAccountList, costAccountList.length, nil)

    # To generate a total line that reports revenue minus cost, we create
    # a temporary Account object that adopts the cost and revenue
    # accounts.
    totalAccount = Account.new(@report.project, '0', "Total", nil)
    totalAccount.adopt(costAccount)
    totalAccount.adopt(revenueAccount)

    totalAccountList = PropertyList.new(@project.accounts)
    totalAccountList.clear
    totalAccountList.setSorting(@report.get('sortAccounts'))
    totalAccountList.query = @report.project.reportContexts.last.query
    totalAccountList << totalAccount

    generateAccountList(totalAccountList,
                        costAccountList.length + revenueAccountList.length,
                        nil)
    @report.project.removeAccount(totalAccount)

  else
    # We are not in balance mode. Simply show a list of all reports that
    # aren't filtered out.
    generateAccountList(accountList, 0, nil)
  end
end