Class: RockBooks::TxByAccount

Inherits:
Object
  • Object
show all
Includes:
Reporter
Defined in:
lib/rock_books/reports/tx_by_account.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) ⇒ TxByAccount

Returns a new instance of TxByAccount.



15
16
17
# File 'lib/rock_books/reports/tx_by_account.rb', line 15

def initialize(report_context)
  @context = report_context
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



12
13
14
# File 'lib/rock_books/reports/tx_by_account.rb', line 12

def context
  @context
end

Instance Method Details

#account_header(account, account_total) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rock_books/reports/tx_by_account.rb', line 32

def (, )
  total_string = "%.2f" % 
  title =  "Total: #{total_string} -- #{()}"

  <<~HEREDOC
  #{banner_line}
  #{center(title)}
  #{banner_line}

  HEREDOC
end

#account_total_line(account_code, account_total) ⇒ Object



45
46
47
48
# File 'lib/rock_books/reports/tx_by_account.rb', line 45

def (, )
   = context.chart_of_accounts.name_for_code()
  "%.2f  Total for account: %s - %s" % [, , ]
end

#generate_headerObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/rock_books/reports/tx_by_account.rb', line 20

def generate_header
  lines = [banner_line]
  lines << center(context.entity || 'Unspecified Entity')
  lines << center("Transactions by Account")
  lines << banner_line
  lines << ''
  lines << ''
  lines << ''
  lines.join("\n")
end

#generate_reportObject Also known as: to_s, call



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rock_books/reports/tx_by_account.rb', line 51

def generate_report
  output = generate_header

  all_entries = Journal.entries_in_documents(context.journals)

  context.chart_of_accounts.accounts.each do ||
    code = .code
     = JournalEntry.(all_entries, code)
     = JournalEntry.total_for_code(, code)
    output << (, )

    .each do |entry|
      output << format_multidoc_entry(entry) << "\n"
      output << "\n" if entry.description && entry.description.length > 0
    end
    output << (code, ) << "\n"
    output  << "\n\n\n"
  end

  totals = AcctAmount.(JournalEntry.entries_acct_amounts(all_entries))
  output << generate_and_format_totals('Totals', totals)

  output
end