Module: RockBooks::TextReportHelper

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

Instance Method Details

#account_code_formatObject



17
18
19
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 17

def 
  @account_code_format ||= "%#{}.#{}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 ()
  "#{.code} -- #{.name}  (#{.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 ()
   = context.chart_of_accounts.()
  raise "Account for code #{} not found" unless 
  ()
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


43
44
45
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 43

def banner_line
  @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_dateObject



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(, 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_stringObject

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
  timestamp = "#{now} (#{now.utc})"
  center("Generated at #{timestamp}") + "\n" + center("by RockBooks version #{RockBooks::VERSION}")
end

#line_item_format_stringObject



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.}s   %s"
end

#max_account_code_lengthObject



54
55
56
# File 'lib/rock_books/reports/helpers/text_report_helper.rb', line 54

def 
  @max_account_code_length ||= context.chart_of_accounts.
end

#page_widthObject



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_dateObject



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_contextObject



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: 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)
  status_message = (amount == 0.0)  ? '(Ok)' : '(Discrepancy)'
  sprintf(line_item_format_string, amount, status_message, '')
end