Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes #104, only send out an email reminder if someone's entered in e…

…stimates for a given week and has NO actuals entered.
  • Loading branch information...
commit c5e27c46fdb06411e2282d9797b97185beb69b96 1 parent cc5dd89
Rob Sterner fermion authored
Showing with 15 additions and 13 deletions.
  1. +15 −13 lib/tasks/scheduler.rake
28 lib/tasks/scheduler.rake
View
@@ -4,22 +4,24 @@ desc "At the beginning of each week, this script will send emails to forgetful p
task :send_reminders => :environment do
if Time.now.to_date.wday == 1 # Only do this on Mondays
year, week = *[:year, :cweek].map {|msg| Date.current.send msg}
+
# Timestamp at begining of past week
- @timestamp = Date.commercial(year, week).to_datetime.to_i * 1000 - 7 * 86400 * 1000
- @users = Assignment.
- joins(:work_weeks).
- select("user_id").
- where("work_weeks.beginning_of_week = ?", @timestamp - 7 * 86400 * 1000).
- where("actual_hours IS NULL OR actual_hours = ?", 0).
- where("estimated_hours IS NOT NULL AND estimated_hours > ?", 0).
- map { |assignment| User.where(:id => assignment.user_id).first }.
- uniq
-
- @users.each do |user|
+ @timestamp = Date.commercial(year, week).to_datetime.to_i * 1000 - 7 * 86400 * 1000
+
+ work_weeks_by_user = WorkWeek.where(beginning_of_week: @timestamp).all.group_by { |ww| ww.user }
+
+ work_weeks_by_user.each do |user, work_weeks|
+ next if user.nil?
+
+ # do they care?
if user.user_preferences.try(:email_reminder)
- user.send_email_reminder
+ # do they need a reminder? work weeks with estimates and NO actuals entered for any assignment
+ # we'll assume that a single work week with actuals is a sign that they've entered their data for the week.
+ has_work_weeks_with_estimates = work_weeks.any? { |ww| (ww.estimated_hours || 0) > 0 }
+ has_no_work_work_weeks_with_actuals = work_weeks.none? { |ww| (ww.actual_hours || 0) > 0 }
+
+ user.send_email_reminder if has_no_work_work_weeks_with_actuals && has_work_weeks_with_estimates
end
end
end
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.