Skip to content

Commit

Permalink
Calculate guilt free
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 committed Nov 18, 2023
1 parent 79c22c3 commit d0f2f44
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
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
13 changes: 13 additions & 0 deletions app/controllers/concerns/guilt_free.rb
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions app/services/guilt_free_calculator.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d0f2f44

Please sign in to comment.