Class: RockBooks::BalanceSheet
- Inherits:
-
Object
- Object
- RockBooks::BalanceSheet
- 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
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
- #end_date ⇒ Object
- #generate_header ⇒ Object
- #generate_report ⇒ Object (also: #to_s, #call)
-
#initialize(report_context) ⇒ BalanceSheet
constructor
A new instance of BalanceSheet.
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
#context ⇒ Object
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_date ⇒ Object
21 22 23 |
# File 'lib/rock_books/reports/balance_sheet.rb', line 21 def end_date context.chart_of_accounts.end_date end |
#generate_header ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rock_books/reports/balance_sheet.rb', line 26 def generate_header lines = [] lines << center(context.entity || 'Unspecified Entity') lines << center("Balance Sheet for Period Ending #{end_date}") lines << lines << '' lines << '' lines << '' lines.join("\n") end |
#generate_report ⇒ Object 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.aggregate_amounts_by_account(acct_amounts) output = generate_header asset_output, asset_total = generate_account_type_section('Assets', totals, :asset, false) liab_output, liab_total = generate_account_type_section('Liabilities', totals, :liability, true) equity_output, equity_total = generate_account_type_section('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 |