diff --git a/app/helpers/scenarios_helper.rb b/app/helpers/scenarios_helper.rb new file mode 100644 index 0000000..e371015 --- /dev/null +++ b/app/helpers/scenarios_helper.rb @@ -0,0 +1,7 @@ +module ScenariosHelper + CHART_COLORS = ["#E07B39", "#D9632B", "#C99A2E", "#B8842B", "#E0954F", "#C76A28"].freeze + + def allocation_chart_color(index) + CHART_COLORS[index % CHART_COLORS.length] + end +end diff --git a/app/models/allocation/one_time.rb b/app/models/allocation/one_time.rb index e78a180..2df868a 100644 --- a/app/models/allocation/one_time.rb +++ b/app/models/allocation/one_time.rb @@ -12,6 +12,13 @@ def one_time? true end + def share_percentage + total = scenario.one_time_giving_amount + return 0 if total.zero? + + (amount.to_i / total.to_f * 100).round + end + private def within_total_giving_amount diff --git a/app/models/allocation/ongoing.rb b/app/models/allocation/ongoing.rb index a7e3b13..6f83ce1 100644 --- a/app/models/allocation/ongoing.rb +++ b/app/models/allocation/ongoing.rb @@ -1,4 +1,6 @@ class Allocation::Ongoing < Allocation + PERPETUITY_PAYOUT_RATE = 0.05 + validates :percentage, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 100 } @@ -7,6 +9,10 @@ def dollar_amount (percentage.to_i / 100.0 * scenario.ongoing_giving_amount).round end + def perpetuity_annual_amount + (dollar_amount * PERPETUITY_PAYOUT_RATE).round + end + def ongoing? true end diff --git a/app/views/scenarios/show.html.erb b/app/views/scenarios/show.html.erb index a36636c..4c19d39 100644 --- a/app/views/scenarios/show.html.erb +++ b/app/views/scenarios/show.html.erb @@ -37,49 +37,97 @@ + <% ongoing_total = @scenario.ongoing_percentage_total %> + <% ongoing_amount = @scenario.ongoing_giving_amount %> + <% one_time_amount = @scenario.one_time_giving_amount %> + <% total_amount = @scenario.total_giving_amount.to_i %>
Set your total above to see a full breakdown.
+ <% if total_amount.positive? %> ++ On going <%= number_to_currency(ongoing_amount, precision: 0) %> + + One-time <%= number_to_currency(one_time_amount, precision: 0) %> + = Total <%= number_to_currency(total_amount, precision: 0) %> +
+ <% else %> +Set your total above to see a full breakdown.
+ <% end %><%= number_to_currency(@scenario.ongoing_giving_amount, precision: 0) %>
+<%= number_to_currency(ongoing_amount, precision: 0) %>
<% if @scenario.ongoing_allocations.any? %> -+ <%= ongoing_total %>% allocated across <%= pluralize(@scenario.ongoing_allocations.count, "cause") %> +
+ + <% remaining = [100 - ongoing_total, 0].max %> ++ ∞ Est. <%= number_to_currency(allocation.perpetuity_annual_amount, precision: 0) %> /yr in perpetuity +
"> - <%= total %>% of 100%<%= " — add #{100 - total}% more" if total < 100 %><%= " — #{total - 100}% over" if total > 100 %> -
<% else %>No ongoing allocations yet.
<% end %>No one-time allocations yet.
- <% end %> -