Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guilt free calculating #20

Merged
merged 5 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/concerns/dashboard_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module DashboardBuilder
include TaxedIncome
include TotalCost
include SaveIncome
include GuiltFree

def build_dashboard_variables!
@incomes = Income.order_by_type
Expand All @@ -13,6 +14,7 @@ def build_dashboard_variables!
@investing_rate = SavingsRate.investing
build_taxed_income_vars!
build_savings_vars!
build_guilt_free_vars!
build_total_cost_vars!
Rails.logger.debug "\n *** Building Vars!!\n "
end
Expand Down
17 changes: 17 additions & 0 deletions app/controllers/concerns/guilt_free.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module GuiltFree
def build_guilt_free_vars!
@guilt_free_salary = GuiltFreeCalculator.new(@salary_taxed.total_net_income, salary_savings_totalizer)
@guilt_free_hourly = GuiltFreeCalculator.new(@hourly_taxed.total_net_income, hourly_savings_totalizer)
end

def salary_savings_totalizer
@salary_saving.annual_saving + @salary_invest.annual_saving
# @salary_saving + @salary_investing
end

def hourly_savings_totalizer
@hourly_saving.annual_saving + @salary_invest.annual_saving
end
end
7 changes: 4 additions & 3 deletions app/controllers/incomes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class IncomesController < ApplicationController
include DashboardBuilder
include TotalCost
include SaveIncome
include GuiltFree

before_action :set_income, only: %i[show edit update destroy]

Expand Down Expand Up @@ -95,15 +96,15 @@ def income_params

def build_locals(taxed_income)
income = taxed_income.income
build_total_cost_vars!
build_savings_vars!
build_dashboard_variables!
{
total_annual_cost: @total_annual_cost,
total_monthly_cost: @total_monthly_cost,
total_bi_weekly_cost: @total_bi_weekly_cost,
income: taxed_income,
investing_amount: income.is_hourly? ? @hourly_invest : @salary_invest,
savings_amount: income.is_hourly? ? @hourly_saving : @salary_saving
savings_amount: income.is_hourly? ? @hourly_saving : @salary_saving,
guilt_free: income.is_hourly? ? @guilt_free_hourly : @guilt_free_salary
}
end
end
51 changes: 51 additions & 0 deletions app/services/guilt_free_calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

class GuiltFreeCalculator
attr_reader :annual_guilt_free,
:biannual_guilt_free,
:quarterly_guilt_free,
:monthly_guilt_free,
:bi_weekly_guilt_free,
:weekly_guilt_free,
:daily_guilt_free

def initialize(taxed_income, savings_totals)
@taxed_income = taxed_income
@savings_totals = savings_totals
@annual_guilt_free = calculate_annual_guilt_free
@biannual_guilt_free = calculate_biannual_guilt_free
@quarterly_guilt_free = calculate_quarterly_guilt_free
@monthly_guilt_free = calculate_monthly_guilt_free
@bi_weekly_guilt_free = calculate_bi_weekly_guilt_free
@weekly_guilt_free = calculate_weekly_guilt_free
@daily_guilt_free = calculate_daily_guilt_free
end

def calculate_annual_guilt_free
@taxed_income - @savings_totals
end

def calculate_biannual_guilt_free
@annual_guilt_free / 2
end

def calculate_quarterly_guilt_free
@annual_guilt_free / 4
end

def calculate_monthly_guilt_free
@annual_guilt_free / 12
end

def calculate_bi_weekly_guilt_free
@annual_guilt_free / 26
end

def calculate_weekly_guilt_free
@annual_guilt_free / 52
end

def calculate_daily_guilt_free
@annual_guilt_free / 365
end
end
3 changes: 2 additions & 1 deletion app/views/budget/_hourly_budget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
total_bi_weekly_cost: total_bi_weekly_cost,
income: income,
investing_amount: investing_amount,
savings_amount: savings_amount
savings_amount: savings_amount,
guilt_free: guilt_free
} %>
</div>
<% end %>
6 changes: 4 additions & 2 deletions app/views/budget/_salary_budget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
total_bi_weekly_cost: total_bi_weekly_cost,
income: income,
investing_amount: investing_amount,
savings_amount: savings_amount
} %>
savings_amount: savings_amount,
guilt_free: guilt_free
}
%>
</div>
<% end %>
3 changes: 2 additions & 1 deletion app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
total_monthly_cost: @total_monthly_cost,
total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed,
investing_amount: @salary_invest,
savings_amount: @salary_saving
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
</div>
Expand Down
6 changes: 4 additions & 2 deletions app/views/fixed_expenses/update.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
total_bi_weekly_cost: @total_bi_weekly_cost,
income: @salary_taxed,
investing_amount: @salary_invest,
savings_amount: @salary_saving
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
Expand All @@ -31,7 +32,8 @@
total_bi_weekly_cost: @total_bi_weekly_cost,
income: @hourly_taxed,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
6 changes: 4 additions & 2 deletions app/views/incomes/update.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
total_bi_weekly_cost: @total_bi_weekly_cost,
income: @salary_taxed,
investing_amount: @salary_invest,
savings_amount: @salary_saving
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
Expand All @@ -30,7 +31,8 @@
total_bi_weekly_cost: @total_bi_weekly_cost,
income: @hourly_taxed,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
6 changes: 4 additions & 2 deletions app/views/savings_rates/update.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
total_bi_weekly_cost: @total_bi_weekly_cost,
income: @salary_taxed,
investing_amount: @salary_invest,
savings_amount: @salary_saving
savings_amount: @salary_saving,
guilt_free: @guilt_free_salary
}
%>
<% end %>
Expand All @@ -21,7 +22,8 @@
total_bi_weekly_cost: @total_bi_weekly_cost,
income: @hourly_taxed,
investing_amount: @hourly_invest,
savings_amount: @hourly_saving
savings_amount: @hourly_saving,
guilt_free: @guilt_free_hourly
}
%>
<% end %>
14 changes: 7 additions & 7 deletions app/views/shared/_budget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%= humanized_money_with_symbol(savings_amount.daily_saving) %>
</div>
<div>
<%= humanized_money_with_symbol((income.daily_income) - total_annual_cost / 365) %>
<%= humanized_money_with_symbol((guilt_free.daily_guilt_free) - total_annual_cost / 365) %>
</div>
</div>

Expand All @@ -19,7 +19,7 @@
<div><%= humanized_money_with_symbol(investing_amount.weekly_saving) %></div>
<div><%= humanized_money_with_symbol(savings_amount.weekly_saving) %></div>
<div>
<%= humanized_money_with_symbol((income.weekly_income) - total_annual_cost / 52) %>
<%= humanized_money_with_symbol((guilt_free.weekly_guilt_free) - total_annual_cost / 52) %>
</div>
</div>

Expand All @@ -29,7 +29,7 @@
<div><%= humanized_money_with_symbol(investing_amount.bi_weekly_saving) %></div>
<div><%= humanized_money_with_symbol(savings_amount.bi_weekly_saving) %></div>
<div>
<%= humanized_money_with_symbol((income.bi_weekly_net_income) - total_bi_weekly_cost) %>
<%= humanized_money_with_symbol((guilt_free.bi_weekly_guilt_free) - total_bi_weekly_cost) %>
</div>
</div>

Expand All @@ -39,7 +39,7 @@
<div><%= humanized_money_with_symbol(investing_amount.monthly_saving) %></div>
<div><%= humanized_money_with_symbol(savings_amount.monthly_saving) %></div>
<div>
<%= humanized_money_with_symbol((income.monthly_income) - total_monthly_cost) %>
<%= humanized_money_with_symbol((guilt_free.monthly_guilt_free) - total_monthly_cost) %>
</div>
</div>

Expand All @@ -49,7 +49,7 @@
<div><%= humanized_money_with_symbol(investing_amount.quarterly_saving) %></div>
<div><%= humanized_money_with_symbol(savings_amount.quarterly_saving) %></div>
<div>
<%= humanized_money_with_symbol((income.quarterly_income) - total_annual_cost / 4) %>
<%= humanized_money_with_symbol((guilt_free.quarterly_guilt_free) - total_annual_cost / 4) %>
</div>
</div>

Expand All @@ -59,7 +59,7 @@
<div><%= humanized_money_with_symbol(investing_amount.biannual_saving) %></div>
<div><%= humanized_money_with_symbol(savings_amount.biannual_saving) %></div>
<div>
<%= humanized_money_with_symbol((income.biannual_income) - total_annual_cost / 2) %>
<%= humanized_money_with_symbol((guilt_free.biannual_guilt_free) - total_annual_cost / 2) %>
</div>
</div>

Expand All @@ -70,6 +70,6 @@
<div><%= humanized_money_with_symbol(investing_amount.annual_saving) %></div>
<div><%= humanized_money_with_symbol(savings_amount.annual_saving) %></div>
<div>
<%= humanized_money_with_symbol(income.total_net_income - total_annual_cost ) %>
<%= humanized_money_with_symbol(guilt_free.annual_guilt_free - total_annual_cost ) %>
</div>
</div>