Module: RockBooks::Reporter
- Included in:
- BalanceSheet, IncomeStatement, MultidocTransactionReport, ReceiptsReport, TransactionReport, TxByAccount, TxOneAccount
- Defined in:
- lib/rock_books/reports/reporter.rb
Constant Summary collapse
- SHORT_NAME_MAX_LENGTH =
16
- SHORT_NAME_FORMAT_STRING =
"%#{SHORT_NAME_MAX_LENGTH}.#{SHORT_NAME_MAX_LENGTH}s"
Class Method Summary collapse
- .account_code_name_type_string(account) ⇒ Object
- .banner_line ⇒ Object
- .center(string) ⇒ Object
- .format_account_code(code) ⇒ Object
-
.format_acct_amount(acct_amount) ⇒ Object
e.g.
- .format_amount(amount) ⇒ Object
- .format_multidoc_entry(entry) ⇒ Object
- .generate_account_type_section(section_caption, totals, section_type, need_to_reverse_sign) ⇒ Object
- .generate_and_format_totals(section_caption, totals) ⇒ Object
- .max_account_code_length ⇒ Object
- .page_width ⇒ Object
Class Method Details
.account_code_name_type_string(account) ⇒ Object
23 24 25 |
# File 'lib/rock_books/reports/reporter.rb', line 23 def account_code_name_type_string(account) "#{account.code} -- #{account.name} (#{account.type.to_s.capitalize})" end |
.banner_line ⇒ Object
43 44 45 |
# File 'lib/rock_books/reports/reporter.rb', line 43 def @banner_line ||= '-' * page_width end |
.center(string) ⇒ Object
48 49 50 51 52 |
# File 'lib/rock_books/reports/reporter.rb', line 48 def center(string) indent = (page_width - string.length) / 2 indent = 0 if indent < 0 (' ' * indent) + string end |
.format_account_code(code) ⇒ Object
18 19 20 |
# File 'lib/rock_books/reports/reporter.rb', line 18 def format_account_code(code) "%*.*s" % [max_account_code_length, max_account_code_length, code] end |
.format_acct_amount(acct_amount) ⇒ Object
e.g. “ 117.70 tr.mileage Travel - Mileage Allowance”
34 35 36 37 38 39 40 |
# File 'lib/rock_books/reports/reporter.rb', line 34 def format_acct_amount(acct_amount) "%s %s %s" % [ format_amount(acct_amount.amount), format_account_code(acct_amount.code), context.chart_of_accounts.name_for_code(acct_amount.code) ] end |
.format_amount(amount) ⇒ Object
28 29 30 |
# File 'lib/rock_books/reports/reporter.rb', line 28 def format_amount(amount) "%9.2f" % amount end |
.format_multidoc_entry(entry) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rock_books/reports/reporter.rb', line 94 def format_multidoc_entry(entry) acct_amounts = entry.acct_amounts # "2017-10-29 hsbc_visa": output = entry.date.to_s << ' ' << (SHORT_NAME_FORMAT_STRING % entry.doc_short_name) << ' ' indent = ' ' * output.length output << format_acct_amount(acct_amounts.first) << "\n" acct_amounts[1..-1].each do |acct_amount| output << indent << format_acct_amount(acct_amount) << "\n" end if entry.description && entry.description.length > 0 output << entry.description end output end |
.generate_account_type_section(section_caption, totals, section_type, need_to_reverse_sign) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rock_books/reports/reporter.rb', line 76 def generate_account_type_section(, totals, section_type, need_to_reverse_sign) account_codes_this_section = context.chart_of_accounts.account_codes_of_type(section_type) totals_this_section = totals.select do |account_code, _amount| account_codes_this_section.include?(account_code) end if need_to_reverse_sign totals_this_section.each { |code, amount| totals_this_section[code] = -amount } end section_total_amount = totals_this_section.map { |aa| aa.last }.sum output = generate_and_format_totals(, totals_this_section) [ output, section_total_amount ] end |
.generate_and_format_totals(section_caption, totals) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rock_books/reports/reporter.rb', line 60 def generate_and_format_totals(, totals) output = output << "\n#{'-' * .length}\n\n" format_string = "%12.2f %-#{context.chart_of_accounts.max_account_code_length}s %s\n" totals.keys.sort.each do |account_code| account_name = context.chart_of_accounts.name_for_code(account_code) account_total = totals[account_code] output << format_string % [account_total, account_code, account_name] end output << "------------\n" output << "%12.2f\n" % totals.values.sum.round(2) output end |
.max_account_code_length ⇒ Object
55 56 57 |
# File 'lib/rock_books/reports/reporter.rb', line 55 def max_account_code_length @max_account_code_length ||= context.chart_of_accounts.max_account_code_length end |
.page_width ⇒ Object
13 14 15 |
# File 'lib/rock_books/reports/reporter.rb', line 13 def page_width context.page_width || 80 end |