diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb index f51613a..2359a51 100644 --- a/app/helpers/admin/property_hires_helper.rb +++ b/app/helpers/admin/property_hires_helper.rb @@ -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 diff --git a/app/models/property.rb b/app/models/property.rb index 59306d5..dca9ecb 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -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