Adding payment stats
This commit is contained in:
@@ -13,8 +13,10 @@ def index
|
||||
@num_door_opens = DoorLog.where("key = 'G'").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
|
||||
@num_door_denieds = DoorLog.where("key = 'f'").count
|
||||
@recent_door_denieds = DoorLog.where("key = 'f' AND created_at > ?", DateTime.now - 7.days).count
|
||||
@num_door_denieds = DoorLog.where("key = 'D'").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
|
||||
@recent_macs = Mac.where("since > ?", DateTime.now - 1.day).count
|
||||
|
||||
|
||||
@@ -16,6 +16,28 @@ class PaymentsController < ApplicationController
|
||||
# GET /payments.json
|
||||
def index
|
||||
@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|
|
||||
format.html # index.html.erb
|
||||
|
||||
Reference in New Issue
Block a user