From 80320b6d3ed5a00cfaedbfe177ad57f8e6a8b1b4 Mon Sep 17 00:00:00 2001 From: Yan Date: Sun, 18 Jun 2017 00:45:39 +0630 Subject: [PATCH] oqs updated --- app/assets/javascripts/OQS.js | 2 ++ app/controllers/oqs/home_controller.rb | 26 ++++++++++++++++++++------ app/models/dining_facility.rb | 20 ++++++++++++++++++-- app/models/order_queue_station.rb | 18 +++++++++--------- app/views/oqs/home/index.html.erb | 1 + 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 8e252749..1ffc71b8 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -30,6 +30,7 @@ $(document).ready(function(){ var orderBy = $(this).children().children().children().children('.order-by').text(); var orderAt = $(this).children().children().children().children('.order-at').text(); var orderCustomer = $(this).children().children('.order-customer').text(); + var order_status = $(this).children().children('.order-status').text(); $('#order-title').text("ORDER DETAILS - " + orderZone); $('#order-by').text(orderBy); @@ -43,6 +44,7 @@ $(document).ready(function(){ $.ajax({ type: 'GET', url: '/oqs/' + orderZone, + data: { 'status' : order_status }, success: function(res){ for (i = 0; i < res.length; i++) { var data = JSON.stringify(res[i]); diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 67f96a26..a6898e85 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -26,15 +26,29 @@ class Oqs::HomeController < BaseOqsController def get_order_items items = [] table_name = params[:table_id] + status = params[:status] dining = DiningFacility.find_by_name(table_name); - booking_id = dining.get_current_booking - BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo| - order=Order.find(bo.order_id); - order.order_items.each do |oi| - items.push(oi) - end + oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) + if status == "" + AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| + oi = OrderItem.find_by_item_code(aoi.item_code) + items.push(oi) + end + else + AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| + oi = OrderItem.find_by_item_code(aoi.item_code) + items.push(oi) + end end + # booking_id = dining.get_new_booking + # BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo| + # order=Order.find(bo.order_id); + # order.order_items.each do |oi| + # items.push(oi) + # end + # end + render :json => items.to_json end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index a3f8948f..6f898989 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -9,8 +9,24 @@ class DiningFacility < ApplicationRecord scope :active, -> {where(is_active: true)} def get_current_booking - puts "enter 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}' and checkout_at is null").limit(1) + puts "enter 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}' and checkout_at is null").limit(1) + + if booking.count > 0 then + return booking[0].booking_id + else + return nil + end + end + + def get_new_booking + # query for new + # if status + # to ask when req bill booking_status? + booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id is null and checkout_at is null").limit(1) + # else + # booking = Booking.where("dining_facility_id = #{self.id} and booking_status ='assign' and sale_id not null").limit(1) + # end if booking.count > 0 then return booking[0].booking_id diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index d6e21c64..86a781d2 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -18,19 +18,19 @@ class OrderQueueStation < ApplicationRecord oqs_stations.each do |oqs| #Get List of items - pq_items = JSON.parse(oqs.processing_items) - - if oqs.id == oqpbz.order_queue_station_id + #Loop through the processing items - pq_items.each do |pq_item| - #Processing through the looping items - order_items.each do |order_item| - if (pq_item == order_item.item_code) + pq_items.each do |pq_item| + #Processing through the looping items + order_items.each do |order_item| + if (pq_item == order_item.item_code) + if oqs.id == oqpbz.order_queue_station_id #Same Order_items can appear in two location. - AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - end + AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + end end end - end + end end #Print OQS where printing is require diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 1f13383d..18e72880 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -60,6 +60,7 @@

+