-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove OpenStruct from fixed expense (#17)
* Refactor to rid of OpenStruct * Refactor user of services * Find and replace all @totals * Extract methods to concerns * Style buttons * Refactor building variables
- Loading branch information
Showing
22 changed files
with
142 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module DashboardBuilder | ||
include TaxedIncome | ||
include TotalCost | ||
|
||
def build_dashboard_variables! | ||
@incomes = Income.order_by_type | ||
@fixed_expenses = FixedExpense.get_ordered | ||
build_taxed_income_vars! | ||
build_total_cost_vars! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module TaxedIncome | ||
def tax_on_salary | ||
income = Income.find_by(income_type: "Salary") | ||
Rails.logger.debug "**** Tax Salary: #{income.inspect}" | ||
IncomeTaxCalculatorService.new(income: income) | ||
end | ||
|
||
def tax_on_hourly | ||
income = Income.find_by(income_type: "Hourly") | ||
IncomeTaxCalculatorService.new(income: income) | ||
end | ||
|
||
def build_taxed_income_vars! | ||
@salary_taxed = tax_on_salary | ||
@hourly_taxed = tax_on_hourly | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module TotalCost | ||
def total_annual_cost | ||
Money.new(get_sum(:annual_cost_cents)) | ||
end | ||
|
||
def total_monthly_cost | ||
Money.new(get_sum(:monthly_cost_cents)) | ||
end | ||
|
||
def total_bi_weekly_cost | ||
Money.new(get_sum(:bi_weekly_cost_cents)) | ||
end | ||
|
||
def build_total_cost_vars! | ||
@total_annual_cost = total_annual_cost | ||
@total_monthly_cost = total_monthly_cost | ||
@total_bi_weekly_cost = total_bi_weekly_cost | ||
end | ||
|
||
private | ||
|
||
def get_sum(time_period) | ||
FixedExpense.sum(&time_period) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
class DashboardController < ApplicationController | ||
include DashboardBuilder | ||
|
||
def index | ||
@incomes = Income.order_by_type | ||
@fixed_expenses = FixedExpense.get_ordered | ||
@totals = FixedExpense.total_costs | ||
@federal_tax_brackets = FederalTaxBracket.order_by_range | ||
@salary_taxed = Income.tax_on_income(income_type: "Salary") | ||
@hourly_taxed = Income.tax_on_income(income_type: "Hourly") | ||
build_dashboard_variables! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.