Class: RockBooks::IncomeStatement
- Inherits:
-
Object
- Object
- RockBooks::IncomeStatement
- Includes:
- Reporter
- Defined in:
- lib/rock_books/reports/income_statement.rb
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) ⇒ IncomeStatement
constructor
A new instance of IncomeStatement.
- #start_date ⇒ Object
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) ⇒ IncomeStatement
Returns a new instance of IncomeStatement.
14 15 16 |
# File 'lib/rock_books/reports/income_statement.rb', line 14 def initialize(report_context) @context = report_context end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
11 12 13 |
# File 'lib/rock_books/reports/income_statement.rb', line 11 def context @context end |
Instance Method Details
#end_date ⇒ Object
24 25 26 |
# File 'lib/rock_books/reports/income_statement.rb', line 24 def end_date context.chart_of_accounts.end_date end |
#generate_header ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rock_books/reports/income_statement.rb', line 29 def generate_header lines = [] lines << center(context.entity || 'Unspecified Entity') lines << "#{center("Income Statement -- #{start_date} to #{end_date}")}" lines << lines << '' lines << '' lines << '' lines.join("\n") end |
#generate_report ⇒ Object Also known as: to_s, call
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rock_books/reports/income_statement.rb', line 41 def generate_report filter = RockBooks::JournalEntryFilters.date_in_range(start_date, end_date) acct_amounts = Journal.acct_amounts_in_documents(context.journals, filter) totals = AcctAmount.aggregate_amounts_by_account(acct_amounts) totals.each { |aa| aa[1] = -aa[1] } # income statement shows credits as positive, debits as negative output = generate_header income_output, income_total = generate_account_type_section('Income', totals, :income, true) expense_output, expense_total = generate_account_type_section('Expenses', totals, :expense, false) grand_total = income_total - expense_total output << [income_output, expense_output].join("\n\n") output << "\n#{"%12.2f Net Income" % grand_total}\n============\n" output end |
#start_date ⇒ Object
19 20 21 |
# File 'lib/rock_books/reports/income_statement.rb', line 19 def start_date context.chart_of_accounts.start_date end |