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



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

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



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

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

#reportObject



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

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

#titleObject



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

def title
  amount
end