add void and cancel on pending bill

This commit is contained in:
nyanlinhtut
2023-04-21 15:13:33 +06:30
parent 6e4017ea4a
commit 7578286ee4
3 changed files with 67 additions and 1 deletions

View File

@@ -292,4 +292,34 @@ class Foodcourt::OrdersController < BaseFoodcourtController
booking.save! booking.save!
end end
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 end

View File

@@ -411,13 +411,15 @@
<% if current_user.role != "waiter" && @status != "order"%> <% if current_user.role != "waiter" && @status != "order"%>
<button type="button" id="pay" class="btn bg-blue btn-block">Pay</button> <button type="button" id="pay" class="btn bg-blue btn-block">Pay</button>
<button type="button" id="void" class="btn btn-block bg-red waves-effect" >VOID</button>
<%end%> <%end%>
<% if @status != "sale"%> <% if @status != "sale"%>
<!-- <button type="button" id="request_bills" class="btn btn-block bg-blue waves-effect">Req.Bill</button> --> <!-- <button type="button" id="request_bills" class="btn btn-block bg-blue waves-effect">Req.Bill</button> -->
<% order_id = @pending.try(:orders).try(:first).try(:order_id) if @status == 'order' %> <% order_id = @pending.try(:orders).try(:first).try(:order_id) if @status == 'order' %>
<button type="button" class="btn btn-block bg-blue waves-effect req_bill" >Req.Bill</button> <button type="button" class="btn btn-block bg-blue waves-effect req_bill" >Req.Bill</button>
<input type="hidden" id="save_order_id" value="<%=order_id%>"> <button type="button" id="order_cancel" class="btn btn-block bg-red waves-effect" >CANCEL</button>
<input type="hidden" id="save_order_id" value="<%=order_id%>">
<%end%> <%end%>
<% elsif @pending && params[:active] == 'completed' %> <% 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();
}
}
});
}
});
});
</script> </script>

View File

@@ -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 '/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 'current_shift_order_count' => 'orders#current_shift_order_count', :as => 'food_court_order_count'
get '/:sale_id/reprint' => 'payments#reprint', :defaults => {:format => 'json'} 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 end
end end