Created
February 24, 2012 09:53
-
-
Save iMagesh/1899858 to your computer and use it in GitHub Desktop.
Reminder email for timesheet defaulters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| task :reminder_mail => [:environment] do | |
| @users = User.active | |
| @holidays = Holiday.all | |
| @holiday_dates = [] | |
| @dates_to_check = [] | |
| @holidays.each {|h| @holiday_dates << h.holiday.to_s} | |
| (Date.new(Time.now.year, Time.now.month, 1)..Date.yesterday).each { |date| @dates_to_check << date.to_s} | |
| @users.each do |user| | |
| missed_hours = [] | |
| @dates_to_check.each do |date| | |
| puts date.to_date.strftime("%A") | |
| @todays_entry = Timeentry.find(:all, :conditions => ["user_id=? && task_date=?",user.id, date]) | |
| @total_hrs = 0 | |
| @todays_entry.each {|entry| @total_hrs = @total_hrs + entry.hours_taken} | |
| if (@todays_entry.empty? || @total_hrs < 8) && !@holiday_dates.include?(date) && (date.to_date.strftime("%A") != "Saturday") && (date.to_date.strftime("%A") != "Sunday") | |
| missed_hours << {:date => date, :total_hrs => @total_hrs} | |
| end | |
| end | |
| if !missed_hours.empty? | |
| UserNotifier.deliver_timesheet_reminder(user, missed_hours) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment