small fix for current property hiring check

This commit is contained in:
Harry Bomrah 2018-01-24 16:51:16 +08:00
parent 77764690af
commit 610f824628
2 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,6 @@
module Admin::PropertyHiresHelper
def check_for_availability(stime, etime, pid, interval, recurring_end_date)
def check_for_availability(stime, etime, pid, interval=nil, recurring_end_date=nil)
property = Property.find(pid)
return {"success" => false, "msg" => "Values are not ok."} if property.nil? || stime.blank? || etime.blank?
stime = DateTime.parse(stime + Time.zone.to_s) rescue nil

View File

@ -97,19 +97,27 @@ class Property
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
begin
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?
tet += stepu
break if !available
break if tst > st
end while (tst += stepu) <= recurring_end_date
end
break if !available
end
break if !available