Fix recurring hire bug.
This commit is contained in:
parent
ce63816765
commit
875c3dc580
|
@ -58,39 +58,60 @@ class PHire
|
|||
end
|
||||
|
||||
def self.recurring_event(start_date,end_date,property_id)
|
||||
@recurring_events = self.where(:property_id => property_id, :recurring_end_date.gte => start_date)
|
||||
@property = Property.find(property_id) rescue nil
|
||||
@recurring = []
|
||||
@recurring_events.each do |re|
|
||||
case re.recurring_interval
|
||||
when "week"
|
||||
@start_date = re.start_time
|
||||
@end_date = re.end_time
|
||||
@i = TimeDifference.between(re.start_time,end_date).in_weeks.to_i
|
||||
(0..@i).each do |i|
|
||||
if i > 0
|
||||
@start_date += 7
|
||||
@end_date += 7
|
||||
if @property != nil
|
||||
unavailable = @property.set_unavailibility && !@property.weekdays.empty? && !@property.start_date.nil? && !@property.end_date.nil?
|
||||
unavailable_start_date = @property.start_date
|
||||
unavailable_end_date = @property.end_date
|
||||
unavailable_start_time = @property.start_time.to_s
|
||||
unavailable_end_time = @property.end_time.to_s
|
||||
unavailable_start_date = DateTime.parse(unavailable_start_date.strftime("%Y-%m-%d " + unavailable_start_time.to_s + unavailable_start_date.zone))
|
||||
unavailable_end_date = DateTime.parse(unavailable_end_date.strftime("%Y-%m-%d " + unavailable_end_time.to_s + unavailable_end_date.zone))
|
||||
unavailable_weekdays = @property.weekdays.collect{|w| w.to_i}
|
||||
@recurring_events = self.where(:property_id => property_id, :recurring_end_date.gte => start_date)
|
||||
@recurring_events.each do |re|
|
||||
case re.recurring_interval
|
||||
when "week"
|
||||
@start_date = re.start_time
|
||||
@end_date = re.end_time
|
||||
@i = TimeDifference.between(re.start_time,end_date).in_weeks.to_i
|
||||
(0..@i).each do |i|
|
||||
if i > 0
|
||||
@start_date += 7
|
||||
@end_date += 7
|
||||
end
|
||||
if unavailable && (unavailable_start_date <= @start_date) && (unavailable_end_date >= @end_date) && !((@start_date.strftime("%w").to_i .. @end_date.strftime("%w").to_i).to_a & unavailable_weekdays).empty?
|
||||
startt = DateTime.parse(@start_date.strftime("%Y-%m-%d " + unavailable_start_time + Time.zone.to_s))
|
||||
endt = DateTime.parse(@end_date.strftime("%Y-%m-%d " + unavailable_end_time + Time.zone.to_s))
|
||||
next if !((startt..endt) & (@start_date..@end_date)).blank?
|
||||
end
|
||||
if @start_date < re.recurring_end_date
|
||||
@recurring << {:id => re.id.to_s, :hiring_person_name => re.hirer_name ,:title=>re.reason_for_hire, :note=>re.reason_for_hire, :start=>@start_date, :end => @end_date, :allDay => false, :recurring => re.recurring, :color => "#FC4040"}
|
||||
end
|
||||
end
|
||||
if @start_date < re.recurring_end_date
|
||||
@recurring << {:id => re.id.to_s, :hiring_person_name => re.hirer_name ,:title=>re.reason_for_hire, :note=>re.reason_for_hire, :start=>@start_date, :end => @end_date, :allDay => false, :recurring => re.recurring, :color => "#FC4040"}
|
||||
when "month"
|
||||
# if !(start_date..end_date).cover?(re.start_time)
|
||||
sd = re.start_time
|
||||
ed = re.end_time
|
||||
@i = TimeDifference.between(re.start_time,end_date).in_months.to_i
|
||||
@start_date = sd
|
||||
# debugger
|
||||
sd = sd + @i.month
|
||||
ed = ed + @i.month
|
||||
if unavailable && !(unavailable_start_date > ed) && !(unavailable_end_date < sd) && !((sd.strftime("%w") .. ed.strftime("%w")).to_a & unavailable_weekdays).empty?
|
||||
startt = DateTime.parse(sd.strftime("%Y-%m-%d " + unavailable_start_time + Time.zone.to_s))
|
||||
endt = DateTime.parse(ed.strftime("%Y-%m-%d " + unavailable_end_time + Time.zone.to_s))
|
||||
next if !((startt..endt) & (sd..ed)).blank?
|
||||
end
|
||||
end
|
||||
when "month"
|
||||
# if !(start_date..end_date).cover?(re.start_time)
|
||||
sd = re.start_time
|
||||
ed = re.end_time
|
||||
@i = TimeDifference.between(re.start_time,end_date).in_months.to_i
|
||||
@start_date = sd
|
||||
# debugger
|
||||
sd = sd >> @i
|
||||
ed = ed >> @i
|
||||
if sd < re.recurring_end_date
|
||||
@recurring << {:id => re.id.to_s, :title=>re.reason_for_hire, :note=>re.reason_for_hire, :start=>sd, :end => ed, :allDay => false, :recurring => re.recurring, :color => "#FC4040"}
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
@recurring
|
||||
if sd < re.recurring_end_date
|
||||
@recurring << {:id => re.id.to_s, :title=>re.reason_for_hire, :note=>re.reason_for_hire, :start=>sd, :end => ed, :allDay => false, :recurring => re.recurring, :color => "#FC4040"}
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
@recurring
|
||||
end
|
||||
|
||||
def time_iterate(&block)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<% OrbitHelper.render_css_in_head(["property_hire_fullcalendar.css","property_hire_calendar.scss"]) %>
|
||||
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
||||
<script type="text/javascript" src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
||||
<script type="text/javascript" src="/assets/property_hire_fullcalendar.min.js"></script>
|
||||
<script type="text/javascript" src="/assets/property_hire_calendar_frontend.js"></script>
|
||||
<%
|
||||
|
|
Loading…
Reference in New Issue