 <div class="container-fluid">
 	<div id="loading_wrapper" style="display:none;">
 		<div id="loading"></div>
 	</div>
 	<div class="row">
 		<!-- Column One -->
 		<div class="col-lg-7 col-md-7 col-sm-7">
 			<!-- Order Details -->
 			<div class="card"  >
 				<div class="card-block">
 					<div class="card-title row">
 						<div class="col-lg-12 col-md-12 col-sm-12">
 							<span class="hidden" id ="table_id" value="<%=@table.id%>"><%=@table.id%></span>
 							<span class="hidden" id="table_type" value="<%=@table.type%>"><%=@table.type%></span>
 							<% if !@order.nil? %>
 							<span class="hidden" id="customer_id" value="<%= @order.customer_id %>"><%= @order.customer_id %></span>
 							<% end %>
 							<p class="m-l-15">Order Lists</p>
 						</div>
 					</div>
 					<div id="split-order-slimscroll" data-height="70">
 						<div class="card-text dining">
 							<% if !@orders.empty? %>
 							<div class="row">
 								<div class="col-lg-12 col-md-12 col-sm-12">
 									<div class="row m-l-5">
 										<div class="col-lg-3 col-md-3 col-sm-3">
 											<ul class="nav nav-tabs tabs-left sideways">
 												<li class="order-row active">
													<a href="#all_order" data-toggle="tab"><strong>All</strong></a>
												</li>
 												<% @orders.each.with_index(0) do |order, order_index| %>
 													<li class="order-row">
 														<a href="#<%= order.order_id %>" data-toggle="tab"><strong><%= order.order_id %></strong></a>
 													</li>
 												<% end %>
 											</ul>
 										</div>
 										<div class="col-lg-8 col-md-8 col-sm-8">
 											<div class="tab-content">
 												<div class="tab-pane active" id="all_order">
													<div class="card-title">
														<p class="m-l-2">Order Items</p>
													</div>
													<div id="order-detail-slimscroll-all_order" data-height="200">
														<div class="card-text dining">
	 														<table class="table table-default" id="order-items-table">
	 															<thead>
	 																<tr>
	 																	<th class="item-name">Items</th>
	 																	<th class="item-attr">QTY</th>
	 																	<th class="item-attr">Price</th>
	 																</tr>
	 															</thead>
	 															<tbody>
	 																<% order_item_count = 0 %>
	 																<% if !@order_items.nil? %>
	 																<% sub_total = 0 %>
	 																<% @order_items.each do |order_item| %>
	 																<% if order_item.include? ('all_order') %>
		 																<% order_item['all_order'].each do |odr_item| %>
			 																<% 
			 																order_item_count = order_item_count.to_i + 1 
			 																sub_total += odr_item['qty'].to_f * odr_item['price'].to_f 
			 																%>
			 																<tr class="item-row" id=<%= odr_item['order_items_id'] %> >
			 																	<td style="width:60%; text-align:left">
			 																		<span id="item-order-id" class="hidden"><%=odr_item['order_id'] %></span>
			 																		<span id="item-account-type" class="hidden"><%=odr_item['account_id'] %></span>
			 																		<span id="item-code" class="hidden"><%=odr_item['item_code'] %></span>
			 																		<span id="item-instance-code" class="hidden"><%=odr_item['item_instance_code'] %></span>
			 																		<span id="item-name-price">
			 																			<%=odr_item['item_name'] %>
			 																			<% if !odr_item['set_menu_items'].nil?  
			 																				odr_item['set_menu_items'].each do |item_instance| %> 
			 																				<br><span class="font-13"><%= item_instance %></span> 
			 																				<% end 
			 																				end %>
			 																			</span>
			 																		</td>
			 																		<td style="width:20%; text-align:right">
			 																			<span id="item-qty"><%=odr_item['qty']%></span>
			 																		</td>
			 																		<td style="width:20%; text-align:right">
			 																			<span id="item-total-price"><%=(odr_item['qty'].to_f * odr_item['price'].to_f)%></span>
			 																		</td>
			 																	</tr>
		 																	<% end %>
	 																	<% end %>
	 																	<%
	 																end 
	 																%>
	 																<% end %>
	 															</tbody>
	 														</table>
														</div>
													</div>
													<!-- <div class="card-footer"> -->
														<table class="table m-b-20" id="order-charges-table" border="0">
	 														<tr>
	 															<td class="charges-name"><strong>Sub Total:</strong></td>
	 															<td class="item-attr align-right"><strong id="order-sub-total"><%=sub_total%></strong></td>
	 														</tr>
 														</table>
													<!-- </div> -->
 												</div>

 												<% @orders.each.with_index(0) do |order, order_index| %>
												<% active_class = "" %>
												<% if order_index == 0 %>
													<% active_class = "active" %>
												<% end %>
 												<div class="tab-pane" id="<%= order.order_id %>">
													<div class="card-title">
														<p class="m-l-2">Order Items</p>
													</div>
													<div id="order-detail-slimscroll-<%= order.order_id %>" data-height="200">
														<div class="card-text dining">
	 														<table class="table table-default" id="order-items-table">
	 															<thead>
	 																<tr>
	 																	<th class="item-name">Items</th>
	 																	<th class="item-attr">QTY</th>
	 																	<th class="item-attr">Price</th>
	 																</tr>
	 															</thead>
	 															<tbody>
	 																<% if !@order_items.nil? %>
	 																<% sub_total = 0 %>
	 																<% @order_items.each do |order_item| %>
	 																<% if order_item.include? (order.order_id.to_s) %>
	 																<% 
	 																sub_total += order_item[order.order_id.to_s]['qty'].to_f * order_item[order.order_id.to_s]['price'].to_f 
	 																%>
	 																<tr class="item-row" id=<%= order_item[order.order_id.to_s]['order_items_id'] %> >
	 																	<td style="width:60%; text-align:left">
	 																		<span id="item-order-id" class="hidden"><%=order_item[order.order_id.to_s]['order_id'] %></span>
	 																		<span id="item-account-type" class="hidden"><%=order_item[order.order_id.to_s]['account_id'] %></span>
	 																		<span id="item-code" class="hidden"><%=order_item[order.order_id.to_s]['item_code'] %></span>
	 																		<span id="item-instance-code" class="hidden"><%=order_item[order.order_id.to_s]['item-instance-code'] %></span>
	 																		<span id="item-name-price">
	 																			<%=order_item[order.order_id.to_s]['item_name'] %>
	 																			<% if !order_item[order.order_id.to_s]['set_menu_items'].nil?  
	 																				order_item[order.order_id.to_s]['set_menu_items'].each do |item_instance| %> 
	 																				<br><span class="font-13"><%= item_instance %></span> 
	 																				<% end 
	 																				end %>
	 																			</span>
	 																		</td>
	 																		<td style="width:20%; text-align:right">
	 																			<span id="item-qty"><%=order_item[order.order_id.to_s]['qty']%></span>
	 																		</td>
	 																		<td style="width:20%; text-align:right">
	 																			<span id="item-total-price"><%=(order_item[order.order_id.to_s]['qty'].to_f * order_item[order.order_id.to_s]['price'].to_f)%></span>
	 																		</td>
	 																	</tr>
	 																	<% end %>
	 																	<%
	 																end 
	 																%>
	 																<% end %>
	 															</tbody>
	 														</table>
														</div>
													</div>
													<!-- <div class="card-footer"> -->
														<table class="table m-b-20" id="order-charges-table" border="0">
	 														<tr>
	 															<td class="charges-name"><strong>Sub Total:</strong></td>
	 															<td class="item-attr align-right"><strong id="order-sub-total"><%=sub_total%></strong></td>
	 														</tr>
 														</table>
													<!-- </div> -->
 												</div>
 												<% end %>
 											</div>
 										</div>
 									</div>
 								</div>
 							</div>
 							<% end %>
 						</div>
 					</div>
 				</div>
 			</div>
 		</div>
 		<!-- Column One -->
 		<!-- Column Two -->
 		<div class="col-lg-4 col-md-4 col-sm-4">
 			<div class="card">
 				<div class="card-block">
 					<div class="card-title row">
 						<p class="m-l-15">Receipt Lists</p>
 					</div>
 					<div id="split-receipt-slimscroll" data-height="150">
 						<div class="card-text dining">
 							<% if !@sale_data.empty? %>
 							<table class="table table-default">
 								<thead>
 									<th>#</th>
 									<th>Receipt No.</th>
 									<th>Total</th>
 									<% if !@current_user.nil? && @current_user.role != 'waiter' %>
 									<th>Action</th>
 									<% end %>
 								</thead>
 								<tbody>
 									<% @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 == 1 %>
	 										<% checked = "checked" %>
	 									<% end %>
	 									<tr class="receipt-row" id=<%= sale_data.receipt_no %> data=<%= sale_data.grand_total %> >
	 										<td><input type="radio" name="rdn_receipt" id="rdn_receipt" value="<%= sale_data.sale_id %>" <%= checked %>></td>
	 										<td><span id="receipt_no"><%= sale_data.receipt_no %></span></td>
	 										<td><span id="grand_total"><%= sale_data.grand_total %></span></td>

 											<% if !@current_user.nil? && @current_user.role != 'waiter' %>
	 										<td>
	 											<button type="button" class="btn btn-block waves-effect btn-primary btn_pay" id=<%= sale_data.sale_id %> >Pay</button>
	 										</td>
	 										<% end %>
	 									</tr>
	 									<% end %>
 									<% end %>
 								</tbody>
 							</table>
 							<% end %>
 						</div>
 					</div>
 					<div class="card-footer"></div>
 				</div>
 			</div>
 		</div>
 		<!-- Column Two -->
 		<!-- Column Three -->
 		<div class="col-lg-1 col-md-1 col-sm-1">
 			<!-- Action Panel -->
 			<div>
 				<button type="button" class="btn bg-default btn-block waves-effect" id="back" ><i class="material-icons">reply</i> Back </button>
 				<% if !@current_user.nil? && @current_user.role != 'waiter' %>
 					<% if !@sale_data.empty? %>
 						<button id="equal_split" class="btn btn-block waves-effect bg-blue">= Split</button>
 					<% end %>
 				<% end %>
 				<% if !@orders.empty? %>
	 				<button id="order_split" class="btn btn-block waves-effect bg-blue">By Order</button>
	 				<button id="order_item_split" class="btn btn-block waves-effect bg-blue">By Order Item</button>
 				<% end %>
 			</div>
 		</div>
 		<!-- Column Three -->
 	</div>

 	<!-- modal for equal person -->
	<div class="modal fade" id="equal_split_modal" tabindex="-1" role="dialog" aria-labelledby="equal_split_modal_label" aria-hidden="true">
	  <div class="modal-dialog" role="document">
	    <div class="modal-content">
	      <div class="modal-header">
	        <h5 class="modal-title" id="equal_split_modal_label">Equal Split (per person)</h5>
	        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
	          <span aria-hidden="true">&times;</span>
	        </button>
	      </div>
	      <div class="modal-body">
				<div class="form-horizontal">
					<div class="col-lg-12 col-md-12 col-sm-12">	
						<div class="form-group">
							<input type="text" id="per_person" name="per_person" class="form-control" onkeypress="return isNumberKey(event);"/><br>
							<span id="per_personErr" style="color:red;"></span>
						</div>					
					</div>
				</div>

				<hr />
				<div class="p-l-50">
					<div class="row">
					<div class="col-lg-12 col-md-12 col-sm-12">
						<div class="row bottom">
							<div class="col-md-9">
								<div class="row">
									<div class="col-md-3 cashier_number" data-value="1" data-type="num" style="margin-left: 6px;">1</div>
									<div class="col-md-3 left cashier_number" data-value="2" data-type="num">2</div>
									<div class="col-md-3 left cashier_number" data-value="3" data-type="num">3</div>
								</div>
							</div>
						</div>

						<div class="row bottom clearfix">
							<div class="col-md-9">
								<div class="row">
									<div class="col-md-3 cashier_number" data-value="4" data-type="num" style="margin-left: 6px;">4</div>
									<div class="col-md-3 left cashier_number" data-value="5" data-type="num">5</div>
									<div class="col-md-3 left cashier_number" data-value="6" data-type="num">6</div>
								</div>
							</div>
						</div>

						<div class="row bottom">
							<div class="col-md-9">
								<div class="row">
									<div class="col-md-3 cashier_number" data-value="7" data-type="num" style="margin-left: 6px;">7</div>
									<div class="col-md-3 left cashier_number" data-value="8" data-type="num">8</div>
									<div class="col-md-3 left cashier_number" data-value="9" data-type="num">9</div>
								</div>
							</div>
						</div>

						<div class="row bottom">
							<div class="col-md-9">
								<div class="row">
									<div class="col-md-3 cashier_number" style="margin-left: 6px;"></div>
									<div class="col-md-3 left cashier_number red" data-type="del">DEL</div>
									<div class="col-md-3 left cashier_number green" data-type="clr">CLR</div>
								</div>
							</div>
						</div>
					</div>
					</div>	
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn bg-default" data-dismiss="modal">Close</button> &nbsp;&nbsp;
				<button type="button" class="btn bg-blue btn_per_person">= Split</button>
			</div>
	    </div>
	  </div>
	</div>
 	<!-- modal for equal person -->
 </div>

 <script type="text/javascript">
 	var split_sale_id = "";
 	var split_receipt_no = "";
 	var cashier_type = '<%= @cashier_type %>';
 	$(document).ready(function(){
	  setHeaderBreadCrumb(_SPLIT_BILL_);
	  /* check webview loaded*/
      var webview = <%= @webview %>;
      showHideNavbar(webview);
      
 		$('#back').on('click',function(){
 			backToOrigami();
 		})

 		$(".cashier_number").on('click', function(event){
 			if(event.handled !== true) {
 				var original_value=0;
 				original_value = $('#per_person').val();
 				var input_type = $(this).attr("data-type");
 				switch (input_type) {
 					case 'num':
	 					var input_value = $(this).attr("data-value");
	 					if (original_value == "0"){
	 						$('#per_person').val(input_value);						
	 					}
	 					else{
	 						$('#per_person').val(original_value + '' + input_value);						
	 					}
 					break;

 					case 'add':
	 					var input_value = $(this).attr("data-value");
	 					amount = parseInt(input_value);
	 					$('#per_person').val(amount);										
 					break;

 					case 'del' :
	 					var discount_text=$('#per_person').val();
	 					$('#per_person').val(discount_text.substr(0,discount_text.length-1));		
 					break;

 					case 'clr':
 						$('#per_person').val("");	            
 					break;
 				}
 				event.handled = true;
 			} else {
 				return false;
 			}
 		});

	// Select Sale Item
	$('.item-row').on('click',function(){
		if($(this).hasClass('selected-split-item') == true){
			$(this).removeClass('selected-split-item');
		}
		else {
			$(this).addClass('selected-split-item');
		}
	});

	//order_item_split
	$('#order_item_split').on('click',function () {
		var cnt_order_item = "<%= order_item_count %>";
		var order_items = get_selected_order_items();// Selected Order Items
		var cnt_items = parseInt(cnt_order_item) - parseInt(order_items.length);
		if (order_items.length > 0){
			// if(cnt_items > 0){
				swal({
					title: "Alert",
					text: "Are you sure, you want to Split?",
					type: "warning",
					showCancelButton: true,
					confirmButtonColor: "#DD6B55",
					confirmButtonText: "Yes, split it!",
					closeOnConfirm: false
				}, function (isConfirm) {
					if(isConfirm){
						orderItemSplitBillProcess(cnt_items);
					}
				});
			// }
			// else{
			// 	orderItemSplitBillProcess(cnt_items);
			// }
		}else{
			swal("Oops","Please select at least one item!","warning");
		}
	});

	// Selected Order 
	$('.order-row').on('click',function(){
		var orders = JSON.parse('<%= @orders.to_json.html_safe %>');
		var check_order_id = $(this).find('a').attr('href').substr(1);
		
		if(check_order_id == 'all_order'){
			if(orders.length > 0){
				$.each(orders, function(key,value){
					if($("a[href$='#"+value.order_id+"']").parent().hasClass('selected-split-item')){
						$("a[href$='#"+value.order_id+"']").parent().removeClass('selected-split-item');
						$(".item-row").removeClass('selected-split-item');
					}
				});
			}
		}else{
			$("a[href$='#all_order']").parent().removeClass('selected-split-item');
		}

		if($(this).hasClass('selected-split-item') == true){
			$(this).removeClass('selected-split-item');
		}
		else {
			$(this).addClass('selected-split-item');
		}
	});

	//order_item_split
	$('#order_split').on('click',function () {
		var cnt_orders = "<%= @orders.count %>";
		var orders = get_selected_orders();// Selected Order Items
		var cnt_odrs = 0;
		if(orders.length == 1){
			if(orders[0].id == 'all_order'){
				cnt_odrs = 0;
			}else{
				cnt_odrs = parseInt(cnt_orders) - parseInt(orders.length);
			}
		}else{
			cnt_odrs = parseInt(cnt_orders) - parseInt(orders.length);
		}

		if (orders.length > 0){
			// if(cnt_odrs > 0){
				swal({
					title: "Alert",
					text: "Are you sure, you want to Split?",
					type: "warning",
					showCancelButton: true,
					confirmButtonColor: "#DD6B55",
					confirmButtonText: "Yes, split it!",
					closeOnConfirm: false
				}, function (isConfirm) {
					if(isConfirm){
						orderSplitBillProcess(cnt_odrs);
					}
				});
			// }
			// else{
			// 	orderSplitBillProcess(cnt_odrs);
			// }
		}else{
			swal("Oops","Please select at least one order!","warning");
		}
	});

	//selected receipt row click
	$('.btn_pay').on('click',function(){
		var dining_id       = $("#table_id").text();
		var sale_id = $(this).attr('id').substr(0,16);
		window.location = '/origami/table/' + dining_id + "/table_invoice/" + sale_id;
	});

	//equal split process
	$('#equal_split').on('click', function(){
		var dining_id = $("#table_id").text();
		split_sale_id = $("input[type='radio'][name='rdn_receipt']:checked").val();
		split_receipt_no = $("input[type='radio'][name='rdn_receipt']:checked").parent().parent().attr('id');

		if(split_sale_id != undefined && split_sale_id != ""){
			$('#equal_split_modal').modal({backdrop: 'static', keyboard: true, show: true});
		}
		else{
			swal("Oops","Please select one receipt!","warning");
		}
	});

	$('.btn_per_person').on('click', function(){
		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/equal_person";
				var dining_id = $("#table_id").text();
				var type     = $("#table_type").text();
				
				$.ajax({
					type: "POST",
					url: ajax_url,
					dataType: 'JSON',
					data: { 'sale_id':split_sale_id, 'total_customer': person },
					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 + "/cashier/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 + "/cashier/payment";
		            }
		        });
			}
		}else{
			$("#per_personErr").html("can't be blank");
		}
		
	});

	//equal split process

	//slimscroll for order, order items, reciept
	var height = ($(window).height() - ($('.legal').outerHeight() + $('.user-info').outerHeight() + $('.navbar').innerHeight()));

	$('#split-order-slimscroll').slimScroll({
		height: height-$('#split-order-slimscroll').attr('data-height'),
		size: '5px',
		color: 'rgba(0,0,0,0.5)',
		alwaysVisible: false,
		borderRadius: '0',
		railBorderRadius: '0'
	});

	$('#split-receipt-slimscroll').slimScroll({
		height: height-$('#split-receipt-slimscroll').attr('data-height'),
		size: '5px',
		color: 'rgba(0,0,0,0.5)',
		alwaysVisible: false,
		borderRadius: '0',
		railBorderRadius: '0'
	});

	$('#order-detail-slimscroll-all_order').slimScroll({
		height: height-$('#split-receipt-slimscroll').attr('data-height'),
		size: '5px',
		color: 'rgba(0,0,0,0.5)',
		alwaysVisible: false,
		borderRadius: '0',
		railBorderRadius: '0'
	});

	var orders = JSON.parse('<%= @orders.to_json.html_safe %>');
	if(orders.length > 0){
		$.each(orders, function(key,order){
			$('#order-detail-slimscroll-'+order.order_id).slimScroll({
				height: height-$('#split-receipt-slimscroll').attr('data-height'),
				size: '5px',
				color: 'rgba(0,0,0,0.5)',
				alwaysVisible: false,
				borderRadius: '0',
				railBorderRadius: '0'
			});
		});
	}
});

/* function for order items split bill process */
function orderItemSplitBillProcess(cnt_items){
	var dining_id       = $("#table_id").text();
	var type     = $("#table_type").text();
	var customer_id     = $("#customer_id").text();
	var order_items = get_selected_order_items();// Selected Order Items
	var json_booking = JSON.parse('<%= @booking.to_json.html_safe %>');
	var booking_id = "";
	if(cnt_items == 0){
		booking_id = json_booking.booking_id;
	}
	console.log(booking_id);

	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: {'cashier_type':cashier_type,'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);
			}
			else {   
            	// if (cnt_items > 0){
            		window.location.reload();
            	// }else{
            	// 	backToOrigami();
            	// }
            }
        }
    });
}

/* function for order items split bill process */
function orderSplitBillProcess(cnt_orders){
	var dining_id       = $("#table_id").text();
	var type     = $("#table_type").text();
	var customer_id     = $("#customer_id").text();
	var orders = get_selected_orders();// Selected Orders
	var json_booking = JSON.parse('<%= @booking.to_json.html_safe %>');
	var booking_id = "";
	if(cnt_orders == 0){
		booking_id = json_booking.booking_id;
	}

	var ajax_url = "/origami/split_bills";
	$.ajax({
		type: "POST",
		url: ajax_url,
		dataType: 'JSON',
		data: {'cashier_type':cashier_type,'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);
			}
			else {   
            	// if (cnt_items > 0){
            		window.location.reload();
            	// }else{
            	// 	backToOrigami();
            	// }
            }
        }
    });
}

/* back to origami */
function backToOrigami(){
	var id       = $("#table_id").text();
	var type     = $("#table_type").text();
	if (type=="Table") {
		window.location.href = '/origami/table/'+id
	}else{
		window.location.href = '/origami/room/'+id
	}
}

/* Get Selected Order Items */
function get_selected_order_items(){
	var order_items = [];	
	$('.item-row.selected-split-item').each(function(i){
		var order_item = {};
		order_item.id = $(this).attr('id').substr(0,16);
		order_item.order_id = $(this).find('#item-order-id').text().trim();
		order_item.item_code = $(this).find('#item-code').text().trim();
		order_item.item_instance_code = $(this).find('#item-instance-code').text().trim();
		order_item.name = $(this).find('#item-name-price').text().split('@')[0];
		order_item.account_id = $(this).find('#item-account-type').text();
		order_item.qty = $(this).find('#item-qty').text();
		order_item.price = $(this).find('#item-total-price').text();
		order_items.push(order_item);
	});	
	return order_items;
}

/* Get Selected Orders */
function get_selected_orders(){
	var orders = [];	
	$('.order-row.selected-split-item').each(function(i){
		var order = {};
		order.id = $(this).find('a').attr('href').substr(1);
		orders.push(order);
	});	
	return orders;
}

//check for isNumber
function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	} else {
		return true;
	}      
}

</script>
