93 lines
2.1 KiB
Ruby
93 lines
2.1 KiB
Ruby
class Admin::BusBookingsController < OrbitMemberAppController
|
|
layout "bus_booking"
|
|
|
|
def index
|
|
@buses = Bus.all.desc(:departure_time).page(params[:page]).per(15)
|
|
end
|
|
|
|
def edit
|
|
@bus = Bus.find(params[:id])
|
|
end
|
|
|
|
def new
|
|
@bus = Bus.new
|
|
end
|
|
|
|
def destroy
|
|
bus = Bus.find(params[:id])
|
|
bus.destroy
|
|
redirect_to admin_bus_bookings_path
|
|
end
|
|
|
|
def update
|
|
bus = Bus.find(params[:id])
|
|
bus.update_attributes(bus_params)
|
|
redirect_to admin_bus_bookings_path
|
|
end
|
|
|
|
def create
|
|
bus = Bus.new(bus_params)
|
|
bus.save
|
|
redirect_to admin_bus_bookings_path
|
|
end
|
|
|
|
def duplicate
|
|
bus = Bus.find(params[:bus_booking_id])
|
|
newbus = bus.clone
|
|
newbus.created_at = Time.now
|
|
newbus.updated_at = Time.now
|
|
newbus.created_by = current_user.id.to_s
|
|
d = DateTime.now
|
|
d = d.change(:hour => newbus.departure_time.strftime("%H").to_i, :min => newbus.departure_time.strftime("%M").to_i)
|
|
newbus.departure_time = d
|
|
d = DateTime.now
|
|
d = d.change(:hour => newbus.reservation_end_time.strftime("%H").to_i, :min => newbus.reservation_end_time.strftime("%M").to_i)
|
|
newbus.reservation_end_time = d
|
|
newbus.save
|
|
redirect_to admin_bus_bookings_path
|
|
end
|
|
|
|
def show
|
|
@bus = Bus.find(params[:id])
|
|
end
|
|
|
|
def cancel
|
|
booking = Booking.find(params[:bus_booking_id]) rescue nil
|
|
booking.destroy if !booking.nil?
|
|
redirect_to admin_bus_bookings_path
|
|
end
|
|
|
|
def export
|
|
@bus = Bus.find(params[:bus_booking_id])
|
|
filename = "#{@bus.bus_route}_#{@bus.departure_time.strftime("%Y_%m_%d_%H_%M")}"
|
|
respond_to do |format|
|
|
format.xlsx {
|
|
response.headers['Content-Disposition'] = 'attachment; filename="' + filename + '.xlsx"'
|
|
}
|
|
end
|
|
end
|
|
|
|
def reserve
|
|
@bus_booking = Booking.new
|
|
@bus = Bus.find(params[:bus_booking_id])
|
|
@already_booked = Booking.where(:user_id => current_user.id.to_s, :bus_id => @bus.id)
|
|
@already_reserved = (@already_booked.count > 0) rescue false
|
|
end
|
|
|
|
def bookbus
|
|
bookbus = Booking.new(book_params)
|
|
bookbus.save
|
|
redirect_to admin_bus_bookings_path
|
|
end
|
|
|
|
private
|
|
|
|
def bus_params
|
|
params.require(:bus).permit!
|
|
end
|
|
|
|
def book_params
|
|
params.require(:booking).permit!
|
|
end
|
|
|
|
end |