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, "image" => property.image.url, "image-thumb" => property.image.thumb.url, "url_to_show" => OrbitHelper.url_to_show(property.to_param), "location" => property.get_location_name, "actions" => actions } end headers = [ { "column" => t("property_hire.title") }, { "column" => t("property_hire.image") }, { "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 if !property.property_number.blank? data << { "header" => t("property_hire.property_number"), "value" => property.property_number } end data << { "header" => t("property_hire.can_be_hired"), "value" => (property.can_be_hired ? "Yes" : "No") } if !property.purchase_date.to_s.blank? data << { "header" => t("property_hire.purchase_date"), "value" => property.purchase_date.strftime("%Y-%m-%d") } end if property.owners.empty? owners = property.other_owner else owners = property.owner_profiles.collect{|mp| mp.name}.join(",") end if !owners.blank? data << { "header" => t("property_hire.owners"), "value" => owners } end if !property.owner_email.blank? data << { "header" => t("property_hire.owner_email"), "value" => property.owner_email } end if !property.owner_phone.blank? data << { "header" => t("property_hire.owner_phone"), "value" => property.owner_phone } end if !property.price.blank? data << { "header" => t("property_hire.price"), "value" => property.price } end if !property.get_location_name.blank? data << { "header" => t("property_hire.location"), "value" => property.get_location_name } end 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 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]) property = Property.find(booking_p[:property_id]) rescue nil if data["success"] == true hire = PHire.new(booking_p) hire.passed = true if PropertyHireSetting.auto_approve_enabled? hire.save 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 HireMethod.send_mail('p_hire',email,property.id,nil,hire.id) end 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 data = check_for_availability params[:stime], params[:etime], params[:property_id], params[:interval], params[:recurring_end_date] 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]) re = PHire.recurring_event(sdt,edt,params[:property_id]) allevents = events.inject(re, :<<) end end respond_to do |format| format.html # index.html.erb format.json { render json: allevents.to_json } end end private def booking_params params.require(:p_hire).permit! end end