2017-01-20 09:02:50 +00:00
|
|
|
class PropertyHiresController < ApplicationController
|
|
|
|
include Admin::PropertyHiresHelper
|
|
|
|
def index
|
|
|
|
properties = Property.filter_by_categories.filter_by_tags.desc(:created_at)
|
|
|
|
data = properties.collect do |property|
|
|
|
|
actions = []
|
|
|
|
if property.can_be_hired
|
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.hire"),
|
|
|
|
"btn-class" => "btn-primary",
|
|
|
|
"link" => OrbitHelper.url_to_show(property.to_param) + "?method=hire"
|
|
|
|
}
|
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.view_calendar"),
|
|
|
|
"btn-class" => "btn-info",
|
|
|
|
"link" => OrbitHelper.url_to_show(property.to_param) + "?method=view_calendar"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"title" => property.title,
|
2020-07-02 14:56:03 +00:00
|
|
|
"image" => (property.image.url.blank? ? '" style="display: none;' : property.image.url),
|
|
|
|
"image-thumb" => (property.image.thumb.url.blank? ? '" style="display: none;' : property.image.thumb.url),
|
2017-01-20 09:02:50 +00:00
|
|
|
"url_to_show" => OrbitHelper.url_to_show(property.to_param),
|
|
|
|
"location" => property.get_location_name,
|
|
|
|
"actions" => actions
|
|
|
|
}
|
|
|
|
end
|
|
|
|
headers = [
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.title")
|
|
|
|
},
|
|
|
|
{
|
2020-07-02 14:56:03 +00:00
|
|
|
"column" => ""
|
2017-01-20 09:02:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.location")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.actions")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
{
|
|
|
|
"properties" => data,
|
|
|
|
"headers" => headers,
|
|
|
|
"total_pages" => properties.total_pages
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
|
|
|
property = Property.where(:uid => params[:uid]).first rescue nil
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
|
|
return {} if property.nil?
|
|
|
|
data = []
|
|
|
|
|
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.title"),
|
|
|
|
"value" => property.title
|
|
|
|
}
|
|
|
|
if !property.property_usage.blank?
|
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.property_usage"),
|
|
|
|
"value" => property.property_usage
|
|
|
|
}
|
|
|
|
end
|
|
|
|
if !property.note.blank?
|
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.note"),
|
|
|
|
"value" => property.note
|
|
|
|
}
|
|
|
|
end
|
2019-06-13 17:33:44 +00:00
|
|
|
if !property.property_number.blank?
|
2019-06-13 14:03:31 +00:00
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.property_number"),
|
|
|
|
"value" => property.property_number
|
|
|
|
}
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.can_be_hired"),
|
|
|
|
"value" => (property.can_be_hired ? "<span class='label label-success'>Yes</span>" : "<span class='label label-danger'>No</span>")
|
|
|
|
}
|
2019-06-13 17:33:44 +00:00
|
|
|
if !property.purchase_date.to_s.blank?
|
2019-06-13 14:03:31 +00:00
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.purchase_date"),
|
|
|
|
"value" => property.purchase_date.strftime("%Y-%m-%d")
|
|
|
|
}
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
if property.owners.empty?
|
|
|
|
owners = property.other_owner
|
|
|
|
else
|
|
|
|
owners = property.owner_profiles.collect{|mp| mp.name}.join(",")
|
|
|
|
end
|
2019-06-13 17:26:53 +00:00
|
|
|
if !owners.blank?
|
2019-06-13 14:03:31 +00:00
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.owners"),
|
|
|
|
"value" => owners
|
|
|
|
}
|
|
|
|
end
|
2019-06-13 17:26:53 +00:00
|
|
|
if !property.owner_email.blank?
|
2019-06-13 14:03:31 +00:00
|
|
|
data << {
|
2019-06-13 17:26:53 +00:00
|
|
|
"header" => t("property_hire.owner_email"),
|
2019-06-13 14:03:31 +00:00
|
|
|
"value" => property.owner_email
|
|
|
|
}
|
|
|
|
end
|
2019-06-13 17:26:53 +00:00
|
|
|
if !property.owner_phone.blank?
|
2019-06-13 14:03:31 +00:00
|
|
|
data << {
|
2019-06-13 17:26:53 +00:00
|
|
|
"header" => t("property_hire.owner_phone"),
|
2019-06-13 14:03:31 +00:00
|
|
|
"value" => property.owner_phone
|
|
|
|
}
|
|
|
|
end
|
2019-06-13 17:26:53 +00:00
|
|
|
if !property.price.blank?
|
2019-06-13 14:03:31 +00:00
|
|
|
data << {
|
2019-06-13 17:26:53 +00:00
|
|
|
"header" => t("property_hire.price"),
|
2019-06-13 14:03:31 +00:00
|
|
|
"value" => property.price
|
|
|
|
}
|
2019-06-13 17:26:53 +00:00
|
|
|
end
|
|
|
|
if !property.get_location_name.blank?
|
|
|
|
data << {
|
|
|
|
"header" => t("property_hire.location"),
|
|
|
|
"value" => property.get_location_name
|
|
|
|
}
|
2019-06-13 14:03:31 +00:00
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
actions = []
|
|
|
|
if property.can_be_hired
|
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.hire"),
|
|
|
|
"btn-class" => "btn-primary",
|
|
|
|
"link" => OrbitHelper.url_to_show(property.to_param) + "?method=hire"
|
|
|
|
}
|
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.view_calendar"),
|
|
|
|
"btn-class" => "btn-info",
|
|
|
|
"link" => OrbitHelper.url_to_show(property.to_param) + "?method=view_calendar"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
{
|
|
|
|
"data" => data,
|
|
|
|
"actions" => actions,
|
|
|
|
"extras" => {
|
|
|
|
"image" => property.image.url,
|
|
|
|
"image-thumb" => property.image.thumb.url,
|
|
|
|
"back_url" => page.url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def view_calendar
|
|
|
|
params = OrbitHelper.params
|
|
|
|
property = Property.where(:uid => params[:uid]).first rescue nil
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
|
|
return {} if property.nil?
|
|
|
|
{
|
|
|
|
"property" => property,
|
|
|
|
"url" => page.url,
|
|
|
|
"current_user" => OrbitHelper.current_user
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_booking
|
|
|
|
booking_p = booking_params
|
2018-01-24 08:29:28 +00:00
|
|
|
data = check_for_availability(booking_p[:start_time],booking_p[:end_time],booking_p[:property_id], booking_p[:recurring_interval], booking_p[:recurring_end_date])
|
2017-01-20 09:02:50 +00:00
|
|
|
property = Property.find(booking_p[:property_id]) rescue nil
|
|
|
|
if data["success"] == true
|
|
|
|
hire = PHire.new(booking_p)
|
2018-02-05 09:15:50 +00:00
|
|
|
hire.passed = true if PropertyHireSetting.auto_approve_enabled?
|
2017-01-20 09:02:50 +00:00
|
|
|
hire.save
|
2020-03-23 17:26:52 +00:00
|
|
|
if !property.nil?
|
|
|
|
email = Array(MemberProfile.find(property.owners)).collect{|v| v.email} rescue []
|
|
|
|
email = User.all.select{|v| v.is_admin? && v.user_name != 'rulingcom'}.collect{|v| v.member_profile.email} if email.length == 0
|
|
|
|
email << hire.hiring_person_email
|
2020-05-20 08:55:19 +00:00
|
|
|
Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id)
|
2020-03-23 17:26:52 +00:00
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
redirect_to params[:url]
|
|
|
|
else
|
|
|
|
session["hire-save-msg"] = data["msg"]
|
|
|
|
if property.nil?
|
|
|
|
redirect_to "/" + I18n.locale.to_s + params[:url]
|
|
|
|
else
|
|
|
|
redirect_to "/" + I18n.locale.to_s + params[:url] + "/#{property.to_param}?method=hire"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def hire
|
|
|
|
params = OrbitHelper.params
|
|
|
|
property = Property.where(:uid => params[:uid]).first rescue nil
|
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
|
|
return {} if property.nil?
|
|
|
|
hire = PHire.new
|
|
|
|
{
|
|
|
|
"hire" => hire,
|
|
|
|
"property" => property,
|
|
|
|
"page" => page.url,
|
|
|
|
"current_user" => OrbitHelper.current_user
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_availability
|
2018-01-24 08:29:28 +00:00
|
|
|
data = check_for_availability params[:stime], params[:etime], params[:property_id], params[:interval], params[:recurring_end_date]
|
2017-01-20 09:02:50 +00:00
|
|
|
render :json => data.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_bookings
|
|
|
|
events =[]
|
|
|
|
property = Property.find(params[:property_id]) rescue nil
|
|
|
|
if !property.nil?
|
|
|
|
if params[:start].present? && params[:end].present?
|
|
|
|
sdt = Time.at(params[:start].to_i)
|
|
|
|
edt = Time.at(params[:end].to_i)
|
|
|
|
events = PHire.monthly_event(sdt,edt,params[:property_id])
|
2018-09-03 09:51:56 +00:00
|
|
|
re = PHire.recurring_event(sdt,edt,params[:property_id])
|
2018-01-24 08:29:28 +00:00
|
|
|
allevents = events.inject(re, :<<)
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
2018-01-24 08:29:28 +00:00
|
|
|
format.json { render json: allevents.to_json }
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def booking_params
|
2020-07-22 10:13:50 +00:00
|
|
|
p_hire_params = params.require(:p_hire).permit!
|
|
|
|
property = Property.find(params[:property_id]) rescue Property.last
|
|
|
|
if(property.enable_notes_selector rescue false)
|
|
|
|
note_texts = ""
|
|
|
|
property.notes_selector.each do |index,sub_hash|
|
|
|
|
name = sub_hash["name"][I18n.locale.to_s]
|
|
|
|
name = sub_hash["name"].values.select{|v| v.present?}.first.to_s if name.blank?
|
|
|
|
values = sub_hash["value"][I18n.locale.to_s]
|
|
|
|
values = sub_hash["value"].values.select{|v| v.present?}.first.to_s if values.blank?
|
|
|
|
value_text = p_hire_params["notes_selector"][index.to_s].to_a.map{|i| values[i.to_i]}.join(",")
|
|
|
|
value_text = I18n.t("property_hire.none") if value_text.blank?
|
|
|
|
note_texts += (name + ":"+value_text)
|
|
|
|
note_texts += "<br>".html_safe
|
|
|
|
end
|
|
|
|
p_hire_params["note_for_hire"] = note_texts
|
|
|
|
p_hire_params.delete("notes_selector")
|
|
|
|
end
|
|
|
|
return p_hire_params
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|