From d50d55879c851b5ef3d9093f65f8c6b5b2f08e6a Mon Sep 17 00:00:00 2001 From: Benjamin Randolph <104036158+neb417@users.noreply.github.com> Date: Tue, 21 Nov 2023 16:33:51 -0700 Subject: [PATCH] Refactor budget view into partial (#21) --- app/views/budget/_budget_headings.html.erb | 4 +- app/views/budget/_display_budget.html.erb | 10 ++ app/views/budget/_salary_budget.html.erb | 1 - app/views/shared/_budget.html.erb | 108 ++++++++++++--------- 4 files changed, 74 insertions(+), 49 deletions(-) create mode 100644 app/views/budget/_display_budget.html.erb diff --git a/app/views/budget/_budget_headings.html.erb b/app/views/budget/_budget_headings.html.erb index 36f8b08..2954fb9 100644 --- a/app/views/budget/_budget_headings.html.erb +++ b/app/views/budget/_budget_headings.html.erb @@ -5,11 +5,11 @@
- Investing + Savings
- Savings + Investing
diff --git a/app/views/budget/_display_budget.html.erb b/app/views/budget/_display_budget.html.erb new file mode 100644 index 0000000..2d93c09 --- /dev/null +++ b/app/views/budget/_display_budget.html.erb @@ -0,0 +1,10 @@ +<%= render partial: "shared/total", locals: { total: total_cost } %> +
+ <%= humanized_money_with_symbol(savings_amount) %> +
+
+ <%= humanized_money_with_symbol(investing_amount) %> +
+
+ <%= humanized_money_with_symbol(guilt_free) %> +
\ 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 9be9edc..1517746 100644 --- a/app/views/budget/_salary_budget.html.erb +++ b/app/views/budget/_salary_budget.html.erb @@ -2,7 +2,6 @@
Salary <%= render partial: "budget/budget_headings" %> - <% Rails.logger.debug "*** Salary_budget #{savings_amount.daily_saving}" %> <%= render partial: "shared/budget", locals: { total_annual_cost: total_annual_cost, diff --git a/app/views/shared/_budget.html.erb b/app/views/shared/_budget.html.erb index 9a7a6da..47ae1b3 100644 --- a/app/views/shared/_budget.html.erb +++ b/app/views/shared/_budget.html.erb @@ -1,75 +1,91 @@
Daily
- <%= render partial: "shared/total", locals: { total: total_annual_cost / 365 } %> -
- <%= humanized_money_with_symbol(investing_amount.daily_saving) %> -
-
- <%= humanized_money_with_symbol(savings_amount.daily_saving) %> -
-
- <%= humanized_money_with_symbol((guilt_free.daily_guilt_free) - total_annual_cost / 365) %> -
+ <%= render partial: "budget/display_budget", + locals: { + total_cost: total_annual_cost/365, + savings_amount: savings_amount.daily_saving, + investing_amount: investing_amount.daily_saving, + guilt_free: guilt_free.daily_guilt_free - total_annual_cost/365 + } + %>
Weekly
- <%= render partial: "shared/total", locals: { total: total_annual_cost / 52 } %> -
<%= humanized_money_with_symbol(investing_amount.weekly_saving) %>
-
<%= humanized_money_with_symbol(savings_amount.weekly_saving) %>
-
- <%= humanized_money_with_symbol((guilt_free.weekly_guilt_free) - total_annual_cost / 52) %> -
+ + <%= render partial: "budget/display_budget", + locals: { + total_cost: total_annual_cost/52, + savings_amount: savings_amount.weekly_saving, + investing_amount: investing_amount.weekly_saving, + guilt_free: guilt_free.weekly_guilt_free - total_annual_cost/52 + } + %>
Bi-Weekly
- <%= render partial: "shared/total", locals: { total: total_bi_weekly_cost } %> -
<%= humanized_money_with_symbol(investing_amount.bi_weekly_saving) %>
-
<%= humanized_money_with_symbol(savings_amount.bi_weekly_saving) %>
-
- <%= humanized_money_with_symbol((guilt_free.bi_weekly_guilt_free) - total_bi_weekly_cost) %> -
+ + <%= render partial: "budget/display_budget", + locals: { + total_cost: total_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 + } + %> +
Monthly
- <%= render partial: "shared/total", locals: { total: total_monthly_cost } %> -
<%= humanized_money_with_symbol(investing_amount.monthly_saving) %>
-
<%= humanized_money_with_symbol(savings_amount.monthly_saving) %>
-
- <%= humanized_money_with_symbol((guilt_free.monthly_guilt_free) - total_monthly_cost) %> -
+ + <%= render partial: "budget/display_budget", + locals: { + total_cost: total_monthly_cost, + savings_amount: savings_amount.monthly_saving, + investing_amount: investing_amount.monthly_saving, + guilt_free: guilt_free.monthly_guilt_free - total_monthly_cost + } + %>
Quarterly
- <%= render partial: "shared/total", locals: { total: total_annual_cost / 4 } %> -
<%= humanized_money_with_symbol(investing_amount.quarterly_saving) %>
-
<%= humanized_money_with_symbol(savings_amount.quarterly_saving) %>
-
- <%= humanized_money_with_symbol((guilt_free.quarterly_guilt_free) - total_annual_cost / 4) %> -
+ + <%= render partial: "budget/display_budget", + locals: { + total_cost: total_annual_cost/4, + savings_amount: savings_amount.quarterly_saving, + investing_amount: investing_amount.quarterly_saving, + guilt_free: guilt_free.quarterly_guilt_free - total_annual_cost / 4 + } + %>
Biannual
- <%= render partial: "shared/total", locals: { total: total_annual_cost / 2 } %> -
<%= humanized_money_with_symbol(investing_amount.biannual_saving) %>
-
<%= humanized_money_with_symbol(savings_amount.biannual_saving) %>
-
- <%= humanized_money_with_symbol((guilt_free.biannual_guilt_free) - total_annual_cost / 2) %> -
+ + <%= render partial: "budget/display_budget", + locals: { + total_cost: total_annual_cost/2, + savings_amount: savings_amount.biannual_saving, + investing_amount: investing_amount.biannual_saving, + guilt_free: guilt_free.biannual_guilt_free - total_annual_cost / 2 + } + %>
Annually
- <%= render partial: "shared/total", locals: { total: total_annual_cost } %> -
<%= humanized_money_with_symbol(investing_amount.annual_saving) %>
-
<%= humanized_money_with_symbol(savings_amount.annual_saving) %>
-
- <%= humanized_money_with_symbol(guilt_free.annual_guilt_free - total_annual_cost ) %> -
+ <%= render partial: "budget/display_budget", + locals: { + total_cost: total_annual_cost, + savings_amount: savings_amount.annual_saving, + investing_amount: investing_amount.annual_saving, + guilt_free: guilt_free.annual_guilt_free - total_annual_cost + } + %>