From 7578286ee44be497a1d139d518a623058c8ca0e2 Mon Sep 17 00:00:00 2001 From: nyanlinhtut Date: Fri, 21 Apr 2023 15:13:33 +0630 Subject: [PATCH] add void and cancel on pending bill --- .../foodcourt/orders_controller.rb | 30 +++++++++++++++ .../foodcourt/orders/app_orders.html.erb | 37 ++++++++++++++++++- config/routes.rb | 1 + 3 files changed, 67 insertions(+), 1 deletion(-) 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