Class: RockBooks::TxOneAccount
- Inherits:
-
Object
- Object
- RockBooks::TxOneAccount
- Includes:
- Reporter
- Defined in:
- lib/rock_books/reports/tx_one_account.rb
Constant Summary
Constants included from Reporter
Reporter::SHORT_NAME_FORMAT_STRING, Reporter::SHORT_NAME_MAX_LENGTH
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#account_code ⇒ Object
readonly
Returns the value of attribute account_code.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #generate_header(account_total) ⇒ Object
- #generate_report ⇒ Object (also: #to_s, #call)
-
#initialize(report_context, account_code) ⇒ TxOneAccount
constructor
A new instance of TxOneAccount.
- #process_account(entries) ⇒ 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, account_code) ⇒ TxOneAccount
Returns a new instance of TxOneAccount.
15 16 17 18 19 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 15 def initialize(report_context, account_code) @context = report_context @account_code = account_code @account = context.chart_of_accounts.account_for_code(account_code) end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
12 13 14 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 12 def account @account end |
#account_code ⇒ Object (readonly)
Returns the value of attribute account_code.
12 13 14 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 12 def account_code @account_code end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 12 def context @context end |
Instance Method Details
#generate_header(account_total) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 22 def generate_header(account_total) lines = [] lines << center(context.entity || 'Unspecified Entity') lines << center("Transactions for Account #{account_code_name_type_string(account)}") lines << center("Total: %.2f" % account_total) lines << lines << '' lines << '' lines << '' lines.join("\n") end |
#generate_report ⇒ Object Also known as: to_s, call
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 43 def generate_report entries = Journal.entries_in_documents(context.journals, JournalEntryFilters.account_code(account_code)) account_total = JournalEntry.total_for_code(entries, account_code) output = generate_header(account_total) if entries.empty? output << "There were no transactions for this account.\n\n\n\n" else output << process_account(entries) totals = AcctAmount.aggregate_amounts_by_account(JournalEntry.entries_acct_amounts(entries)) output << generate_and_format_totals('Totals', totals) end output end |
#process_account(entries) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rock_books/reports/tx_one_account.rb', line 35 def process_account(entries) entries.each_with_object('') do |entry, output| output << format_multidoc_entry(entry) << "\n" output << "\n" if entry.description && entry.description.length > 0 end end |