Class: PaymentApplication

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

Overview

Schema Definition ################################################

create_table "payment_applications", :force => true do |t|
  t.integer  "financial_txn_id"
  t.integer  "payment_applied_to_id"
  t.string   "payment_applied_to_type"
  t.integer  "applied_money_amount_id"
  t.string   "comment"
  t.datetime "created_at",              :null => false
  t.datetime "updated_at",              :null => false
  end

  add_index "payment_applications", ["applied_money_amount_id"], :name => "index_payment_applications_on_applied_money_amount_id"
  add_index "payment_applications", ["financial_txn_id"], :name => "index_payment_applications_on_financial_txn_id"
  add_index "payment_applications", ["payment_applied_to_id", "payment_applied_to_type"], :name => "payment_applied_to_idx"

Instance Method Summary collapse

Instance Method Details

#apply_paymentObject



33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/payment_application.rb', line 33

def apply_payment
  #check the calculate balance strategy, if it includes payments then do nothing
  #if it doesn't include payments then update the balance on the model
  unless self.payment_applied_to.calculate_balance_strategy_type.nil?
    unless self.payment_applied_to.calculate_balance_strategy_type.iid =~ /payment/
      update_applied_to_balance(:debit)
    end
  else
    update_applied_to_balance(:debit)
  end
end

#is_pending?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/payment_application.rb', line 29

def is_pending?
  self.financial_txn.nil? or (self.financial_txn.is_scheduled? or self.financial_txn.is_pending?) 
end

#unapply_paymentObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/payment_application.rb', line 45

def unapply_payment
  #check the calculate balance strategy, if it includes payments then do nothing
  #if it doesn't include payments then update the balance on the model
  if self.payment_applied_to.respond_to? :calculate_balance_strategy_type
    if !self.payment_applied_to.calculate_balance_strategy_type.nil?
      if self.payment_applied_to.calculate_balance_strategy_type.iid !=~ /payment/ and !self.is_pending?
        update_applied_to_balance(:credit)
      end
    elsif !self.is_pending?
      update_applied_to_balance(:credit)
    end
  end
end