From 9533cbfc5089f7cd9a17b99640f80911cfb85127 Mon Sep 17 00:00:00 2001 From: "Benjamin Randolphgit config --global user.email neb417@gmail.comgit config --global init.defaultBranch maingit config --global core.editor atom" Date: Wed, 22 Nov 2023 15:22:41 -0700 Subject: [PATCH 1/3] Update streaming --- app/controllers/concerns/dashboard_builder.rb | 14 ++++- app/controllers/concerns/stream.rb | 61 +++++++++++++++++++ app/controllers/incomes_controller.rb | 44 ++++++------- app/controllers/savings_rates_controller.rb | 1 - app/views/budget/_hourly_budget.html.erb | 2 +- .../fixed_expenses/create.turbo_stream.erb | 32 +++++++++- .../fixed_expenses/destroy.turbo_stream.erb | 32 +++++++++- 7 files changed, 150 insertions(+), 36 deletions(-) create mode 100644 app/controllers/concerns/stream.rb diff --git a/app/controllers/concerns/dashboard_builder.rb b/app/controllers/concerns/dashboard_builder.rb index 64e48c1..80cef16 100644 --- a/app/controllers/concerns/dashboard_builder.rb +++ b/app/controllers/concerns/dashboard_builder.rb @@ -16,6 +16,18 @@ def build_dashboard_variables! build_savings_vars! build_guilt_free_vars! build_total_cost_vars! - Rails.logger.debug "\n *** Building Vars!!\n " + end + + def build_locals(taxed_income) + income = taxed_income.income + { + 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, + guilt_free: income.is_hourly? ? @guilt_free_hourly : @guilt_free_salary + } end end diff --git a/app/controllers/concerns/stream.rb b/app/controllers/concerns/stream.rb new file mode 100644 index 0000000..0a16cef --- /dev/null +++ b/app/controllers/concerns/stream.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module Stream + include DashboardBuilder + include TaxedIncome + + def render_respond_to(turbo_replace) + respond_to do |format| + format.turbo_stream do + render turbo_stream: turbo_replace + end + end + end + + def switch_to_hourly + [ + turbo_stream.replace("salary_budget", + partial: "budget/hourly_budget", + locals: build_locals(tax_on_hourly) + ) + ] + end + + def switch_to_salary + [ + turbo_stream.replace( "hourly_budget", + partial: "budget/salary_budget", + locals: build_locals(tax_on_salary) + ) + ] + end + + def render_dashboard + [ + turbo_stream.replace( "hourly_budget", + partial: "budget/salary_budget", + locals: build_locals(tax_on_salary) + ), + turbo_stream.replace( "salary_budget", + partial: "budget/hourly_budget", + locals: build_locals(tax_on_hourly) + ), + turbo_stream.replace("total_costs", + partial: "shared/total_costs", + locals: { + total_annual_cost: @total_annual_cost, + total_monthly_cost: @total_monthly_cost, + total_bi_weekly_cost: @total_bi_weekly_cost + } + ), + turbo_stream.replace("taxed_incomes", + partial: "shared/taxed_incomes", + locals: { + salary_taxed: @salary_taxed, + hourly_taxed: @hourly_taxed + } + ) + ] + end + +end diff --git a/app/controllers/incomes_controller.rb b/app/controllers/incomes_controller.rb index 1f9b53d..def3700 100644 --- a/app/controllers/incomes_controller.rb +++ b/app/controllers/incomes_controller.rb @@ -3,6 +3,7 @@ class IncomesController < ApplicationController include TotalCost include SaveIncome include GuiltFree + include Stream before_action :set_income, only: %i[show edit update destroy] @@ -63,22 +64,11 @@ def destroy end def income_switch + build_dashboard_variables! if params[:enabled] == "0" - respond_to do |format| - format.turbo_stream { - render turbo_stream: turbo_stream.replace("hourly_budget", - partial: "budget/salary_budget", - locals: build_locals(tax_on_salary)) - } - end + render_respond_to(switch_to_salary) else - respond_to do |format| - format.turbo_stream { - render turbo_stream: turbo_stream.replace("salary_budget", - partial: "budget/hourly_budget", - locals: build_locals(tax_on_hourly)) - } - end + render_respond_to(switch_to_hourly) end end @@ -94,17 +84,17 @@ def income_params params.require(:income).permit(:income_type, :rate, :hours, :weekly_income) end - def build_locals(taxed_income) - income = taxed_income.income - 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, - guilt_free: income.is_hourly? ? @guilt_free_hourly : @guilt_free_salary - } - end + # def build_locals(taxed_income) + # income = taxed_income.income + # 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, + # guilt_free: income.is_hourly? ? @guilt_free_hourly : @guilt_free_salary + # } + # end end diff --git a/app/controllers/savings_rates_controller.rb b/app/controllers/savings_rates_controller.rb index be14377..d461a2d 100644 --- a/app/controllers/savings_rates_controller.rb +++ b/app/controllers/savings_rates_controller.rb @@ -40,7 +40,6 @@ def create def update respond_to do |format| if @savings_rate.update_from_dashboard(params: savings_rate_params) - # calculate new savings amounts for both hourly and salary and new guilt free build_dashboard_variables! format.turbo_stream else diff --git a/app/views/budget/_hourly_budget.html.erb b/app/views/budget/_hourly_budget.html.erb index 91f9f81..5f6eb77 100644 --- a/app/views/budget/_hourly_budget.html.erb +++ b/app/views/budget/_hourly_budget.html.erb @@ -14,4 +14,4 @@ guilt_free: guilt_free } %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/fixed_expenses/create.turbo_stream.erb b/app/views/fixed_expenses/create.turbo_stream.erb index 8a9a854..d18719b 100644 --- a/app/views/fixed_expenses/create.turbo_stream.erb +++ b/app/views/fixed_expenses/create.turbo_stream.erb @@ -3,13 +3,39 @@ <% end %> <%= turbo_stream.replace "total_costs" do %> - <%= render partial: "shared/total_costs", locals: { total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost } %> + <%= render partial: "shared/total_costs", + locals: { + total_annual_cost: @total_annual_cost, + total_monthly_cost: @total_monthly_cost, + total_bi_weekly_cost: @total_bi_weekly_cost + } + %> <% end %> <%= turbo_stream.replace "salary_budget" do %> - <%= render partial: "budget/salary_budget", locals: {total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed} %> + <%= render partial: "budget/salary_budget", + locals: { + total_annual_cost: @total_annual_cost, + 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, + guilt_free: @guilt_free_salary + } + %> <% end %> <%= turbo_stream.replace "hourly_budget" do %> - <%= render partial: "budget/hourly_budget", locals: {total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed} %> + <%= render partial: "budget/hourly_budget", + locals: { + total_annual_cost: @total_annual_cost, + total_monthly_cost: @total_monthly_cost, + total_bi_weekly_cost: @total_bi_weekly_cost, + income: @hourly_taxed, + investing_amount: @hourly_invest, + savings_amount: @hourly_saving, + guilt_free: @guilt_free_hourly + } + %> <% end %> diff --git a/app/views/fixed_expenses/destroy.turbo_stream.erb b/app/views/fixed_expenses/destroy.turbo_stream.erb index 44ec110..178dc65 100644 --- a/app/views/fixed_expenses/destroy.turbo_stream.erb +++ b/app/views/fixed_expenses/destroy.turbo_stream.erb @@ -1,13 +1,39 @@ <%= turbo_stream.remove @fixed_expense %> <%= turbo_stream.replace "total_costs" do %> - <%= render partial: "shared/total_costs", locals: { total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost } %> + <%= render partial: "shared/total_costs", + locals: { + total_annual_cost: @total_annual_cost, + total_monthly_cost: @total_monthly_cost, + total_bi_weekly_cost: @total_bi_weekly_cost + } + %> <% end %> <%= turbo_stream.replace "salary_budget" do %> - <%= render partial: "budget/salary_budget", locals: {total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed} %> + <%= render partial: "budget/salary_budget", + locals: { + total_annual_cost: @total_annual_cost, + 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, + guilt_free: @guilt_free_salary + } + %> <% end %> <%= turbo_stream.replace "hourly_budget" do %> - <%= render partial: "budget/hourly_budget", locals: {total_annual_cost: @total_annual_cost, total_monthly_cost: @total_monthly_cost, total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed} %> + <%= render partial: "budget/hourly_budget", + locals: { + total_annual_cost: @total_annual_cost, + total_monthly_cost: @total_monthly_cost, + total_bi_weekly_cost: @total_bi_weekly_cost, + income: @hourly_taxed, + investing_amount: @hourly_invest, + savings_amount: @hourly_saving, + guilt_free: @guilt_free_hourly + } + %> <% end %> From ca8eb98437eeb2a0e23a797cf796c8713d2f29ea Mon Sep 17 00:00:00 2001 From: "Benjamin Randolphgit config --global user.email neb417@gmail.comgit config --global init.defaultBranch maingit config --global core.editor atom" Date: Wed, 22 Nov 2023 15:57:33 -0700 Subject: [PATCH 2/3] Refactor total cost to service --- app/controllers/concerns/dashboard_builder.rb | 4 +- app/controllers/concerns/total_cost.rb | 9 ++-- app/services/total_cost_calculator.rb | 45 +++++++++++++++++++ app/views/budget/_hourly_budget.html.erb | 7 ++- app/views/budget/_salary_budget.html.erb | 4 +- app/views/dashboard/index.html.erb | 11 ++--- .../fixed_expenses/create.turbo_stream.erb | 16 ++----- .../fixed_expenses/destroy.turbo_stream.erb | 16 ++----- .../fixed_expenses/update.turbo_stream.erb | 16 ++----- app/views/incomes/update.turbo_stream.erb | 8 +--- .../savings_rates/update.turbo_stream.erb | 8 +--- app/views/shared/_budget.html.erb | 28 ++++++------ app/views/shared/_total_costs.html.erb | 6 +-- 13 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 app/services/total_cost_calculator.rb diff --git a/app/controllers/concerns/dashboard_builder.rb b/app/controllers/concerns/dashboard_builder.rb index 80cef16..eaa0644 100644 --- a/app/controllers/concerns/dashboard_builder.rb +++ b/app/controllers/concerns/dashboard_builder.rb @@ -21,10 +21,8 @@ def build_dashboard_variables! def build_locals(taxed_income) income = taxed_income.income { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, 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 diff --git a/app/controllers/concerns/total_cost.rb b/app/controllers/concerns/total_cost.rb index 003e2f9..38cbfb1 100644 --- a/app/controllers/concerns/total_cost.rb +++ b/app/controllers/concerns/total_cost.rb @@ -13,10 +13,13 @@ def total_bi_weekly_cost Money.new(get_sum(:bi_weekly_cost_cents)) end + def total_cost + cost = FixedExpense.sum(&:annual_cost) + TotalCostCalculator.new(cost: cost) + 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 + @total_cost = total_cost end private diff --git a/app/services/total_cost_calculator.rb b/app/services/total_cost_calculator.rb new file mode 100644 index 0000000..f15bdfd --- /dev/null +++ b/app/services/total_cost_calculator.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +class TotalCostCalculator + attr_reader :annual_cost, + :biannual_cost, + :quarterly_cost, + :monthly_cost, + :bi_weekly_cost, + :weekly_cost, + :daily_cost + + def initialize(cost:) + @annual_cost = cost + @biannual_cost = calculate_biannual_cost + @quarterly_cost = calculate_quarterly_cost + @monthly_cost = calculate_monthly_cost + @bi_weekly_cost = calculate_bi_weekly_cost + @weekly_cost = calculate_weekly_cost + @daily_cost = calculate_daily_cost + end + + def calculate_biannual_cost + @annual_cost / 2 + end + + def calculate_quarterly_cost + @annual_cost / 4 + end + + def calculate_monthly_cost + @annual_cost / 12 + end + + def calculate_bi_weekly_cost + @annual_cost / 26 + end + + def calculate_weekly_cost + @annual_cost / 52 + end + + def calculate_daily_cost + @annual_cost / 365 + end +end diff --git a/app/views/budget/_hourly_budget.html.erb b/app/views/budget/_hourly_budget.html.erb index 5f6eb77..1f0e91f 100644 --- a/app/views/budget/_hourly_budget.html.erb +++ b/app/views/budget/_hourly_budget.html.erb @@ -5,13 +5,12 @@ <%= render partial: "budget/budget_headings" %> <%= render partial: "shared/budget", locals: { - total_annual_cost: total_annual_cost, - total_monthly_cost: total_monthly_cost, - total_bi_weekly_cost: total_bi_weekly_cost, income: income, + total_cost: total_cost, investing_amount: investing_amount, savings_amount: savings_amount, guilt_free: guilt_free - } %> + } + %> <% end %> diff --git a/app/views/budget/_salary_budget.html.erb b/app/views/budget/_salary_budget.html.erb index 1517746..8ace22f 100644 --- a/app/views/budget/_salary_budget.html.erb +++ b/app/views/budget/_salary_budget.html.erb @@ -4,10 +4,8 @@ <%= render partial: "budget/budget_headings" %> <%= render partial: "shared/budget", locals: { - total_annual_cost: total_annual_cost, - total_monthly_cost: total_monthly_cost, - total_bi_weekly_cost: total_bi_weekly_cost, income: income, + total_cost: total_cost, investing_amount: investing_amount, savings_amount: savings_amount, guilt_free: guilt_free diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 8d6d111..9b181dc 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -39,9 +39,8 @@
<%= render partial: "budget/salary_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed, + income: @salary_taxed, + total_cost: @total_cost, investing_amount: @salary_invest, savings_amount: @salary_saving, guilt_free: @guilt_free_salary @@ -85,11 +84,7 @@ <% end %> <%= turbo_frame_tag "total_costs" do %> - <%= render partial: "shared/total_costs", - locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost } %> + <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %> <% end %>
diff --git a/app/views/fixed_expenses/create.turbo_stream.erb b/app/views/fixed_expenses/create.turbo_stream.erb index d18719b..eb1d77a 100644 --- a/app/views/fixed_expenses/create.turbo_stream.erb +++ b/app/views/fixed_expenses/create.turbo_stream.erb @@ -3,22 +3,14 @@ <% end %> <%= turbo_stream.replace "total_costs" do %> - <%= render partial: "shared/total_costs", - locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost - } - %> + <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %> <% end %> <%= turbo_stream.replace "salary_budget" do %> <%= render partial: "budget/salary_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed, + total_cost: @total_cost, investing_amount: @salary_invest, savings_amount: @salary_saving, guilt_free: @guilt_free_salary @@ -29,10 +21,8 @@ <%= turbo_stream.replace "hourly_budget" do %> <%= render partial: "budget/hourly_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed, + total_cost: @total_cost, investing_amount: @hourly_invest, savings_amount: @hourly_saving, guilt_free: @guilt_free_hourly diff --git a/app/views/fixed_expenses/destroy.turbo_stream.erb b/app/views/fixed_expenses/destroy.turbo_stream.erb index 178dc65..083204b 100644 --- a/app/views/fixed_expenses/destroy.turbo_stream.erb +++ b/app/views/fixed_expenses/destroy.turbo_stream.erb @@ -1,22 +1,14 @@ <%= turbo_stream.remove @fixed_expense %> <%= turbo_stream.replace "total_costs" do %> - <%= render partial: "shared/total_costs", - locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost - } - %> + <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %> <% end %> <%= turbo_stream.replace "salary_budget" do %> <%= render partial: "budget/salary_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed, + total_cost: @total_cost, investing_amount: @salary_invest, savings_amount: @salary_saving, guilt_free: @guilt_free_salary @@ -27,10 +19,8 @@ <%= turbo_stream.replace "hourly_budget" do %> <%= render partial: "budget/hourly_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed, + total_cost: @total_cost, investing_amount: @hourly_invest, savings_amount: @hourly_saving, guilt_free: @guilt_free_hourly diff --git a/app/views/fixed_expenses/update.turbo_stream.erb b/app/views/fixed_expenses/update.turbo_stream.erb index db59b34..695ceee 100644 --- a/app/views/fixed_expenses/update.turbo_stream.erb +++ b/app/views/fixed_expenses/update.turbo_stream.erb @@ -1,22 +1,14 @@ <%= turbo_stream.update @fixed_expense %> <%= turbo_stream.replace "total_costs" do %> - <%= render partial: "shared/total_costs", - locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost - } - %> + <%= render partial: "shared/total_costs", locals: { total_cost: @total_cost } %> <% end %> <%= turbo_stream.replace "salary_budget" do %> <%= render partial: "budget/salary_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed, + total_cost: @total_cost, investing_amount: @salary_invest, savings_amount: @salary_saving, guilt_free: @guilt_free_salary @@ -27,10 +19,8 @@ <%= turbo_stream.replace "hourly_budget" do %> <%= render partial: "budget/hourly_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed, + total_cost: @total_cost, investing_amount: @hourly_invest, savings_amount: @hourly_saving, guilt_free: @guilt_free_hourly diff --git a/app/views/incomes/update.turbo_stream.erb b/app/views/incomes/update.turbo_stream.erb index 05eca50..e0124c8 100644 --- a/app/views/incomes/update.turbo_stream.erb +++ b/app/views/incomes/update.turbo_stream.erb @@ -12,10 +12,8 @@ <%= turbo_stream.replace "salary_budget" do %> <%= render partial: "budget/salary_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed, + total_cost: @total_cost, investing_amount: @salary_invest, savings_amount: @salary_saving, guilt_free: @guilt_free_salary @@ -26,10 +24,8 @@ <%= turbo_stream.replace "hourly_budget" do %> <%= render partial: "budget/hourly_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed, + total_cost: @total_cost, investing_amount: @hourly_invest, savings_amount: @hourly_saving, guilt_free: @guilt_free_hourly diff --git a/app/views/savings_rates/update.turbo_stream.erb b/app/views/savings_rates/update.turbo_stream.erb index dd214b8..c279cfb 100644 --- a/app/views/savings_rates/update.turbo_stream.erb +++ b/app/views/savings_rates/update.turbo_stream.erb @@ -3,10 +3,8 @@ <%= turbo_stream.replace "salary_budget" do %> <%= render partial: "budget/salary_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @salary_taxed, + total_cost: @total_cost, investing_amount: @salary_invest, savings_amount: @salary_saving, guilt_free: @guilt_free_salary @@ -17,10 +15,8 @@ <%= turbo_stream.replace "hourly_budget" do %> <%= render partial: "budget/hourly_budget", locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost, income: @hourly_taxed, + total_cost: @total_cost, investing_amount: @hourly_invest, savings_amount: @hourly_saving, guilt_free: @guilt_free_hourly diff --git a/app/views/shared/_budget.html.erb b/app/views/shared/_budget.html.erb index 47ae1b3..2e3c377 100644 --- a/app/views/shared/_budget.html.erb +++ b/app/views/shared/_budget.html.erb @@ -3,10 +3,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_annual_cost/365, + total_cost: total_cost.daily_cost, savings_amount: savings_amount.daily_saving, investing_amount: investing_amount.daily_saving, - guilt_free: guilt_free.daily_guilt_free - total_annual_cost/365 + guilt_free: guilt_free.daily_guilt_free - total_cost.daily_cost } %> @@ -16,10 +16,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_annual_cost/52, + total_cost: total_cost.weekly_cost, savings_amount: savings_amount.weekly_saving, investing_amount: investing_amount.weekly_saving, - guilt_free: guilt_free.weekly_guilt_free - total_annual_cost/52 + guilt_free: guilt_free.weekly_guilt_free - total_cost.weekly_cost } %> @@ -29,10 +29,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_bi_weekly_cost, + total_cost: total_cost.bi_weekly_cost, savings_amount: savings_amount.bi_weekly_saving, investing_amount: investing_amount.bi_weekly_saving, - guilt_free: guilt_free.bi_weekly_guilt_free - total_bi_weekly_cost + guilt_free: guilt_free.bi_weekly_guilt_free - total_cost.bi_weekly_cost } %> @@ -43,10 +43,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_monthly_cost, + total_cost: total_cost.monthly_cost, savings_amount: savings_amount.monthly_saving, investing_amount: investing_amount.monthly_saving, - guilt_free: guilt_free.monthly_guilt_free - total_monthly_cost + guilt_free: guilt_free.monthly_guilt_free - total_cost.monthly_cost } %> @@ -56,10 +56,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_annual_cost/4, + total_cost: total_cost.quarterly_cost, savings_amount: savings_amount.quarterly_saving, investing_amount: investing_amount.quarterly_saving, - guilt_free: guilt_free.quarterly_guilt_free - total_annual_cost / 4 + guilt_free: guilt_free.quarterly_guilt_free - total_cost.quarterly_cost } %> @@ -69,10 +69,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_annual_cost/2, + total_cost: total_cost.biannual_cost, savings_amount: savings_amount.biannual_saving, investing_amount: investing_amount.biannual_saving, - guilt_free: guilt_free.biannual_guilt_free - total_annual_cost / 2 + guilt_free: guilt_free.biannual_guilt_free - total_cost.biannual_cost } %> @@ -82,10 +82,10 @@ <%= render partial: "budget/display_budget", locals: { - total_cost: total_annual_cost, + total_cost: total_cost.annual_cost, savings_amount: savings_amount.annual_saving, investing_amount: investing_amount.annual_saving, - guilt_free: guilt_free.annual_guilt_free - total_annual_cost + guilt_free: guilt_free.annual_guilt_free - total_cost.annual_cost } %> diff --git a/app/views/shared/_total_costs.html.erb b/app/views/shared/_total_costs.html.erb index 7ba865a..a89dffe 100644 --- a/app/views/shared/_total_costs.html.erb +++ b/app/views/shared/_total_costs.html.erb @@ -5,19 +5,19 @@
- <%= render partial: "shared/total", locals: { total: total_annual_cost } %> + <%= render partial: "shared/total", locals: { total: total_cost.annual_cost } %>
- <%= render partial: "shared/total", locals: { total: total_monthly_cost } %> + <%= render partial: "shared/total", locals: { total: total_cost.monthly_cost } %>
- <%= render partial: "shared/total", locals: { total: total_bi_weekly_cost } %> + <%= render partial: "shared/total", locals: { total: total_cost.bi_weekly_cost } %>
From 97b085797d5d1d866662081c13a67a18ed2f6910 Mon Sep 17 00:00:00 2001 From: "Benjamin Randolphgit config --global user.email neb417@gmail.comgit config --global init.defaultBranch maingit config --global core.editor atom" Date: Wed, 22 Nov 2023 15:58:09 -0700 Subject: [PATCH 3/3] Lint --- app/controllers/concerns/stream.rb | 51 ++++++++++++--------------- app/services/total_cost_calculator.rb | 12 +++---- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/app/controllers/concerns/stream.rb b/app/controllers/concerns/stream.rb index 0a16cef..1497ad8 100644 --- a/app/controllers/concerns/stream.rb +++ b/app/controllers/concerns/stream.rb @@ -15,47 +15,40 @@ def render_respond_to(turbo_replace) def switch_to_hourly [ turbo_stream.replace("salary_budget", - partial: "budget/hourly_budget", - locals: build_locals(tax_on_hourly) - ) + partial: "budget/hourly_budget", + locals: build_locals(tax_on_hourly)) ] end def switch_to_salary [ - turbo_stream.replace( "hourly_budget", - partial: "budget/salary_budget", - locals: build_locals(tax_on_salary) - ) + turbo_stream.replace("hourly_budget", + partial: "budget/salary_budget", + locals: build_locals(tax_on_salary)) ] end def render_dashboard [ - turbo_stream.replace( "hourly_budget", - partial: "budget/salary_budget", - locals: build_locals(tax_on_salary) - ), - turbo_stream.replace( "salary_budget", - partial: "budget/hourly_budget", - locals: build_locals(tax_on_hourly) - ), + turbo_stream.replace("hourly_budget", + partial: "budget/salary_budget", + locals: build_locals(tax_on_salary)), + turbo_stream.replace("salary_budget", + partial: "budget/hourly_budget", + locals: build_locals(tax_on_hourly)), turbo_stream.replace("total_costs", - partial: "shared/total_costs", - locals: { - total_annual_cost: @total_annual_cost, - total_monthly_cost: @total_monthly_cost, - total_bi_weekly_cost: @total_bi_weekly_cost - } - ), + partial: "shared/total_costs", + locals: { + total_annual_cost: @total_annual_cost, + total_monthly_cost: @total_monthly_cost, + total_bi_weekly_cost: @total_bi_weekly_cost + }), turbo_stream.replace("taxed_incomes", - partial: "shared/taxed_incomes", - locals: { - salary_taxed: @salary_taxed, - hourly_taxed: @hourly_taxed - } - ) + partial: "shared/taxed_incomes", + locals: { + salary_taxed: @salary_taxed, + hourly_taxed: @hourly_taxed + }) ] end - end diff --git a/app/services/total_cost_calculator.rb b/app/services/total_cost_calculator.rb index f15bdfd..c40065e 100644 --- a/app/services/total_cost_calculator.rb +++ b/app/services/total_cost_calculator.rb @@ -2,12 +2,12 @@ class TotalCostCalculator attr_reader :annual_cost, - :biannual_cost, - :quarterly_cost, - :monthly_cost, - :bi_weekly_cost, - :weekly_cost, - :daily_cost + :biannual_cost, + :quarterly_cost, + :monthly_cost, + :bi_weekly_cost, + :weekly_cost, + :daily_cost def initialize(cost:) @annual_cost = cost