Class: RockBooks::BsIsData

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ BsIsData

Returns a new instance of BsIsData.



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

def initialize(context)
  @context = context
  @start_date = context.chart_of_accounts.start_date
  @end_date = context.chart_of_accounts.end_date
  filter = JournalEntryFilters.date_on_or_before(end_date)
  acct_amounts = Journal.acct_amounts_in_documents(context.journals, filter)
  @journals_acct_totals = AcctAmount.(acct_amounts)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



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

def end_date
  @end_date
end

#journals_acct_totalsObject (readonly)

Returns the value of attribute journals_acct_totals.



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

def journals_acct_totals
  @journals_acct_totals
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



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

def start_date
  @start_date
end

#totalsObject (readonly)

Returns the value of attribute totals.



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

def totals
  @totals
end

Instance Method Details

#bal_sheet_dataObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rock_books/reports/data/bs_is_data.rb', line 30

def bal_sheet_data
  sections = {
    asset:       section_data(:asset),
    liability:   section_data(:liability),
    equity:      section_data(:equity),
  }
  {
      end_date:    end_date,
      entity:      context.entity,
      sections:    sections,
      grand_total: grand_total(sections)
  }
end

#grand_total(sections) ⇒ Object



26
27
28
# File 'lib/rock_books/reports/data/bs_is_data.rb', line 26

def grand_total(sections)
  (sections[:asset][:total] - sections[:liability][:total] - sections[:equity][:total]).round(2)
end

#inc_stat_dataObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rock_books/reports/data/bs_is_data.rb', line 45

def inc_stat_data
  income_section_data = section_data(:income)
  expense_section_data = section_data(:expense)
  net_income = (income_section_data[:acct_totals].values.sum.round(2) -
      expense_section_data[:acct_totals].values.sum.round(2)
      ).round(2)

  {
      start_date: start_date,
      end_date:   end_date,
      entity:     context.entity,
      sections: {
        income:     income_section_data,
        expense:    expense_section_data,
      },
      net_income: net_income
  }
end

#section_data(type) ⇒ Object



22
23
24
# File 'lib/rock_books/reports/data/bs_is_data.rb', line 22

def section_data(type)
  BsIsSectionData.new(type, context, journals_acct_totals).fetch
end