Class: RockBooks::JournalData

Inherits:
Object
  • Object
show all
Defined in:
lib/rock_books/reports/data/journal_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(journal, report_context, filter = nil) ⇒ JournalData

Returns a new instance of JournalData.



8
9
10
11
12
# File 'lib/rock_books/reports/data/journal_data.rb', line 8

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/rock_books/reports/data/journal_data.rb', line 6

def context
  @context
end

#filterObject (readonly)

Returns the value of attribute filter.



6
7
8
# File 'lib/rock_books/reports/data/journal_data.rb', line 6

def filter
  @filter
end

#journalObject (readonly)

Returns the value of attribute journal.



6
7
8
# File 'lib/rock_books/reports/data/journal_data.rb', line 6

def journal
  @journal
end

Instance Method Details

#entriesObject



14
15
16
17
18
19
# File 'lib/rock_books/reports/data/journal_data.rb', line 14

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

#fetchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rock_books/reports/data/journal_data.rb', line 21

def fetch
  totals = AcctAmount.(JournalEntry.entries_acct_amounts(entries))
  {
    code: journal.,
    name: journal.chart_of_accounts.name_for_code(journal.),
    title: journal.title,
    short_name: journal.short_name,
    debit_or_credit: journal.debit_or_credit,
    start_date: context.chart_of_accounts.start_date,
    end_date: context.chart_of_accounts.end_date,
    entries: entries,
    totals: totals,
    grand_total: totals.values.sum.round(2),
    max_acct_code_len: context.chart_of_accounts.
  }
end