From a69128da0d9473abec0eeaba5b72b869bfd63aac Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Sun, 1 Jul 2018 17:14:08 +0630 Subject: [PATCH] update new request fixed --- app/controllers/origami/home_controller.rb | 11 +++++------ app/controllers/origami/rooms_controller.rb | 8 ++++---- app/models/dining_facility.rb | 9 +++++++++ .../api/restaurant/zones/index.json.jbuilder | 16 ++++++++++++---- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index e3981649..c863029a 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -4,8 +4,8 @@ class Origami::HomeController < BaseOrigamiController def index @webview = check_mobile - @tables = Table.all.active.order('status desc') - @rooms = Room.all.active.order('status desc') + @tables = Table.unscoped.all.active.order('status desc') + @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @shop = Shop.first @@ -17,8 +17,8 @@ class Origami::HomeController < BaseOrigamiController def show @webview = check_mobile - @tables = Table.all.active.order('status desc') - @rooms = Room.all.active.order('status desc') + @tables = Table.unscoped.all.active.order('status desc') + @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @@ -29,9 +29,8 @@ class Origami::HomeController < BaseOrigamiController @shop = Shop.first @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all - @dining_booking = @dining.bookings.active.where("DATE_FORMAT(created_at,'%Y-%m-%d') = '#{DateTime.now.strftime('%Y-%m-%d')}' OR DATE_FORMAT(created_at,'%Y-%m-%d') = '#{Date.today.prev_day}' ") - + #@dining_booking = @dining.bookings.active.where("created_at between '#{DateTime.now.utc - 12.hours}' and '#{DateTime.now.utc}'") @dining_booking.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index a460e27d..6877f8aa 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -1,7 +1,7 @@ class Origami::RoomsController < BaseOrigamiController def index - @tables = Table.all.active.order('status desc') - @rooms = Room.all.active.order('status desc') + @tables = Table.unscoped.all.active.order('status desc') + @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') # @shift = ShiftSale.current_open_shift(current_user.id) @@ -17,8 +17,8 @@ class Origami::RoomsController < BaseOrigamiController @webview = true end - @tables = Table.all.active.order('status desc') - @rooms = Room.all.active.order('status desc') + @tables = Table.unscoped.all.active.order('status desc') + @rooms = Room.unscoped.all.active.order('status desc') @complete = Sale.where("DATE_FORMAT(created_at,'%Y-%m-%d') = ? and sale_status != 'new'",DateTime.now.strftime('%Y-%m-%d')) @orders = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index c0843dbd..e5eb8c3a 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -177,7 +177,16 @@ class DiningFacility < ApplicationRecord if ENV["SERVER_MODE"] != 'cloud' ActionCable.server.broadcast "checkin_channel",table: table,from:from end + end end + + def get_current_booking_status + 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) #and checkout_at is null + if booking.count > 0 then + return booking[0] + else + return nil + end end end diff --git a/app/views/api/restaurant/zones/index.json.jbuilder b/app/views/api/restaurant/zones/index.json.jbuilder index 4a8666b4..bb05fb8f 100755 --- a/app/views/api/restaurant/zones/index.json.jbuilder +++ b/app/views/api/restaurant/zones/index.json.jbuilder @@ -6,21 +6,25 @@ if @zones #List all tables json.tables zone.tables do |table| if table.is_active + booking = table.get_current_booking_status json.id table.id json.name table.name json.status table.status json.zone_id table.zone_id #Add this zone_id to keep data structure consistance - json.current_booking table.get_current_booking.booking_id rescue "" + json.current_booking booking.booking_id rescue "" + json.sale_id booking.sale_id rescue "" end end json.rooms zone.rooms do |room| if room.is_active + booking = room.get_current_booking_status json.id room.id json.name room.name json.status room.status json.zone_id room.zone_id #Add this zone_id to keep data structure consistance - json.current_booking room.get_current_booking.booking_id rescue "" + json.current_booking booking.booking_id rescue "" + json.sale_id booking.sale_id rescue "" end end end @@ -28,21 +32,25 @@ if @zones else #list all tables and rooms with out zones json.tables @all_tables do |table| if table.is_active + booking = table.get_current_booking_status json.id table.id json.name table.name json.status table.status json.zone_id table.zone_id #Add this zone_id to keep data structure consistance - json.current_booking table.get_current_booking.booking_id rescue "" + json.current_booking booking.booking_id rescue "" + json.sale_id booking.sale_id rescue "" end end json.rooms @all_rooms do |room| if room.is_active + booking = room.get_current_booking_status json.id room.id json.name room.name json.status room.status json.zone_id room.zone_id #Add this zone_id to keep data structure consistance - json.current_booking room.get_current_booking.booking_id rescue "" + json.current_booking booking.booking_id rescue "" + json.sale_id booking.sale_id rescue "" end end end