Class: Collection

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collect!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/collection.rb', line 24

def self.collect!
  payments = Payment.uncollected.complete.all

  return false if payments.blank?

  self.transaction do
    collection = self.create!(
      :banknotes => Payment.merge_banknotes(payments),
      :payment_ids => payments.map(&:id)
    )

    payments.each{|x| x.update_attribute :collection_id, collection.id}

    return collection
  end

  return false
end

Instance Method Details

#amountObject



51
52
53
# File 'app/models/collection.rb', line 51

def amount
  banknotes.inject(0){|sum, (nominal, count)| sum + nominal.to_i*count.to_i }
end

#reportObject



47
48
49
# File 'app/models/collection.rb', line 47

def report
  Payments::CollectWorker.perform_async(id)
end

#titleObject



43
44
45
# File 'app/models/collection.rb', line 43

def title
  amount
end