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 index ea79b81..8b2432d 100644 --- a/app/controllers/concerns/guilt_free.rb +++ b/app/controllers/concerns/guilt_free.rb @@ -1,4 +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/services/guilt_free_calculator.rb b/app/services/guilt_free_calculator.rb index 1eb3ced..4d92754 100644 --- a/app/services/guilt_free_calculator.rb +++ b/app/services/guilt_free_calculator.rb @@ -1,8 +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