This commit is contained in:
邱博亞 2024-10-02 09:38:50 +08:00
parent 420ce3b065
commit e190f1e23c
4 changed files with 34 additions and 36 deletions

View File

@ -34,7 +34,7 @@ class PropertyHiresController < ApplicationController
def index_data(properties, url)
ma = ModuleApp.find_by_key("property_hire")
is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
is_user_manager = OrbitHelper.current_user && (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
data = properties.collect do |property|
actions = []
url_to_show = "#{url}/#{property.to_param}?method=hire"
@ -334,7 +334,7 @@ class PropertyHiresController < ApplicationController
allow_no_logins_user = PropertyHireSetting.first.allow_no_logins_user
all_day_settings = property.all_day_settings.map{|d,settings| [d,settings.map{|s| [s.id.to_s,s.title]}]}.to_h
ma = ModuleApp.find_by_key("property_hire")
is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
is_user_manager = OrbitHelper.current_user && (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
{
"hire" => hire,
"property" => property,
@ -370,16 +370,16 @@ class PropertyHiresController < ApplicationController
@need_check_events = allevents.map{|e| [e[:date],e[:s_id]]}
@special_unavailable_dates = property.special_unavailable_dates.map{|dt| Date.parse(dt)}
ma = ModuleApp.find_by_key("property_hire")
is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
is_user_manager = OrbitHelper.current_user && (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
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
@check_start_date = property.start_date ? property.start_date.to_date : nil
@check_end_date = property.end_date ? property.end_date.to_date : nil
if check_setting
if (@check_start_date > edt rescue false) || (@check_end_date < sdt rescue false)
if (@check_start_date && @check_start_date > edt) || (@check_end_date && @check_end_date < sdt)
check_setting = false
end
end
@ -429,7 +429,9 @@ class PropertyHiresController < ApplicationController
available = false
end
if DateTime.now >= @property.start_date && DateTime.now <= @property.end_date
need_check_unavailable = (@check_start_date.nil? || date >= @check_start_date) && (@check_end_date.nil? || date <= @check_end_date)
if need_check_unavailable
if @property.hours_restriction > 0 && @is_user_manager === false
check = false
sd = nil
@ -461,13 +463,13 @@ class PropertyHiresController < ApplicationController
end
if available
if DateTime.now >= @property.start_date && DateTime.now <= @property.end_date
if need_check_unavailable
available = date > (DateTime.now + (@property.need_hire_before).send(@property.need_hire_before_unit))
end
end
if @check_setting && allow_times.select{|a| !a[5]}.count != 0
available = (date > @check_end_date rescue false) || (date < @check_start_date rescue false)
available = !need_check_unavailable
if available
available = @property.weekdays.include?(date.wday.to_s) ? false : true
end
@ -509,7 +511,7 @@ class PropertyHiresController < ApplicationController
@weeknumber = 0
@monthnumber = 0
ma = ModuleApp.find_by_key("property_hire")
@is_user_manager = (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
@is_user_manager = OrbitHelper.current_user && (OrbitHelper.current_user.is_admin? || OrbitHelper.current_user.is_manager?(ma) || OrbitHelper.current_user.is_sub_manager?(ma))
def generate_events(start_wday,end_wday,type=0,start_validate=false)
if type == 0
(start_wday..end_wday).each_with_index do |wday,i|

View File

@ -4,19 +4,13 @@ module Admin::PropertyHiresHelper
include OrbitBackendHelper
def check_for_availability(stime, etime, pid, interval=nil, recurring_end_date=nil, time_setting_id=nil)
property = Property.find(pid)
return {"success" => false, "msg" => I18n.t("property_hire.values_are_not_ok",:default=>"Values are not ok.")} if property.nil? || stime.blank? || etime.blank?
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
if !stime.blank?
stime = DateTime.parse(stime + timezone) rescue nil
else
stime = nil
end
if !etime.blank?
etime = DateTime.parse(etime + timezone) rescue nil
else
etime = nil
end
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

View File

@ -46,8 +46,8 @@ class Property
field :weekdays, type: Array, default: []
field :special_unavailable_dates, type: Array, default: []
field :special_unavailable_dates_title, type: Array, default: []
field :start_date, type: DateTime
field :end_date, type: DateTime
field :start_date, type: DateTime # unavailable start date
field :end_date, type: DateTime # unavailable end date
field :hours_restriction, type: Integer, default: 0
field :hours_restriction_duration, type: String
field :description, :localize => true
@ -148,9 +148,10 @@ class Property
end
def can_reserve
start_time = self.p_hire_start_time || Time.now
end_time = self.p_hire_end_time || Time.now
return Time.now >= start_time && end_time >= Time.now
now = Time.now
start_time = self.p_hire_start_time || now
end_time = self.p_hire_end_time || now
return now >= start_time && end_time >= now
end
def p_hire_fields_enabled
@ -339,14 +340,17 @@ class Property
end
end
if DateTime.now > self.start_date && DateTime.now < self.end_date
startt = self.start_date.nil? ? stime : self.start_date
endt = self.end_date.nil? ? etime : self.end_date
if (stime >= startt) && (etime <= endt)
if self.hours_restriction > 0 && !user.nil?
sd = nil
edd = nil
case self.hours_restriction_duration
when "week"
sd = stime - stime.wday
edd = stime + (6 - stime.wday)
edd = sd + 6
when "month"
sd = Date.new(stime.year, stime.month, 1)
edd = sd.next_month.prev_day
@ -356,10 +360,8 @@ class Property
end
end
end
startt = self.start_date.nil? ? stime : self.start_date
endt = self.end_date.nil? ? etime : self.end_date
available = 1 if (startt > stime && endt > etime)
available = 1 if (endt < stime)
available = 1 if startt > etime
available = 1 if endt < stime
weekdays = self.weekdays.collect{|w| w.to_i}
if !startt.nil?
if available == 0

View File

@ -265,7 +265,7 @@
<% session.delete("hire-save-msg") %>
<% end %>
</article>
<% if property.calendar_type == 0 %>
<% if calendar_type == 0 %>
<div id="orbit_calendar" class="col-lg-<%=12-right_col%>">
<div id="sec1">
<div class="btn-toolbar" id="navigation">
@ -454,7 +454,7 @@
<div class="col-lg-<%=right_col%>">
<% if property.can_reserve === true || is_user_manager %>
<%= form_for hire, :url => "/xhr/property_hires/make_booking", html: { class: "form-horizontal", id: "hire_form" } do |f| %>
<% if property.set_availability || is_user_manager %>
<% if property.set_availability %>
<div class="form-group">
<%= f.label :date, "*"+t("property_hire.date"), :class => "col-sm-#{label_col} control-label" %>
<div class="col-sm-<%=input_col%>" id="date_target_block">
@ -472,7 +472,7 @@
<% if property_day_setting %>
<%= select_tag "#{f.object_name}[time]", options_for_select([[t("property_hire.please_select"),""],[property_day_setting.title,property_day_setting.id.to_s]],hire.property_day_setting_id), :required=>"required" %>
<% else %>
<% if property.calendar_type == 0 %>
<% if calendar_type == 0 %>
<%= f.text_field :time, :value=>t("property_hire.please_choose_date"),:readonly=>"",:onclick=>"goto_calendar()" %>
<% else %>
<%= select_tag "#{f.object_name}[time]", options_for_select([[t("property_hire.please_choose_date"),""]]), :required=>"required" %>
@ -483,7 +483,7 @@
<% else %>
<div class="form-group">
<%= f.label :start_time, "*"+t("property_hire.start_time"), :class => "col-sm-#{label_col} control-label" %>
<% if property.calendar_type == 0 %>
<% if calendar_type == 0 %>
<div class="col-sm-<%=input_col%>">
<%= f.datetime_picker :start_time, :no_label => true, :new_record => hire.new_record? && !recover, :class => "pull-left", :data=>{"picker-type" => "range", "range" => "start", "fv-validation" => "required;", "fv-messages" => "Cannot be empty;"} %>
<button type="button" id="pick_start_date" onclick="change_pick(this)" class="btn btn-primary btn-sm pull-left" style="margin-left: 1em;"><%=t("property_hire.pick_from_calendar")%></button>