diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss
index 30d8a090..01b4780f 100755
--- a/app/assets/stylesheets/origami.scss
+++ b/app/assets/stylesheets/origami.scss
@@ -390,3 +390,9 @@ i.logout_icon{
}
/* End Notify */
+
+/* selected color for split bills */
+.selected-split-item {
+ color: #fff !important;
+ background-color: #5DADE2 !important;
+}
diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb
index e1432951..d50c0cd4 100644
--- a/app/controllers/origami/split_bill_controller.rb
+++ b/app/controllers/origami/split_bill_controller.rb
@@ -5,6 +5,7 @@ class Origami::SplitBillController < BaseOrigamiController
dining_id = params[:dining_id]
@table = DiningFacility.find(dining_id)
@booking = @table.get_booking
+ @orders = Array.new
@order_items = Array.new
@sale_data = Array.new
@@ -19,9 +20,20 @@ class Origami::SplitBillController < BaseOrigamiController
@booking.booking_orders.each do |booking_order|
@order = Order.find(booking_order.order_id)
if (@order.status == "new")
- @order.order_items.each do |item|
- @order_items.push(item)
- end
+ @orders.push(@order)
+
+ @order.order_items.each do |item|
+ 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)
+ end
+ item.set_menu_items = arr_instance_item_sets
+ end
+ @order_items.push(item)
+ end
end
end
else
@@ -31,8 +43,15 @@ class Origami::SplitBillController < BaseOrigamiController
def create
order_ids = params[:order_ids]
- order_items = JSON.parse(params[:order_items])
- # byebug
+ orders = nil
+ if !params[:orders].empty?
+ orders = JSON.parse(params[:orders])
+ end
+ order_items = nil
+ if !params[:order_items].empty?
+ order_items = JSON.parse(params[:order_items])
+ end
+
status = false
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
#create Bill by Booking ID
@@ -64,72 +83,111 @@ class Origami::SplitBillController < BaseOrigamiController
else
type = "RoomBooking"
end
-
+
booking = Booking.create({:dining_facility_id => params[:dining_id],:type => type,
- :checkin_at => Time.now.utc, :checkin_by => current_user.name,
- :booking_status => "assign" })
+ :checkin_at => Time.now.utc, :checkin_by => current_user.name,
+ :booking_status => "assign" })
- order_item_count = 0
- order_id = nil
-
- order_items.each do |order_item|
+ if !orders.nil?
+ orders.each do |order|
+ BookingOrder.create({:booking_id => booking.booking_id, :order_id => order["id"]})
+ end
+ elsif !order_items.nil?
order_item_count = 0
- order = Order.find(order_item["order_id"])
- if order.order_items.count == 1
- order_id = order.id
- break
- else
- order_item_count += 1
- end
- end
+ order_id_count = 0
+ order_id = nil
- if !order_id.nil?
- 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|
- orderItem = OrderItem.find(order_item["id"])
- orderItem.order_id = order_id
- orderItem.save!
- end
- else
- if order_ids.count == 1 && order_item_count == 1
- BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
- 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
+ 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
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!
+ if !order_id.nil?
+ if 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)
+ end
+ end
- BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.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.create({:booking_id => booking.booking_id, :order_id => odr_id})
+ end
+ end
- order_items.each do |order_item|
- orderItem = OrderItem.find(order_item["id"])
- orderItem.order_id = order.order_id
- orderItem.save!
- end
+ order_items.each do |order_item|
+ if updated_order_id.include?(order_item["order_id"])
+ orderItem = OrderItem.find(order_item["id"])
+ orderItem.order_id = order_id
+ orderItem.save!
+ end
+ 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})
+ end
+ end
+ else
+ 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|
+ orderItem = OrderItem.find(order_item["id"])
+ orderItem.order_id = order_id
+ orderItem.save!
+ end
+ end
+ else
+ if order_ids.count == 1 && order_item_count == 1
+ BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]})
+ 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|
+ orderItem = OrderItem.find(order_item["id"])
+ orderItem.order_id = order.order_id
+ orderItem.save!
+ end
+ end
end
end
- sale = Sale.new
+ sale = Sale.new
status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, get_cashier_by_terminal)
sale_data = Sale.find_by_sale_id(sale_id)
end
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb
index 7f16833e..48da04e3 100755
--- a/app/views/origami/home/show.html.erb
+++ b/app/views/origami/home/show.html.erb
@@ -367,6 +367,9 @@
%>
+ <% if !@spit_bill.nil? && @spit_bill == '1' %>
+
+ <% end %>
<% end %>
<% if @sale_array.size > 1 %>
@@ -692,11 +695,11 @@
var lookup_split_bill = '<%= @spit_bill %>';
if(lookup_split_bill == '1'){
swal({
- title: "Alert",
- text: "Are you sure, you want to Split bill?",
- type: "warning",
+ title: "Information!",
+ text: "Do you want to Split bill?",
+ type: "success",
showCancelButton: true,
- confirmButtonColor: "#DD6B55",
+ confirmButtonColor: "#009900",
confirmButtonText: "Yes, split it!",
closeOnConfirm: false
}, function (isConfirm) {
@@ -740,8 +743,8 @@
})
$('#add_invoice').on('click', function () {
- var dining_id = "<%= @dining.id %>"
- var sale_id = "<%= @obj_sale.sale_id rescue "" %>"
+ var dining_id = "<%= @dining.id %>";
+ var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %>
var ajax_url = "/origami/sale/append_order";
$.ajax({
type: "POST",
@@ -867,4 +870,22 @@
}
});
});
+
+ /* split bill in add to existing invoice*/
+ $('#split_bill').on('click', function(){
+ swal({
+ title: "Alert",
+ text: "Are you sure, you want to split bill?",
+ type: "warning",
+ showCancelButton: true,
+ confirmButtonColor: "#DD6B55",
+ confirmButtonText: "Yes, split it!",
+ closeOnConfirm: false
+ }, function (isConfirm) {
+ if(isConfirm){
+ var dining_id = "<%= @dining.id %>";
+ window.location.href = '/origami/table/' + dining_id + "/split_bills";
+ }
+ });
+ });
diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb
index 26986ac6..b0568a34 100755
--- a/app/views/origami/rooms/show.html.erb
+++ b/app/views/origami/rooms/show.html.erb
@@ -344,7 +344,10 @@
end
%>
-
+
+ <% if !@spit_bill.nil? && @spit_bill == '1' %>
+
+ <% end %>
<% end %>
<% if @sale_array.size > 1 %>
@@ -694,11 +697,11 @@ $('#request_bills').click(function() {
var lookup_split_bill = '<%= @spit_bill %>';
if(lookup_split_bill == '1'){
swal({
- title: "Alert",
- text: "Are you sure, you want to Split bill?",
- type: "warning",
+ title: "Information!",
+ text: "Do you want to Split bill?",
+ type: "success",
showCancelButton: true,
- confirmButtonColor: "#DD6B55",
+ confirmButtonColor: "#009900",
confirmButtonText: "Yes, split it!",
closeOnConfirm: false
}, function (isConfirm) {
@@ -871,4 +874,22 @@ $('#add_invoice').on('click',function(){
var dining_id = "<%= @room.id %>"
window.location.href = '/origami/addorders/' + dining_id;
});
+
+ /* split bill in add to existing invoice*/
+ $('#split_bill').on('click', function(){
+ swal({
+ title: "Alert",
+ text: "Are you sure, you want to split bill?",
+ type: "warning",
+ showCancelButton: true,
+ confirmButtonColor: "#DD6B55",
+ confirmButtonText: "Yes, split it!",
+ closeOnConfirm: false
+ }, function (isConfirm) {
+ if(isConfirm){
+ var dining_id = "<%= @room.id %>";
+ window.location.href = '/origami/table/' + dining_id + "/split_bills";
+ }
+ });
+ });
diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb
index 6cac0e72..999302d0 100755
--- a/app/views/origami/split_bill/index.html.erb
+++ b/app/views/origami/split_bill/index.html.erb
@@ -7,158 +7,205 @@
Order Lists
-| Items | -QTY | -Price | -
|---|---|---|
| - <%=order_item.order_id%> - <%=order_item.account_id%> - <%=order_item.item_name%> - | -- <%=order_item.qty%> - | -- <%=(order_item.qty*order_item.price)%> - | -
Receipt Lists
-| Receipt No. - <%= sale_data.receipt_no %> | -
Order Lists
+Order Items
+| Items | +QTY | +Price | +
|---|---|---|
|
+ <%=order_item.order_id%>
+ <%=order_item.account_id%>
+
+ <%=order_item.item_name%>
+ <% if !order_item.set_menu_items.nil?
+ order_item.set_menu_items.each do |item_instance| %>
+ <%= item_instance %> + <% end + end %> + + |
+ + <%=order_item.qty%> + | ++ <%=(order_item.qty*order_item.price)%> + | +
| Sub Total: | +<%=sub_total%> | +
Receipt Lists
+| Receipt No. - <%= sale_data.receipt_no %> | +