module RockBooks::TextReportHelper

Constants

SHORT_NAME_FORMAT_STRING
SHORT_NAME_MAX_LENGTH

Public Instance Methods

account_code_format() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
center(string) click to toggle source
# 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() click to toggle source
# 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) click to toggle source

e.g. “ 117.70 tr.mileage Travel - Mileage Allowance”

# 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) click to toggle source
# 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() click to toggle source

e.g. “Generated at 2021-01-09 18:22:18 by RockBooks version 0.7.1”

# File lib/rock_books/reports/helpers/text_report_helper.rb, line 114
def generation_info_display_string
  now = Time.now
  timestamp = "#{now} (#{now.utc})"
  center("Generated at #{timestamp}") + "\n" + center("by RockBooks version #{RockBooks::VERSION}")
end
line_item_format_string() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/rock_books/reports/helpers/text_report_helper.rb, line 12
def page_width
  context.page_width || 80
end
section_heading(section_type) click to toggle source

:asset => “Assetsn——”

# 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() click to toggle source
# 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() click to toggle source
# 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: 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) click to toggle source
# File lib/rock_books/reports/helpers/text_report_helper.rb, line 59
def total_with_ok_or_discrepancy(amount)
  status_message = (amount == 0.0)  ? '(Ok)' : '(Discrepancy)'
  sprintf(line_item_format_string, amount, status_message, '')
end