fixed set menu item update and individual payment
This commit is contained in:
@@ -25,6 +25,13 @@ class Oqs::EditController < BaseOqsController
|
|||||||
order_item.item_order_by = current_user.name
|
order_item.item_order_by = current_user.name
|
||||||
order_item.qty = qty_weight
|
order_item.qty = qty_weight
|
||||||
order_item.remark = remarks
|
order_item.remark = remarks
|
||||||
|
if !order_item.set_menu_items.nil?
|
||||||
|
instance_item_sets = JSON.parse(order_item.set_menu_items)
|
||||||
|
instance_item_sets.each_with_index do |instance_item, instance_index|
|
||||||
|
instance_item_sets[instance_index]["quantity"] = qty_weight
|
||||||
|
end
|
||||||
|
order_item.set_menu_items = instance_item_sets.to_json
|
||||||
|
end
|
||||||
order_item.save
|
order_item.save
|
||||||
|
|
||||||
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
|
||||||
|
|||||||
70
app/controllers/origami/split_bill_controller.rb
Normal file → Executable file
70
app/controllers/origami/split_bill_controller.rb
Normal file → Executable file
@@ -77,6 +77,10 @@ class Origami::SplitBillController < BaseOrigamiController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
order_ids = params[:order_ids]
|
order_ids = params[:order_ids]
|
||||||
|
arr_order_ids = nil
|
||||||
|
if !params[:arr_order_ids].nil?
|
||||||
|
arr_order_ids = JSON.parse(params[:arr_order_ids])
|
||||||
|
end
|
||||||
orders = nil
|
orders = nil
|
||||||
if !params[:orders].empty?
|
if !params[:orders].empty?
|
||||||
orders = JSON.parse(params[:orders])
|
orders = JSON.parse(params[:orders])
|
||||||
@@ -136,14 +140,15 @@ class Origami::SplitBillController < BaseOrigamiController
|
|||||||
order_id_count = 0
|
order_id_count = 0
|
||||||
order_id = nil
|
order_id = nil
|
||||||
|
|
||||||
order_items.each do |order_item|
|
arr_order_ids.each do |order|
|
||||||
order_item_count = 0
|
order.each do |odr|
|
||||||
order = Order.find(order_item["order_id"])
|
data = Order.find(odr[0])
|
||||||
if order.order_items.count == 1
|
if data.order_items.count == odr[1]
|
||||||
order_id = order.id
|
order_id = odr[0]
|
||||||
order_id_count += 1
|
order_id_count += 1
|
||||||
else
|
else
|
||||||
order_item_count += 1
|
order_item_count += 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -158,10 +163,12 @@ class Origami::SplitBillController < BaseOrigamiController
|
|||||||
puts "order_id_count > 1"
|
puts "order_id_count > 1"
|
||||||
|
|
||||||
updated_order_id = Array.new
|
updated_order_id = Array.new
|
||||||
order_ids.each do |odr_id|
|
arr_order_ids.each do |order|
|
||||||
odr = Order.find(odr_id)
|
order.each do |odr|
|
||||||
if odr.order_items.count > 1
|
data = Order.find(odr[0])
|
||||||
updated_order_id.push(odr_id)
|
if data.order_items.count != odr[1]
|
||||||
|
updated_order_id.push(odr[0])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -266,12 +273,32 @@ class Origami::SplitBillController < BaseOrigamiController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# puts order_ids
|
if order_ids.count == 1 && order_item_count == 1
|
||||||
if order_ids.count == 1 && order_id_count == 0 && order_item_count == 1
|
if order_id_count == 0
|
||||||
BookingOrder.find_by_order_id(order_ids[0]).delete
|
customer = Customer.find(params[:customer_id])
|
||||||
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
|
order_type = "dine_in"
|
||||||
order_items.each do |order_item|
|
if !customer.nil?
|
||||||
update_order_item(order_ids[0], order_item)
|
if customer.customer_type == "Takeaway"
|
||||||
|
order_type = "takeaway"
|
||||||
|
elsif customer.customer_type == "Delivery"
|
||||||
|
order_type = "delivery"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# begin
|
||||||
|
order = create_order(params,order_type,order_items.count,current_user)
|
||||||
|
|
||||||
|
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
|
||||||
|
|
||||||
|
order_items.each do |order_item|
|
||||||
|
update_order_item(order.order_id, order_item)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
BookingOrder.find_by_order_id(order_ids[0]).delete
|
||||||
|
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
|
||||||
|
order_items.each do |order_item|
|
||||||
|
update_order_item(order_ids[0], order_item)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
customer = Customer.find(params[:customer_id])
|
customer = Customer.find(params[:customer_id])
|
||||||
@@ -366,4 +393,11 @@ class Origami::SplitBillController < BaseOrigamiController
|
|||||||
|
|
||||||
render :json => { status: true }
|
render :json => { status: true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#Shop Name in Navbor
|
||||||
|
helper_method :shop_detail
|
||||||
|
def shop_detail
|
||||||
|
@shop = Shop.first
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -491,8 +491,8 @@ class ReceiptBillA5Pdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
|
|
||||||
#individual payment per person
|
#individual payment per person
|
||||||
def individual_payment(sale_data, survey, precision, delimiter)
|
def individual_payment(sale_data, precision, delimiter)
|
||||||
per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
|
per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
move_down line_move
|
move_down line_move
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
|
|||||||
@@ -494,8 +494,8 @@ class ReceiptBillPdf < Prawn::Document
|
|||||||
end
|
end
|
||||||
|
|
||||||
#individual payment per person
|
#individual payment per person
|
||||||
def individual_payment(sale_data, survey, precision, delimiter)
|
def individual_payment(sale_data, precision, delimiter)
|
||||||
per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
|
per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i
|
||||||
stroke_horizontal_rule
|
stroke_horizontal_rule
|
||||||
move_down line_move
|
move_down line_move
|
||||||
y_position = cursor
|
y_position = cursor
|
||||||
|
|||||||
23
app/views/origami/split_bill/index.html.erb
Normal file → Executable file
23
app/views/origami/split_bill/index.html.erb
Normal file → Executable file
@@ -623,20 +623,39 @@ function orderItemSplitBillProcess(cnt_items){
|
|||||||
}
|
}
|
||||||
|
|
||||||
var order_ids = [];
|
var order_ids = [];
|
||||||
|
var arr_order_ids = [];
|
||||||
if(order_items!=undefined && order_items!=null){
|
if(order_items!=undefined && order_items!=null){
|
||||||
$.each(order_items,function(key,value){
|
$.each(order_items,function(key,value){
|
||||||
|
var orderIds = {};
|
||||||
if($.inArray(value.order_id,order_ids) == -1){
|
if($.inArray(value.order_id,order_ids) == -1){
|
||||||
order_ids.push(value.order_id);
|
order_ids.push(value.order_id);
|
||||||
|
orderIds[value.order_id] = 1;
|
||||||
|
arr_order_ids.push(orderIds);
|
||||||
|
}else{
|
||||||
|
if(arr_order_ids != null & arr_order_ids!=""){
|
||||||
|
if(arr_order_ids.length > 0){
|
||||||
|
$.each(arr_order_ids, function(k,val){
|
||||||
|
$.each(val,function(kk,vval){
|
||||||
|
if((val[kk]!= undefined) && (kk == value.order_id)){
|
||||||
|
val[kk] += 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
arr_order_ids[k] = val;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// console.log(JSON.stringify(arr_order_ids));
|
||||||
|
|
||||||
var ajax_url = "/origami/split_bills";
|
var ajax_url = "/origami/split_bills";
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: {'dining_id' : dining_id, 'type': type, 'customer_id' : customer_id, 'booking_id' : booking_id, 'order_ids' : order_ids, 'order_items' : JSON.stringify(order_items), 'orders' : ''},
|
data: {'dining_id' : dining_id, 'type': type, 'customer_id' : customer_id, 'booking_id' : booking_id, 'order_ids' : order_ids, 'arr_order_ids': JSON.stringify(arr_order_ids), 'order_items' : JSON.stringify(order_items), 'orders' : ''},
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (!result.status) {
|
if (!result.status) {
|
||||||
swal("Information!", result.error_message);
|
swal("Information!", result.error_message);
|
||||||
@@ -669,7 +688,7 @@ function orderSplitBillProcess(cnt_orders){
|
|||||||
type: "POST",
|
type: "POST",
|
||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
dataType: 'JSON',
|
dataType: 'JSON',
|
||||||
data: {'dining_id' : dining_id, 'type': type, 'customer_id' : customer_id, 'booking_id' : booking_id, 'order_ids' : [], 'order_items' : '', 'orders' : JSON.stringify(orders)},
|
data: {'dining_id' : dining_id, 'type': type, 'customer_id' : customer_id, 'booking_id' : booking_id, 'order_ids' : [], 'order_items' : '', 'orders' : JSON.stringify(orders), 'arr_order_ids': []},
|
||||||
success: function (result) {
|
success: function (result) {
|
||||||
if (!result.status) {
|
if (!result.status) {
|
||||||
swal("Information!", result.error_message);
|
swal("Information!", result.error_message);
|
||||||
|
|||||||
Reference in New Issue
Block a user