Created
October 30, 2010 00:38
-
-
Save bikashp/654726 to your computer and use it in GitHub Desktop.
This file contains 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
## Employee.rb | |
def self.upcoming_events | |
events = Employee.find(:all, :conditions => ["dob is not null"]).sort_by(&:next_birthday).first(10).map{|e|[e, e.dob, "birthday"] } | |
events += Employment.find(:all, :conditions => ["joined_date is not null"]).sort_by(&:next_probation_expiration).first(10).map{|e| [e.employee, e.joined_date+90.days, "probation"] } | |
events += PerformanceReview.find(:all, :conditions => ["rev_to is not null"]).sort_by(&:next_review).first(10).map{|p|[p.employee,p.rev_to+6.months, "review"] } | |
# employee with no performance_reviews | |
emp_ids = Employee.all.map(&:id) - PerformanceReview.all.map(&:employee_id) | |
@new_employments = [] | |
emp_ids.each do |id| | |
@new_employments << Employee.find(id).employment | |
end | |
events += @new_employments.compact.sort_by(&:next_first_review).first(10).map{|e|[e.employee, e.joined_date, "review"] } | |
events.sort!{|x,y| | |
if y[1].strftime('%m') == x[1].strftime('%m') | |
x[1].strftime('%d') <=> y[1].strftime('%d') | |
else | |
y[1].to_datetime.to_i <=> x[1].to_datetime.to_i | |
end | |
} | |
events | |
end | |
private | |
def next_birthday | |
year = Date.today.year | |
mmdd = self.dob.strftime('%m%d') | |
year += 1 if mmdd < Date.today.strftime('%m%d') | |
mmdd = '0301' if mmdd == '0229' && !Date.parse("#{year}0101").leap? | |
return Date.parse("#{year}#{mmdd}") | |
end | |
## employment.rb | |
def next_probation_expiration | |
year = Date.today.year | |
mmdd = (self.joined_date+90.days).strftime('%m%d') | |
year += 1 if mmdd < Date.today.strftime('%m%d') | |
mmdd = '0301' if mmdd == '0229' && !Date.parse("#{year}0101").leap? | |
return Date.parse("#{year}#{mmdd}") | |
end | |
def next_first_review | |
year = Date.today.year | |
mmdd = (self.joined_date+6.months).strftime('%m%d') | |
year += 1 if mmdd < Date.today.strftime('%m%d') | |
mmdd = '0301' if mmdd == '0229' && !Date.parse("#{year}0101").leap? | |
return Date.parse("#{year}#{mmdd}") | |
end | |
## performance.rb | |
def next_review | |
year = Date.today.year | |
mmdd = (self.rev_to+6.months).strftime('%m%d') | |
year += 1 if mmdd < Date.today.strftime('%m%d') | |
mmdd = '0301' if mmdd == '0229' && !Date.parse("#{year}0101").leap? | |
return Date.parse("#{year}#{mmdd}") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment