From bebdd5e30d7c3be39b4cf844cb5522bc5fa8cdd8 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Thu, 23 Feb 2023 21:46:05 -0500 Subject: [PATCH] Hack together a quick dashboard Also fix bug in member calc --- app/controllers/dashboard_controller.rb | 7 +++ app/models/member.rb | 6 +-- app/views/dashboard/show.html.erb | 70 +++++++++++++++++++++++++ config/routes.rb | 3 +- 4 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 app/controllers/dashboard_controller.rb create mode 100644 app/views/dashboard/show.html.erb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 0000000..40ce240 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,7 @@ +class DashboardController < ApplicationController + def show + @incomes = Income.includes(:member).all + @expenses = Expense.all + @members = Member.all + end +end diff --git a/app/models/member.rb b/app/models/member.rb index cfa4796..4e713a3 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -10,14 +10,14 @@ class Member < ApplicationRecord end def others_included_income - Income.where(included: true) - included_income + Income.where(included: true).sum(&:amount) - included_income end def burden_percent - (Income.total - others_included_income) / Income.total + ((Income.total - others_included_income) / Income.total).round(2) end def burden_amount - burden_percent * Expense.total + burden_percent * Expense.all.map(&:monthly).sum.round(2) end end diff --git a/app/views/dashboard/show.html.erb b/app/views/dashboard/show.html.erb new file mode 100644 index 0000000..7edbc72 --- /dev/null +++ b/app/views/dashboard/show.html.erb @@ -0,0 +1,70 @@ +
+
+ + + + + + + + + + <% @members.each do |member| %> + + + + + + <% end %> + +
MemberBurden PercentBurden Amount
<%= member.name %><%= member.burden_percent * 100 %>%<%= number_to_currency(member.burden_amount) %>
+ + + + + + + + + + + + <% @incomes.each do |income| %> + + + + + + + <% end %> + +
MemberForAmountIncluded
<%= income.member.name %><%= income.description %><%= number_to_currency(income.amount) %><%= income.included %>
+
+ +
+ + + + + + + + + + + + + <% @expenses.each do |expense| %> + + + + + + + + + <% end %> + +
BillPaymentPeriodMontlyAutopaidEstimated
<%= expense.description %><%= number_to_currency(expense.payment) %><%= expense.period %><%= number_to_currency(expense.monthly) %><%= expense.autopaid %><%= expense.estimated %>
+
+
diff --git a/config/routes.rb b/config/routes.rb index 1b25320..7d04545 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,9 +1,10 @@ Rails.application.routes.draw do + resource :dashboard, only: :show resources :incomes resources :members resources :expenses # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") - # root "articles#index" + root "dashboard#show" end