fix error

This commit is contained in:
chiu 2020-05-19 23:07:06 +08:00
parent ec3e4463ca
commit 304dffbe9f
1 changed files with 25 additions and 12 deletions

View File

@ -92,25 +92,38 @@ class Property
end end
if available if available
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| case interval
interval = booking.recurring_interval when 'week'
if interval == 'month' d_step = 1.week
sdata = stime.day*10000 + stime.hour*100 + stime.minute when 'day'
edata = etime.day*10000 + etime.hour*100 + etime.minute d_step = 1.day
elsif interval == 'week' else
sdata = stime.wday*10000 + stime.hour*100 + stime.minute d_step = 0
edata = etime.wday*10000 + etime.hour*100 + etime.minute
end end
if interval == 'month' bookings.each do |booking|
b_interval = booking.recurring_interval
if b_interval == 'month'
b_sdata = booking.start_time.day*10000 + booking.start_time.hour*100 + booking.start_time.minute 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 b_edata = booking.end_time.day*10000 + booking.end_time.hour*100 + booking.end_time.minute
elsif interval == 'week' elsif b_interval == 'week'
b_sdata = booking.start_time.wday*10000 + booking.start_time.hour*100 + booking.start_time.minute 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 b_edata = booking.end_time.wday*10000 + booking.end_time.hour*100 + booking.end_time.minute
end end
while True:
if b_interval == 'month'
sdata = stime.day*10000 + stime.hour*100 + stime.minute
edata = etime.day*10000 + etime.hour*100 + etime.minute
elsif b_interval == 'week'
sdata = stime.wday*10000 + stime.hour*100 + stime.minute
edata = etime.wday*10000 + etime.hour*100 + etime.minute
end
if (b_sdata <= sdata && b_edata >= sdata) || (b_sdata >= sdata && b_edata <= edata) || (b_sdata <= edata && b_edata >= edata) if (b_sdata <= sdata && b_edata >= sdata) || (b_sdata >= sdata && b_edata <= edata) || (b_sdata <= edata && b_edata >= edata)
available = false available = false
end end
stime = stime + d_step
etime = etime + d_step
break if recurring_end_date.nil? || recurring_end_date < stime
end
break if available == false break if available == false
end end
end end