mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
* Add loan and credit card views * Lint fix * Clean up overview card markup * Lint fix * Test fix
15 lines
540 B
Ruby
15 lines
540 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.zero? || term_months.zero?
|
|
|
|
annual_rate = interest_rate / 100.0
|
|
monthly_rate = annual_rate / 12.0
|
|
|
|
payment = (account.original_balance * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
|
|
|
|
Money.new(payment.round, account.currency)
|
|
end
|
|
end
|