diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 71ce212d..46c7e236 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -11,6 +11,7 @@ class Origami::HomeController < BaseOrigamiController @customers = Customer.pluck("customer_id, name") @shop = shop_detail + @occupied_table = DiningFacility.where("status='occupied'").count; # @shift = ShiftSale.current_open_shift(current_user.id) end diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 594e4b7c..f66c4017 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -6,12 +6,17 @@ class Origami::PendingOrderController < BaseOrigamiController @order = Sale.pending_order @completed = Sale.completed_sale("quick_service") @customers = Customer.pluck("customer_id, name") + + @occupied_table = @sale.count.length + @order.count.length end def show @sales = Sale.pending_sale @orders = Sale.pending_order @completed = Sale.completed_sale("quick_service") @customers = Customer.pluck("customer_id, name") + + @occupied_table = @sales.count.length + @orders.count.length + @id = params[:sale_id] if(@id[0,3] == "SAL") @sale = Sale.find(@id) @@ -50,6 +55,9 @@ class Origami::PendingOrderController < BaseOrigamiController @orders = Sale.pending_order @completed = Sale.completed_sale("quick_service") @customers = Customer.pluck("customer_id, name") + + @occupied_table = @sales.count.length + @orders.count.length + @id = params[:sale_id] @sale = Sale.find(@id) @@ -78,6 +86,9 @@ class Origami::PendingOrderController < BaseOrigamiController @sales = Sale.pending_sale @orders = Sale.pending_order @completed = Sale.completed_sale("quick_service") + + @occupied_table = @sales.count.length + @orders.count.length + @id = params[:sale_id] @customers = Customer.pluck("customer_id, name") diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 5c374475..6e5167e5 100755 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -184,7 +184,7 @@ - + <%end%> @@ -319,19 +319,26 @@ $('#cash_out').on('click',function(){ $('#close_cashier').on('click',function(e){ e.preventDefault(); // Prevent the href from redirecting directly var linkURL = '/origami/shift/cashier/close'; - warnBeforeRedirect(linkURL); + occupied_count = $(this).data("count"); + warnBeforeRedirect(linkURL,occupied_count); }) $('#back').on('click',function(){ window.location.href = '/origami/dashboard'; }) -function warnBeforeRedirect(linkURL) { +function warnBeforeRedirect(linkURL,occupied_count) { + if (occupied_count>0) { + text = "
We have "+occupied_count+" occupied table
.
Are you sure you want to close cashier? "; + }else{ + text = "Are you sure you want to close cashier?"; + } swal({ title: "Alert!", - text: "Are you sure you want to close cashier?", + text: text, type: "warning", - showCancelButton: true + showCancelButton: true, + html: true }, function() { // Redirect the user window.location.href = linkURL; diff --git a/app/views/origami/pending_order/completed_sale.html.erb b/app/views/origami/pending_order/completed_sale.html.erb index 7540a1e0..bc4719f9 100644 --- a/app/views/origami/pending_order/completed_sale.html.erb +++ b/app/views/origami/pending_order/completed_sale.html.erb @@ -224,7 +224,7 @@ <% end %> <% end %> - + <% end %> @@ -337,8 +337,30 @@ $(document).ready(function(){ $('#close_cashier').on('click',function(e){ e.preventDefault(); // Prevent the href from redirecting directly var linkURL = '/origami/shift/quick_service/close'; - warnBeforeRedirect(linkURL); + occupied_count = $(this).data("count"); + warnBeforeRedirect(linkURL,occupied_count); }); + + + function warnBeforeRedirect(linkURL,occupied_count) { + + if (occupied_count>0) { + text = "
We have "+occupied_count+" pending orders and sales
.
Are you sure you want to close cashier? "; + }else{ + text = "Are you sure you want to close cashier?"; + } + swal({ + title: "Alert!", + text: text, + type: "warning", + showCancelButton: true, + html: true + }, function() { + // Redirect the user + window.location.href = linkURL; + }); + } + $('#cash_in').on('click',function(){ window.location.href = '/origami/quick_service/cash_ins'; }) diff --git a/app/views/origami/pending_order/credit_sale.html.erb b/app/views/origami/pending_order/credit_sale.html.erb index aefc3c98..f8fd7ceb 100644 --- a/app/views/origami/pending_order/credit_sale.html.erb +++ b/app/views/origami/pending_order/credit_sale.html.erb @@ -215,7 +215,7 @@ <% if current_user.role != "waiter" %> - + <% end %> @@ -255,7 +255,9 @@ $(document).ready(function(){ $('#close_cashier').on('click',function(e){ e.preventDefault(); // Prevent the href from redirecting directly var linkURL = '/origami/shift/quick_service/close'; - warnBeforeRedirect(linkURL); + occupied_count = $(this).data("count"); + + warnBeforeRedirect(linkURL,occupied_count); }); $('#cash_in').on('click',function(){ @@ -270,5 +272,25 @@ $(document).ready(function(){ var sale_id = '<%= @sale.sale_id %>'; window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/credit_payment"; }); + + + function warnBeforeRedirect(linkURL,occupied_count) { + + if (occupied_count>0) { + text = "
We have "+occupied_count+" pending orders and sales
.
Are you sure you want to close cashier? "; + }else{ + text = "Are you sure you want to close cashier?"; + } + swal({ + title: "Alert!", + text: text, + type: "warning", + showCancelButton: true, + html: true + }, function() { + // Redirect the user + window.location.href = linkURL; + }); + } }); diff --git a/app/views/origami/pending_order/index.html.erb b/app/views/origami/pending_order/index.html.erb index f785449f..a6e91d63 100644 --- a/app/views/origami/pending_order/index.html.erb +++ b/app/views/origami/pending_order/index.html.erb @@ -91,7 +91,7 @@ <%= t("views.btn.back") %> <% if current_user.role != "waiter" %> - + <% end %> @@ -135,7 +135,8 @@ $('#close_cashier').on('click',function(e){ e.preventDefault(); // Prevent the href from redirecting directly var linkURL = '/origami/shift/quick_service/close'; - warnBeforeRedirect(linkURL); + occupied_count = $(this).data("count"); + warnBeforeRedirect(linkURL,occupied_count); }); $('#cash_in').on('click',function(){ @@ -147,11 +148,18 @@ }); }); - function warnBeforeRedirect(linkURL) { + function warnBeforeRedirect(linkURL,occupied_count) { + + if (occupied_count>0) { + text = "
We have "+occupied_count+" pending orders and sales
.
Are you sure you want to close cashier? "; + }else{ + text = "Are you sure you want to close cashier?"; + } swal({ title: "Alert!", - text: "Are you sure you want to close cashier?", + text: text, type: "warning", + html: true, showCancelButton: true }, function() { // Redirect the user diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index 9658f1c5..bf0e7d3a 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -224,7 +224,7 @@ <%end%> <% if current_user.role != "waiter" %> - + <% end %> @@ -353,15 +353,23 @@ $(document).ready(function(){ $('#close_cashier').on('click',function(e){ e.preventDefault(); // Prevent the href from redirecting directly var linkURL = '/origami/shift/quick_service/close'; - warnBeforeRedirect(linkURL); + occupied_count = $(this).data("count"); + warnBeforeRedirect(linkURL,occupied_count); }); - function warnBeforeRedirect(linkURL) { + function warnBeforeRedirect(linkURL,occupied_count) { + + if (occupied_count>0) { + text = "
We have "+occupied_count+" pending orders and sales
.
Are you sure you want to close cashier? "; + }else{ + text = "Are you sure you want to close cashier?"; + } swal({ title: "Alert!", - text: "Are you sure you want to close cashier?", + text: text, type: "warning", - showCancelButton: true + showCancelButton: true, + html: true }, function() { // Redirect the user window.location.href = linkURL;