Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant
This commit is contained in:
@@ -25,6 +25,13 @@ class Oqs::EditController < BaseOqsController
|
||||
order_item.item_order_by = current_user.name
|
||||
order_item.qty = qty_weight
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
if !params[:orders].empty?
|
||||
orders = JSON.parse(params[:orders])
|
||||
@@ -136,14 +140,15 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
order_id_count = 0
|
||||
order_id = nil
|
||||
|
||||
order_items.each do |order_item|
|
||||
order_item_count = 0
|
||||
order = Order.find(order_item["order_id"])
|
||||
if order.order_items.count == 1
|
||||
order_id = order.id
|
||||
order_id_count += 1
|
||||
else
|
||||
order_item_count += 1
|
||||
arr_order_ids.each do |order|
|
||||
order.each do |odr|
|
||||
data = Order.find(odr[0])
|
||||
if data.order_items.count == odr[1]
|
||||
order_id = odr[0]
|
||||
order_id_count += 1
|
||||
else
|
||||
order_item_count += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -158,10 +163,12 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
puts "order_id_count > 1"
|
||||
|
||||
updated_order_id = Array.new
|
||||
order_ids.each do |odr_id|
|
||||
odr = Order.find(odr_id)
|
||||
if odr.order_items.count > 1
|
||||
updated_order_id.push(odr_id)
|
||||
arr_order_ids.each do |order|
|
||||
order.each do |odr|
|
||||
data = Order.find(odr[0])
|
||||
if data.order_items.count != odr[1]
|
||||
updated_order_id.push(odr[0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -266,12 +273,32 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
else
|
||||
# puts order_ids
|
||||
if order_ids.count == 1 && order_id_count == 0 && order_item_count == 1
|
||||
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)
|
||||
if order_ids.count == 1 && order_item_count == 1
|
||||
if order_id_count == 0
|
||||
customer = Customer.find(params[:customer_id])
|
||||
order_type = "dine_in"
|
||||
if !customer.nil?
|
||||
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
|
||||
else
|
||||
customer = Customer.find(params[:customer_id])
|
||||
@@ -366,4 +393,11 @@ class Origami::SplitBillController < BaseOrigamiController
|
||||
|
||||
render :json => { status: true }
|
||||
end
|
||||
|
||||
#Shop Name in Navbor
|
||||
helper_method :shop_detail
|
||||
def shop_detail
|
||||
@shop = Shop.first
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -491,8 +491,8 @@ class ReceiptBillA5Pdf < Prawn::Document
|
||||
end
|
||||
|
||||
#individual payment per person
|
||||
def individual_payment(sale_data, survey, precision, delimiter)
|
||||
per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
|
||||
def individual_payment(sale_data, precision, delimiter)
|
||||
per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i
|
||||
stroke_horizontal_rule
|
||||
move_down line_move
|
||||
y_position = cursor
|
||||
|
||||
@@ -493,8 +493,8 @@ class ReceiptBillPdf < Prawn::Document
|
||||
end
|
||||
|
||||
#individual payment per person
|
||||
def individual_payment(sale_data, survey, precision, delimiter)
|
||||
per_person = sale_data.grand_total.to_f / survey.total_customer.to_i
|
||||
def individual_payment(sale_data, precision, delimiter)
|
||||
per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i
|
||||
stroke_horizontal_rule
|
||||
move_down line_move
|
||||
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 arr_order_ids = [];
|
||||
if(order_items!=undefined && order_items!=null){
|
||||
$.each(order_items,function(key,value){
|
||||
var orderIds = {};
|
||||
if($.inArray(value.order_id,order_ids) == -1){
|
||||
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";
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
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) {
|
||||
if (!result.status) {
|
||||
swal("Information!", result.error_message);
|
||||
@@ -669,7 +688,7 @@ function orderSplitBillProcess(cnt_orders){
|
||||
type: "POST",
|
||||
url: ajax_url,
|
||||
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) {
|
||||
if (!result.status) {
|
||||
swal("Information!", result.error_message);
|
||||
|
||||
Reference in New Issue
Block a user