mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 11:04:14 +00:00
* Fixed crypto and loan add menus * Changed unspecified crypto account type to none for consistency * Added default add message for loan subtype * Made the short form of non-mortgage loans in loans.rb match the long form * Edited the crypto tooltip to be country generic * Update config/locales/views/loans/en.yml Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Geoffrey <79559478+CYBRXT@users.noreply.github.com> * Update app/views/loans/_form.html.erb Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Geoffrey <79559478+CYBRXT@users.noreply.github.com> * Following Dosu's comment on my issue for consistency --------- Signed-off-by: Geoffrey <79559478+CYBRXT@users.noreply.github.com> Co-authored-by: Geoffrey <geoffrey@github.worker> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
45 lines
1.2 KiB
Ruby
45 lines
1.2 KiB
Ruby
class Loan < ApplicationRecord
|
|
include Accountable
|
|
|
|
SUBTYPES = {
|
|
"mortgage" => { short: "Mortgage", long: "Mortgage" },
|
|
"student" => { short: "Student Loan", long: "Student Loan" },
|
|
"auto" => { short: "Auto Loan", long: "Auto Loan" },
|
|
"other" => { short: "Other Loan", long: "Other Loan" }
|
|
}.freeze
|
|
|
|
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.loan.original_balance.amount.zero? || term_months.zero?
|
|
|
|
annual_rate = interest_rate / 100.0
|
|
monthly_rate = annual_rate / 12.0
|
|
|
|
if monthly_rate.zero?
|
|
payment = account.loan.original_balance.amount / term_months
|
|
else
|
|
payment = (account.loan.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
|
|
end
|
|
|
|
Money.new(payment.round, account.currency)
|
|
end
|
|
|
|
def original_balance
|
|
Money.new(account.first_valuation_amount, account.currency)
|
|
end
|
|
|
|
class << self
|
|
def color
|
|
"#D444F1"
|
|
end
|
|
|
|
def icon
|
|
"hand-coins"
|
|
end
|
|
|
|
def classification
|
|
"liability"
|
|
end
|
|
end
|
|
end
|