module Admin::PropertyHiresHelper
data = File.open(File.join(File.dirname(__FILE__), '../../../config', 'list.yml')).read
$property_list = YAML::load(ERB.new(data).result(binding)).symbolize_keys
include OrbitBackendHelper
def check_for_availability(stime, etime, pid, interval=nil, recurring_end_date=nil, time_setting_id=nil)
property = Property.find(pid)
values_not_ok = {"success" => false, "msg" => I18n.t("property_hire.values_are_not_ok",:default=>"Values are not ok.")}
return values_not_ok if property.nil? || stime.blank? || etime.blank?
timezone = (params[:timezone] rescue nil)
timezone = timezone ? timezone : Time.zone.to_s
stime = DateTime.parse(stime + timezone) rescue nil
etime = DateTime.parse(etime + timezone) rescue nil
return values_not_ok if stime.nil? || etime.nil?
if !recurring_end_date.blank?
recurring_end_date = DateTime.parse(recurring_end_date + timezone) rescue nil
begin
interval_time = 1.send(interval)
tmp_date = recurring_end_date - interval_time
if tmp_date < etime
I18n.with_locale(params[:locale]) do
interval_str= I18n.t("property_hire.1_#{interval}","1 #{interval}")
default_msg = "Recurring end date must exceed hire end time than #{interval_str}!"
msg = I18n.t("property_hire.recurring_end_date_must_exceed_time",{:time=>interval_str,:default=>default_msg})
return {"success" => false, "msg" => msg}
end
end
rescue
end
else
recurring_end_date = nil
end
data = {}
if stime > etime
I18n.with_locale(params[:locale]) do
return {"success" => false, "msg" => I18n.t("property_hire.starting_time_cannot_be_greater_than_ending_time")}
end
end
mp = OrbitHelper.current_user.member_profile rescue nil
available_flag = property.is_available_for_hire?(stime, etime, interval, recurring_end_date, time_setting_id, mp)
if available_flag == 1
if property.not_yet_hired?(stime, etime, interval, recurring_end_date,params[:phire_id], time_setting_id)
data = {"success" => true}
else
I18n.with_locale(params[:locale]) do
data = {"success" => false, "msg" => I18n.t("property_hire.property_is_already_hired_during_this_time")}
end
end
else
I18n.with_locale(params[:locale]) do
msg = I18n.t("property_hire.property_is_unavailable_during_this_time")
if available_flag == 2 ## need hire after
if recurring_end_date.present?
stime = [stime,recurring_end_date].max
end
can_hire_date = stime - (property.can_hire_before_months).month
msg += ("
" + I18n.t("property_hire.please_hire_after_date",{:date=>"{#{can_hire_date.new_offset(0).to_json.gsub('"','')}}"}))
elsif available_flag == 3 ## need hire before
default_msg = "This property must be reserved #{property.need_hire_before} #{property.need_hire_before_unit}s in advance."
msg += I18n.t("property_hire.unavailable_hint3",{:month=>property.need_hire_before,:unit=>I18n.t("property_hire._#{property.need_hire_before_unit}",:default=>property.need_hire_before_unit),:default=>default_msg})
elsif available_flag == 0
msg += ("
" + property.render_unavailable_message)
end
data = {"success" => false, "msg" => msg}
end
end
return data
end
def render_custom_text_field(f,field_name,type)
text = "