dashboard ui and checkin checkout process
This commit is contained in:
78
app/controllers/api/check_in_process_controller.rb
Normal file
78
app/controllers/api/check_in_process_controller.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
class Api::CheckInProcessController < Api::ApiController
|
||||
|
||||
def check_in_process
|
||||
if params[:dining_id]
|
||||
dining_facility = DiningFacility.find(params[:dining_id])
|
||||
if dining_facility.status == "available"
|
||||
dining_charge = DiningCharge.select('charge_type','charge_block')
|
||||
.where('dining_facility_id = ?',params[:dining_id])
|
||||
.first()
|
||||
|
||||
checkout_at = Time.now.utc
|
||||
|
||||
if !dining_charge.nil?
|
||||
hr = (dining_charge.charge_block.utc.strftime("%H").to_i).to_int
|
||||
min = (dining_charge.charge_block.utc.strftime("%M").to_i).to_int
|
||||
# if dining_charge.charge_type == 'hr'
|
||||
checkout_at = checkout_at + hr.hour + min.minutes
|
||||
# else
|
||||
|
||||
# end
|
||||
end
|
||||
|
||||
dining_facility.status = "occupied"
|
||||
dining_facility.save!
|
||||
|
||||
if dining_facility.type == "Table"
|
||||
type = "TableBooking"
|
||||
else
|
||||
type = "RoomBooking"
|
||||
end
|
||||
|
||||
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type,
|
||||
:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign" })
|
||||
booking.save!
|
||||
|
||||
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.strftime("%Y-%m-%d %H:%M") }
|
||||
else
|
||||
error_message = "#{dining_facility.type} is not available!"
|
||||
render :json => { :status => false, :error_message => error_message }
|
||||
end
|
||||
else
|
||||
error_message = "dining_id is required!"
|
||||
render :json => { :status => false, :error_message => error_message }
|
||||
end
|
||||
end
|
||||
|
||||
def request_time
|
||||
if !params[:booking_id].nil? && !params[:time].nil?
|
||||
time = Time.parse(params[:time])
|
||||
booking = Booking.find(params[:booking_id])
|
||||
|
||||
checkout_at = booking.checkout_at.utc
|
||||
|
||||
hr = (time.strftime("%H").to_i).to_int
|
||||
min = (time.strftime("%M").to_i).to_int
|
||||
checkout_at = checkout_at + hr.hour + min.minutes
|
||||
|
||||
booking.checkout_at = checkout_at
|
||||
booking.save!
|
||||
|
||||
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.strftime("%Y-%m-%d %H:%M") }
|
||||
elsif !params[:booking_id].nil? && params[:time].nil?
|
||||
error_message = "time is required!"
|
||||
render :json => { :status => false, :error_message => error_message }
|
||||
elsif params[:booking_id].nil? && !params[:time].nil?
|
||||
error_message = "booking_id is required!"
|
||||
render :json => { :status => false, :error_message => error_message }
|
||||
else
|
||||
error_message = "booking_id and time are required!"
|
||||
render :json => { :status => false, :error_message => error_message }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_in_process_params
|
||||
params.permit(:dining_id,:booking_id,:time)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user