diff --git a/app/controllers/concerns/dashboard_builder.rb b/app/controllers/concerns/dashboard_builder.rb index ae6f97a..64e48c1 100644 --- a/app/controllers/concerns/dashboard_builder.rb +++ b/app/controllers/concerns/dashboard_builder.rb @@ -5,6 +5,7 @@ module DashboardBuilder include TaxedIncome include TotalCost include SaveIncome + include GuiltFree def build_dashboard_variables! @incomes = Income.order_by_type @@ -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 diff --git a/app/controllers/concerns/guilt_free.rb b/app/controllers/concerns/guilt_free.rb new file mode 100644 index 0000000..8b2432d --- /dev/null +++ b/app/controllers/concerns/guilt_free.rb @@ -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 diff --git a/app/controllers/incomes_controller.rb b/app/controllers/incomes_controller.rb index 8e4501c..1f9b53d 100644 --- a/app/controllers/incomes_controller.rb +++ b/app/controllers/incomes_controller.rb @@ -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] @@ -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 diff --git a/app/services/guilt_free_calculator.rb b/app/services/guilt_free_calculator.rb new file mode 100644 index 0000000..a7db717 --- /dev/null +++ b/app/services/guilt_free_calculator.rb @@ -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 diff --git a/app/views/budget/_hourly_budget.html.erb b/app/views/budget/_hourly_budget.html.erb index bd5b031..91f9f81 100644 --- a/app/views/budget/_hourly_budget.html.erb +++ b/app/views/budget/_hourly_budget.html.erb @@ -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 } %> <% end %> \ No newline at end of file diff --git a/app/views/budget/_salary_budget.html.erb b/app/views/budget/_salary_budget.html.erb index d6f13e0..9be9edc 100644 --- a/app/views/budget/_salary_budget.html.erb +++ b/app/views/budget/_salary_budget.html.erb @@ -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 + } + %> <% end %> diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 2e6eccf..8d6d111 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -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 } %> diff --git a/app/views/fixed_expenses/update.turbo_stream.erb b/app/views/fixed_expenses/update.turbo_stream.erb index 770766e..db59b34 100644 --- a/app/views/fixed_expenses/update.turbo_stream.erb +++ b/app/views/fixed_expenses/update.turbo_stream.erb @@ -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 %> @@ -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 %> diff --git a/app/views/incomes/update.turbo_stream.erb b/app/views/incomes/update.turbo_stream.erb index b8aa8ff..05eca50 100644 --- a/app/views/incomes/update.turbo_stream.erb +++ b/app/views/incomes/update.turbo_stream.erb @@ -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 %> @@ -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 %> \ No newline at end of file diff --git a/app/views/savings_rates/update.turbo_stream.erb b/app/views/savings_rates/update.turbo_stream.erb index b4779e5..dd214b8 100644 --- a/app/views/savings_rates/update.turbo_stream.erb +++ b/app/views/savings_rates/update.turbo_stream.erb @@ -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 %> @@ -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 %> \ No newline at end of file diff --git a/app/views/shared/_budget.html.erb b/app/views/shared/_budget.html.erb index e42b434..9a7a6da 100644 --- a/app/views/shared/_budget.html.erb +++ b/app/views/shared/_budget.html.erb @@ -9,7 +9,7 @@ <%= humanized_money_with_symbol(savings_amount.daily_saving) %>