Module: RockBooks::TextReportHelper
- Included in:
- BalanceSheet, IncomeStatement, IndexHtmlPage, JournalReport, MultidocTransactionByAccountReport, MultidocTransactionReport, MultidocTxnByAccountData, ReceiptsReport, TxOneAccount, TxOneAccountData
- Defined in:
- lib/rock_books/reports/helpers/text_report_helper.rb
Constant Summary collapse
- SHORT_NAME_MAX_LENGTH =
16
- SHORT_NAME_FORMAT_STRING =
"%#{SHORT_NAME_MAX_LENGTH}.#{SHORT_NAME_MAX_LENGTH}s"
Instance Method Summary collapse
- #account_code_format ⇒ Object
- #account_code_name_type_string(account) ⇒ Object
- #account_code_name_type_string_for_code(account_code) ⇒ Object
- #acct_name(code) ⇒ Object
- #banner_line ⇒ Object
- #center(string) ⇒ Object
- #end_date ⇒ Object
-
#format_acct_amount(acct_amount) ⇒ Object
e.g.
- #format_multidoc_entry(entry) ⇒ Object
-
#generation_info_display_string ⇒ Object
e.g.
- #line_item_format_string ⇒ Object
- #max_account_code_length ⇒ Object
- #page_width ⇒ Object
-
#section_heading(section_type) ⇒ Object
:asset => “Assetsn——”.
- #start_date ⇒ Object
- #template_presentation_context ⇒ Object
- #total_with_ok_or_discrepancy(amount) ⇒ Object
Instance Method Details
#account_code_format ⇒ Object
17 18 19 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 17 def account_code_format @account_code_format ||= "%#{max_account_code_length}.#{max_account_code_length}s" end |
#account_code_name_type_string(account) ⇒ Object
22 23 24 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 22 def account_code_name_type_string(account) "#{account.code} -- #{account.name} (#{account.type.to_s.capitalize})" end |
#account_code_name_type_string_for_code(account_code) ⇒ Object
27 28 29 30 31 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 27 def account_code_name_type_string_for_code(account_code) account = context.chart_of_accounts.account_for_code(account_code) raise "Account for code #{account_code} not found" unless account account_code_name_type_string(account) end |
#acct_name(code) ⇒ Object
98 99 100 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 98 def acct_name(code) context.chart_of_accounts.name_for_code(code) end |
#banner_line ⇒ Object
43 44 45 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 43 def @banner_line ||= '-' * page_width end |
#center(string) ⇒ Object
48 49 50 51 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 48 def center(string) indent = [(page_width - string.length) / 2, 0].max (' ' * indent) + string end |
#end_date ⇒ Object
108 109 110 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 108 def end_date context.chart_of_accounts.end_date end |
#format_acct_amount(acct_amount) ⇒ Object
e.g. “ 117.70 tr.mileage Travel - Mileage Allowance”
35 36 37 38 39 40 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 35 def format_acct_amount(acct_amount) sprintf("%s %s %s", sprintf("%9.2f", acct_amount.amount), sprintf(account_code_format, acct_amount.code), context.chart_of_accounts.name_for_code(acct_amount.code)) end |
#format_multidoc_entry(entry) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 65 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 |
#generation_info_display_string ⇒ Object
e.g. “Generated at 2021-01-09 18:22:18 by RockBooks version 0.7.1”
114 115 116 117 118 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 114 def generation_info_display_string now = Time.now = "#{now} (#{now.utc})" center("Generated at #{}") + "\n" + center("by RockBooks version #{RockBooks::VERSION}") end |
#line_item_format_string ⇒ Object
86 87 88 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 86 def line_item_format_string @line_item_format_string ||= "%12.2f %-#{context.chart_of_accounts.max_account_code_length}s %s" end |
#max_account_code_length ⇒ Object
54 55 56 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 54 def max_account_code_length @max_account_code_length ||= context.chart_of_accounts.max_account_code_length end |
#page_width ⇒ Object
12 13 14 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 12 def page_width context.page_width || 80 end |
#section_heading(section_type) ⇒ Object
:asset => “Assetsn——”
92 93 94 95 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 92 def section_heading(section_type) title = AccountType.symbol_to_type(section_type).plural_name "\n\n" + title + "\n" + ('-' * title.length) end |
#start_date ⇒ Object
103 104 105 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 103 def start_date context.chart_of_accounts.start_date end |
#template_presentation_context ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 121 def template_presentation_context { accounting_period: "#{start_date} to #{end_date}", banner_line: , end_date: end_date, entity: context.entity, fn_acct_name: method(:acct_name), fn_account_code_name_type_string_for_code: method(:account_code_name_type_string_for_code), fn_center: method(:center), fn_erb_render_binding: ErbHelper.method(:render_binding), fn_erb_render_hashes: ErbHelper.method(:render_hashes), fn_format_multidoc_entry: method(:format_multidoc_entry), fn_section_heading: method(:section_heading), fn_total_with_ok_or_discrepancy: method(:total_with_ok_or_discrepancy), generated: generation_info_display_string, line_item_format_string: line_item_format_string, short_name_format_string: SHORT_NAME_FORMAT_STRING, start_date: start_date, } end |
#total_with_ok_or_discrepancy(amount) ⇒ Object
59 60 61 62 |
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 59 def total_with_ok_or_discrepancy(amount) = (amount == 0.0) ? '(Ok)' : '(Discrepancy)' sprintf(line_item_format_string, amount, , '') end |