From 46bbd90df53f58859269299407cfc5d057d8a1f4 Mon Sep 17 00:00:00 2001 From: phyusin Date: Fri, 8 Dec 2017 10:14:28 +0630 Subject: [PATCH] add fun: for checkin and checkout --- app/controllers/api/check_in_process_controller.rb | 8 ++++---- .../origami/check_in_process_controller.rb | 2 +- app/models/dining_facility.rb | 2 +- app/views/origami/home/index.html.erb | 12 ++++++++++-- app/views/origami/home/show.html.erb | 14 +++++++++++--- app/views/origami/rooms/show.html.erb | 14 +++++++++++--- 6 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/controllers/api/check_in_process_controller.rb b/app/controllers/api/check_in_process_controller.rb index edaa7596..99cd7d8c 100644 --- a/app/controllers/api/check_in_process_controller.rb +++ b/app/controllers/api/check_in_process_controller.rb @@ -3,7 +3,7 @@ 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_booking + 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") @@ -51,10 +51,10 @@ class Api::CheckInProcessController < Api::ApiController end booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type, - :checkin_by=>get_cashier[0].name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign" }) + :checkin_by=>get_cashier[0].name,:checkin_at => Time.now.utc,:checkout_at =>checkout_at, :booking_status => "assign", :reserved_at => checkout_at, :reserved_by => get_cashier[0].name }) booking.save! - render :json => { :status => true, :checkout_at => booking.checkout_at.utc.strftime("%Y-%m-%d %H:%M") } + 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 } @@ -79,7 +79,7 @@ class Api::CheckInProcessController < Api::ApiController booking.checkout_at = checkout_at booking.save! - render :json => { :status => true, :checkout_at => booking.checkout_at.utc.strftime("%Y-%m-%d %H:%M") } + 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 } diff --git a/app/controllers/origami/check_in_process_controller.rb b/app/controllers/origami/check_in_process_controller.rb index eab59f5e..bc77e51c 100644 --- a/app/controllers/origami/check_in_process_controller.rb +++ b/app/controllers/origami/check_in_process_controller.rb @@ -27,7 +27,7 @@ class Origami::CheckInProcessController < BaseOrigamiController 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" }) + :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! respond = {:status => 'ok'} diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 3b8eb22e..1b0f3fbe 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -67,7 +67,7 @@ class DiningFacility < ApplicationRecord end def get_current_checkout_booking - booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}'").limit(1) + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and reserved_by is not null").limit(1) if booking.count > 0 then return booking[0] else diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index df7d3f5f..346a1fce 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -41,14 +41,22 @@ <% @tables.each do |table| %> <% if table.status == 'occupied' %> <% if table.get_booking.nil? %> + <% if table.get_current_checkout_booking.nil? %>
+ <% else %> +
+ <% end %>
Zone <%= table.zone_id %>
Table <%= table.name %> ( <%= table.seater %> Seat )
- <% else %> -
+ <% else %> + <% if table.get_current_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %>
Zone <%= table.zone_id %>
Table <%= table.name %> ( <%= table.seater %> Seat ) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 718eb73c..df38a590 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -40,15 +40,23 @@ <% @tables.each do |table| %> <% if table.status == 'occupied' %> <% if table.get_booking.nil? %> -
+ <% if table.get_current_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %>
<%= table.name %> billed
- <% else %> -
+ <% else %> + <% if table.get_current_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %>
<%= table.name %> new diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 7b76ecd3..cbf43601 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -39,15 +39,23 @@
<% @tables.each do |table| %> <% if table.status == 'occupied' %> - <% if table.get_booking.nil? %> -
+ <% if table.get_booking.nil? %> + <% if table.get_current_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %>
<%= table.name %> billed
<% else %> -
+ <% if table.get_current_checkout_booking.nil? %> +
+ <% else %> +
+ <% end %>
<%= table.name %> new