control order to logout

This commit is contained in:
Yan
2017-06-29 19:09:01 +06:30
parent fd857146e8
commit dd95b29d7d
3 changed files with 31 additions and 18 deletions

View File

@@ -71,7 +71,7 @@ class Api::OrdersController < Api::ApiController
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
@@ -82,7 +82,7 @@ class Api::OrdersController < Api::ApiController
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
@@ -91,30 +91,32 @@ class Api::OrdersController < Api::ApiController
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
end
else else
@order.new_booking = false @order.new_booking = false
@order.booking_id = booking.booking_id @order.booking_id = booking.booking_id
@@ -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

View File

@@ -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

View File

@@ -54,7 +54,7 @@ class Order < ApplicationRecord
end end
return false, @message = "booking fail" return false
end end