mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-29 10:09:39 +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
|
def account_params
|
||||||
params.require(:account)
|
params.require(:account)
|
||||||
.permit(
|
.permit(
|
||||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||||
accountable_attributes: [
|
accountable_attributes: [
|
||||||
:id,
|
:id,
|
||||||
:available_credit,
|
:available_credit,
|
||||||
|
|
|
@ -27,7 +27,7 @@ class LoansController < ApplicationController
|
||||||
def account_params
|
def account_params
|
||||||
params.require(:account)
|
params.require(:account)
|
||||||
.permit(
|
.permit(
|
||||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||||
accountable_attributes: [
|
accountable_attributes: [
|
||||||
:id,
|
:id,
|
||||||
:rate_type,
|
:rate_type,
|
||||||
|
|
|
@ -27,7 +27,7 @@ class PropertiesController < ApplicationController
|
||||||
def account_params
|
def account_params
|
||||||
params.require(:account)
|
params.require(:account)
|
||||||
.permit(
|
.permit(
|
||||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||||
accountable_attributes: [
|
accountable_attributes: [
|
||||||
:id,
|
:id,
|
||||||
:year_built,
|
:year_built,
|
||||||
|
|
|
@ -27,7 +27,7 @@ class VehiclesController < ApplicationController
|
||||||
def account_params
|
def account_params
|
||||||
params.require(:account)
|
params.require(:account)
|
||||||
.permit(
|
.permit(
|
||||||
:name, :balance, :start_date, :start_balance, :currency, :accountable_type,
|
:name, :balance, :institution_id, :start_date, :start_balance, :currency, :accountable_type,
|
||||||
accountable_attributes: [
|
accountable_attributes: [
|
||||||
:id,
|
:id,
|
||||||
:make,
|
:make,
|
||||||
|
|
|
@ -83,7 +83,8 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def original_balance
|
def original_balance
|
||||||
balances.chronological.first&.balance || balance
|
balance_amount = balances.chronological.first&.balance || balance
|
||||||
|
Money.new(balance_amount, currency)
|
||||||
end
|
end
|
||||||
|
|
||||||
def owns_ticker?(ticker)
|
def owns_ticker?(ticker)
|
||||||
|
|
|
@ -1,3 +1,15 @@
|
||||||
class CreditCard < ApplicationRecord
|
class CreditCard < ApplicationRecord
|
||||||
include Accountable
|
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
|
end
|
||||||
|
|
|
@ -3,12 +3,12 @@ class Loan < ApplicationRecord
|
||||||
|
|
||||||
def monthly_payment
|
def monthly_payment
|
||||||
return nil if term_months.nil? || interest_rate.nil? || rate_type.nil? || rate_type != "fixed"
|
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
|
annual_rate = interest_rate / 100.0
|
||||||
monthly_rate = annual_rate / 12.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)
|
Money.new(payment.round, account.currency)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
<div class="grid grid-cols-3 gap-2">
|
<div class="grid grid-cols-3 gap-2">
|
||||||
<%= summary_card title: t(".amount_owed") do %>
|
<%= summary_card title: t(".amount_owed") do %>
|
||||||
<%= format_money(account.balance) %>
|
<%= format_money(account.balance_money) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= summary_card title: t(".available_credit") do %>
|
<%= 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 %>
|
<% end %>
|
||||||
|
|
||||||
<%= summary_card title: t(".minimum_payment") do %>
|
<%= 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 %>
|
<% end %>
|
||||||
|
|
||||||
<%= summary_card title: t(".apr") do %>
|
<%= summary_card title: t(".apr") do %>
|
||||||
|
@ -22,6 +22,6 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= summary_card title: t(".annual_fee") do %>
|
<%= 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 %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= summary_card title: t(".remaining_principal") do %>
|
<%= summary_card title: t(".remaining_principal") do %>
|
||||||
<%= format_money account.balance %>
|
<%= format_money account.balance_money %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= summary_card title: t(".interest_rate") do %>
|
<%= summary_card title: t(".interest_rate") do %>
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<div>
|
<div>
|
||||||
<h2 class="font-medium text-xl"><%= @account.name %></h2>
|
<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>
|
<p class="text-gray-500"><%= @account.property.address %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue