control order to logout
This commit is contained in:
@@ -68,10 +68,10 @@ class Api::OrdersController < Api::ApiController
|
|||||||
if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved'
|
if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved'
|
||||||
if !booking.sale_id.nil?
|
if !booking.sale_id.nil?
|
||||||
sale_status = check_order_with_booking(booking)
|
sale_status = check_order_with_booking(booking)
|
||||||
puts "WWwwWWWWWWww"
|
puts "WWwwWWWWWWww"
|
||||||
puts sale_status
|
puts sale_status
|
||||||
if sale_status
|
if sale_status
|
||||||
return false , @message = "bill requested"
|
return return_json_status_with_code(400, "bill requested")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@order.new_booking = false
|
@order.new_booking = false
|
||||||
@@ -79,43 +79,45 @@ class Api::OrdersController < Api::ApiController
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
sale_status = check_order_with_table(params[:table_id])
|
sale_status = check_order_with_table(params[:table_id])
|
||||||
puts "OOOOOOOOO"
|
puts "OOOOOOOOO"
|
||||||
puts sale_status
|
puts sale_status
|
||||||
if sale_status
|
if sale_status
|
||||||
return false , @message = "bill requested"
|
return return_json_status_with_code(400, "bill requested")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end #booking exists
|
end #booking exists
|
||||||
else
|
else
|
||||||
sale_status = check_order_with_table(params[:table_id])
|
sale_status = check_order_with_table(params[:table_id])
|
||||||
puts "MMMMMMMM"
|
puts "MMMMMMMM"
|
||||||
puts sale_status
|
puts sale_status
|
||||||
if sale_status
|
if sale_status
|
||||||
return false , @message = "bill requested"
|
# return false , @message = "bill requested"
|
||||||
|
return return_json_status_with_code(400, "bill requested")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@status, @booking = @order.generate
|
@status, @booking = @order.generate
|
||||||
end
|
end
|
||||||
|
|
||||||
# render json for http status code 202
|
# render json for http status code
|
||||||
def return_json_status_with_code(code, msg, booking_id)
|
def return_json_status_with_code(code, msg)
|
||||||
render status: code, json: {
|
render status: code, json: {
|
||||||
message: msg,
|
message: msg
|
||||||
booking_id: booking_id
|
|
||||||
}.to_json
|
}.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_order_with_table(table_id)
|
def check_order_with_table(table_id)
|
||||||
table = DiningFacility.find(table_id)
|
table = DiningFacility.find(table_id)
|
||||||
if table
|
if table
|
||||||
booking = table.get_current_booking
|
booking = table.get_moved_booking
|
||||||
puts booking
|
puts booking
|
||||||
if booking
|
if booking
|
||||||
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
|
if !booking.sale_id.nil?
|
||||||
|
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
|
||||||
@order.new_booking = true
|
@order.new_booking = true
|
||||||
return true
|
return true
|
||||||
else
|
end
|
||||||
|
else
|
||||||
@order.new_booking = false
|
@order.new_booking = false
|
||||||
@order.booking_id = booking.booking_id
|
@order.booking_id = booking.booking_id
|
||||||
return false
|
return false
|
||||||
@@ -124,8 +126,9 @@ class Api::OrdersController < Api::ApiController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# this can always true
|
||||||
def check_order_with_booking(booking)
|
def check_order_with_booking(booking)
|
||||||
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "billed"
|
if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
|
||||||
@order.new_booking = true
|
@order.new_booking = true
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -39,6 +39,16 @@ class DiningFacility < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_moved_booking
|
||||||
|
booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='moved' and checkin_at between '#{DateTime.now.utc - 5.hours}' and '#{DateTime.now.utc}' and checkout_at is null").limit(1)
|
||||||
|
|
||||||
|
if booking.count > 0 then
|
||||||
|
return booking[0]
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_new_booking
|
def get_new_booking
|
||||||
# query for new
|
# query for new
|
||||||
# if status
|
# if status
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class Order < ApplicationRecord
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, @message = "booking fail"
|
return false
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user