2017-01-20 09:02:50 +00:00
|
|
|
class Admin::PropertyHiresController < OrbitAdminController
|
|
|
|
|
|
|
|
def index
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories.enabled
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
|
|
|
@table_fields = ["property_hire.title", :category, "property_hire.location", "property_hire.available_for_hire"]
|
|
|
|
|
|
|
|
@properties = Property.where(:title.ne => "")
|
|
|
|
.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag"))
|
|
|
|
|
|
|
|
@properties = search_data(@properties,[:title]).page(params[:page]).per(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@property = Property.new
|
|
|
|
@locations = PropertyLocation.all.desc(:created_at).collect{|loc| [loc.title, loc.id.to_s]}
|
|
|
|
@locations << ["Other", "other_location"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@property = Property.where(:uid => params[:id].split("-").last).first rescue nil
|
|
|
|
@locations = PropertyLocation.all.desc(:created_at).collect{|loc| [loc.title, loc.id.to_s]}
|
|
|
|
@locations << ["Other", "other_location"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@table_fields = ["property_hire.hiring_person_name", "property_hire.reason_for_hire", "property_hire.hiring_person_number", "property_hire.period", "property_hire.passed", :actions]
|
|
|
|
@property = Property.where(:uid => params[:id].split("-").last).first rescue nil
|
|
|
|
@bookings = @property.p_hires.desc(:created_at).page(params[:page]).per(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
property = Property.find(params[:id]) rescue nil
|
|
|
|
property.destroy if !property.nil?
|
|
|
|
if params[:page]
|
|
|
|
redirect_to admin_property_hires_path(:page => params[:page])
|
|
|
|
else
|
|
|
|
redirect_to admin_property_hires_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
property = Property.where(:uid => params[:id].split("-").last).first rescue nil
|
|
|
|
redirect_to admin_property_hires_path and return if property.nil?
|
|
|
|
property.update_attributes(property_params)
|
|
|
|
if params[:page]
|
|
|
|
redirect_to admin_property_hires_path(:page => params[:page])
|
|
|
|
else
|
|
|
|
redirect_to admin_property_hires_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
property = Property.new(property_params)
|
|
|
|
if property.save
|
|
|
|
redirect_to admin_property_hires_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_booking_details
|
|
|
|
@booking = PHire.find(params[:id]) rescue nil
|
|
|
|
end
|
|
|
|
|
2018-01-17 07:53:58 +00:00
|
|
|
def delete_booking_details
|
|
|
|
booking = PHire.find(params[:id])
|
|
|
|
property = booking.property
|
|
|
|
booking.destroy
|
|
|
|
redirect_to admin_property_hire_path(property)
|
|
|
|
end
|
|
|
|
|
2017-01-20 09:02:50 +00:00
|
|
|
def pass_booking
|
|
|
|
phire = PHire.find(params[:id]) rescue nil
|
|
|
|
case params[:status]
|
|
|
|
when "accept"
|
|
|
|
phire.passed = true
|
|
|
|
when "reject"
|
|
|
|
phire.passed = false
|
|
|
|
end
|
|
|
|
phire.save
|
|
|
|
if params[:ref] == "index"
|
|
|
|
if params[:page]
|
|
|
|
redirect_to admin_property_hire_path(phire.property, :page => params[:page])
|
|
|
|
else
|
|
|
|
redirect_to admin_property_hire_path(phire.property)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
redirect_to show_booking_details_admin_property_hire_path(phire)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def manage_locations
|
|
|
|
@table_fields = ["property_hire.location", "property_hire.property_count"]
|
|
|
|
@locations = PropertyLocation.all.desc(:created_at).page(params[:page]).per(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_location
|
|
|
|
@location = PropertyLocation.new
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_location
|
|
|
|
PropertyLocation.create(location_params)
|
|
|
|
redirect_to manage_locations_admin_property_hires_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit_location
|
|
|
|
@location = PropertyLocation.find(params[:id])
|
|
|
|
render :layout => false
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_location
|
|
|
|
location = PropertyLocation.find(params[:id]) rescue nil
|
|
|
|
if location.nil?
|
|
|
|
redirect_to manage_locations_admin_property_hires_path
|
|
|
|
else
|
|
|
|
location.update_attributes(location_params)
|
|
|
|
if params[:page]
|
|
|
|
redirect_to manage_locations_admin_property_hires_path(:page => params[:page])
|
|
|
|
else
|
|
|
|
redirect_to manage_locations_admin_property_hires_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_location
|
|
|
|
location = PropertyLocation.find(params[:id]) rescue nil
|
|
|
|
if location.nil?
|
|
|
|
redirect_to manage_locations_admin_property_hires_path
|
|
|
|
else
|
|
|
|
location.destroy
|
|
|
|
if params[:page]
|
|
|
|
redirect_to manage_locations_admin_property_hires_path(:page => params[:page])
|
|
|
|
else
|
|
|
|
redirect_to manage_locations_admin_property_hires_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def location_params
|
|
|
|
params.require(:property_location).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
def property_params
|
|
|
|
prop = params.require(:property).permit!
|
|
|
|
prop.delete(:property_location) if prop[:property_location] == "other"
|
|
|
|
prop
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|