diff --git a/app/controllers/foodcourt/orders_controller.rb b/app/controllers/foodcourt/orders_controller.rb
index bf48bb2f..59fea916 100755
--- a/app/controllers/foodcourt/orders_controller.rb
+++ b/app/controllers/foodcourt/orders_controller.rb
@@ -292,4 +292,34 @@ class Foodcourt::OrdersController < BaseFoodcourtController
booking.save!
end
end
+
+ def cancel_order
+ order_id = params[:order_id]
+
+ if order_id.present?
+ order = Order.find(order_id)
+ booking = order.booking
+ if order && booking
+ if order.order_items.present?
+ order.order_items.update_all(order_item_status: 'cancelled')
+ end
+ order.status = 'cancelled'
+ order.save
+ booking.booking_status = 'cancelled'
+ booking.save
+ respond_to do |format|
+ format.json { render :json => { :status => true, :order_id => order_id } }
+ end
+ else
+ respond_to do |format|
+ format.json { render :json => { :status => false, :error_message => "Order not found" } }
+ end
+ end
+ else
+ respond_to do |format|
+ format.json { render :json => { :status => false, :error_message => "OrderID does not exist" } }
+ end
+ end
+ end
+
end
diff --git a/app/views/foodcourt/orders/app_orders.html.erb b/app/views/foodcourt/orders/app_orders.html.erb
index 6333e39e..08af8de2 100644
--- a/app/views/foodcourt/orders/app_orders.html.erb
+++ b/app/views/foodcourt/orders/app_orders.html.erb
@@ -411,13 +411,15 @@
<% if current_user.role != "waiter" && @status != "order"%>
+
<%end%>
<% if @status != "sale"%>
<% order_id = @pending.try(:orders).try(:first).try(:order_id) if @status == 'order' %>
-
+
+
<%end%>
<% elsif @pending && params[:active] == 'completed' %>
@@ -718,4 +720,37 @@ $('#reprint').on('click', function () {
});
}
+ $('#order_cancel').on('click', function () {
+ var order_id = $('#save_order_id').val();
+ swal({
+ title: "Alert",
+ text: "Are you sure want to cancel this order?",
+ type: "warning",
+ showCancelButton: true,
+ confirmButtonColor: "#DD6B55",
+ confirmButtonText: "Yes, cancel it!",
+ closeOnConfirm: false
+ }, function (isConfirm) {
+ if (isConfirm) {
+ $('.confirm').prop("disabled",true);
+ $.ajax({
+ type: "GET",
+ url: "/foodcourt/food_court/"+order_id+"/cancel_order" ,
+ data: {},
+ dataType: "json",
+ success: function(data) {
+ if(data.status == true)
+ {
+ window.location.href = '/foodcourt/app_orders';
+ }else{
+ alert("error")
+ swal("Alert!", "Error!", data.error_message);
+ location.reload();
+ }
+ }
+ });
+ }
+ });
+ });
+
diff --git a/config/routes.rb b/config/routes.rb
index 4abb2ab6..ac343262 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -741,6 +741,7 @@ scope "(:locale)", locale: /en|mm/ do
get '/food_court/:order_id/request_bill' => 'orders#request_bill', :as => 'food_court_request_bill'
get 'current_shift_order_count' => 'orders#current_shift_order_count', :as => 'food_court_order_count'
get '/:sale_id/reprint' => 'payments#reprint', :defaults => {:format => 'json'}
+ get '/food_court/:order_id/cancel_order' => 'orders#cancel_order', :as => 'cancel_order'
end
end
end