mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
Fix currency formatting for 0 values (#1276)
* Fix currency formatting for 0 values * Fix loan payment calculation for zero interest rate
This commit is contained in:
parent
a2ab217925
commit
0a303ccbd5
3 changed files with 12 additions and 4 deletions
|
@ -26,7 +26,7 @@ class PagesController < ApplicationController
|
||||||
|
|
||||||
# TODO: Placeholders for trendlines
|
# TODO: Placeholders for trendlines
|
||||||
placeholder_series_data = 10.times.map do |i|
|
placeholder_series_data = 10.times.map do |i|
|
||||||
{ date: Date.current - i.days, value: Money.new(0) }
|
{ date: Date.current - i.days, value: Money.new(0, Current.family.currency) }
|
||||||
end
|
end
|
||||||
@investing_series = TimeSeries.new(placeholder_series_data)
|
@investing_series = TimeSeries.new(placeholder_series_data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -129,17 +129,21 @@ class Account::Entry < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def income_total(currency = "USD")
|
def income_total(currency = "USD")
|
||||||
without_transfers.account_transactions.includes(:entryable)
|
total = without_transfers.account_transactions.includes(:entryable)
|
||||||
.where("account_entries.amount <= 0")
|
.where("account_entries.amount <= 0")
|
||||||
.map { |e| e.amount_money.exchange_to(currency, date: e.date, fallback_rate: 0) }
|
.map { |e| e.amount_money.exchange_to(currency, date: e.date, fallback_rate: 0) }
|
||||||
.sum
|
.sum
|
||||||
|
|
||||||
|
Money.new(total, currency)
|
||||||
end
|
end
|
||||||
|
|
||||||
def expense_total(currency = "USD")
|
def expense_total(currency = "USD")
|
||||||
without_transfers.account_transactions.includes(:entryable)
|
total = without_transfers.account_transactions.includes(:entryable)
|
||||||
.where("account_entries.amount > 0")
|
.where("account_entries.amount > 0")
|
||||||
.map { |e| e.amount_money.exchange_to(currency, date: e.date, fallback_rate: 0) }
|
.map { |e| e.amount_money.exchange_to(currency, date: e.date, fallback_rate: 0) }
|
||||||
.sum
|
.sum
|
||||||
|
|
||||||
|
Money.new(total, currency)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(params)
|
def search(params)
|
||||||
|
|
|
@ -8,7 +8,11 @@ class Loan < ApplicationRecord
|
||||||
annual_rate = interest_rate / 100.0
|
annual_rate = interest_rate / 100.0
|
||||||
monthly_rate = annual_rate / 12.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)
|
if monthly_rate.zero?
|
||||||
|
payment = account.original_balance.amount / term_months
|
||||||
|
else
|
||||||
|
payment = (account.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
|
||||||
|
end
|
||||||
|
|
||||||
Money.new(payment.round, account.currency)
|
Money.new(payment.round, account.currency)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue