'
+ oos_item + oos_header
- +'
+ m.categories.forEach(c =>
+ c.items.forEach(i =>
+ i.instances.forEach(instance => {
+ if (instance.code == item_code) {
+ if (data.status == true) {
+ instance.out_of_stock = true;
+ oos_header = '
OUT OF STOCK
';
+ $(item_code_id).css({"height": "100%", "pointer-events": "none", "opacity": "0.4"});
+ $(oos_header).insertBefore($(oos_id));
+ } else {
+ instance.out_of_stock = false;
+ $(item_code_id).css({"height": "", "pointer-events": "", "opacity": ""});
+ $(rm_oos).remove();
+ }
+ }
+ })
+ )
+ )
+ );
+ localStorage.setItem('menus', JSON.stringify(menus));
+ }
+ }
+ }
+});
diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb
index 89fe509d..fddbee21 100755
--- a/app/channels/application_cable/channel.rb
+++ b/app/channels/application_cable/channel.rb
@@ -8,16 +8,16 @@ module ApplicationCable
# Order Queue Station Channel
class OrderQueueStationChannel < ActionCable::Channel::Base
-
+
end
# Order Queue Station Channel
class BillChannel < ActionCable::Channel::Base
-
+
end
# Call Waiter Channel
class CallWaiterChannel < ActionCable::Channel::Base
-
+
end
end
diff --git a/app/channels/out_of_stock_channel.rb b/app/channels/out_of_stock_channel.rb
new file mode 100644
index 00000000..6eb2d31f
--- /dev/null
+++ b/app/channels/out_of_stock_channel.rb
@@ -0,0 +1,10 @@
+class OutOfStockChannel < ApplicationCable::Channel
+ def subscribed
+ stream_from "out_of_stock_channel"
+ end
+
+ def unsubscribed
+ stop_all_streams
+ # Any cleanup needed when channel is unsubscribed
+ end
+end
diff --git a/app/controllers/settings/out_of_stock_controller.rb b/app/controllers/settings/out_of_stock_controller.rb
index beb51bd2..64c7e25c 100644
--- a/app/controllers/settings/out_of_stock_controller.rb
+++ b/app/controllers/settings/out_of_stock_controller.rb
@@ -27,6 +27,7 @@ class Settings::OutOfStockController < ApplicationController
item_instance.update(is_out_of_stock: true)
items_arr.each do |i|
OutOfStock.create_out_of_stock(date,i)
+ ActionCable.server.broadcast "out_of_stock_channel", item_instance_code: i, status: true
end
elsif item_instance.first.is_out_of_stock?
item_instance.update(is_out_of_stock: false)
@@ -41,6 +42,8 @@ class Settings::OutOfStockController < ApplicationController
item_instance = MenuItemInstance.find_by_id(params[:id])
unless item_instance.nil?
item_instance.update(is_out_of_stock: false)
+ ActionCable.server.broadcast "out_of_stock_channel", item_instance_code: item_instance.item_instance_code, status: false
+ OutOfStock.where(item_instance_code: item_instance.item_instance_code, created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).destroy_all
flash[:message] = 'Out of stock was successfully destroyed.'
render :json => {:status=> "Success", :url => settings_out_of_stock_index_url }.to_json
end
@@ -48,9 +51,15 @@ class Settings::OutOfStockController < ApplicationController
def reset_all
item_instance = MenuItemInstance.where(is_out_of_stock: true)
- item_instance.update(is_out_of_stock: false)
- flash[:message] = 'Out of stock was successfully destroyed.'
- render :json => {:status=> "Success", :url => settings_out_of_stock_index_url }.to_json
+ unless item_instance.nil?
+ item_instance.update(is_out_of_stock: false)
+ item_instance.each do |i|
+ ActionCable.server.broadcast "out_of_stock_channel", item_instance_code: i.item_instance_code, status: false
+ OutOfStock.where(item_instance_code: i.item_instance_code, created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).destroy_all
+ end
+ flash[:message] = 'Out of stock was successfully destroyed.'
+ render :json => {:status=> "Success", :url => settings_out_of_stock_index_url }.to_json
+ end
end
private