Class: RockBooks::TransactionReport

Inherits:
Object
  • Object
show all
Includes:
Reporter
Defined in:
lib/rock_books/reports/transaction_report.rb

Constant Summary

Constants included from Reporter

Reporter::SHORT_NAME_FORMAT_STRING, Reporter::SHORT_NAME_MAX_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Reporter

account_code_name_type_string, banner_line, center, format_account_code, format_acct_amount, format_amount, format_multidoc_entry, generate_account_type_section, generate_and_format_totals, max_account_code_length, page_width

Constructor Details

#initialize(journal, report_context) ⇒ TransactionReport

Returns a new instance of TransactionReport.



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

def initialize(journal, report_context)
  @journal = journal
  @context = report_context
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



10
11
12
# File 'lib/rock_books/reports/transaction_report.rb', line 10

def context
  @context
end

#journalObject

Returns the value of attribute journal.



10
11
12
# File 'lib/rock_books/reports/transaction_report.rb', line 10

def journal
  @journal
end

Instance Method Details

#format_entry(entry) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/rock_books/reports/transaction_report.rb', line 74

def format_entry(entry)
  if entry.acct_amounts.size > 2
    format_entry_with_split(entry)
  else
    format_entry_no_split(entry)
  end
end

#format_entry_first_acct_amount(entry) ⇒ Object



37
38
39
40
41
42
# File 'lib/rock_books/reports/transaction_report.rb', line 37

def format_entry_first_acct_amount(entry)
  entry.date.to_s \
      << '  ' \
      << format_acct_amount(entry.acct_amounts.first) \
      << "\n"
end

#format_entry_no_split(entry) ⇒ Object

Formats an entry like this, with entry description added on additional line(s) if it exists: 2018-05-21 $120.00 701 Office Supplies



47
48
49
50
51
52
53
54
# File 'lib/rock_books/reports/transaction_report.rb', line 47

def format_entry_no_split(entry)
  output = format_entry_first_acct_amount(entry)

  if entry.description && entry.description.length > 0
    output << entry.description
  end
  output
end

#format_entry_with_split(entry) ⇒ Object

Formats an entry like this, with entry description added on additional line(s) if it exists

2018-05-21 $120.00 95.00 701 Office Supplies

25.00     751  Gift to Customer


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rock_books/reports/transaction_report.rb', line 60

def format_entry_with_split(entry)
  output = format_entry_first_acct_amount(entry)
  indent = ' ' * 12

  entry.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
end

#generate_headerObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rock_books/reports/transaction_report.rb', line 19

def generate_header

  code = journal.
  name = journal.chart_of_accounts.name_for_code(code)
  title = "Transactions for Account ##{code} -- #{name}"

  lines = [banner_line]
  lines << center(context.entity || 'Unspecified Entity')
  lines << center(journal.title) if journal.title && journal.title.length > 0
  lines << center(title)
  lines << banner_line
  lines << ''
  lines << ''
  lines << ''
  lines.join("\n")
end

#generate_report(filter = nil) ⇒ Object Also known as: to_s, call



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rock_books/reports/transaction_report.rb', line 83

def generate_report(filter = nil)
  sio = StringIO.new
  sio << generate_header

  entries = journal.entries
  if filter
    entries = entries.select { |entry| filter.(entry) }
  end

  entries.each { |entry| sio << format_entry(entry) << "\n" }
  totals = AcctAmount.(JournalEntry.entries_acct_amounts(entries))
  sio << generate_and_format_totals('Totals', totals)
  sio.string
end