diff --git a/app/controllers/property_hires_controller.rb b/app/controllers/property_hires_controller.rb index a606650..013d3ab 100644 --- a/app/controllers/property_hires_controller.rb +++ b/app/controllers/property_hires_controller.rb @@ -221,6 +221,13 @@ class PropertyHiresController < ApplicationController params[:phire_id] = booking_p[:id] 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) + 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 if data["success"] == true hire = nil if params[:phire_id] @@ -240,6 +247,7 @@ class PropertyHiresController < ApplicationController end redirect_to index_page + "?method=hire_success" else + session[:hire_data] = booking_p session["hire-save-msg"] = data["msg"] if property.nil? redirect_to index_page diff --git a/app/helpers/admin/p_hire_field_helper.rb b/app/helpers/admin/p_hire_field_helper.rb index c1cc29a..33360b8 100644 --- a/app/helpers/admin/p_hire_field_helper.rb +++ b/app/helpers/admin/p_hire_field_helper.rb @@ -20,7 +20,7 @@ module Admin::PHireFieldHelper @member = member @attribute_value = @member.get_value_from_field_id(id,p_hire) @attribute_type = attribute_type - @new_attribute = @attribute_value.nil? + @new_attribute = @attribute_value.nil? || @attribute_value.new_record? @attribute_value = @attribute_value || p_hire.p_hire_field_values.build(p_hire_field_id: id) @prefiled_value = value || @attribute_value.value rescue nil return instance_eval("render_#{markup}") rescue "" diff --git a/app/models/property.rb b/app/models/property.rb index 1bfd21c..5eb2a10 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -371,7 +371,8 @@ class Property else d_step = 0 end - bookings = bookings.any_of([{:start_time.gte => etime},{:end_time.gte => etime}]) + not_in_ids = bookings.any_of([{:end_time.lt=>stime},{:start_time.gt=>etime}]).pluck(:id) + bookings = bookings.where(:id.nin=>not_in_ids) if time_setting_id recurring_bookings = recurring_bookings.where(:property_day_setting_id=>time_setting_id) bookings = recurring_bookings.where(:property_day_setting_id=>time_setting_id) @@ -465,7 +466,45 @@ class Property end return available end - + def check_require_fields(booking_p) + fields_name = self.get_all_fields + has_p_hire_fields = self.p_hire_fields.count != 0 + p_hire_fields = {} + if has_p_hire_fields + p_hire_fields = self.p_hire_fields.map{|rf| [rf.id.to_s,rf]}.to_h + end + error_messages = "" + form_index = 0 + cross_lang_types = ['select','date','radio_button','checkbox'] + unfilled_text = I18n.t('property_hire.unfilled') + available_locales = I18n.available_locales + available_locales_trans = available_locales.map{|l| [l, I18n.t(l)]}.to_h + fields_name.each do |field_name| + if has_p_hire_fields && field_name.include?("p_hire_fields") + rf = p_hire_fields[field_name.sub("p_hire_fields.",'')] + if rf.markup != 'hint_text' && rf.to_require + v = booking_p["p_hire_field_values_attributes"][form_index.to_s]['value'] + if cross_lang_types.include?(rf.markup) || rf.get_data["cross_lang"] == "true" + if v.blank? + error_messages += "#{rf.title}: #{unfilled_text}\n" + end + else + available_locales.each do |l| + if (v[l].blank? rescue true) + error_messages += "#{rf.title}(#{available_locales_trans[l]}): #{unfilled_text}\n" + end + end + end + end + form_index = form_index +1 + else + if self.send(field_name)["required"] == "true" && booking_p[field_name].blank? + error_messages += "#{self.custom_text(field_name,"name")}: #{unfilled_text}\n" + end + end + end + error_messages + end def self.time_iterate(start_time, end_time, step, &block) times = [] if block_given? diff --git a/app/views/property_hires/hire.html.erb b/app/views/property_hires/hire.html.erb index 76837b2..cafbdb0 100644 --- a/app/views/property_hires/hire.html.erb +++ b/app/views/property_hires/hire.html.erb @@ -3,6 +3,7 @@ +<%= javascript_include_tag "basic/jquery.nanoscroller.js" %> <% data = action_data hire = data["hire"] @@ -257,8 +258,8 @@ <% end %> <% if session["hire-save-msg"].present? %> -
- + + <% session.delete("hire-save-msg") %> <% end %> @@ -304,7 +305,7 @@