|
@ -65,15 +65,14 @@ class User < ActiveRecord::Base |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def total_credits_spent |
|
|
def total_credits_spent |
|
|
log_action = ::ActsAsLoggable::TransactionAction.find_by_action("TIME") |
|
|
log_action_id = 1 #TIME |
|
|
transaction_logs. |
|
|
transaction_logs. |
|
|
where( "log_action_id = ? AND log_action_type = ?", |
|
|
where( "log_action_id = ? AND log_action_type = ?", |
|
|
log_action.id, log_action.class.to_s). |
|
|
log_action_id, ::ActsAsLoggable::TransactionAction.to_s). |
|
|
sum{ |r| r.description.to_i }.round(2) |
|
|
sum{ |r| r.description.to_i }.round(2) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def total_earned_credits |
|
|
def total_earned_credits |
|
|
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") |
|
|
|
|
|
volunteer_id = 1 |
|
|
volunteer_id = 1 |
|
|
staff_id = 3 |
|
|
staff_id = 3 |
|
|
|
|
|
|
|
@ -98,20 +97,20 @@ class User < ActiveRecord::Base |
|
|
ORDER BY logs.created_at, conversion.created_at DESC", |
|
|
ORDER BY logs.created_at, conversion.created_at DESC", |
|
|
{id: self.id, |
|
|
{id: self.id, |
|
|
credit_actions: [volunteer_id, staff_id], |
|
|
credit_actions: [volunteer_id, staff_id], |
|
|
log_action_type: log_action.class.to_s}]). |
|
|
log_action_type: ::ActsAsLoggable::UserAction.to_s}]). |
|
|
sum{ |l| ((l.end_date - l.start_date)/3600) * l.conversion.to_i}.round(2) |
|
|
sum{ |l| ((l.end_date - l.start_date)/3600) * l.conversion.to_i}.round(2) |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
def total_hours |
|
|
def total_hours |
|
|
log_action = ::ActsAsLoggable::UserAction.find_by_action("CHECKIN") |
|
|
log_action_id = 4 #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) |
|
|
logs.where("log_action_id != ? AND log_action_type = ?", log_action_id, ::ActsAsLoggable::UserAction.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") |
|
|
log_action_id = 4 #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) |
|
|
logs.where("log_action_id != ? AND log_action_type = ?", log_action.id, log_action.class.to_s) |
|
|
logs.where("log_action_id != ? AND log_action_type = ?", log_action_id, ::ActsAsLoggable::UserAction.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 } |
|
|