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| %>
+
+ <%= form.check_box :enabled, class: "sr-only peer", onchange: "this.form.requestSubmit()" %>
+
+ Switch income type
+
+<% 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