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



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rock_books/reports/data/bs_is_data.rb', line 27

def bal_sheet_data
  {
      end_date:    end_date,
      entity:      context.entity,
      sections: {
        asset:       section_data(:asset),
        liability:   section_data(:liability),
        equity:      section_data(:equity),
      },
      grand_total: journals_acct_totals.values.sum.round(2)
  }
end

#inc_stat_dataObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rock_books/reports/data/bs_is_data.rb', line 41

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