diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 5ed26997..ed5defe3 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -23,17 +23,22 @@ $(document).ready(function(){ // setTimeout(function(){ // window.location.reload(1); // }, 10000); + // $oqs_count = document.getElementById("oqsBox").style.order =1; + // $("#oqsBox").css("order", 1); + $(".nav-completed").on("click", function(){ $("#completed").removeClass('hide') $(".oqs_append").addClass('hide') }); $(".oqs_click").on("click", function(){ - $("#completed").addClass('hide') - $(".oqs_append").removeClass('hide') - + $(".oqs_click").removeClass('oqs_active'); + $("#completed").addClass('hide'); + $(".oqs_append").removeClass('hide'); + $(this).addClass('oqs_active'); var oqs_id = $(this).find(".oqs-id").text(); var url = 'oqs/get_items/'+oqs_id; + show_details(url); }); //End Click @@ -52,7 +57,7 @@ $(document).ready(function(){ for(var field in data) { var price = parseFloat(data[field].price).toFixed(2); - if (data[field]["options"] == "[]") { + if (data[field]["options"] == "[]" || data[field]["options"] == "") { var options = ""; }else{ var options = data.options; diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 095ae4e0..a27b4afd 100644 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -276,6 +276,7 @@ $(function(){ disabled = "" status =""; + if(parseInt(jQuery.inArray(value[i], selected_item))!== -1){ status = "selected-attribute"; } @@ -417,7 +418,7 @@ $(function(){ }); //End Add Icon Click function show_item_detail(data){ - console.log(data) + qty = parseInt(data.attr('data-qty')); append = 0; price = parseFloat(data.attr('data-price')).toFixed(2); @@ -599,7 +600,7 @@ $(function(){ var item_row = $('.summary-items tbody tr'); $(item_row).each(function(i){ var order_item = {}; - console.log($(item_row[i]).attr('data-options')); + order_item.order_item_id = $(item_row[i]).attr('data-row'); order_item.item_instance_code = $(item_row[i]).attr('data-instance-code'); order_item.quantity = $(item_row[i]).children('#item_qty').text(); diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js index ce5ac871..55bfd46b 100644 --- a/app/assets/javascripts/cable.js +++ b/app/assets/javascripts/cable.js @@ -1,14 +1,14 @@ // Action Cable provides the framework to deal with WebSockets in Rails. // You can generate new channels where WebSocket features live using the `rails generate channel` command. -// + //= require action_cable //= require_self //= require_tree ./channels // Temp Disable -// (function() { -// this.App || (this.App = {}); +(function() { + this.App || (this.App = {}); -// App.cable = ActionCable.createConsumer(); + App.cable = ActionCable.createConsumer(); -// }).call(this); +}).call(this); diff --git a/app/assets/javascripts/channels/order.js b/app/assets/javascripts/channels/order.js new file mode 100644 index 00000000..eb73c5d1 --- /dev/null +++ b/app/assets/javascripts/channels/order.js @@ -0,0 +1,16 @@ +App.order = App.cable.subscriptions.create('OrderChannel', { +// App.messages = App.cable.subscriptions.create('MessagesChannel', { + + connected: function() {}, + + disconnected: function() {}, + + received: function(data) { + + $('.table_'+data.table.id).removeClass('green'); + $('.table_'+data.table.id).addClass('blue'); + + }, + +}); + diff --git a/app/assets/javascripts/channels/order_queue_station.js b/app/assets/javascripts/channels/order_queue_station.js index 85706bb5..5c7c710a 100644 --- a/app/assets/javascripts/channels/order_queue_station.js +++ b/app/assets/javascripts/channels/order_queue_station.js @@ -1,24 +1,76 @@ -// App.order_queue_station = App.cable.subscriptions.create("OrderQueueStationChannel", { -// connected: function() {}, +App.order_queue_station = App.cable.subscriptions.create('OrderQueueStationChannel', { +// App.messages = App.cable.subscriptions.create('MessagesChannel', { -// disconnected: function() {}, + connected: function() {}, -// received: function(message) { -// alert(message); -// }, + disconnected: function() {}, -// order: function(message) { -// return this.perform('order', { -// message: message -// }); -// } -// }); + received: function(data) { + // console.log(data.order); + var oqs_id = $('.oqs_active').attr('data-id'); + items = data.order; + for(var field in items) { + var price = parseFloat(items[field].price).toFixed(2); + if (items[field]["options"] == "[]" || data[field]["options"] == "") { + var options = ""; + }else{ + var options = items.options; + } + //for count + test = document.getElementsByClassName("oqs_count"); + + for (var i = 0; i < test.length; i++) { + oqs_count_id = $(".oqs_count"+i).attr("data-id"); + oqs_count = $(".oqs_count"+i).text(); + if ( oqs_count_id == items[field]["order_queue_station_id"]) { + oqs_count_total = +oqs_count +1 ; + $(".oqs_count"+i).text(oqs_count_total) + } + } + //end count + + var date = new Date(items[field]["created_at"]); + var show_date = date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear() + ' ' + date.getHours()+ ':' + date.getMinutes(); + + if (oqs_id == items[field]["order_queue_station_id"]) { + + row ='
' + +'
' + +'

' + +''+items[field]["table_type"]+'- ' + +''+ items[field]["zone"] +'' + +''+ items[field]["order_id"] +'- ' + +'

' + + +'

' + +''+ items[field]["item_name"] +'- ' + +''+ items[field]["qty"] +'- ' + +'

' + + +'

'+ options +'

' + + +'

' + +'Order at' + +''+ show_date +' - ' + + +''+ items[field]["item_order_by"] +' ' + +' ' + +'

' + + +' ' + +' ' + +'
' + + +'' + +'
'; + $('.oqs_append').append(row); + } + } + // $("[data-behaviour='message']").html(data.order); + }, + +}); -// $(function(){ -// $("#submit_order").on('click', function(event) { -// var orderData=$("#new_order").serializeObject(); -// App.order_station.order(orderData); -// //orderData=''; -// return event.preventDefault(); -// }); -// }); diff --git a/app/assets/stylesheets/OQS.scss b/app/assets/stylesheets/OQS.scss index 74a8032f..108c7541 100644 --- a/app/assets/stylesheets/OQS.scss +++ b/app/assets/stylesheets/OQS.scss @@ -25,3 +25,5 @@ font-size: 18px; margin: 0px 0px 5px 0px; } + + diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index a66bc071..a087eaec 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -7,7 +7,7 @@ module ApplicationCable end # Order Queue Station Channel - class OQSChannel < ActionCable::Channel::Base + class OrderQueueStationChannel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442f..9da60bf4 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,4 +1,7 @@ module ApplicationCable class Connection < ActionCable::Connection::Base + def connect + logger.add_tags "ActionCable" + end end end diff --git a/app/channels/order_channel.rb b/app/channels/order_channel.rb new file mode 100644 index 00000000..82b32b85 --- /dev/null +++ b/app/channels/order_channel.rb @@ -0,0 +1,11 @@ +class OrderChannel < ApplicationCable::Channel + def subscribed + stream_from "order_channel" + end + + def unsubscribed + stop_all_streams + # Any cleanup needed when channel is unsubscribed + end + +end diff --git a/app/channels/order_queue_station_channel.rb b/app/channels/order_queue_station_channel.rb index 8206c64b..b815a446 100644 --- a/app/channels/order_queue_station_channel.rb +++ b/app/channels/order_queue_station_channel.rb @@ -4,6 +4,7 @@ class OrderQueueStationChannel < ApplicationCable::Channel end def unsubscribed + stop_all_streams # Any cleanup needed when channel is unsubscribed end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index dae8b02f..af843c7e 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -131,6 +131,7 @@ class Oqs::HomeController < BaseOqsController 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}' #{oqs} ") query = query.where("df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) + .order("assigned_order_items.assigned_order_item_id desc") .group("assigned_order_items.assigned_order_item_id") end diff --git a/app/jobs/order_broadcast_job.rb b/app/jobs/order_broadcast_job.rb index 28a152ce..ac483993 100644 --- a/app/jobs/order_broadcast_job.rb +++ b/app/jobs/order_broadcast_job.rb @@ -1,9 +1,8 @@ class OrderBroadcastJob < ApplicationJob queue_as :default - def perform(message) - order = Order.find(message) # message come as order_id - ApplicationCable.server.broadcast "order_queue_station_channel", order: order + def perform(table) + ActionCable.server.broadcast "order_channel",table: table end end diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index 5b3423dc..ede2ea54 100644 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -4,14 +4,24 @@ class OrderQueueProcessorJob < ApplicationJob def perform(order_id, table_id) # Do something later #Order ID - order = Order.find(order_id) + order = Order.find(order_id) + assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) #Loop through the order stations and process the items #Execute orders and send to order stations if order oqs = OrderQueueStation.new oqs.process_order(order, table_id) end - + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order end + + # private + + # def render_order(assign_order) + # ApplicationController.renderer.render(partial: 'oqs/oqs_test', + # locals: { order: assign_order}) + # end +# Read more at https://www.pluralsight.com/guides/ruby-ruby-on-rails/creating-a-chat-using-rails-action-cable#TehYiuqlHDOXaQQk.99 + end diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index 3ac84077..34c97c6f 100644 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -17,6 +17,29 @@ class AssignedOrderItem < ApplicationRecord assigned_order_item.save end + def self.assigned_order_item_by_job(order_id) + order_item = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, + assigned_order_items.order_queue_station_id, + oqs.id as station_id, oqs.station_name, + oqs.is_active, oqpz.zone_id, + df.name as zone, df.type as table_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.order_id = '#{order_id}' AND assigned_order_items.delivery_status = false AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' ") + .order("assigned_order_items.assigned_order_item_id desc") + .group("assigned_order_items.assigned_order_item_id") + return order_item + end + private def generate_custom_id self.assigned_order_item_id = SeedGenerator.generate_id(self.class.name, "AOI") diff --git a/app/models/order.rb b/app/models/order.rb index 0551a1c9..1887585c 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -49,7 +49,7 @@ class Order < ApplicationRecord process_order_queue #send order to broadcast job - #send_order_broadcast + send_order_broadcast(booking) return true, booking @@ -214,9 +214,10 @@ class Order < ApplicationRecord #send order items and send to order queue - def send_order_broadcast + def send_order_broadcast(booking) + table = DiningFacility.find(booking.dining_facility_id) #Send to background job for processing - OrderBroadcastJob.perform_later(self.id) + OrderBroadcastJob.perform_later(table) end #Origami: Cashier : to view order Table diff --git a/app/views/oqs/_oqs_test.html.erb b/app/views/oqs/_oqs_test.html.erb new file mode 100644 index 00000000..32b749ad --- /dev/null +++ b/app/views/oqs/_oqs_test.html.erb @@ -0,0 +1,51 @@ +<% order.each do |qid|%> + +
+
+

+ <%= qid.table_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%> + \ No newline at end of file diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 824618e6..79e0e69f 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,58 +1,60 @@ -
-
-
- <%= form_tag oqs_root_path, :method => :get do %> -
- -
-
- -
- - <% end %> -
-

-
+
+
+
+ <%= form_tag oqs_root_path, :method => :get do %> +
+ +
+ +
+ +
+ <% end %> +
+
@@ -107,7 +109,6 @@ -
diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 4cdcf01d..9eb16a30 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -38,30 +38,30 @@
<% @tables.each do |table| %> - <% if table.status == 'occupied' %> - <% if table.get_booking.nil? %> -
-
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) -
-
+ <% if table.status == 'occupied' %> + <% if table.get_booking.nil? %> +
+
+ Zone <%= table.zone_id %>
+ Table <%= table.name %> ( <%= table.seater %> Seat ) +
+
+ <% else %> +
+
+ Zone <%= table.zone_id %>
+ Table <%= table.name %> ( <%= table.seater %> Seat ) +
+
+ <% end %> <% else %> -
+
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) + Zone <%= table.zone_id %>
+ Table <%= table.name %> ( <%= table.seater %> Seat )
<% end %> - <% else %> -
-
- Zone <%= table.zone_id %>
- Table <%= table.name %> ( <%= table.seater %> Seat ) -
-
- <% end %> <% end %>
@@ -70,19 +70,19 @@
<% @rooms.each do |room| %> - <% if room.status == 'occupied' %> -
-
- <%= room.name %> -
-
- <% else %> -
-
- <%= room.name %> -
-
- <% end %> + <% if room.status == 'occupied' %> +
+
+ <%= room.name %> +
+
+ <% else %> +
+
+ <%= room.name %> +
+
+ <% end %> <% end %>
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 2105918b..2d7cb895 100644 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -59,7 +59,7 @@
<% end %> <% else %> -
+
<%= table.name %>
@@ -86,7 +86,7 @@
<% else %> -
+
<%= room.name %>
diff --git a/config/cable.yml b/config/cable.yml index 0bbde6f7..a383c5af 100644 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,9 +1,7 @@ -development: - adapter: async - -test: - adapter: async - -production: +redis: &redis adapter: redis url: redis://localhost:6379/1 + +production: *redis +development: *redis +test: *redis \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 4d8fc580..4c681ee6 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -45,6 +45,8 @@ Rails.application.configure do # Suppress logger output for asset requests. config.assets.quiet = true + config.web_console.whiny_requests = false + # Raises error for missing translations # config.action_view.raise_on_missing_translations = true @@ -53,5 +55,5 @@ Rails.application.configure do config.file_watcher = ActiveSupport::EventedFileUpdateChecker # Set Cable URL - # config.action_cable.url = "ws://192.168.1.140:3002/cable" + config.action_cable.url = "ws://192.168.1.39:3002/cable" end diff --git a/config/routes.rb b/config/routes.rb index 65b7ab8a..95315b8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ Rails.application.routes.draw do mount Sidekiq::Web => '/kiq' # Action Cable Creation - # mount ActionCable.server => "/cable" + mount ActionCable.server => "/cable" #--------- SmartSales Installation ------------# get 'install' => 'install#index' diff --git a/public/image/menu_images/images__4_.jpg b/public/image/menu_images/images__4_.jpg new file mode 100644 index 00000000..d47dafb7 Binary files /dev/null and b/public/image/menu_images/images__4_.jpg differ diff --git a/public/image/menu_images/images__5_.jpg b/public/image/menu_images/images__5_.jpg new file mode 100644 index 00000000..08eb6859 Binary files /dev/null and b/public/image/menu_images/images__5_.jpg differ