Hack together a quick dashboard

Also fix bug in member calc
This commit is contained in:
Andrew Tomaka 2023-02-23 21:46:05 -05:00
parent 8a7a0cc720
commit bebdd5e30d
Signed by: atomaka
GPG key ID: 61209BF70A5B18BE
4 changed files with 82 additions and 4 deletions

View file

@ -0,0 +1,7 @@
class DashboardController < ApplicationController
def show
@incomes = Income.includes(:member).all
@expenses = Expense.all
@members = Member.all
end
end

View file

@ -10,14 +10,14 @@ class Member < ApplicationRecord
end end
def others_included_income def others_included_income
Income.where(included: true) - included_income Income.where(included: true).sum(&:amount) - included_income
end end
def burden_percent def burden_percent
(Income.total - others_included_income) / Income.total ((Income.total - others_included_income) / Income.total).round(2)
end end
def burden_amount def burden_amount
burden_percent * Expense.total burden_percent * Expense.all.map(&:monthly).sum.round(2)
end end
end end

View file

@ -0,0 +1,70 @@
<div class="flex flex-wrap">
<div class="m-8">
<table class="min-w-full mb-8">
<thead class="border-b">
<tr>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Member</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Burden Percent</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Burden Amount</th>
</tr>
</thead>
<tbody>
<% @members.each do |member| %>
<tr class="even:bg-gray-50 border-b">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= member.name %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= member.burden_percent * 100 %>%</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= number_to_currency(member.burden_amount) %></td>
</tr>
<% end %>
</tbody>
</table>
<table class="min-w-full">
<thead class="border-b">
<tr>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Member</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">For</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Amount</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Included</th>
</tr>
</thead>
<tbody>
<% @incomes.each do |income| %>
<tr class="even:bg-gray-50 border-b">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= income.member.name %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= income.description %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= number_to_currency(income.amount) %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= income.included %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="m-8">
<table class="min-w-full">
<thead class="border-b">
<tr>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Bill</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Payment</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Period</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Montly</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Autopaid</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">Estimated</th>
</tr>
</thead>
<tbody>
<% @expenses.each do |expense| %>
<tr class="even:bg-gray-50 border-b">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= expense.description %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= number_to_currency(expense.payment) %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= expense.period %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= number_to_currency(expense.monthly) %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= expense.autopaid %></td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap"><%= expense.estimated %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

View file

@ -1,9 +1,10 @@
Rails.application.routes.draw do Rails.application.routes.draw do
resource :dashboard, only: :show
resources :incomes resources :incomes
resources :members resources :members
resources :expenses resources :expenses
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Defines the root path route ("/") # Defines the root path route ("/")
# root "articles#index" root "dashboard#show"
end end