1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +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:
Zach Gollwitzer 2024-10-09 18:11:36 -04:00 committed by GitHub
parent a2ab217925
commit 0a303ccbd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

View file

@ -129,17 +129,21 @@ class Account::Entry < ApplicationRecord
end
def income_total(currency = "USD")
without_transfers.account_transactions.includes(:entryable)
total = without_transfers.account_transactions.includes(:entryable)
.where("account_entries.amount <= 0")
.map { |e| e.amount_money.exchange_to(currency, date: e.date, fallback_rate: 0) }
.sum
Money.new(total, currency)
end
def expense_total(currency = "USD")
without_transfers.account_transactions.includes(:entryable)
total = without_transfers.account_transactions.includes(:entryable)
.where("account_entries.amount > 0")
.map { |e| e.amount_money.exchange_to(currency, date: e.date, fallback_rate: 0) }
.sum
Money.new(total, currency)
end
def search(params)