diff --git a/README.md b/README.md index cb35bff4..b42782e7 100755 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ SQL Update after rake clear:data runned Change type in mysql *run if you got font error for Myanmar, Chinese, etc... => ALTER TABLE [table_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for table - => ALTER DATABASE [database_name] CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci #for database + => ALTER DATABASE [database_name] CHARACTER SET utf8 COLLATE utf8_unicode_ci #for database For split bill 1) settings/lookups => { type:split_bill, name:SplitBill, value:1 } diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 9c7ddda1..58f64a27 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -38,6 +38,8 @@ class Origami::HomeController < BaseOrigamiController if !order.order_items.empty? if !@order_items_count.key?(booking.dining_facility_id) @order_items_count.store(booking.dining_facility_id, order.order_items.count) + else + @order_items_count[booking.dining_facility_id] += order.order_items.count end end end @@ -47,6 +49,8 @@ class Origami::HomeController < BaseOrigamiController if sale.sale_status !='completed' if !@order_items_count.key?(booking.dining_facility_id) @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) + else + @order_items_count[booking.dining_facility_id] += sale.sale_items.count end end end @@ -116,9 +120,9 @@ class Origami::HomeController < BaseOrigamiController @checkout_alert_time = Lookup.collection_of('checkout_alert_time') #for split bill lookup_spit_bill = Lookup.collection_of('split_bill') - @spit_bill = 0 + @split_bill = 0 if !lookup_spit_bill[0].nil? - @spit_bill = lookup_spit_bill[0][1] + @split_bill = lookup_spit_bill[0][1] end end diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb index ea976ffd..b4d7baf0 100755 --- a/app/controllers/origami/orders_controller.rb +++ b/app/controllers/origami/orders_controller.rb @@ -13,6 +13,21 @@ class Origami::OrdersController < BaseOrigamiController end end + @orders.each do |order| + order.order_items.each_with_index do |item, index| + if !item.set_menu_items.nil? + instance_item_sets = JSON.parse(item.set_menu_items) + arr_instance_item_sets = Array.new + instance_item_sets.each do |instance_item| + item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name + arr_instance_item_sets.push(item_instance_name) + item.price = item.price.to_f + instance_item["price"].to_f + end + order.order_items[index].set_menu_items = arr_instance_item_sets + end + end + end + @order_items_count = Hash.new bookings = Booking.all if !bookings.nil? @@ -24,6 +39,8 @@ class Origami::OrdersController < BaseOrigamiController if !order.order_items.empty? if !@order_items_count.key?(booking.dining_facility_id) @order_items_count.store(booking.dining_facility_id, order.order_items.count) + else + @order_items_count[booking.dining_facility_id] += order.order_items.count end end end @@ -33,6 +50,8 @@ class Origami::OrdersController < BaseOrigamiController if sale.sale_status !='completed' if !@order_items_count.key?(booking.dining_facility_id) @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) + else + @order_items_count[booking.dining_facility_id] += sale.sale_items.count end end end diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 3902354d..fd28230e 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -34,6 +34,8 @@ class Origami::RoomsController < BaseOrigamiController if !order.order_items.empty? if !@order_items_count.key?(booking.dining_facility_id) @order_items_count.store(booking.dining_facility_id, order.order_items.count) + else + @order_items_count[booking.dining_facility_id] += order.order_items.count end end end @@ -43,6 +45,8 @@ class Origami::RoomsController < BaseOrigamiController if sale.sale_status !='completed' if !@order_items_count.key?(booking.dining_facility_id) @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) + else + @order_items_count[booking.dining_facility_id] += sale.sale_items.count end end end @@ -119,9 +123,9 @@ class Origami::RoomsController < BaseOrigamiController # end lookup_spit_bill = Lookup.collection_of('split_bill') - @spit_bill = 0 + @split_bill = 0 if !lookup_spit_bill[0].nil? - @spit_bill = lookup_spit_bill[0][1] + @split_bill = lookup_spit_bill[0][1] end end diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 12f5780f..5d9cbec7 100644 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -28,11 +28,40 @@ class Origami::SplitBillController < BaseOrigamiController arr_instance_item_sets = Array.new instance_item_sets.each do |instance_item| item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name + item.price = item.price.to_f + instance_item["price"].to_f arr_instance_item_sets.push(item_instance_name) end item.set_menu_items = arr_instance_item_sets end - @order_items.push(item) + + arr_item = Hash.new + if item.qty.to_i > 1 + i = 1 + while i <= item.qty.to_i do + arr_item = {'order_items_id' => item.order_items_id, + 'order_id' => item.order_id, + 'order_item_status' => item.order_item_status, + 'item_order_by' => item.item_order_by, + 'item_code' => item.item_code, + 'item_instance_code' => item.item_instance_code, + 'item_name' => item.item_name, + 'alt_name' => item.alt_name, + 'account_id' => item.account_id, + 'qty' => '1.0', + 'price' => item.price, + 'remark' => item.remark, + 'options' => item.options, + 'set_menu_items' => item.set_menu_items, + 'taxable' => item.taxable, + 'completed_by' => item.completed_by, + 'created_at' => item.created_at, + 'updated_at' => item.updated_at} + i += 1 + @order_items.push({@order.order_id => arr_item}) + end + else + @order_items.push({@order.order_id => item}) + end end end end @@ -186,8 +215,25 @@ class Origami::SplitBillController < BaseOrigamiController order_items.each do |order_item| orderItem = OrderItem.find(order_item["id"]) - orderItem.order_id = order.order_id - orderItem.save! + if orderItem.qty.to_f != order_item['qty'].to_f + OrderItem.processs_item(orderItem.item_code, + orderItem.item_instance_code, + orderItem.item_name, + orderItem.alt_name, + orderItem.account_id, + order_item['qty'], + orderItem.price, + orderItem.options, + orderItem.set_menu_items, + orderItem.order_id, + orderItem.item_order_by, + orderItem.taxable) + + orderItem.qty = orderItem.qty.to_f - order_item['qty'].to_f + else + orderItem.order_id = order.order_id + end + orderItem.save! end end end diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index fe7f9a7f..19f308a1 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -386,9 +386,9 @@ end %> - + <% if !@spit_bill.nil? && @spit_bill == '1' %> - + <% end %> <% end %> <% if @sale_array.size > 1 %> @@ -439,6 +439,11 @@ + <% if !@split_bill.nil? %> + <% if @split_bill == '1' %> + + <% end %> + <% end %> @@ -711,30 +716,6 @@ // Bill Request $('#request_bills').click(function () { - var lookup_split_bill = '<%= @spit_bill %>'; - if(lookup_split_bill == '1'){ - swal({ - title: "Information!", - text: "Do you want to Split bill?", - type: "success", - showCancelButton: true, - confirmButtonColor: "#009900", - confirmButtonText: "Yes, split it!", - closeOnConfirm: false - }, function (isConfirm) { - if (isConfirm) { - var dining_id = "<%= @dining.id %>"; - window.location.href = '/origami/table/' + dining_id + "/split_bills"; - }else{ - requestBillProcess(); - } - }); - }else{ - requestBillProcess(); - } - }); - - function requestBillProcess(){ var order_id = $('#save_order_id').attr('data-order'); var ajax_url = "/origami/" + order_id + "/request_bills"; $.ajax({ @@ -749,8 +730,14 @@ location.reload(); } } - }); - } + }); + }); + + //split bill process + $('#split_bills').click(function(){ + var dining_id = "<%= @dining.id %>"; + window.location.href = '/origami/table/' + dining_id + "/split_bills"; + }); $('#move').on('click', function () { var dining_id = "<%= @dining.id %>"; diff --git a/app/views/origami/orders/show.html.erb b/app/views/origami/orders/show.html.erb index d98e9bc2..a1a914fd 100755 --- a/app/views/origami/orders/show.html.erb +++ b/app/views/origami/orders/show.html.erb @@ -200,7 +200,14 @@ %> <% unless sale_item.price <= 0 %>