Class: RockBooks::BalanceSheet

Inherits:
Object
  • Object
show all
Includes:
Reporter
Defined in:
lib/rock_books/reports/balance_sheet.rb

Overview

Reports the balance sheet as of the specified date. Unlike other reports, we need to process transactions from the beginning of time in order to calculate the correct balances, so we ignore the global $filter.

Constant Summary

Constants included from Reporter

Reporter::SHORT_NAME_FORMAT_STRING, Reporter::SHORT_NAME_MAX_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reporter

account_code_name_type_string, banner_line, center, format_account_code, format_acct_amount, format_amount, format_multidoc_entry, generate_account_type_section, generate_and_format_totals, max_account_code_length, page_width

Constructor Details

#initialize(report_context) ⇒ BalanceSheet

Returns a new instance of BalanceSheet.



16
17
18
# File 'lib/rock_books/reports/balance_sheet.rb', line 16

def initialize(report_context)
  @context = report_context
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



14
15
16
# File 'lib/rock_books/reports/balance_sheet.rb', line 14

def context
  @context
end

Instance Method Details

#end_dateObject



21
22
23
# File 'lib/rock_books/reports/balance_sheet.rb', line 21

def end_date
  context.chart_of_accounts.end_date
end

#generate_headerObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/rock_books/reports/balance_sheet.rb', line 26

def generate_header
  lines = [banner_line]
  lines << center(context.entity || 'Unspecified Entity')
  lines << center("Balance Sheet for Period Ending #{end_date}")
  lines << banner_line
  lines << ''
  lines << ''
  lines << ''
  lines.join("\n")
end

#generate_reportObject Also known as: to_s, call



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rock_books/reports/balance_sheet.rb', line 38

def generate_report
  filter = RockBooks::JournalEntryFilters.date_on_or_before(end_date)
  acct_amounts = Journal.acct_amounts_in_documents(context.journals, filter)
  totals = AcctAmount.(acct_amounts)
  output = generate_header

  asset_output,  asset_total  = ('Assets',      totals, :asset,     false)
  liab_output,   liab_total   = ('Liabilities', totals, :liability, true)
  equity_output, equity_total = ('Equity',      totals, :equity,    true)

  output << [asset_output, liab_output, equity_output].join("\n\n")

  grand_total = asset_total - (liab_total + equity_total)

  output << "\n#{"%12.2f    Assets - (Liabilities + Equity)" % grand_total}\n============\n"
  output
end