From c7f11c2a330704c2248a98e6b4ad63e7ec114265 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 15 Mar 2018 11:15:43 +0630 Subject: [PATCH] fixed set menu item update and individual payment --- app/controllers/oqs/edit_controller.rb | 7 ++ .../origami/split_bill_controller.rb | 70 ++++++++++++++----- app/pdf/receipt_bill_a5_pdf.rb | 4 +- app/pdf/receipt_bill_pdf.rb | 4 +- app/views/origami/split_bill/index.html.erb | 23 +++++- 5 files changed, 84 insertions(+), 24 deletions(-) mode change 100644 => 100755 app/controllers/origami/split_bill_controller.rb mode change 100644 => 100755 app/views/origami/split_bill/index.html.erb diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index e8d9615d..b123ac73 100755 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -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 diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb old mode 100644 new mode 100755 index 1790624a..16239750 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -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 diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 206c7a0a..604d99dd 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -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 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index efc85c7f..fe1ee628 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -494,8 +494,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 diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb old mode 100644 new mode 100755 index 517195d0..fb97b51d --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -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);