mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
* Default for credit card fields * Save institution on new account forms * Fix property, vehicle, loan, credit card pages
16 lines
554 B
Ruby
16 lines
554 B
Ruby
class Loan < ApplicationRecord
|
|
include Accountable
|
|
|
|
def monthly_payment
|
|
return nil if term_months.nil? || interest_rate.nil? || rate_type.nil? || rate_type != "fixed"
|
|
return Money.new(0, account.currency) if account.original_balance.amount.zero? || term_months.zero?
|
|
|
|
annual_rate = interest_rate / 100.0
|
|
monthly_rate = annual_rate / 12.0
|
|
|
|
payment = (account.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
|
|
|
|
Money.new(payment.round, account.currency)
|
|
end
|
|
end
|