Class: RockBooks::IncomeStatement

Inherits:
Object
  • Object
show all
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

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) ⇒ 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

#contextObject

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_dateObject



24
25
26
# File 'lib/rock_books/reports/income_statement.rb', line 24

def end_date
  context.chart_of_accounts.end_date
end

#generate_headerObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/rock_books/reports/income_statement.rb', line 29

def generate_header
  lines = [banner_line]
  lines << center(context.entity || 'Unspecified Entity')
  lines << "#{center("Income Statement -- #{start_date} to #{end_date}")}"
  lines << banner_line
  lines << ''
  lines << ''
  lines << ''
  lines.join("\n")
end

#generate_reportObject 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.(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  = ('Income',   totals, :income,  true)
  expense_output, expense_total = ('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_dateObject



19
20
21
# File 'lib/rock_books/reports/income_statement.rb', line 19

def start_date
  context.chart_of_accounts.start_date
end