1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Add loan and credit card views (#1268)

* Add loan and credit card views

* Lint fix

* Clean up overview card markup

* Lint fix

* Test fix
This commit is contained in:
Zach Gollwitzer 2024-10-08 17:16:37 -04:00 committed by GitHub
parent 9263dd3bbe
commit fd941d714d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 564 additions and 102 deletions

View file

@ -1,3 +1,15 @@
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