Class: Comee::Core::Payment

Inherits:
ApplicationRecord show all
Defined in:
app/models/comee/core/payment.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



15
16
17
# File 'app/models/comee/core/payment.rb', line 15

def self.ransackable_associations(_auth_object = nil)
  %w[payment_deposit invoice]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



11
12
13
# File 'app/models/comee/core/payment.rb', line 11

def self.ransackable_attributes(_auth_object = nil)
  %w[id created_at updated_at]
end

Instance Method Details

#calculate_amount_paidObject



29
30
31
32
# File 'app/models/comee/core/payment.rb', line 29

def calculate_amount_paid
  invoice.amount_paid = invoice.calculate_amount_paid
  invoice.save!
end

#validate_amountObject



19
20
21
22
23
24
25
26
27
# File 'app/models/comee/core/payment.rb', line 19

def validate_amount
  return unless amount && payment_deposit

  running_total = payment_deposit.payments.sum(:amount)
  running_total -= amount_was if id
  remaining = payment_deposit.amount - running_total
  error = "Amount exceeded. The maximum amount you can set is #{remaining}"
  errors.add(:base, error) if amount > remaining
end