module Admin::PropertyHiresHelper def check_for_availability(stime, etime, pid) 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 etime = DateTime.parse(etime + Time.zone.to_s) rescue nil data = {} return {"success" => false, "msg" => "Starting time cannot be greater than ending time."} if stime > etime if property.is_available_for_hire?(stime, etime) if property.is_already_hired?(stime, etime) data = {"success" => true} else data = {"success" => false, "msg" => "Property is already hired during this time."} end else data = {"success" => false, "msg" => "Property is unavailable during this time."} end return data end end