Class: DoubleEntry::LineAggregate

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
EncapsulateAsMoney
Defined in:
lib/double_entry/line_aggregate.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.aggregate(function, account, code, scope, range, named_scopes) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/double_entry/line_aggregate.rb', line 6

def self.aggregate(function, , code, scope, range, named_scopes)
  collection = aggregate_collection(named_scopes)
  collection = collection.where(:account => )
  collection = collection.where(:created_at => range.start..range.finish)
  collection = collection.where(:code => code) if code
  collection.send(function, :amount)
end

.aggregate_collection(named_scopes) ⇒ Object

a lot of the trickier reports will use filters defined in named_scopes to bring in data from other tables.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/double_entry/line_aggregate.rb', line 16

def self.aggregate_collection(named_scopes)
  if named_scopes
    collection = Line
    named_scopes.each do |named_scope|
      if named_scope.is_a?(Hash)
        method_name = named_scope.keys[0]
        collection = collection.send(method_name, named_scope[method_name])
      else
        collection = collection.send(named_scope)
      end
    end
    collection
  else
    Line
  end
end

Instance Method Details

#keyObject



33
34
35
# File 'lib/double_entry/line_aggregate.rb', line 33

def key
  "#{year}:#{month}:#{week}:#{day}:#{hour}"
end