93 lines
3.2 KiB
Ruby
93 lines
3.2 KiB
Ruby
class Api::CheckInProcessController < Api::ApiController
|
|
|
|
def check_in_time
|
|
if params[:dining_id]
|
|
dining_facility = DiningFacility.find(params[:dining_id])
|
|
booking = dining_facility.get_current_checkout_booking
|
|
if !booking.nil?
|
|
check_in_time = booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M")
|
|
check_out_time = booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M")
|
|
render :json => { :status => true, :check_in_time => check_in_time, :check_out_time => check_out_time }
|
|
else
|
|
render :json => { :status => false, :error_message => "No current booking!" }
|
|
end
|
|
end
|
|
end
|
|
|
|
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_by=>current_login_employee.name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => current_login_employee.name })
|
|
booking.save!
|
|
|
|
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.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.getlocal.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
|