mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Bug fixes for specialized account pages (#1275)
* Default for credit card fields * Save institution on new account forms * Fix property, vehicle, loan, credit card pages
This commit is contained in:
parent
b4d0fdbe0d
commit
a2ab217925
10 changed files with 26 additions and 13 deletions
|
@ -27,7 +27,7 @@ class CreditCardsController < ApplicationController
|
|||
def account_params
|
||||
params.require(:account)
|
||||
.permit(
|
||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
||||
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||
accountable_attributes: [
|
||||
:id,
|
||||
:available_credit,
|
||||
|
|
|
@ -27,7 +27,7 @@ class LoansController < ApplicationController
|
|||
def account_params
|
||||
params.require(:account)
|
||||
.permit(
|
||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
||||
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||
accountable_attributes: [
|
||||
:id,
|
||||
:rate_type,
|
||||
|
|
|
@ -27,7 +27,7 @@ class PropertiesController < ApplicationController
|
|||
def account_params
|
||||
params.require(:account)
|
||||
.permit(
|
||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
||||
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||
accountable_attributes: [
|
||||
:id,
|
||||
:year_built,
|
||||
|
|
|
@ -27,7 +27,7 @@ class VehiclesController < ApplicationController
|
|||
def account_params
|
||||
params.require(:account)
|
||||
.permit(
|
||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
||||
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||
accountable_attributes: [
|
||||
:id,
|
||||
:make,
|
||||
|
|
|
@ -83,7 +83,8 @@ class Account < ApplicationRecord
|
|||
end
|
||||
|
||||
def original_balance
|
||||
balances.chronological.first&.balance || balance
|
||||
balance_amount = balances.chronological.first&.balance || balance
|
||||
Money.new(balance_amount, currency)
|
||||
end
|
||||
|
||||
def owns_ticker?(ticker)
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
class CreditCard < ApplicationRecord
|
||||
include Accountable
|
||||
|
||||
def available_credit_money
|
||||
available_credit ? Money.new(available_credit, account.currency) : nil
|
||||
end
|
||||
|
||||
def minimum_payment_money
|
||||
minimum_payment ? Money.new(minimum_payment, account.currency) : nil
|
||||
end
|
||||
|
||||
def annual_fee_money
|
||||
annual_fee ? Money.new(annual_fee, account.currency) : nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,12 +3,12 @@ class Loan < ApplicationRecord
|
|||
|
||||
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?
|
||||
return Money.new(0, account.currency) if account.original_balance.amount.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)
|
||||
payment = (account.original_balance.amount * monthly_rate * (1 + monthly_rate)**term_months) / ((1 + monthly_rate)**term_months - 1)
|
||||
|
||||
Money.new(payment.round, account.currency)
|
||||
end
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
<div class="grid grid-cols-3 gap-2">
|
||||
<%= summary_card title: t(".amount_owed") do %>
|
||||
<%= format_money(account.balance) %>
|
||||
<%= format_money(account.balance_money) %>
|
||||
<% end %>
|
||||
|
||||
<%= summary_card title: t(".available_credit") do %>
|
||||
<%= format_money(account.credit_card.available_credit) || t(".unknown") %>
|
||||
<%= format_money(account.credit_card.available_credit_money) || t(".unknown") %>
|
||||
<% end %>
|
||||
|
||||
<%= summary_card title: t(".minimum_payment") do %>
|
||||
<%= format_money(account.credit_card.minimum_payment) || t(".unknown") %>
|
||||
<%= format_money(account.credit_card.minimum_payment_money) || Money.new(0, account.currency) %>
|
||||
<% end %>
|
||||
|
||||
<%= summary_card title: t(".apr") do %>
|
||||
|
@ -22,6 +22,6 @@
|
|||
<% end %>
|
||||
|
||||
<%= summary_card title: t(".annual_fee") do %>
|
||||
<%= format_money(account.credit_card.annual_fee) || t(".unknown") %>
|
||||
<%= format_money(account.credit_card.annual_fee_money) || Money.new(0, account.currency) %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<% end %>
|
||||
|
||||
<%= summary_card title: t(".remaining_principal") do %>
|
||||
<%= format_money account.balance %>
|
||||
<%= format_money account.balance_money %>
|
||||
<% end %>
|
||||
|
||||
<%= summary_card title: t(".interest_rate") do %>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<div>
|
||||
<h2 class="font-medium text-xl"><%= @account.name %></h2>
|
||||
|
||||
<% if @account.property? && @account.property.address %>
|
||||
<% if @account.property? && @account.property.address&.line1.present? %>
|
||||
<p class="text-gray-500"><%= @account.property.address %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue