From 7a225342e250ff4d909f747902483719fca8ca09 Mon Sep 17 00:00:00 2001 From: Benjamin Randolph <104036158+neb417@users.noreply.github.com> Date: Tue, 14 Nov 2023 08:45:34 -0700 Subject: [PATCH] Income switch (#14) * Add partials for income types * Add route and method for switch to display income type --- app/controllers/incomes_controller.rb | 31 ++++++++++++++++++++++++ app/views/budget/_hourly_budget.html.erb | 12 +++++---- app/views/budget/_salary_budget.html.erb | 12 +++++---- app/views/components/_income_switch.erb | 7 ++++++ app/views/dashboard/index.html.erb | 12 ++++----- config/routes.rb | 1 + 6 files changed, 58 insertions(+), 17 deletions(-) create mode 100644 app/views/components/_income_switch.erb diff --git a/app/controllers/incomes_controller.rb b/app/controllers/incomes_controller.rb index 1e34b9d..28c4486 100644 --- a/app/controllers/incomes_controller.rb +++ b/app/controllers/incomes_controller.rb @@ -60,6 +60,37 @@ def destroy end end + def income_switch + totals = FixedExpense.total_costs + if params[:enabled] == "0" + salary = Income.tax_on_income(income_type: "Salary") + + respond_to do |format| + format.turbo_stream { + render turbo_stream: turbo_stream.replace("hourly_budget", + partial: "budget/salary_budget", + locals: { + totals: totals, + income: salary + }) + } + end + else + hourly = Income.tax_on_income(income_type: "Hourly") + + respond_to do |format| + format.turbo_stream { + render turbo_stream: turbo_stream.replace("salary_budget", + partial: "budget/hourly_budget", + locals: { + totals: totals, + income: hourly + }) + } + end + end + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/app/views/budget/_hourly_budget.html.erb b/app/views/budget/_hourly_budget.html.erb index 0627d23..f369823 100644 --- a/app/views/budget/_hourly_budget.html.erb +++ b/app/views/budget/_hourly_budget.html.erb @@ -1,5 +1,7 @@ -
- Hourly - <%= render partial: "budget/budget_headings" %> - <%= render partial: "shared/budget", locals: {totals: totals, income: income} %> -
\ No newline at end of file +<%= turbo_frame_tag "hourly_budget" do %> +
+ Hourly + <%= render partial: "budget/budget_headings" %> + <%= render partial: "shared/budget", locals: {totals: totals, income: income} %> +
+<% end %> \ No newline at end of file diff --git a/app/views/budget/_salary_budget.html.erb b/app/views/budget/_salary_budget.html.erb index 3538073..1f4ee0f 100644 --- a/app/views/budget/_salary_budget.html.erb +++ b/app/views/budget/_salary_budget.html.erb @@ -1,5 +1,7 @@ -
- Salary - <%= render partial: "budget/budget_headings" %> - <%= render partial: "shared/budget", locals: {totals: totals, income: income} %> -
+<%= turbo_frame_tag "salary_budget" do %> +
+ Salary + <%= render partial: "budget/budget_headings" %> + <%= render partial: "shared/budget", locals: {totals: totals, income: income} %> +
+<% end %> diff --git a/app/views/components/_income_switch.erb b/app/views/components/_income_switch.erb new file mode 100644 index 0000000..91f51b7 --- /dev/null +++ b/app/views/components/_income_switch.erb @@ -0,0 +1,7 @@ +<%= form_with url: income_switch_url, local: true do |form| %> + +<% end %> \ No newline at end of file diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index cd6a37b..167456a 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -11,15 +11,13 @@

Final Budget

+
+ <%= render partial: "components/income_switch" %> +
- - <%= turbo_frame_tag "salary_budget" do %> +
<%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %> - <% end %> - - <%= turbo_frame_tag "hourly_budget" do %> - <%= render partial: "budget/hourly_budget", locals: {totals: @totals, income: @hourly_taxed} %> - <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 66d0347..d07e0e3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,5 @@ resources :fixed_expenses root "dashboard#index" resources :incomes + post "/income_switch", to: "incomes#income_switch" end