From f67d4197ec22e22f033c7c5c716f4d25e84a0e35 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 7 Sep 2017 15:35:00 +0630 Subject: [PATCH] add bill channel for req bill --- app/assets/javascripts/channels/bill.js | 17 +++++++++++++++++ app/channels/application_cable/channel.rb | 4 ++++ app/channels/bill_channel.rb | 10 ++++++++++ app/channels/order_channel.rb | 1 - app/controllers/api/bill_controller.rb | 9 +++++++++ app/jobs/bill_broadcast_job.rb | 7 +++++++ app/jobs/order_broadcast_job.rb | 1 - app/jobs/order_queue_processor_job.rb | 2 +- 8 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/channels/bill.js create mode 100644 app/channels/bill_channel.rb create mode 100644 app/jobs/bill_broadcast_job.rb diff --git a/app/assets/javascripts/channels/bill.js b/app/assets/javascripts/channels/bill.js new file mode 100644 index 00000000..0a9e7821 --- /dev/null +++ b/app/assets/javascripts/channels/bill.js @@ -0,0 +1,17 @@ +App.order = App.cable.subscriptions.create('BillChannel', { +// App.messages = App.cable.subscriptions.create('MessagesChannel', { + + connected: function() {}, + + disconnected: function() {}, + + received: function(data) { + + $('.table_'+data.table.id).removeClass('blue'); + $('.table_'+data.table.id).addClass('red'); + $('.new_text_'+data.table.id).removeClass('hide') + + }, + +}); + diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index a087eaec..b2cb741f 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -11,4 +11,8 @@ module ApplicationCable end + # Order Queue Station Channel + class BillChannel < ActionCable::Channel::Base + + end end diff --git a/app/channels/bill_channel.rb b/app/channels/bill_channel.rb new file mode 100644 index 00000000..ed5efbe6 --- /dev/null +++ b/app/channels/bill_channel.rb @@ -0,0 +1,10 @@ +class BillChannel < ApplicationCable::Channel + def subscribed + stream_from "bill_channel" + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + stop_all_streams + end +end diff --git a/app/channels/order_channel.rb b/app/channels/order_channel.rb index 82b32b85..d261e48b 100644 --- a/app/channels/order_channel.rb +++ b/app/channels/order_channel.rb @@ -7,5 +7,4 @@ class OrderChannel < ApplicationCable::Channel stop_all_streams # Any cleanup needed when channel is unsubscribed end - end diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 2b323d0f..ac12e453 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -7,8 +7,11 @@ class Api::BillController < Api::ApiController @error_message = "Order ID or Booking ID is require to request for a bill." if ShiftSale.current_shift #create Bill by Booking ID + table = 0 if (params[:booking_id]) booking = Booking.find(params[:booking_id]) + # for Job + table = DiningFacility.find(booking.dining_facility_id) if booking if booking.sale_id.nil? @@ -23,8 +26,14 @@ class Api::BillController < Api::ApiController elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee, get_cashier) + + # for Job + booking = Booking.find_by_sale_id(@sale_id) + table = DiningFacility.find(booking.dining_facility_id) end Promotion.promo_activate(@sale) + + BillBroadcastJob.perform_later(table) else @status = false @error_message = "No Current Open Shift" diff --git a/app/jobs/bill_broadcast_job.rb b/app/jobs/bill_broadcast_job.rb new file mode 100644 index 00000000..d6be4d0a --- /dev/null +++ b/app/jobs/bill_broadcast_job.rb @@ -0,0 +1,7 @@ +class BillBroadcastJob < ApplicationJob + queue_as :default + + def perform(table) + ActionCable.server.broadcast "bill_channel",table: table + end +end diff --git a/app/jobs/order_broadcast_job.rb b/app/jobs/order_broadcast_job.rb index ac483993..55ba2f21 100644 --- a/app/jobs/order_broadcast_job.rb +++ b/app/jobs/order_broadcast_job.rb @@ -3,6 +3,5 @@ class OrderBroadcastJob < ApplicationJob 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 ede2ea54..96b08220 100644 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -7,7 +7,7 @@ class OrderQueueProcessorJob < ApplicationJob 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