2017-01-20 09:02:50 +00:00
|
|
|
class PropertyHiresController < ApplicationController
|
|
|
|
include Admin::PropertyHiresHelper
|
2022-10-22 08:05:20 +00:00
|
|
|
FrontendMethods = ["hire", "view_calendar", "hire_success"]
|
2017-01-20 09:02:50 +00:00
|
|
|
def index
|
2024-09-04 13:03:02 +00:00
|
|
|
properties = Property.can_display.filter_by_categories.sort_order
|
2023-05-01 15:35:38 +00:00
|
|
|
url = "/#{I18n.locale}#{OrbitHelper.page.get_url}"
|
|
|
|
data = index_data(properties, url)
|
2024-10-23 07:33:50 +00:00
|
|
|
filterprops = data.dup
|
|
|
|
filterprops.insert(0,{
|
|
|
|
"title" => t("property_hire.all_properties"),
|
|
|
|
"id" => "all&page_id=" + OrbitHelper.page.id.to_s
|
|
|
|
})
|
2023-05-01 15:35:38 +00:00
|
|
|
headers = [
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.title")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => ""
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.location")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.actions")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
{
|
|
|
|
"properties" => data,
|
2024-10-23 07:33:50 +00:00
|
|
|
"filterprops" => filterprops,
|
2023-05-01 15:35:38 +00:00
|
|
|
"headers" => headers,
|
2024-07-11 07:42:16 +00:00
|
|
|
"extras" => {
|
2024-10-23 07:33:50 +00:00
|
|
|
"first_property_id" => filterprops.first["id"],
|
|
|
|
"today" => t("property_hire.today"),
|
|
|
|
"day" => t("property_hire.day"),
|
|
|
|
"week" => t("property_hire.week"),
|
|
|
|
"month" => t("property_hire.month"),
|
|
|
|
"language" => OrbitHelper.get_site_locale
|
2024-07-11 07:42:16 +00:00
|
|
|
},
|
|
|
|
"manage_booking_btn" => (OrbitHelper.current_user.nil? ? false : true),
|
|
|
|
"manage_booking" => t("property_hire.manage_booking"),
|
|
|
|
"manage_booking_url" => "/" + OrbitHelper.get_site_locale.to_s + "/admin/property_hires/my_bookings",
|
2023-05-01 15:35:38 +00:00
|
|
|
"total_pages" => (properties.total_pages rescue 1)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_data(properties, url)
|
2024-10-23 07:33:50 +00:00
|
|
|
is_user_manager = check_if_user_is_manager?
|
2017-01-20 09:02:50 +00:00
|
|
|
data = properties.collect do |property|
|
2024-07-11 07:42:16 +00:00
|
|
|
actions = []
|
|
|
|
url_to_show = "#{url}/#{property.to_param}?method=hire"
|
2023-10-18 13:56:19 +00:00
|
|
|
hire_url = nil
|
2024-09-04 13:03:02 +00:00
|
|
|
if (property.can_be_hired_frontend && property.can_reserve) || is_user_manager
|
2024-07-11 07:42:16 +00:00
|
|
|
hire_url = url_to_show
|
2017-01-20 09:02:50 +00:00
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.hire"),
|
|
|
|
"btn-class" => "btn-primary",
|
2021-09-06 16:45:14 +00:00
|
|
|
"link" => hire_url
|
2017-01-20 09:02:50 +00:00
|
|
|
}
|
2023-08-26 03:16:56 +00:00
|
|
|
end
|
2024-09-04 13:03:02 +00:00
|
|
|
if (!property.disable_view_calendar_page && property.can_be_show_frontend && property.can_reserve) || is_user_manager
|
2023-08-26 03:16:56 +00:00
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.view_calendar"),
|
|
|
|
"btn-class" => "btn-info",
|
2024-07-11 07:42:16 +00:00
|
|
|
"link" => url_to_show
|
2023-08-26 03:16:56 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
if property.disable_content_page
|
|
|
|
if hire_url
|
2021-09-06 16:45:14 +00:00
|
|
|
url_to_show = hire_url
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"title" => property.title,
|
2024-07-11 07:42:16 +00:00
|
|
|
"id" => property.id.to_s,
|
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),
|
2021-09-06 16:45:14 +00:00
|
|
|
"url_to_show" => url_to_show,
|
2017-01-20 09:02:50 +00:00
|
|
|
"location" => property.get_location_name,
|
|
|
|
"actions" => actions
|
|
|
|
}
|
|
|
|
end
|
2023-05-01 15:35:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def widget
|
2024-07-11 07:42:16 +00:00
|
|
|
properties = Property.filter_by_widget_categories.sort_order.can_display
|
2023-05-01 15:35:38 +00:00
|
|
|
url = OrbitHelper.get_current_widget.get_read_more_page_url
|
|
|
|
data = index_data(properties, url)
|
2017-01-20 09:02:50 +00:00
|
|
|
headers = [
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.title")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.location")
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"column" => t("property_hire.actions")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
{
|
|
|
|
"properties" => data,
|
|
|
|
"headers" => headers,
|
2023-05-01 15:35:38 +00:00
|
|
|
"total_pages" => (properties.total_pages rescue 1)
|
2017-01-20 09:02:50 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
2024-07-11 07:42:16 +00:00
|
|
|
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
|
2023-10-18 14:01:09 +00:00
|
|
|
if property.owners.blank?
|
2017-01-20 09:02:50 +00:00
|
|
|
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
|
|
|
|
}
|
2024-07-11 07:42:16 +00:00
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
actions = []
|
2021-10-25 10:29:03 +00:00
|
|
|
url_to_show = OrbitHelper.url_to_show(property.to_param)
|
2023-08-26 03:16:56 +00:00
|
|
|
if property.can_be_hired_frontend
|
2017-01-20 09:02:50 +00:00
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.hire"),
|
|
|
|
"btn-class" => "btn-primary",
|
2021-10-25 10:29:03 +00:00
|
|
|
"link" => url_to_show + "?method=hire"
|
2017-01-20 09:02:50 +00:00
|
|
|
}
|
2023-08-26 03:16:56 +00:00
|
|
|
end
|
2023-10-18 13:56:19 +00:00
|
|
|
if !property.disable_view_calendar_page && property.can_be_show_frontend
|
2023-08-26 03:16:56 +00:00
|
|
|
actions << {
|
|
|
|
"text" => t("property_hire.view_calendar"),
|
|
|
|
"btn-class" => "btn-info",
|
|
|
|
"link" => url_to_show + "?method=view_calendar"
|
|
|
|
}
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
{
|
|
|
|
"data" => data,
|
|
|
|
"actions" => actions,
|
|
|
|
"extras" => {
|
|
|
|
"image" => property.image.url,
|
|
|
|
"image-thumb" => property.image.thumb.url,
|
|
|
|
"back_url" => page.url
|
|
|
|
}
|
|
|
|
}
|
2024-07-11 07:42:16 +00:00
|
|
|
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def view_calendar
|
|
|
|
params = OrbitHelper.params
|
|
|
|
property = Property.where(:uid => params[:uid]).first rescue nil
|
2023-10-18 13:56:19 +00:00
|
|
|
if property.disable_view_calendar_page || !property.can_be_show_frontend
|
|
|
|
return nil
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
|
|
return {} if property.nil?
|
|
|
|
{
|
|
|
|
"property" => property,
|
|
|
|
"url" => page.url,
|
|
|
|
"current_user" => OrbitHelper.current_user
|
|
|
|
}
|
|
|
|
end
|
2021-10-22 14:09:10 +00:00
|
|
|
def hire_success
|
|
|
|
params = OrbitHelper.params
|
|
|
|
@property = Property.where(:uid => params[:uid]).first rescue nil
|
|
|
|
page = OrbitHelper.page rescue Page.where(:page_id => params[:page_id]).first
|
2021-10-25 10:36:12 +00:00
|
|
|
back_button_text = I18n.t("property_hire.go_to_infos_page")
|
|
|
|
back_url = (page.url + (params[:slug].present? ? "/#{params[:slug]}" : "") rescue "#")
|
|
|
|
if @property.disable_content_page
|
|
|
|
back_url += "?method=hire" if params[:slug].present?
|
|
|
|
back_button_text = I18n.t("property_hire.back_to_hire_page")
|
|
|
|
end
|
|
|
|
{"back_url"=>back_url,"back_button_text"=>back_button_text}
|
2021-10-22 14:09:10 +00:00
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
def make_booking
|
|
|
|
booking_p = booking_params
|
2021-09-06 16:45:14 +00:00
|
|
|
time_setting_id = booking_p[:time]
|
|
|
|
start_time = booking_p[:start_time]
|
|
|
|
end_time = booking_p[:end_time]
|
|
|
|
time_setting = nil
|
2021-09-08 02:10:44 +00:00
|
|
|
is_admin_page = (params[:url] == "admin")
|
2021-09-06 16:45:14 +00:00
|
|
|
if time_setting_id.present?
|
|
|
|
start_time = booking_p[:date]
|
|
|
|
end_time = start_time
|
|
|
|
time_setting = PropertyDaySetting.find(time_setting_id)
|
2021-09-07 05:07:09 +00:00
|
|
|
if booking_p[:recurring_end_date].present?
|
2021-09-08 02:10:44 +00:00
|
|
|
booking_p[:recurring_end_date] = DateTime.parse(booking_p[:recurring_end_date].split(" ")[0] + ' ' + time_setting.end_time + Time.zone.to_s)
|
2021-09-07 05:07:09 +00:00
|
|
|
end
|
2021-09-08 02:10:44 +00:00
|
|
|
booking_p[:start_time] = booking_p[:date] + " " + time_setting.start_time
|
|
|
|
booking_p[:end_time] = booking_p[:date] + " " + time_setting.end_time
|
|
|
|
booking_p[:property_day_setting_id] = booking_p[:time]
|
|
|
|
booking_p.delete(:time)
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
property = Property.find(booking_p[:property_id]) rescue nil
|
2021-09-08 02:10:44 +00:00
|
|
|
begin
|
|
|
|
index_page = is_admin_page ? "/#{I18n.locale}/admin/property_hires/#{property.to_param}" : "/#{I18n.locale}#{params[:url]}/#{property.to_param}"
|
|
|
|
rescue
|
|
|
|
index_page = is_admin_page ? "/#{I18n.locale}/admin/property_hires" : "/#{I18n.locale}#{params[:url]}"
|
|
|
|
end
|
|
|
|
hire_page = is_admin_page ? request.referer : "#{index_page}?method=hire"
|
2024-03-14 12:10:33 +00:00
|
|
|
need_validate = (PropertyHireSetting.first.allow_no_logins_user rescue false) && current_user.nil?
|
2021-09-08 02:10:44 +00:00
|
|
|
session.delete(:hire_data)
|
|
|
|
if need_validate
|
|
|
|
unless gotcha_valid?
|
|
|
|
session[:hire_data] = booking_p
|
|
|
|
session["hire-save-msg"] = I18n.t("property_hire.recaptcha.errors.verification_failed")
|
|
|
|
if property.nil?
|
|
|
|
redirect_to index_page and return
|
|
|
|
else
|
|
|
|
redirect_to hire_page and return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-08-04 08:00:20 +00:00
|
|
|
phire_id = params[:phire_id] || params[:p_hire][:id]
|
2021-09-08 02:10:44 +00:00
|
|
|
if params[:url] == "admin"
|
2022-08-04 08:00:20 +00:00
|
|
|
phire_id = booking_p[:id]
|
2021-09-08 02:10:44 +00:00
|
|
|
end
|
|
|
|
data = check_for_availability(start_time,end_time,booking_p[:property_id], booking_p[:recurring_interval], booking_p[:recurring_end_date], time_setting_id)
|
2022-06-20 02:01:36 +00:00
|
|
|
if data["success"] == true
|
|
|
|
error_messages = property.check_require_fields(booking_p)
|
|
|
|
if error_messages.present?
|
|
|
|
data["msg"] = error_messages
|
|
|
|
data["success"] = false
|
|
|
|
end
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
if data["success"] == true
|
2021-09-08 02:10:44 +00:00
|
|
|
hire = nil
|
2022-08-04 08:00:20 +00:00
|
|
|
if phire_id
|
|
|
|
hire = PHire.find(phire_id) rescue nil
|
|
|
|
if hire.nil?
|
|
|
|
hire = PHire.new(booking_p)
|
|
|
|
else
|
|
|
|
hire.update_attributes(booking_p)
|
|
|
|
end
|
2021-09-08 02:10:44 +00:00
|
|
|
else
|
|
|
|
hire = PHire.new(booking_p)
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
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
|
2021-09-08 02:10:44 +00:00
|
|
|
if !property.nil? && !is_admin_page
|
2024-08-24 03:00:08 +00:00
|
|
|
email = property.get_owner_emails
|
2020-03-23 17:26:52 +00:00
|
|
|
email << hire.hiring_person_email
|
2021-09-19 07:56:01 +00:00
|
|
|
email = email.select{|e| e.present?}
|
|
|
|
Admin::PropertyHiresHelper::HireMethod.send_mail('p_hire',email,property.id,nil,hire.id,(current_user.id rescue nil))
|
2020-03-23 17:26:52 +00:00
|
|
|
end
|
2021-10-22 14:09:10 +00:00
|
|
|
redirect_to index_page + "?method=hire_success"
|
2017-01-20 09:02:50 +00:00
|
|
|
else
|
2022-06-20 02:01:36 +00:00
|
|
|
session[:hire_data] = booking_p
|
2017-01-20 09:02:50 +00:00
|
|
|
session["hire-save-msg"] = data["msg"]
|
|
|
|
if property.nil?
|
2021-09-08 02:10:44 +00:00
|
|
|
redirect_to index_page
|
2017-01-20 09:02:50 +00:00
|
|
|
else
|
2021-09-08 02:10:44 +00:00
|
|
|
redirect_to hire_page
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def hire
|
|
|
|
params = OrbitHelper.params
|
|
|
|
property = Property.where(:uid => params[:uid]).first rescue nil
|
2023-10-18 13:56:19 +00:00
|
|
|
if !property.can_be_hired_frontend
|
|
|
|
return nil
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
page = Page.where(:page_id => params[:page_id]).first
|
|
|
|
return {} if property.nil?
|
2021-09-08 02:10:44 +00:00
|
|
|
hire = nil
|
|
|
|
session = OrbitHelper.request.session rescue {}
|
|
|
|
recover = false
|
|
|
|
if (session[:hire_data] rescue false)
|
|
|
|
begin
|
2022-08-04 08:35:33 +00:00
|
|
|
if session[:hire_data][:property_id] != property.id.to_s
|
|
|
|
session.delete(:hire_data)
|
|
|
|
hire = PHire.new(:id=>nil)
|
|
|
|
else
|
|
|
|
hire = PHire.new({:id=>nil}.merge(session[:hire_data]))
|
|
|
|
recover = true
|
|
|
|
end
|
2021-09-08 02:10:44 +00:00
|
|
|
rescue => e
|
|
|
|
puts e.to_s
|
|
|
|
hire = PHire.new(:id=>nil)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
hire = PHire.new(:id=>nil)
|
|
|
|
end
|
2024-03-14 12:10:33 +00:00
|
|
|
allow_no_logins_user = PropertyHireSetting.first.allow_no_logins_user
|
2021-09-08 02:10:44 +00:00
|
|
|
all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.id.to_s,s.title]}]}.to_h
|
2024-10-23 07:33:50 +00:00
|
|
|
is_user_manager = check_if_user_is_manager?
|
2017-01-20 09:02:50 +00:00
|
|
|
{
|
|
|
|
"hire" => hire,
|
|
|
|
"property" => property,
|
|
|
|
"page" => page.url,
|
2024-09-04 13:03:02 +00:00
|
|
|
"is_user_manager" => is_user_manager,
|
2021-09-08 02:10:44 +00:00
|
|
|
"current_user" => OrbitHelper.current_user,
|
|
|
|
"allow_no_logins_user" => allow_no_logins_user,
|
|
|
|
"carousel_display_style" => "width: #{property.carousel_image_width};",
|
|
|
|
"all_day_settings" => all_day_settings,
|
2024-10-23 07:33:50 +00:00
|
|
|
"recover" => recover,
|
|
|
|
"language" => OrbitHelper.get_site_locale
|
2017-01-20 09:02:50 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_availability
|
2021-09-06 16:45:14 +00:00
|
|
|
time_setting_id = params[:time_setting_id]
|
|
|
|
data = check_for_availability params[:stime], params[:etime], params[:property_id], params[:interval], params[:recurring_end_date], time_setting_id
|
2017-01-20 09:02:50 +00:00
|
|
|
render :json => data.to_json
|
|
|
|
end
|
|
|
|
|
2024-10-23 07:33:50 +00:00
|
|
|
|
|
|
|
|
2017-01-20 09:02:50 +00:00
|
|
|
def get_bookings
|
|
|
|
events =[]
|
2022-11-24 11:59:47 +00:00
|
|
|
allevents = []
|
2024-10-23 07:33:50 +00:00
|
|
|
if params[:property_id] == "all"
|
|
|
|
categories = Page.find(params["page_id"]).categories rescue []
|
|
|
|
properties = Property.where(:category_id.in => categories)
|
|
|
|
properties.each do |property|
|
|
|
|
allevents += get_each_booking(property)
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
2024-10-23 07:33:50 +00:00
|
|
|
else
|
|
|
|
property = Property.find(params[:property_id]) rescue nil
|
|
|
|
allevents = get_each_booking(property)
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|
2024-10-23 07:33:50 +00:00
|
|
|
|
2017-01-20 09:02:50 +00:00
|
|
|
respond_to do |format|
|
2021-07-05 10:05:49 +00:00
|
|
|
format.html { render json: allevents.to_json }# 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
|
2024-07-11 07:42:16 +00:00
|
|
|
|
|
|
|
def special_unavailable_dates_labels(property)
|
|
|
|
events = []
|
|
|
|
@special_unavailable_dates.each_with_index do |dt, idx|
|
|
|
|
events << {:title=>property.special_unavailable_dates_title[idx][OrbitHelper.get_site_locale], :start=>dt.to_s, :end => (dt + 1.day).to_s, :allDay => true, :color => "#d33535", :classNames=>["special_unavailable_btn"], :note => ""}
|
|
|
|
end
|
|
|
|
events
|
|
|
|
end
|
|
|
|
|
2021-09-06 16:45:14 +00:00
|
|
|
def reserve_calendar_event(date,title,allow_times)
|
2021-09-08 02:10:44 +00:00
|
|
|
available = true
|
2024-07-11 07:42:16 +00:00
|
|
|
if @special_unavailable_dates.include?(date)
|
|
|
|
available = false
|
|
|
|
end
|
2024-10-23 07:33:50 +00:00
|
|
|
if DateTime.now >= (@property.start_date || DateTime.now - 1.day) && DateTime.now <= (@property.end_date || DateTime.now + 1.month)
|
2024-09-04 13:03:02 +00:00
|
|
|
if @property.hours_restriction > 0 && @is_user_manager === false
|
|
|
|
check = false
|
|
|
|
sd = nil
|
|
|
|
ed = nil
|
|
|
|
case @property.hours_restriction_duration
|
|
|
|
when "week"
|
|
|
|
weeknumber = date.strftime("%U").to_i
|
|
|
|
if @weeknumber != weeknumber
|
|
|
|
sd = date - date.wday
|
|
|
|
ed = date + (6 - date.wday)
|
|
|
|
@weeknumber = weeknumber
|
|
|
|
check = true
|
|
|
|
end
|
|
|
|
when "month"
|
|
|
|
if @monthnumber != date.month
|
|
|
|
sd = Date.new(date.year, date.month, 1)
|
|
|
|
ed = sd.next_month.prev_day
|
|
|
|
@monthnumber = date.month
|
|
|
|
check = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if check === true
|
|
|
|
@user_total_hired_hours = @property.get_user_total_user_hired_hours(OrbitHelper.current_user.id.to_s, sd, ed)
|
|
|
|
end
|
|
|
|
if @user_total_hired_hours >= @property.hours_restriction
|
|
|
|
available = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if available
|
2024-10-23 07:33:50 +00:00
|
|
|
if DateTime.now >= (@property.start_date || DateTime.now - 1.day) && DateTime.now <= (@property.end_date || DateTime.now + 1.month)
|
2024-09-04 13:03:02 +00:00
|
|
|
available = date > (DateTime.now + (@property.need_hire_before).send(@property.need_hire_before_unit))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-09 02:14:57 +00:00
|
|
|
if @check_setting && allow_times.select{|a| !a[5]}.count != 0
|
2024-10-02 01:38:50 +00:00
|
|
|
available = !need_check_unavailable
|
2024-09-04 13:03:02 +00:00
|
|
|
if available
|
|
|
|
available = @property.weekdays.include?(date.wday.to_s) ? false : true
|
|
|
|
end
|
|
|
|
|
2021-09-08 02:10:44 +00:00
|
|
|
unless available
|
|
|
|
allow_times = allow_times.select do |allow_time|
|
2021-09-09 02:14:57 +00:00
|
|
|
if allow_time[5]
|
|
|
|
true
|
|
|
|
elsif (allow_time[0] > @check_end_time || allow_time[1] < @check_start_time)
|
2021-09-08 02:10:44 +00:00
|
|
|
true
|
2024-09-04 13:03:02 +00:00
|
|
|
elsif
|
2021-09-08 02:10:44 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
available = (allow_times.count != 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if available
|
|
|
|
{:title=>title, :start=>date.to_s, :end => (date + 1.day).to_s, :allDay => true, :color => "#3788d8",:allow_times=>allow_times,:classNames=>["reserve_btn"]}
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
end
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
2021-09-08 02:10:44 +00:00
|
|
|
def generate_all_reserve_buttons(startt,endt,all_day_settings,check_setting=false)
|
|
|
|
@check_setting = check_setting
|
2021-09-06 16:45:14 +00:00
|
|
|
@display_title = I18n.t("property_hire.reserve")
|
|
|
|
@allevents = []
|
2021-09-08 02:10:44 +00:00
|
|
|
startt = startt.in_time_zone(Time.zone)
|
|
|
|
endt = endt.in_time_zone(Time.zone)
|
2021-09-06 16:45:14 +00:00
|
|
|
start_wday = startt.wday
|
|
|
|
start_date = startt.to_date
|
2024-07-11 07:42:16 +00:00
|
|
|
@start_date = start_date
|
2021-09-06 16:45:14 +00:00
|
|
|
end_date = endt.to_date
|
|
|
|
@end_date = end_date
|
|
|
|
@first_check_time = startt.strftime("%H:%M")
|
|
|
|
@all_day_settings = all_day_settings
|
|
|
|
@startt = startt
|
|
|
|
@endt = endt
|
2024-09-04 13:03:02 +00:00
|
|
|
@weeknumber = 0
|
|
|
|
@monthnumber = 0
|
2024-10-23 07:33:50 +00:00
|
|
|
@is_user_manager = check_if_user_is_manager?
|
2021-09-07 05:07:09 +00:00
|
|
|
def generate_events(start_wday,end_wday,type=0,start_validate=false)
|
2021-09-06 16:45:14 +00:00
|
|
|
if type == 0
|
2021-09-07 05:07:09 +00:00
|
|
|
(start_wday..end_wday).each_with_index do |wday,i|
|
2021-09-06 16:45:14 +00:00
|
|
|
wday_str = wday.to_s
|
2021-09-07 05:07:09 +00:00
|
|
|
is_start_day = (i == 0 && start_validate)
|
2021-09-06 16:45:14 +00:00
|
|
|
if @all_day_settings.has_key?(wday_str)
|
|
|
|
check_time = nil
|
|
|
|
check_time = @first_check_time if is_start_day
|
2021-09-08 02:10:44 +00:00
|
|
|
i = @need_check_events.index{|e| e[0] > @start_date}
|
|
|
|
if i.nil?
|
|
|
|
if @need_check_events.length != 0 && @need_check_events[-1][0] <= @start_date
|
|
|
|
i = @need_check_events.length - 1
|
|
|
|
else
|
2021-09-07 05:07:09 +00:00
|
|
|
i = -1
|
|
|
|
end
|
2021-09-08 02:10:44 +00:00
|
|
|
elsif i != -1
|
|
|
|
i -= 1
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
|
|
|
check_events = []
|
|
|
|
if i != -1
|
|
|
|
check_events = @need_check_events[0..i]
|
|
|
|
end
|
|
|
|
@need_check_events = @need_check_events[(i+1)..-1]
|
|
|
|
settings = @all_day_settings[wday_str]
|
2024-10-23 07:33:50 +00:00
|
|
|
|
2021-09-06 16:45:14 +00:00
|
|
|
if check_events.count != 0
|
|
|
|
settings = settings.select do |s|
|
|
|
|
flag = true
|
|
|
|
if check_time
|
|
|
|
if check_time > s[1]
|
|
|
|
flag = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if flag
|
2021-09-07 05:07:09 +00:00
|
|
|
if s[4] == 0 #reservation_limit == 0 => no limit
|
2021-09-06 16:45:14 +00:00
|
|
|
true
|
|
|
|
else
|
2021-09-07 05:07:09 +00:00
|
|
|
check_events.select{|e| e[1] == s[2] }.count < s[4]
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if settings.count != 0
|
|
|
|
@allevents << reserve_calendar_event(@start_date,@display_title,settings)
|
|
|
|
end
|
2024-10-23 07:33:50 +00:00
|
|
|
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
|
|
|
@start_date += 1.day
|
|
|
|
if @start_date > @end_date
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@all_day_settings.each do |wday_str,settings|
|
2024-07-11 07:42:16 +00:00
|
|
|
tmp_date = @start_date + wday_str.to_i.send("day")
|
2021-09-08 02:10:44 +00:00
|
|
|
i = @need_check_events.index{|e| e[0] > tmp_date}
|
|
|
|
if i.nil?
|
|
|
|
if @need_check_events.length != 0 && @need_check_events[-1][0] <= tmp_date
|
|
|
|
i = @need_check_events.length - 1
|
|
|
|
else
|
2021-09-07 05:07:09 +00:00
|
|
|
i = -1
|
|
|
|
end
|
2021-09-08 02:10:44 +00:00
|
|
|
elsif i != -1
|
|
|
|
i -= 1
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
|
|
|
check_events = []
|
|
|
|
if i != -1
|
|
|
|
check_events = @need_check_events[0..i]
|
|
|
|
end
|
|
|
|
@need_check_events = @need_check_events[(i+1)..-1]
|
|
|
|
if check_events.count != 0
|
|
|
|
settings = settings.select do |s|
|
2021-09-07 05:07:09 +00:00
|
|
|
if s[4] == 0 #reservation_limit == 0 => no limit
|
|
|
|
true
|
|
|
|
else
|
|
|
|
check_events.select{|e| e[1] == s[2] }.count < s[4]
|
|
|
|
end
|
2021-09-06 16:45:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if settings.count != 0
|
|
|
|
@allevents << reserve_calendar_event(tmp_date,@display_title,settings)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@start_date += 7.day
|
|
|
|
end
|
|
|
|
end
|
|
|
|
all_days = (end_date-start_date).to_i
|
|
|
|
end_wday = 6
|
|
|
|
end_date_wday = end_date.wday
|
|
|
|
only_first_week = false
|
|
|
|
if (start_wday + all_days <= 6)
|
|
|
|
end_wday = end_date_wday
|
|
|
|
only_first_week = true
|
|
|
|
end
|
2021-09-07 05:07:09 +00:00
|
|
|
generate_events(start_wday,end_wday,0,true)
|
2021-09-06 16:45:14 +00:00
|
|
|
unless only_first_week
|
|
|
|
all_days = all_days - (end_wday - start_wday)
|
|
|
|
while all_days > 6 do
|
2021-09-07 05:07:09 +00:00
|
|
|
generate_events(0,6,1)
|
2021-09-06 16:45:14 +00:00
|
|
|
all_days -= 7
|
|
|
|
end
|
|
|
|
generate_events(0,all_days)
|
|
|
|
end
|
|
|
|
@allevents
|
|
|
|
end
|
2017-01-20 09:02:50 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def booking_params
|
2024-07-11 07:42:16 +00:00
|
|
|
p_hire_params = params.require(:p_hire).permit!
|
2021-09-06 16:45:14 +00:00
|
|
|
property = Property.find(params[:p_hire][:property_id]) rescue Property.last
|
2020-07-22 10:13:50 +00:00
|
|
|
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?
|
2021-09-06 16:45:14 +00:00
|
|
|
value_text = p_hire_params["notes_selector"][index.to_s].to_a.map{|i| values[i.to_i]}.join(",") rescue ""
|
2020-07-22 10:13:50 +00:00
|
|
|
value_text = I18n.t("property_hire.none") if value_text.blank?
|
|
|
|
note_texts += (name + ":"+value_text)
|
2024-07-11 07:42:16 +00:00
|
|
|
note_texts += "<br>".html_safe
|
2020-07-22 10:13:50 +00:00
|
|
|
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
|
|
|
|
|
2024-10-23 07:33:50 +00:00
|
|
|
def get_each_booking(property)
|
|
|
|
events =[]
|
|
|
|
allevents = []
|
|
|
|
@property = property
|
|
|
|
|
|
|
|
unless 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,property.id.to_s,property.set_availability)
|
|
|
|
re = PHire.recurring_event(sdt,edt,property.id.to_s,property.set_availability)
|
|
|
|
events = events.map{|e| e.as_json}
|
|
|
|
allevents = events.inject(re, :<<)
|
|
|
|
allevents = allevents.sort_by{|e| e[:start]}
|
|
|
|
@need_check_events = allevents.map{|e| [e[:date],e[:s_id]]}
|
|
|
|
@special_unavailable_dates = property.special_unavailable_dates.map{|dt| Date.parse(dt)}
|
|
|
|
is_user_manager = check_if_user_is_manager?
|
|
|
|
if property.set_availability && params[:display_hire_event] == "true"
|
|
|
|
check_setting = property.set_unavailibility && (property.property_day_settings.where(:enable=>false).count != 0)
|
|
|
|
@check_start_time = property.start_time.blank? ? "00:00" : property.start_time
|
|
|
|
@check_end_time = property.end_time.blank? ? "24:00" : property.end_time
|
|
|
|
@check_start_date = property.start_date.to_date rescue nil
|
|
|
|
@check_end_date = property.end_date.to_date rescue nil
|
|
|
|
if check_setting
|
|
|
|
if (@check_start_date > edt rescue false) || (@check_end_date < sdt rescue false)
|
|
|
|
check_setting = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.start_time,s.end_time,s.id.to_s,s.title,s.reservation_limit,s.enable]}]}.to_h
|
|
|
|
if all_day_settings.count != 0
|
|
|
|
time_now = Time.zone.now
|
|
|
|
if is_user_manager
|
|
|
|
get_start_time = property.p_open_start_time
|
|
|
|
get_end_time = property.p_open_end_time
|
|
|
|
else
|
|
|
|
get_start_time = [sdt,time_now].max
|
|
|
|
get_end_time = edt
|
|
|
|
end
|
|
|
|
if property.set_unavailibility
|
|
|
|
if property.can_hire_before_months != 0
|
|
|
|
get_end_time = [time_now + (property.can_hire_before_months).send("month"),edt].min
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if property.can_reserve || is_user_manager
|
|
|
|
allevents += generate_all_reserve_buttons(get_start_time,get_end_time,all_day_settings,check_setting)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if @special_unavailable_dates.count > 0
|
|
|
|
allevents += special_unavailable_dates_labels(property)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return allevents
|
|
|
|
end
|
|
|
|
|
2017-01-20 09:02:50 +00:00
|
|
|
end
|