From 60762ee5158ef63d68e0ce2f1ab9dead5824d907 Mon Sep 17 00:00:00 2001 From: Benjamin Randolph <104036158+neb417@users.noreply.github.com> Date: Wed, 15 Nov 2023 08:18:38 -0700 Subject: [PATCH] Add color style forms (#15) * Clean up forms and add attributes to income_tax_calculator.rb * Style dashboard page --- .../stylesheets/application.tailwind.css | 30 +++++- app/poros/income_tax_calculator.rb | 37 ++++++- app/views/components/_income_switch.erb | 2 +- app/views/dashboard/index.html.erb | 99 +++++++++---------- .../fixed_expenses/_fixed_expense.html.erb | 6 +- app/views/incomes/_form.html.erb | 21 ++-- app/views/incomes/_income.html.erb | 4 +- app/views/layouts/application.html.erb | 4 +- app/views/shared/_budget.html.erb | 18 +++- 9 files changed, 136 insertions(+), 85 deletions(-) diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index c07f405..2d19c26 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -4,19 +4,39 @@ @layer components { .btn-primary { - @apply py-2 px-4 bg-blue-200; + @apply rounded-lg px-4 bg-purple-800 inline-block font-medium text-white; + } + + .btn-danger { + @apply rounded-lg px-4 bg-red-600 inline-block font-medium text-white; + } + + h1 { + @apply text-3xl font-bold tracking-tight text-gray-800 + } + + h3 { + @apply text-2xl font-bold tracking-tight text-gray-800; } .flex-container { - display: inline-flex; - flex-direction: row; - flex-wrap: wrap; - justify-content: space-evenly; + display: inline-flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: space-evenly; } .flex-item { order: 5; } + + .primary-card { + background-color: white; + box-shadow: #2E2F30; + margin-bottom: 0.5rem; + border-radius: 0.5rem; + color: #2b2b2b; + } } diff --git a/app/poros/income_tax_calculator.rb b/app/poros/income_tax_calculator.rb index 6cdac50..0a1f112 100644 --- a/app/poros/income_tax_calculator.rb +++ b/app/poros/income_tax_calculator.rb @@ -5,7 +5,12 @@ class IncomeTaxCalculator :net_after_fed_tax, :state_tax, :total_net_income, - :bi_weekly_net_income + :bi_weekly_net_income, + :daily_income, + :monthly_income, + :weekly_income, + :quarterly_income, + :biannual_income def initialize(income:) @income = income @@ -15,6 +20,11 @@ def initialize(income:) @state_tax = nil @total_net_income = nil @bi_weekly_net_income = nil + @daily_income = nil + @weekly_income = nil + @monthly_income = nil + @quarterly_income = nil + @biannual_income = nil end def calculate_taxes @@ -23,6 +33,11 @@ def calculate_taxes @state_tax = calculate_state_tax @total_net_income = calculate_total_net_income @bi_weekly_net_income = calculate_bi_weekly_income + @daily_income = calculate_daily_income + @weekly_income = calculate_weekly_income + @monthly_income = calculate_monthly_income + @quarterly_income = calculate_quarterly_income + @biannual_income = calculate_biannual_income end private @@ -49,4 +64,24 @@ def calculate_total_net_income def calculate_bi_weekly_income Money.new(@total_net_income.fractional / 26) end + + def calculate_daily_income + Money.new(@total_net_income.fractional / 365) + end + + def calculate_weekly_income + Money.new(@total_net_income.fractional / 52) + end + + def calculate_monthly_income + Money.new(@total_net_income.fractional / 12) + end + + def calculate_quarterly_income + Money.new(@total_net_income.fractional / 4) + end + + def calculate_biannual_income + Money.new(@total_net_income.fractional / 2) + end end diff --git a/app/views/components/_income_switch.erb b/app/views/components/_income_switch.erb index 91f51b7..fe8154a 100644 --- a/app/views/components/_income_switch.erb +++ b/app/views/components/_income_switch.erb @@ -1,7 +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 167456a..b5014d5 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -1,66 +1,57 @@
-
-
-

Budget Calculator

+
+
+

Budget Calculator

-
+
-
- -
-
-
-

Final Budget

-
- <%= render partial: "components/income_switch" %> -
-
-
- <%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %> -
+
+
+

Final Budget

+
+ <%= render partial: "components/income_switch" %>
-
- -
-
- <%= turbo_frame_tag "income_header_frame" do %> -
-

Income

- <%= link_to "New Income", new_income_path, data: { turbo_frame: :incomes } %> -
- <% end %> - -
- <%= turbo_frame_tag :incomes do %> - <%= render "incomes/index" %> - <% end %> -
- -
- <%= turbo_frame_tag "taxed_incomes" do %> - <%= render partial: "shared/taxed_incomes", locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed} %> - <% end %> -
+
+ <%= render partial: "budget/salary_budget", locals: {totals: @totals, income: @salary_taxed} %>
- -
-
- <%= turbo_frame_tag "fixed_expense_header_frame" do %> -
-

Fixed Expenses

- <%= link_to "New Fixed Expense", new_fixed_expense_path, data: { turbo_frame: :fixed_expenses } %> -
+
+ +
+
+ <%= turbo_frame_tag "income_header_frame" do %> +

Income

+ <%= link_to "New Income", new_income_path, data: { turbo_frame: :incomes }, class: "btn btn-primary" %> + <% end %> + +
+ <%= turbo_frame_tag :incomes do %> + <%= render "incomes/index" %> <% end %> +
- <%= turbo_frame_tag :fixed_expenses do %> - <%= render "fixed_expenses/index" %> - <% end %> - - <%= turbo_frame_tag "total_costs" do %> - <%= render partial: "shared/total_costs", locals: { totals: @totals } %> +
+ <%= turbo_frame_tag "taxed_incomes" do %> + <%= render partial: "shared/taxed_incomes", locals: { salary_taxed: @salary_taxed, hourly_taxed: @hourly_taxed} %> <% end %>
-
+ + +
+
+ <%= turbo_frame_tag "fixed_expense_header_frame" do %> +

Fixed Expenses

+ <%= link_to "New Fixed Expense", new_fixed_expense_path, data: { turbo_frame: :fixed_expenses }, class: "btn btn-primary" %> + <% end %> + + <%= turbo_frame_tag :fixed_expenses do %> + <%= render "fixed_expenses/index" %> + <% end %> + + <%= turbo_frame_tag "total_costs" do %> + <%= render partial: "shared/total_costs", locals: { totals: @totals } %> + <% end %> +
+
diff --git a/app/views/fixed_expenses/_fixed_expense.html.erb b/app/views/fixed_expenses/_fixed_expense.html.erb index 7e59067..0a523c5 100644 --- a/app/views/fixed_expenses/_fixed_expense.html.erb +++ b/app/views/fixed_expenses/_fixed_expense.html.erb @@ -1,10 +1,10 @@ <%= turbo_frame_tag dom_id(fixed_expense) do %> -
+
<% attributes = [fixed_expense.expense_name, humanized_money_with_symbol(fixed_expense.annual_cost), humanized_money_with_symbol(fixed_expense.monthly_cost), humanized_money_with_symbol(fixed_expense.bi_weekly_cost)] %> <% attributes.each do |attribute| %>
<%= attribute %>
<% end %> -
<%= link_to "Edit", edit_fixed_expense_path(fixed_expense), class:"rounded-lg px-2 bg-gray-100 inline-block font-medium" %>
-
<%= button_to "Delete", fixed_expense_path(fixed_expense), method: :delete, class:"rounded-lg px-2 bg-gray-100 inline-block font-medium" %>
+
<%= link_to "Edit", edit_fixed_expense_path(fixed_expense), class:"btn btn-primary" %>
+
<%= button_to "Delete", fixed_expense_path(fixed_expense), method: :delete, class:"btn btn-danger" %>
<% end %> diff --git a/app/views/incomes/_form.html.erb b/app/views/incomes/_form.html.erb index 7735812..9c53ff6 100644 --- a/app/views/incomes/_form.html.erb +++ b/app/views/incomes/_form.html.erb @@ -14,35 +14,30 @@
<%= form.label :income_type %>
<% if @income.income_type.nil? %> - <%= form.select :income_type, [["Salary", "SA"], ["Hourly", "HR"]], {}, {class: "block shadow rounded-md border border-gray-200 px-3 py-2 mt-2 w-full"} %> + <%= form.select :income_type, [["Salary", "SA"], ["Hourly", "HR"]], {}, {class: "block shadow rounded-md border border-gray-200 px-3 py-2 w-full"} %> <% elsif @income.is_salary? %> - <%= form.select :income_type, [["Salary", "SA"]], {}, {class: "block shadow rounded-md border border-gray-200 px-3 py-2 mt-2 w-full"} %> + <%= form.select :income_type, [["Salary", "SA"]], {}, {class: "block shadow rounded-md border border-gray-200 px-3 py-2 w-full"} %> <% else %> - <%= form.select :income_type, [["Hourly", "HR"]], {}, {class: "block shadow rounded-md border border-gray-200 px-3 py-2 mt-2 w-full"} %> + <%= form.select :income_type, [["Hourly", "HR"]], {}, {class: "block shadow rounded-md border border-gray-200 px-3 py-2 w-full"} %> <% end %>
<%= form.label :rate %> - <%= form.number_field :rate, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> + <%= form.number_field :rate, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 w-full" %>
<%= form.label :hours %> - <%= form.number_field :hours, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> -
- -
- <%= form.label :weekly_income %> - <%= form.number_field :weekly_income, readonly: true, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> + <%= form.number_field :hours, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 w-full" %>
-
- <%= form.submit class: "rounded-lg py-1 px-4 bg-gray-100 inline-block font-medium" %> +
+ <%= form.submit class: "rounded-lg px-2 bg-gray-100 inline-block font-medium" %>
- <%= link_to "Cancel", root_path, class: "rounded-lg py-1 px-4 bg-gray-100 inline-block font-medium" %> + <%= link_to "Cancel", root_path, class: "rounded-lg px-2 bg-gray-100 inline-block font-medium" %>
diff --git a/app/views/incomes/_income.html.erb b/app/views/incomes/_income.html.erb index d2e8745..27392c3 100644 --- a/app/views/incomes/_income.html.erb +++ b/app/views/incomes/_income.html.erb @@ -1,9 +1,9 @@ <%= turbo_frame_tag dom_id(income) do %> -
+
<% attributes = [income.income_type, humanized_money_with_symbol(income.rate), income.hours, humanized_money_with_symbol(income.weekly_income)] %> <% attributes.each do |attribute| %>
<%= attribute %>
<% end %> -
<%= link_to "Edit", edit_income_path(income), class:"rounded-lg px-2 bg-gray-100 inline-block font-medium" %>
+
<%= link_to "Edit", edit_income_path(income), class:"btn btn-primary" %>
<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 8cb25db..5823923 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,8 +11,8 @@ <%= javascript_importmap_tags %> - -
+ +
<%= yield %>
diff --git a/app/views/shared/_budget.html.erb b/app/views/shared/_budget.html.erb index 41f6b0b..9cc30a7 100644 --- a/app/views/shared/_budget.html.erb +++ b/app/views/shared/_budget.html.erb @@ -4,7 +4,7 @@
0
0
- <%= humanized_money_with_symbol((income.total_net_income.fractional / 100) / 365 - totals.total_annual_cost / 365) %> + <%= humanized_money_with_symbol((income.daily_income.fractional / 100) - totals.total_annual_cost / 365) %>
@@ -14,7 +14,7 @@
0
0
- <%= humanized_money_with_symbol((income.bi_weekly_net_income.fractional / 100) / 2 - totals.total_bi_weekly_cost / 2) %> + <%= humanized_money_with_symbol((income.weekly_income.fractional / 100) - totals.total_bi_weekly_cost / 2) %>
@@ -34,7 +34,7 @@
0
0
- <%= humanized_money_with_symbol((income.total_net_income.fractional / 100) / 12 - totals.total_monthly_cost) %> + <%= humanized_money_with_symbol((income.monthly_income.fractional / 100) - totals.total_monthly_cost) %>
@@ -44,7 +44,17 @@
0
0
- <%= humanized_money_with_symbol((income.total_net_income.fractional / 100.0) / 4 - totals.total_annual_cost / 4) %> + <%= humanized_money_with_symbol((income.quarterly_income.fractional / 100.0) - totals.total_annual_cost / 4) %> +
+ + +
+
Biannual
+ <%= render partial: "shared/total", locals: { total: totals.total_annual_cost / 4 } %> +
0
+
0
+
+ <%= humanized_money_with_symbol((income.biannual_income.fractional / 100.0) - totals.total_annual_cost / 4) %>