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

Class Method Details

.account_code_name_type_string(account) ⇒ Object



23
24
25
# File 'lib/rock_books/reports/reporter.rb', line 23

def ()
  "#{.code} -- #{.name}  (#{.type.to_s.capitalize})"
end


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

def banner_line
  @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 (code)
  "%*.*s" % [, , 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),
      (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 (section_caption, totals, section_type, need_to_reverse_sign)
   = context.chart_of_accounts.(section_type)

  totals_this_section = totals.select do |, _amount|
    .include?()
  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(section_caption, 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(section_caption, totals)
  output = section_caption
  output << "\n#{'-' * section_caption.length}\n\n"
  format_string = "%12.2f   %-#{context.chart_of_accounts.}s   %s\n"
  totals.keys.sort.each do ||
     = context.chart_of_accounts.name_for_code()
     = totals[]
    output << format_string % [, , ]
  end

  output << "------------\n"
  output << "%12.2f\n" % totals.values.sum.round(2)
  output
end

.max_account_code_lengthObject



55
56
57
# File 'lib/rock_books/reports/reporter.rb', line 55

def 
  @max_account_code_length ||= context.chart_of_accounts.
end

.page_widthObject



13
14
15
# File 'lib/rock_books/reports/reporter.rb', line 13

def page_width
  context.page_width || 80
end