From f5ba08ae253455bddf2768716b309c1eea6dda0e Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 27 Nov 2018 19:04:32 +0630 Subject: [PATCH] checkin checkout time fun: --- .../api/check_in_process_controller.rb | 42 ++++++++++++------- app/models/dining_facility.rb | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index 6f0ae28c..c10d9593 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -64,24 +64,35 @@ class Api::CheckInProcessController < Api::ApiController dining_facility = DiningFacility.find(params[:dining_id]) if dining_facility.status == "available" if params[:checkin_time] - if dining_facility.check_time(params[:checkin_time], "checkin") - booking = dining_facility.get_current_booking - if booking.nil? - checkin_at = Time.parse(params[:checkin_time]).utc - 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 }) - if booking.save! - dining_facility.status = "occupied" - dining_facility.save! - render :json => { :status => true, :booking_id => booking.booking_id, :checkin_at => booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M:%S"), :message => "Check-in success" } + 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 + if booking.nil? + + 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 }) + if booking.save! + dining_facility.status = "occupied" + dining_facility.save! + render :json => { :status => true, :booking_id => booking.booking_id, :checkin_at => booking.checkin_at.utc.getlocal.strftime("%Y-%m-%d %H:%M:%S"), :message => "Check-in success" } + else + render :json => { :status => false, :error_message => "Booking does not create successfully!" } + end else - render :json => { :status => false, :error_message => "Booking does not create successfully!" } + render :json => { :status => false, :error_message => "Booking already exist!" } end else - render :json => { :status => false, :error_message => "Booking already exist!" } + render :json => { :status => false, :error_message => "Checkin time not available!" } end else - render :json => { :status => false, :error_message => "Checkin time not available!" } + render :json => { :status => false, :error_message => "Operation failed!" } end else booking = dining_facility.get_current_checkout_booking @@ -181,8 +192,9 @@ class Api::CheckInProcessController < Api::ApiController if !params[:booking_id].nil? && !params[:checkout_time].nil? booking = Booking.find(params[:booking_id]) dining_facility = DiningFacility.find(booking.dining_facility_id) - if dining_facility.check_time(params[:checkout_time], booking, "checkout") - checkout_time = Time.parse(params[:checkout_time].strip).utc.getlocal + checkout_at = Time.parse(params[:checkout_time]).utc + if dining_facility.check_time(checkout_at, booking, "checkout") + checkout_time = checkout_at.getlocal booking.checkout_at = checkout_time booking.reserved_at = checkout_time booking.reserved_by = current_login_employee.name diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 165fbe3a..12020320 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -183,7 +183,7 @@ class DiningFacility < ApplicationRecord def check_time(time, booking = nil, type) status = true 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 check_time < today status = false