fix error
This commit is contained in:
parent
bb3d9ffeb9
commit
ec3e4463ca
|
@ -83,45 +83,35 @@ class Property
|
|||
end
|
||||
|
||||
def is_already_hired?(stime, etime, interval, recurring_end_date)
|
||||
bookings = self.p_hires.where(:end_time.gte => stime, :recurring => false)
|
||||
bookings = self.p_hires.where(:start_time.lte => stime,:end_time.gte => stime,:recurring => false)
|
||||
.or(:start_time.gte => stime,:end_time.lte => etime,:recurring => false)
|
||||
.or(:start_time.lte => etime,:end_time.gte => etime,:recurring => false)
|
||||
available = true
|
||||
bookings.each do |booking|
|
||||
common_time = (booking.start_time..booking.end_time) & (stime..etime)
|
||||
if !common_time.nil?
|
||||
if bookings.count != 0
|
||||
available = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if available
|
||||
case interval
|
||||
when "week"
|
||||
stepu = 1.week
|
||||
when "month"
|
||||
stepu = 1.month
|
||||
else
|
||||
stepu = 0
|
||||
end
|
||||
bookings = self.p_hires.where(:recurring_end_date.gte => stime, :recurring => true)
|
||||
bookings.each do |booking|
|
||||
booking.time_iterate do |st,et|
|
||||
tst = stime
|
||||
tet = etime
|
||||
if stepu != 0
|
||||
begin
|
||||
common_time = (tst..tet) & (st..et)
|
||||
available = false if !common_time.nil?
|
||||
tet += stepu
|
||||
break if !available
|
||||
break if tst > st
|
||||
end while (tst += stepu) <= recurring_end_date
|
||||
else
|
||||
common_time = (tst..tet) & (st..et)
|
||||
available = false if !common_time.nil?
|
||||
break if !available
|
||||
interval = booking.recurring_interval
|
||||
if interval == 'month'
|
||||
sdata = stime.day*10000 + stime.hour*100 + stime.minute
|
||||
edata = etime.day*10000 + etime.hour*100 + etime.minute
|
||||
elsif interval == 'week'
|
||||
sdata = stime.wday*10000 + stime.hour*100 + stime.minute
|
||||
edata = etime.wday*10000 + etime.hour*100 + etime.minute
|
||||
end
|
||||
break if !available
|
||||
if interval == 'month'
|
||||
b_sdata = booking.start_time.day*10000 + booking.start_time.hour*100 + booking.start_time.minute
|
||||
b_edata = booking.end_time.day*10000 + booking.end_time.hour*100 + booking.end_time.minute
|
||||
elsif interval == 'week'
|
||||
b_sdata = booking.start_time.wday*10000 + booking.start_time.hour*100 + booking.start_time.minute
|
||||
b_edata = booking.end_time.wday*10000 + booking.end_time.hour*100 + booking.end_time.minute
|
||||
end
|
||||
break if !available
|
||||
if (b_sdata <= sdata && b_edata >= sdata) || (b_sdata >= sdata && b_edata <= edata) || (b_sdata <= edata && b_edata >= edata)
|
||||
available = false
|
||||
end
|
||||
break if available == false
|
||||
end
|
||||
end
|
||||
return available
|
||||
|
|
Loading…
Reference in New Issue