Skip to content

Commit

Permalink
Remove unused local, refactor taxed income module. (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 authored Nov 5, 2024
1 parent 9cff1c2 commit 792987b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
9 changes: 4 additions & 5 deletions app/controllers/concerns/dashboard_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ def build_dashboard_variables!
end

def build_locals(taxed_income)
income = taxed_income.income
{
income: taxed_income,

total_cost: @total_cost,
investing_amount: income.is_hourly? ? @hourly_invest : @salary_invest,
savings_amount: income.is_hourly? ? @hourly_saving : @salary_saving,
guilt_free: income.is_hourly? ? @guilt_free_hourly : @guilt_free_salary
investing_amount: taxed_income.is_hourly? ? @hourly_invest : @salary_invest,
savings_amount: taxed_income.is_hourly? ? @hourly_saving : @salary_saving,
guilt_free: taxed_income.is_hourly? ? @guilt_free_hourly : @guilt_free_salary
}
end
end
4 changes: 2 additions & 2 deletions app/controllers/concerns/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def switch_to_hourly
[
turbo_stream.replace("salary_budget",
partial: "budget/hourly_budget",
locals: build_locals(tax_on_hourly))
locals: build_locals(hourly_income))
]
end

def switch_to_salary
[
turbo_stream.replace("hourly_budget",
partial: "budget/salary_budget",
locals: build_locals(tax_on_salary))
locals: build_locals(salary_income))
]
end

Expand Down
13 changes: 7 additions & 6 deletions app/controllers/concerns/taxed_income.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def build_income_tax_variables!
end

def salary_income
@salary_income = Income.find_by(income_type: "Salary").weekly_income * 52
@salary_income = Income.find_by(income_type: "Salary")
end

def hourly_income
@hourly_income = Income.find_by(income_type: "Hourly").weekly_income * 52
@hourly_income = Income.find_by(income_type: "Hourly")
end

def federal_tax_table_type_id
Expand All @@ -22,10 +22,11 @@ def federal_tax_table_type_id
end

def build_income_tax_object(income:)
federal_tax = FederalTaxCalculator.call(income: income, federal_tax_table_type_id: federal_tax_table_type_id)
fica_tax = FicaTaxCalculator.call(income: income)
state_tax = StateTaxCalculator.call(income: income)
net_income = income - (fica_tax + federal_tax + state_tax)
annual_income = income.weekly_income * 52
federal_tax = FederalTaxCalculator.call(income: annual_income, federal_tax_table_type_id: federal_tax_table_type_id)
fica_tax = FicaTaxCalculator.call(income: annual_income)
state_tax = StateTaxCalculator.call(income: annual_income)
net_income = annual_income - (fica_tax + federal_tax + state_tax)
OpenStruct.new(federal_tax: federal_tax, fica_tax: fica_tax, state_tax: state_tax, net_income: net_income)
end
end
1 change: 0 additions & 1 deletion app/views/budget/_hourly_budget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<%= render partial: "budget/budget_headings" %>
<%= render partial: "shared/budget",
locals: {
income: income,
total_cost: total_cost,
investing_amount: investing_amount,
savings_amount: savings_amount,
Expand Down
1 change: 0 additions & 1 deletion app/views/budget/_salary_budget.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<%= render partial: "budget/budget_headings" %>
<%= render partial: "shared/budget",
locals: {
income: income,
total_cost: total_cost,
investing_amount: investing_amount,
savings_amount: savings_amount,
Expand Down

0 comments on commit 792987b

Please sign in to comment.