Adding payment stats

This commit is contained in:
Will Bradley 2013-09-28 01:30:52 -07:00
parent 4631489eba
commit d1985dae12
4 changed files with 37 additions and 2 deletions

View File

@ -13,8 +13,10 @@ def index
@num_door_opens = DoorLog.where("key = 'G'").count @num_door_opens = DoorLog.where("key = 'G'").count
@today_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 1.day).count @today_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 1.day).count
@recent_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 7.days).count @recent_door_opens = DoorLog.where("key = 'G' AND created_at > ?", DateTime.now - 7.days).count
@num_door_denieds = DoorLog.where("key = 'f'").count @num_door_denieds = DoorLog.where("key = 'D'").count
@recent_door_denieds = DoorLog.where("key = 'f' AND created_at > ?", DateTime.now - 7.days).count @recent_door_denieds = DoorLog.where("key = 'D' AND created_at > ?", DateTime.now - 7.days).count
@num_logins = User.sum('sign_in_count')
@recent_logins = User.where('current_sign_in_at > ?',Date.today - 7.days).count
@num_macs = Mac.count @num_macs = Mac.count
@recent_macs = Mac.where("since > ?", DateTime.now - 1.day).count @recent_macs = Mac.where("since > ?", DateTime.now - 1.day).count

View File

@ -16,6 +16,28 @@ class PaymentsController < ApplicationController
# GET /payments.json # GET /payments.json
def index def index
@payments = @payments.order("date DESC") @payments = @payments.order("date DESC")
payment_months = @payments.group_by{ |p| p.date.beginning_of_month }
@payments_by_month = []
payment_months.each do |month|
# Only grab the last year from today
if month.first > (Date.today - 1.year) && month.first < Date.today
# Calculate sum of amounts for each month and store at end of month array
@payments_by_month << {:month => month.first, :sum => month.last.sum{|p|
if p.amount
p.amount.to_i
else
if p.user
Rails.logger.info p.user.member_level
p.user.member_level.to_i
else
Rails.logger.info p.inspect
Rails.logger.info p.user.inspect
0
end
end
}}
end
end
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb

View File

@ -35,6 +35,8 @@
<dd><%= @num_door_opens %> (<%= @today_door_opens %> today, <%= @recent_door_opens %> in the last 7 days)</dd> <dd><%= @num_door_opens %> (<%= @today_door_opens %> today, <%= @recent_door_opens %> in the last 7 days)</dd>
<dt># of Door Accesses Denied:</dt> <dt># of Door Accesses Denied:</dt>
<dd><%= @num_door_denieds %> (<%= @recent_door_denieds %> in the last 7 days)</dd> <dd><%= @num_door_denieds %> (<%= @recent_door_denieds %> in the last 7 days)</dd>
<dt># of Logins:</dt>
<dd><%= @num_logins %> (<%= @recent_logins %> users today)</dd>
<dt># of Computers in this DB:</dt> <dt># of Computers in this DB:</dt>
<dd><%= @num_macs %> (<%= @recent_macs %> seen today)</dd> <dd><%= @num_macs %> (<%= @recent_macs %> seen today)</dd>
</dl> </dl>

View File

@ -7,6 +7,15 @@
<%= link_to 'IPN', ipns_path %> <%= link_to 'IPN', ipns_path %>
</p> </p>
<p>
<h3>Payments by Month</h3>
<dl>
<% @payments_by_month.each do |month| %>
<dt><%= month[:month] %></dt>
<dd><%= month[:sum] %></dd>
<% end %>
</dl>
<table> <table>
<tr> <tr>
<th>Payee</th> <th>Payee</th>