checkin checkout time fun:

This commit is contained in:
phyusin
2018-11-27 19:04:32 +06:30
parent 30f0852f56
commit f5ba08ae25
2 changed files with 28 additions and 16 deletions

View File

@@ -64,10 +64,18 @@ class Api::CheckInProcessController < Api::ApiController
dining_facility = DiningFacility.find(params[:dining_id]) dining_facility = DiningFacility.find(params[:dining_id])
if dining_facility.status == "available" if dining_facility.status == "available"
if params[:checkin_time] if params[:checkin_time]
if dining_facility.check_time(params[:checkin_time], "checkin") checkin_at = nil
if !params[:checkin_time].empty?
checkin_at = Time.parse(params[:checkin_time]).utc
else
checkin_at = Time.now.utc
end
if !checkin_at.nil?
if dining_facility.check_time(checkin_at, "checkin")
booking = dining_facility.get_current_booking booking = dining_facility.get_current_booking
if booking.nil? if booking.nil?
checkin_at = Time.parse(params[:checkin_time]).utc
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking", booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
:checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil }) :checkin_by=>current_login_employee.name,:checkin_at => checkin_at,:checkout_at =>nil, :booking_status => "assign", :reserved_at => nil, :reserved_by => nil })
if booking.save! if booking.save!
@@ -83,6 +91,9 @@ class Api::CheckInProcessController < Api::ApiController
else else
render :json => { :status => false, :error_message => "Checkin time not available!" } render :json => { :status => false, :error_message => "Checkin time not available!" }
end end
else
render :json => { :status => false, :error_message => "Operation failed!" }
end
else else
booking = dining_facility.get_current_checkout_booking booking = dining_facility.get_current_checkout_booking
if booking.nil? if booking.nil?
@@ -181,8 +192,9 @@ class Api::CheckInProcessController < Api::ApiController
if !params[:booking_id].nil? && !params[:checkout_time].nil? if !params[:booking_id].nil? && !params[:checkout_time].nil?
booking = Booking.find(params[:booking_id]) booking = Booking.find(params[:booking_id])
dining_facility = DiningFacility.find(booking.dining_facility_id) dining_facility = DiningFacility.find(booking.dining_facility_id)
if dining_facility.check_time(params[:checkout_time], booking, "checkout") checkout_at = Time.parse(params[:checkout_time]).utc
checkout_time = Time.parse(params[:checkout_time].strip).utc.getlocal if dining_facility.check_time(checkout_at, booking, "checkout")
checkout_time = checkout_at.getlocal
booking.checkout_at = checkout_time booking.checkout_at = checkout_time
booking.reserved_at = checkout_time booking.reserved_at = checkout_time
booking.reserved_by = current_login_employee.name booking.reserved_by = current_login_employee.name

View File

@@ -183,7 +183,7 @@ class DiningFacility < ApplicationRecord
def check_time(time, booking = nil, type) def check_time(time, booking = nil, type)
status = true status = true
today = Time.now.utc.strftime("%Y-%m-%d %H:%M") today = Time.now.utc.strftime("%Y-%m-%d %H:%M")
check_time = Time.parse(time.strip).utc.strftime("%Y-%m-%d %H:%M") check_time = time.strftime("%Y-%m-%d %H:%M")
if type.downcase == "checkin" if type.downcase == "checkin"
if check_time < today if check_time < today
status = false status = false