23 lines
1008 B
Ruby
23 lines
1008 B
Ruby
module Admin::PropertyHiresHelper
|
|
|
|
def check_for_availability(stime, etime, pid, interval, recurring_end_date)
|
|
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
|
|
recurring_end_date = DateTime.parse(recurring_end_date + 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, interval, recurring_end_date)
|
|
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 |