Class: RockBooks::TxByAccount
- Inherits:
-
Object
- Object
- RockBooks::TxByAccount
- 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
-
#context ⇒ Object
Returns the value of attribute context.
Instance Method Summary collapse
- #account_header(account, account_total) ⇒ Object
- #account_total_line(account_code, account_total) ⇒ Object
- #generate_header ⇒ Object
- #generate_report ⇒ Object (also: #to_s, #call)
-
#initialize(report_context) ⇒ TxByAccount
constructor
A new instance of TxByAccount.
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
#context ⇒ Object
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 account_header(account, account_total) total_string = "%.2f" % account_total title = "Total: #{total_string} -- #{account_code_name_type_string(account)}" <<~HEREDOC #{} #{center(title)} #{} 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 account_total_line(account_code, account_total) account_name = context.chart_of_accounts.name_for_code(account_code) "%.2f Total for account: %s - %s" % [account_total, account_code, account_name] end |
#generate_header ⇒ Object
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 = [] lines << center(context.entity || 'Unspecified Entity') lines << center("Transactions by Account") lines << lines << '' lines << '' lines << '' lines.join("\n") end |
#generate_report ⇒ Object 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 |account| code = account.code account_entries = JournalEntry.entries_containing_account_code(all_entries, code) account_total = JournalEntry.total_for_code(account_entries, code) output << account_header(account, account_total) account_entries.each do |entry| output << format_multidoc_entry(entry) << "\n" output << "\n" if entry.description && entry.description.length > 0 end output << account_total_line(code, account_total) << "\n" output << "\n\n\n" end totals = AcctAmount.aggregate_amounts_by_account(JournalEntry.entries_acct_amounts(all_entries)) output << generate_and_format_totals('Totals', totals) output end |