From 4501762300174a235898fe86e0e6180c71177204 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 10 Aug 2017 14:50:47 +0630 Subject: [PATCH 1/2] start for oqs --- app/controllers/oqs/backhome_controller.rb | 126 +++++++++++++ app/controllers/oqs/home_controller.rb | 39 ++-- app/views/oqs/home/bkindex.html.erb | 197 +++++++++++++++++++++ app/views/oqs/home/index.html.erb | 20 +-- 4 files changed, 351 insertions(+), 31 deletions(-) create mode 100644 app/controllers/oqs/backhome_controller.rb create mode 100644 app/views/oqs/home/bkindex.html.erb diff --git a/app/controllers/oqs/backhome_controller.rb b/app/controllers/oqs/backhome_controller.rb new file mode 100644 index 00000000..cef7c6b6 --- /dev/null +++ b/app/controllers/oqs/backhome_controller.rb @@ -0,0 +1,126 @@ +class Oqs::HomeController < BaseOqsController + def index + queue_stations=OrderQueueStation.all + + # Query for OQS with delivery status false + @queue_items_details = queue_items_query(false) + + # Query for OQS with delivery status true + @queue_completed_item = completed_order + + @queue_stations_items=Array.new + + # Calculate Count for each station tab + queue_stations.each do |que| + i = 0 + zone_id = 0 + @queue_items_details.each do |qid| + dining = DiningFacility.find_by_name(qid.zone) + que.order_queue_process_by_zones.each do |qz| + if qid.station_id == qz.order_queue_station_id && qid.zone_id == qz.zone_id + zone_id = qid.zone_id + i=i+1 + end + end + end + @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) + end + + # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) + @queue_stations_items + end + + # Get Order items + def get_order_items + items = [] + table_name = params[:table_id] + status = params[:status] + dining = DiningFacility.find_by_name(table_name); + # 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 = Booking.find_by_dining_facility_id(dining.id) + BookingOrder.where("booking_id='#{ booking.booking_id }'").find_each do |bo| + order=Order.find(bo.order_id) + order.order_items.each do |oi| + 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 + + def show + end + + # update delivery status when complete click + def update_delivery_status + removed_item = [] + assigned_item_id = params[:id] + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + + # update delivery status for completed same order items + assigned_items.each do |ai| + ai.delivery_status=true + ai.save + removed_item.push(ai.assigned_order_item_id) + end + render :json => removed_item.to_json + end + + # Query for OQS with delivery status + def queue_items_query(status) + AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id + left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id + left join orders as od ON od.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") + .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}'") + .group("assigned_order_items.assigned_order_item_id") + .order("assigned_order_items.created_at") + end + + # Completed Order + def completed_order + AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id + left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id + left join orders as od ON od.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") + .where("assigned_order_items.delivery_status = true AND odt.price <> 0 AND assigned_order_items.created_at between '#{Time.now.beginning_of_day.utc}' and '#{Time.now.end_of_day.utc}'") + .group("assigned_order_items.order_id") + .limit(20) + .order("assigned_order_items.created_at") + + + # completed_order = AssignedOrderItem.group(:order_id).where('delivery_status=true'); + end + +end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index cef7c6b6..c4c801fa 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -1,33 +1,34 @@ class Oqs::HomeController < BaseOqsController def index - queue_stations=OrderQueueStation.all + + @queue_stations = OrderQueueStation.all # Query for OQS with delivery status false - @queue_items_details = queue_items_query(false) + # @queue_items_details = queue_items_query(false) # Query for OQS with delivery status true @queue_completed_item = completed_order - @queue_stations_items=Array.new + # @queue_stations_items=Array.new # Calculate Count for each station tab - queue_stations.each do |que| - i = 0 - zone_id = 0 - @queue_items_details.each do |qid| - dining = DiningFacility.find_by_name(qid.zone) - que.order_queue_process_by_zones.each do |qz| - if qid.station_id == qz.order_queue_station_id && qid.zone_id == qz.zone_id - zone_id = qid.zone_id - i=i+1 - end - end - end - @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) - end + # @queue_stations.each do |que| + # i = 0 + # zone_id = 0 + # @queue_items_details.each do |qid| + # dining = DiningFacility.find_by_name(qid.zone) + # que.order_queue_process_by_zones.each do |qz| + # if qid.station_id == qz.order_queue_station_id && qid.zone_id == qz.zone_id + # zone_id = qid.zone_id + # i=i+1 + # end + # end + # end + # @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) + # end - # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) - @queue_stations_items + # # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) + # @queue_stations_items end # Get Order items diff --git a/app/views/oqs/home/bkindex.html.erb b/app/views/oqs/home/bkindex.html.erb new file mode 100644 index 00000000..be62d989 --- /dev/null +++ b/app/views/oqs/home/bkindex.html.erb @@ -0,0 +1,197 @@ +
+ +
+ + + + +
+ +
+
+ <% + @queue_completed_item.each do |qid| + %> +
+
+

+ <%= qid.type %> - + <%= qid.zone %> + <%= qid.order_id %> +

+

+ + <%= qid.item_name %> + [x + + <%= qid.qty %> + ] +

+ +

<%= qid.options == "[]"? "" : qid.options %>

+ +

+ Order at + + <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> + - + + <%= qid.item_order_by %> + + +

+ + + +
+
+ <% + end + %> +
+
+ + + + <% + @queue_stations_items.each do |qsi| + %> + +
role="tabpanel"> + +
+ <% + @queue_items_details.each do |qid| + if qid.price != 0 + if qid.zone_id == qsi[:zone_id] && qid.station_name == qsi[:station_name] + %> +
+
+

+ <%= qid.type %> - + <%= qid.zone %> + <%= qid.order_id %> +

+

+ <%= qid.item_name %> [x + <%= qid.qty %> ] +

+ +

<%= qid.options == "[]"? "" : qid.options %>

+ +

+ Order at + + <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> + - + + <%= qid.item_order_by %> + + +

+ + + +
+ +
+ <% + end + end + end + %> + + +
+
+ + <% end %> + +
+
+ + +
+
+
+
ORDER DETAILS - Table
+
+
+
+ + + + + + + + + + + + + + + + + +
Order ByOrder At + Customer +
Table/Room
+
+
+ + + + + + + + + + +
ItemsQTY
+
+ +
+
+
+ + +
+ + + Back + + +
+
+ diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 71077ec4..ed27aa13 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,29 +1,25 @@
-
@@ -193,4 +144,82 @@
+ diff --git a/config/routes.rb b/config/routes.rb index 0753b64b..599ec8c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -198,6 +198,8 @@ Rails.application.routes.draw do # Pass assigned_order_item_id get 'print/print/:id', to: "print#print" get 'print/print_order_summary/:id', to: "print#print_order_summary" + + get "/get_items/:id" =>"home#get_items_by_oqs", :as => "get_order_items_by_oqs" #dashboard # end