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