Browse Source

Bug in user_stats queries

eperez-timeinput
Jason Denney 12 years ago
parent
commit
db1732f7bf
  1. 6
      app/models/user.rb

6
app/models/user.rb

@ -40,13 +40,15 @@ class User < ActiveRecord::Base
### TODO methods below probably belong somewhere else ### TODO methods below probably belong somewhere else
def total_hours def total_hours
ActsAsLoggable::Log.where( :loggable_type => self.class.to_s, :loggable_id => self.id).sum { |l| (l.end_date - l.start_date)/3600 }.round(2) log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN")
logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s).sum { |l| (l.end_date - l.start_date)/3600 }.round(2)
end end
def current_month_hours def current_month_hours
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN")
#TODO need to prevent users from saving logs across months, force to create a new log if crossing month #TODO need to prevent users from saving logs across months, force to create a new log if crossing month
current_month_range = (Time.now.beginning_of_month..Time.now.end_of_month) current_month_range = (Time.now.beginning_of_month..Time.now.end_of_month)
ActsAsLoggable::Log.where( :loggable_type => self.class.to_s, :loggable_id => self.id) logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s)
.where( :start_date => current_month_range) .where( :start_date => current_month_range)
.where( :end_date => current_month_range) .where( :end_date => current_month_range)
.sum { |l| (l.end_date - l.start_date)/3600 } .sum { |l| (l.end_date - l.start_date)/3600 }

Loading…
Cancel
Save