property_hire/app/helpers/admin/property_hires_helper.rb

23 lines
1016 B
Ruby
Raw Normal View History

2017-01-20 09:02:50 +00:00
module Admin::PropertyHiresHelper
def check_for_availability(stime, etime, pid, interval=nil, recurring_end_date=nil)
2017-01-20 09:02:50 +00:00
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
2018-01-24 08:29:28 +00:00
recurring_end_date = DateTime.parse(recurring_end_date + Time.zone.to_s) rescue nil
2017-01-20 09:02:50 +00:00
data = {}
return {"success" => false, "msg" => "Starting time cannot be greater than ending time."} if stime > etime
if property.is_available_for_hire?(stime, etime)
2018-01-24 08:29:28 +00:00
if property.is_already_hired?(stime, etime, interval, recurring_end_date)
2017-01-20 09:02:50 +00:00
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