update api/resturant/menu
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
class Api::CheckInProcessController < Api::ApiController
|
class Api::CheckInProcessController < Api::ApiController
|
||||||
# before_action :authenticate
|
# before_action :authenticate
|
||||||
def check_in_time
|
def check_in_time
|
||||||
if params[:dining_id]
|
if params[:dining_id]
|
||||||
dining_facility = DiningFacility.find(params[:dining_id])
|
dining_facility = DiningFacility.find(params[:dining_id])
|
||||||
if params[:booking_id]
|
if params[:booking_id]
|
||||||
data = Booking.where("dining_facility_id = #{params[:dining_id]} AND booking_id = '#{params[:booking_id]}'")
|
data = Booking.where("dining_facility_id = #{params[:dining_id]} AND booking_id = '#{params[:booking_id]}'")
|
||||||
if data.count > 0
|
if data.count > 0
|
||||||
@@ -10,7 +10,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
else
|
else
|
||||||
booking = nil
|
booking = nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
booking = dining_facility.get_current_booking
|
booking = dining_facility.get_current_booking
|
||||||
end
|
end
|
||||||
if !booking.nil?
|
if !booking.nil?
|
||||||
@@ -21,7 +21,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
#Send to background job for processing
|
#Send to background job for processing
|
||||||
if ENV["SERVER_MODE"] == 'cloud'
|
if ENV["SERVER_MODE"] == 'cloud'
|
||||||
from = request.subdomain + "." + request.domain
|
from = request.subdomain + "." + request.domain
|
||||||
else
|
else
|
||||||
from = ""
|
from = ""
|
||||||
end
|
end
|
||||||
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
|
ActionCable.server.broadcast "check_in_booking_channel",table: table,from:from
|
||||||
@@ -37,7 +37,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
lookup_checkout_time = Lookup.collection_of("checkout_alert_time")
|
||||||
|
|
||||||
if !lookup_checkout_time.empty?
|
if !lookup_checkout_time.empty?
|
||||||
now = Time.now.utc
|
now = Time.now.utc
|
||||||
lookup_checkout_time.each do |checkout_time|
|
lookup_checkout_time.each do |checkout_time|
|
||||||
@@ -52,16 +52,18 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
else
|
else
|
||||||
render :json => { :status => true }
|
render :json => { :status => true }
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
render :json => { :status => false, :error_message => "No current booking!" }
|
render :json => { :status => false, :error_message => "No current booking!" }
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
render :json => { :status => false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_in_process
|
def check_in_process
|
||||||
if params[:dining_id]
|
if params[:dining_id]
|
||||||
dining_facility = DiningFacility.find(params[:dining_id])
|
dining_facility = DiningFacility.find(params[:dining_id])
|
||||||
if dining_facility.is_active && dining_facility.status == "available"
|
if dining_facility.is_active && dining_facility.status == "available"
|
||||||
if params[:checkin_time]
|
if params[:checkin_time]
|
||||||
checkin_at = nil
|
checkin_at = nil
|
||||||
@@ -75,7 +77,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
if dining_facility.check_time(checkin_at, "checkin")
|
if dining_facility.check_time(checkin_at, "checkin")
|
||||||
booking = dining_facility.get_current_booking
|
booking = dining_facility.get_current_booking
|
||||||
if booking.nil?
|
if booking.nil?
|
||||||
|
|
||||||
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
|
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 })
|
: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!
|
if booking.save!
|
||||||
@@ -98,7 +100,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
booking = dining_facility.get_current_checkout_booking
|
booking = dining_facility.get_current_checkout_booking
|
||||||
if booking.nil?
|
if booking.nil?
|
||||||
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
lookup_checkout_time = Lookup.collection_of("checkout_time")
|
||||||
|
|
||||||
if !lookup_checkout_time.empty?
|
if !lookup_checkout_time.empty?
|
||||||
today = Time.now.utc.getlocal
|
today = Time.now.utc.getlocal
|
||||||
checkout_at = Time.now.utc.getlocal
|
checkout_at = Time.now.utc.getlocal
|
||||||
@@ -118,7 +120,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
# else
|
# else
|
||||||
# type = "RoomBooking"
|
# type = "RoomBooking"
|
||||||
# end
|
# end
|
||||||
|
|
||||||
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
|
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => "TableBooking",
|
||||||
: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 })
|
: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 })
|
||||||
if booking.save!
|
if booking.save!
|
||||||
@@ -133,13 +135,13 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
unique_code = "CheckInOutPdf"
|
unique_code = "CheckInOutPdf"
|
||||||
printer = PrintSetting.find_by_unique_code(unique_code)
|
printer = PrintSetting.find_by_unique_code(unique_code)
|
||||||
|
|
||||||
# print when complete click
|
# print when complete click
|
||||||
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
order_queue_printer = Printer::OrderQueuePrinter.new(printer)
|
||||||
|
|
||||||
if !printer.nil?
|
if !printer.nil?
|
||||||
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
|
order_queue_printer.print_check_in_out(printer, cashier_terminal, booking, dining_facility)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
render :json => { :status => true, :booking_id => booking.booking_id, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
|
render :json => { :status => true, :booking_id => booking.booking_id, :checkout_at => booking.checkout_at.utc.getlocal.strftime("%Y-%m-%d %H:%M") }
|
||||||
else
|
else
|
||||||
render :json => { :status => true }
|
render :json => { :status => true }
|
||||||
@@ -176,7 +178,7 @@ class Api::CheckInProcessController < Api::ApiController
|
|||||||
booking.save!
|
booking.save!
|
||||||
|
|
||||||
render :json => { :status => true, :checkout_at => booking.checkout_at.utc.getlocal.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?
|
elsif !params[:booking_id].nil? && params[:time].nil?
|
||||||
error_message = "time is required!"
|
error_message = "time is required!"
|
||||||
render :json => { :status => false, :error_message => error_message }
|
render :json => { :status => false, :error_message => error_message }
|
||||||
elsif params[:booking_id].nil? && !params[:time].nil?
|
elsif params[:booking_id].nil? && !params[:time].nil?
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ class Api::Restaurant::MenuController < Api::ApiController
|
|||||||
param_checksum = params[:checksum]
|
param_checksum = params[:checksum]
|
||||||
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
|
# checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp
|
||||||
|
|
||||||
all_menu = Menu.active.all
|
all_menu = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
|
||||||
|
|
||||||
@request_url = ''
|
@request_url = ''
|
||||||
if ENV["SERVER_MODE"] == "cloud"
|
if ENV["SERVER_MODE"] == "cloud"
|
||||||
@request_url = request.base_url
|
@request_url = request.base_url
|
||||||
@@ -14,20 +15,21 @@ class Api::Restaurant::MenuController < Api::ApiController
|
|||||||
# to hash
|
# to hash
|
||||||
menu_array = []
|
menu_array = []
|
||||||
all_menu.each do |m|
|
all_menu.each do |m|
|
||||||
menu_array.push(m.to_json(:include => {:menu_categories =>
|
menu_array.push(m.to_json(:include => { :menu_categories => { :include => { :menu_items => { :include => [ :item_sets, :menu_item_instances => { :include => :menu_instance_item_sets } ] } } } } ))
|
||||||
{ :include => { :menu_items =>
|
end
|
||||||
{ :include => [:menu_item_sets, :menu_item_instances =>
|
|
||||||
{ :include => :menu_instance_item_sets}]} } }}))
|
|
||||||
end
|
|
||||||
|
|
||||||
#export Checksum file generate by md5
|
#export Checksum file generate by md5
|
||||||
menu_checksum = Digest::MD5.hexdigest(menu_array.to_json)
|
menu_checksum = Digest::MD5.hexdigest(menu_array.to_json)
|
||||||
|
|
||||||
if menu_checksum != param_checksum
|
if menu_checksum != param_checksum
|
||||||
response.headers['CHECKSUM'] = menu_checksum
|
response.headers['CHECKSUM'] = menu_checksum
|
||||||
@menus = all_menu
|
@menus = all_menu
|
||||||
|
@item_attributes = MenuItemAttribute.all.load
|
||||||
|
@item_options = MenuItemOption.all.load
|
||||||
|
else
|
||||||
|
render :json => nil
|
||||||
end
|
end
|
||||||
# @current_menu = Menu.current_menu
|
# @current_menu = Menu.current_menu
|
||||||
end
|
end
|
||||||
|
|
||||||
#Description
|
#Description
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ class Origami::DashboardController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_all_menu
|
def get_all_menu
|
||||||
@menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.all
|
@menus = Menu.includes(:menu_categories => [:children, :menu_items => [:menu_item_instances => :menu_instance_item_sets, :item_sets => :menu_item_instances]]).active.all
|
||||||
@item_attributes = MenuItemAttribute.all.load
|
@item_attributes = MenuItemAttribute.all.load
|
||||||
@item_options = MenuItemOption.all.load
|
@item_options = MenuItemOption.all.load
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,52 +1,21 @@
|
|||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
attr_format = []
|
attr_format = []
|
||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
if item.is_available
|
if item.is_available
|
||||||
if item.item_attributes.count > 0
|
# Format for attributes json
|
||||||
item.item_attributes.each do|attr_id|
|
attr_format = []
|
||||||
menu_attr = MenuItemAttribute.find(attr_id)
|
# Format for attributes json
|
||||||
if attr_format.count == 0
|
if item.item_attributes.count > 0
|
||||||
attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] })
|
item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) }
|
||||||
next
|
attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
end
|
|
||||||
|
|
||||||
attr_format.each do |af|
|
|
||||||
if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]}
|
|
||||||
if menu_attr.attribute_type == af[:type]
|
|
||||||
af[:values].push(menu_attr.name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] }
|
|
||||||
attr_format.push(new_attr)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Format for option json
|
# Format for option json
|
||||||
opt_format = []
|
opt_format = []
|
||||||
# Format for attributes json
|
# Format for attributes json
|
||||||
if item.item_options.count > 0
|
if item.item_options.count > 0
|
||||||
item.item_options.each do|opt|
|
item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) }
|
||||||
menu_opt = MenuItemOption.find(opt)
|
opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} }
|
||||||
if opt_format.count == 0
|
|
||||||
opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] })
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
opt_format.each do |of|
|
|
||||||
if menu_opt.option_type.in? opt_format.map {|k| k[:type]}
|
|
||||||
if menu_opt.option_type == of[:type]
|
|
||||||
of[:values].push(menu_opt.name)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] }
|
|
||||||
opt_format.push(new_opt)
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#Menu Item Information
|
#Menu Item Information
|
||||||
@@ -68,17 +37,15 @@ if item.is_available
|
|||||||
json.is_sub_item item.is_sub_item
|
json.is_sub_item item.is_sub_item
|
||||||
json.unit item.unit
|
json.unit item.unit
|
||||||
|
|
||||||
# Item Sets of Menu Item
|
# Item Sets of Menu Item
|
||||||
json.item_sets item.item_sets do |its|
|
json.item_sets item.item_sets do |its|
|
||||||
json.id its.id
|
json.id its.id
|
||||||
json.name its.name
|
json.name its.name
|
||||||
json.alt_name its.alt_name
|
json.alt_name its.alt_name
|
||||||
json.min_selectable_qty its.min_selectable_qty
|
json.min_selectable_qty its.min_selectable_qty
|
||||||
json.max_selectable_qty its.max_selectable_qty
|
json.max_selectable_qty its.max_selectable_qty
|
||||||
json.instances its.menu_item_instances do |i|
|
json.instances its.menu_item_instances.map { |i| {id: i.id} }
|
||||||
json.id i.id
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
json.attributes attr_format
|
json.attributes attr_format
|
||||||
json.options opt_format
|
json.options opt_format
|
||||||
@@ -97,25 +64,18 @@ if item.is_available
|
|||||||
json.instances item.menu_item_instances do |is|
|
json.instances item.menu_item_instances do |is|
|
||||||
if is.is_available
|
if is.is_available
|
||||||
# Convert id to name for attributes
|
# Convert id to name for attributes
|
||||||
instance_attr = []
|
instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name)
|
||||||
|
|
||||||
is.item_attributes.each do |ia|
|
json.id is.id
|
||||||
# mItemAttr = MenuItemAttribute.find(is)
|
json.code is.item_instance_code
|
||||||
# instance_attr.push(ia)
|
json.name is.item_instance_name
|
||||||
mItemAttr = MenuItemAttribute.find(ia).name
|
json.price is.price
|
||||||
instance_attr.push(mItemAttr)
|
json.is_available is.is_available
|
||||||
end
|
json.is_default is.is_default
|
||||||
|
json.is_on_promotion is.is_on_promotion
|
||||||
json.id is.id
|
json.promotion_price is.promotion_price
|
||||||
json.code is.item_instance_code
|
json.values instance_attr
|
||||||
json.name is.item_instance_name
|
# json.item_sets is.item_sets
|
||||||
json.price is.price
|
|
||||||
json.is_available is.is_available
|
|
||||||
json.is_default is.is_default
|
|
||||||
json.is_on_promotion is.is_on_promotion
|
|
||||||
json.promotion_price is.promotion_price
|
|
||||||
json.values instance_attr
|
|
||||||
# json.item_sets is.item_sets
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -125,4 +85,4 @@ if item.is_available
|
|||||||
# json.partial! 'api/restaurant/menu/menu_item', item: item
|
# json.partial! 'api/restaurant/menu/menu_item', item: item
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user