From f608aa8516b28ffa28ed121bf055427f51a52f2f Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 1 Feb 2018 17:00:57 +0630 Subject: [PATCH] check checkin time is available or valid time --- .../api/check_in_process_controller.rb | 27 ++++++++++------- .../origami/check_in_process_controller.rb | 29 ++++++++++--------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index a033c49a..6f32c613 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -42,6 +42,7 @@ class Api::CheckInProcessController < Api::ApiController lookup_checkout_time = Lookup.collection_of("checkout_time") if !lookup_checkout_time.empty? + today = Time.now.utc.getlocal checkout_at = Time.now.utc.getlocal lookup_checkout_time.each do |checkout_time| @@ -53,20 +54,24 @@ class Api::CheckInProcessController < Api::ApiController end end - dining_facility.status = "occupied" - dining_facility.save! + if checkout_at.strftime("%Y-%m-%d %H:%M%p") > today.strftime("%Y-%m-%d %H:%M%p") + dining_facility.status = "occupied" + dining_facility.save! - if dining_facility.type == "Table" - type = "TableBooking" + 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 - type = "RoomBooking" + render :json => { :status => true } 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 render :json => { :status => true } end diff --git a/app/controllers/origami/check_in_process_controller.rb b/app/controllers/origami/check_in_process_controller.rb index 67191b6e..2c5b0b38 100644 --- a/app/controllers/origami/check_in_process_controller.rb +++ b/app/controllers/origami/check_in_process_controller.rb @@ -2,6 +2,7 @@ class Origami::CheckInProcessController < BaseOrigamiController def check_in_process lookup_checkout_time = Lookup.collection_of("checkout_time") + today = Time.now.utc.getlocal checkout_at = Time.now.utc.getlocal if !lookup_checkout_time.empty? lookup_checkout_time.each do |checkout_time| @@ -12,20 +13,22 @@ class Origami::CheckInProcessController < BaseOrigamiController checkout_at = checkout_at + (checkout_time[1]).to_i.minutes end end - - @dining_facility = DiningFacility.find(params[:dining_id]) - @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! + if checkout_at.strftime("%Y-%m-%d %H:%M%p") > today.strftime("%Y-%m-%d %H:%M%p") + @dining_facility = DiningFacility.find(params[:dining_id]) + @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! + end end respond = {:status => 'ok'} respond_to do |format|