Skip to content

Commit

Permalink
Update budget with turbo
Browse files Browse the repository at this point in the history
  • Loading branch information
neb417 committed Nov 6, 2023
1 parent 3f10a83 commit ba2e594
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/controllers/fixed_expenses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def create
if @fixed_expense.save
@totals = FixedExpense.total_costs
@fixed_expenses = FixedExpense.get_ordered
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
format.html { redirect_to root_path, notice: "Fixed expense was successfully created." }
format.turbo_stream
else
Expand All @@ -41,6 +43,8 @@ def update
respond_to do |format|
if @fixed_expense.update_from_dashboard(params: params[:fixed_expense])
@totals = FixedExpense.total_costs
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
format.html { redirect_to root_path, notice: "Fixed expense was successfully updated." }
format.turbo_stream
else
Expand All @@ -55,6 +59,8 @@ def destroy
@fixed_expense.destroy
@totals = FixedExpense.total_costs
@fixed_expenses = FixedExpense.get_ordered
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
respond_to do |format|
format.html { redirect_to fixed_expenses_path, notice: "Fixed expense was successfully destroyed." }
format.turbo_stream
Expand Down
1 change: 1 addition & 0 deletions app/controllers/incomes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def update
if @income.update_from_dashboard(params: params)
@salary_taxed = Income.tax_on_income(income_type: "Salary")
@hourly_taxed = Income.tax_on_income(income_type: "Hourly")
@totals = FixedExpense.total_costs
format.html { redirect_to root_path, notice: "Income was successfully updated." }
format.turbo_stream
else
Expand Down
8 changes: 8 additions & 0 deletions app/views/fixed_expenses/create.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@
<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { totals: @totals } %>
<% end %>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %>
<% end %>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget", locals: {totals: @totals, income: @hourly_taxed} %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/fixed_expenses/destroy.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { totals: @totals } %>
<% end %>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %>
<% end %>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget", locals: {totals: @totals, income: @hourly_taxed} %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/fixed_expenses/update.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
<%= turbo_stream.replace "total_costs" do %>
<%= render partial: "shared/total_costs", locals: { totals: @totals } %>
<% end %>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %>
<% end %>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget", locals: {totals: @totals, income: @hourly_taxed} %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/incomes/update.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@

<%= turbo_stream.replace "taxed_incomes" do %>
<%= render partial: "shared/taxed_incomes", locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed } %>
<% end %>

<%= turbo_stream.replace "salary_budget" do %>
<%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %>
<% end %>

<%= turbo_stream.replace "hourly_budget" do %>
<%= render partial: "budget/hourly_budget", locals: {totals: @totals, income: @hourly_taxed} %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/shared/_total.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="px-5">
<span><strong><%= humanized_money_with_symbol(total) %></strong></span>
<span><%= humanized_money_with_symbol(total) %></span>
</div>
12 changes: 9 additions & 3 deletions app/views/shared/_total_costs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
</div>

<div>
<%= render partial: "shared/total", locals: { total: @totals.total_annual_cost } %>
<strong>
<%= render partial: "shared/total", locals: { total: @totals.total_annual_cost } %>
</strong>
</div>

<div>
<%= render partial: "shared/total", locals: { total: @totals.total_monthly_cost } %>
<strong>
<%= render partial: "shared/total", locals: { total: @totals.total_monthly_cost } %>
</strong>
</div>

<div>
<%= render partial: "shared/total", locals: { total: @totals.total_bi_weekly_cost } %>
<strong>
<%= render partial: "shared/total", locals: { total: @totals.total_bi_weekly_cost } %>
</strong>
</div>
</div>

0 comments on commit ba2e594

Please sign in to comment.