diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb index fced3d02..fb8f68b9 100755 --- a/app/controllers/origami/orders_controller.rb +++ b/app/controllers/origami/orders_controller.rb @@ -15,6 +15,13 @@ class Origami::OrdersController < BaseOrigamiController @booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type}) end + #for split bill + lookup_spit_bill = Lookup.collection_of('split_bill') + @split_bill = 0 + if !lookup_spit_bill[0].nil? + @split_bill = lookup_spit_bill[0][1] + end + sale_order = SaleOrder.find_by_order_id(@order.order_id) if sale_order unless sale_order.sale_id.nil? diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index dd8dd990..037f3f6c 100644 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -149,6 +149,8 @@ class Origami::SplitBillController < BaseOrigamiController if !order_id.nil? if order_id_count > 1 + puts "order_id_count > 1" + updated_order_id = Array.new order_ids.each do |odr_id| odr = Order.find(odr_id) @@ -157,10 +159,13 @@ class Origami::SplitBillController < BaseOrigamiController end end + puts "updated_order_id" + puts updated_order_id + if !updated_order_id.empty? order_ids.each do |odr_id| unless updated_order_id.include?(odr_id) - # BookingOrder.find_by_order_id(odr_id).delete + BookingOrder.find_by_order_id(odr_id).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id}) end end @@ -172,16 +177,102 @@ class Origami::SplitBillController < BaseOrigamiController end else order_ids.each do |odr_id| - # BookingOrder.find_by_order_id(odr_id).delete - BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id}) + new_order_status = true + order_items.each do |order_item| + orderItem = OrderItem.find_by_order_id(odr_id) + if !orderItem.nil? + if order_item["id"] == orderItem.order_items_id + if orderItem.qty.to_f != order_item['qty'].to_f + new_order_status = false + end + end + end + end + + if new_order_status + BookingOrder.find_by_order_id(odr_id).delete + BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id}) + else + 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 = Order.new + order.source = "cashier" + order.order_type = order_type + order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + order.item_count = order_items.count + order.status = "new" + order.table_id = params[:dining_id] # this is dining facilities's id + order.waiters = current_user.name + order.employee_name = current_user.name + order.guest_info = nil + order.save! + + 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 + end end end else - BookingOrder.find_by_order_id(order_id).delete - BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id}) - + puts "order_id_count < 1" + new_order_status = true order_items.each do |order_item| - update_order_item(order_id, order_item) + orderItem = OrderItem.find_by_order_id(order_id) + if !orderItem.nil? + if order_item["id"] == orderItem.order_items_id + if orderItem.qty.to_f != order_item['qty'].to_f + new_order_status = false + end + end + end + end + + if new_order_status + BookingOrder.find_by_order_id(order_id).delete + BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id}) + order_items.each do |order_item| + update_order_item(order_id, order_item) + end + else + 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 = Order.new + order.source = "cashier" + order.order_type = order_type + order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + order.item_count = order_items.count + order.status = "new" + order.table_id = params[:dining_id] # this is dining facilities's id + order.waiters = current_user.name + order.employee_name = current_user.name + order.guest_info = nil + order.save! + + 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 end end else @@ -217,7 +308,7 @@ class Origami::SplitBillController < BaseOrigamiController BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id}) order_items.each do |order_item| - update_order_item(order.id, order_item) + update_order_item(order.order_id, order_item) end end end diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 898b8cf3..6125078b 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -478,11 +478,17 @@ class ReceiptBillA5Pdf < Prawn::Document stroke_horizontal_rule move_down 5 y_position = cursor + bounding_box([0,y_position], :width =>self.label_width+50) do + text "Individual amount for #{survey.total_customer} persons", :size => self.item_font_size+1,:align => :left + end + bounding_box([0,y_position], :width =>self.label_width) do - text "Individual amount", :size => self.item_font_size,:align => :left + move_down 15 + text "Total", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 15 text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index e8ca4bb2..a2a6ce5a 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -478,11 +478,17 @@ class ReceiptBillPdf < Prawn::Document stroke_horizontal_rule move_down 5 y_position = cursor + bounding_box([0,y_position], :width =>self.label_width+50) do + text "Individual amount for #{survey.total_customer} persons", :size => self.item_font_size+1,:align => :left + end + bounding_box([0,y_position], :width =>self.label_width) do - text "Individual amount", :size => self.item_font_size,:align => :left + move_down 15 + text "Total", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do + move_down 15 text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right end end diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 28094ee8..0c047e56 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -387,14 +387,7 @@ %> - <% if !@split_bill.nil? %> - <% if @split_bill == '1' %> - - - <% else %> - - <% end %> - <% end %> + <% end %> <% if @sale_array.size > 1 %>

@@ -412,11 +405,6 @@ - <% if !@split_bill.nil? %> - <% if @split_bill == '1' %> - - <% end %> - <% end %> @@ -476,6 +464,11 @@ <%end%> <% end %> + <% if !@split_bill.nil? %> + <% if @split_bill == '1' %> + + <% end %> + <% end %> <% end %> diff --git a/app/views/origami/orders/show.html.erb b/app/views/origami/orders/show.html.erb index 4e9d09b1..4ffe9de6 100755 --- a/app/views/origami/orders/show.html.erb +++ b/app/views/origami/orders/show.html.erb @@ -241,7 +241,9 @@
+ <% if !@split_bill.nil? && @split_bill == '1' %> + <% end %> <% if @sale_status != 'completed' %> <% end %> @@ -312,7 +314,7 @@ var order = JSON.parse('<%= @order.to_json.html_safe %>'); var arr_order = []; arr_order.push({id : order.order_id}); - + var dining_id = booking[0].dining_facility_id || 0; var type = booking[0].type || ''; var customer_id = order.customer_id || ''; diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index b367f212..f9523e3f 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -364,10 +364,7 @@ end %> - - <% if !@split_bill.nil? && @split_bill == '1' %> - - <% end %> + <% end %> <% if @sale_array.size > 1 %>

@@ -440,6 +437,11 @@ <%end%> <%end%> + <% if !@split_bill.nil? %> + <% if @split_bill == '1' %> + + <% end %> + <% end %> <% end %> diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index 216507ea..31e6a5d0 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -200,7 +200,7 @@ <% @sale_data.each_with_index do |sale_data, sale_index| %> <% if sale_data.sale_status != 'completed' && sale_data.sale_status != 'void' %> <% checked = "" %> - <% if sale_index == 0 %> + <% if sale_index == 1 %> <% checked = "checked" %> <% end %> data=<%= sale_data.grand_total %> > @@ -250,7 +250,8 @@
- +
+
@@ -304,7 +305,7 @@
@@ -483,58 +484,68 @@ }); $('.btn_per_person').on('click', function(){ - $('#equal_split_modal').modal('hide'); - var person = parseInt($('#per_person').val()); - if(person > 1){ - var ajax_url = "/origami/split_bills/surveys"; - var dining_id = $("#table_id").text(); - var type = $("#table_type").text(); - - $.ajax({ - type: "POST", - url: ajax_url, - dataType: 'JSON', - data: {'dining_id':dining_id, 'sale_id':split_sale_id, 'receipt_no':split_receipt_no, 'total_customer': person, 'total_amount':split_total_amount }, - success: function (result) { - console.log(result); - if(result.status){ - var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill"; - $.ajax({ - type: "GET", - url: ajax_url, - success: function (result) { - if((split_receipt_no!=undefined) && (split_receipt_no!="")) - createReceiptNoInFirstBillData(split_receipt_no,""); - - location.reload(); - // if(type=='Table'){ - // window.location.href = '/origami/table/' + dining_id; - // }else{ - // window.location.href = '/origami/room/' + dining_id; - // } - } - }); - } - } - }); + var person = $('#per_person').val(); + + if((person!=undefined) && (person!="")){ + $("#per_personErr").html(''); + $('#equal_split_modal').modal('hide'); + if(person > 1){ + var ajax_url = "/origami/split_bills/surveys"; + var dining_id = $("#table_id").text(); + var type = $("#table_type").text(); + + $.ajax({ + type: "POST", + url: ajax_url, + dataType: 'JSON', + data: {'dining_id':dining_id, 'sale_id':split_sale_id, 'receipt_no':split_receipt_no, 'total_customer': person, 'total_amount':split_total_amount }, + success: function (result) { + console.log(result); + if(result.status){ + var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill"; + $.ajax({ + type: "GET", + url: ajax_url, + success: function (result) { + if((split_receipt_no!=undefined) && (split_receipt_no!="")) + createReceiptNoInFirstBillData(split_receipt_no,""); + + // location.reload(); + // if(type=='Table'){ + // window.location.href = '/origami/table/' + dining_id; + // }else{ + // window.location.href = '/origami/room/' + dining_id; + // } + + window.location.href = '/origami/sale/' + split_sale_id + "/payment"; + } + }); + } + } + }); + }else{ + var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill"; + $.ajax({ + type: "GET", + url: ajax_url, + success: function (result) { + if((split_receipt_no!=undefined) && (split_receipt_no!="")) + createReceiptNoInFirstBillData(split_receipt_no,""); + + // location.reload(); + // if(type=='Table'){ + // window.location.href = '/origami/table/' + dining_id; + // }else{ + // window.location.href = '/origami/room/' + dining_id; + // } + window.location.href = '/origami/sale/' + split_sale_id + "/payment"; + } + }); + } }else{ - var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill"; - $.ajax({ - type: "GET", - url: ajax_url, - success: function (result) { - if((split_receipt_no!=undefined) && (split_receipt_no!="")) - createReceiptNoInFirstBillData(split_receipt_no,""); - - location.reload(); - // if(type=='Table'){ - // window.location.href = '/origami/table/' + dining_id; - // }else{ - // window.location.href = '/origami/room/' + dining_id; - // } - } - }); + $("#per_personErr").html("can't be blank"); } + }); //equal split process