<?php
include "include/config.php"; 
include "include/date.php"; 
ob_start();
session_start();
include "include/config.php"; 
include "include/date.php"; 
if($_SESSION['status']!="Active")
{
    header("location: login.php");
}
$fid=$_SESSION['fid'];
$employeeid=$_SESSION['employeeid'];
$third_party=$_SESSION['third_party'];
$incomplete = $_SESSION['incomplete'];
$gst=$_SESSION['gst'];
$gst="No";
if($incomplete=="No")
{
    
}
else
{
 $incomplete="Order No. $incomplete is in incomplete state";
 echo'<script>
 alert("' . $incomplete . '");
 </script>';
 $incomplete = $_SESSION['incomplete']="No";
}
if($fid=='21')
	  {
	      echo'<script>
	      alert("Please Contact Owner");
	     window.location.replace("login.php");
	      </script>';
	  }
// if($fid=='62')
// 	  {
// 	      echo'<script>
// 	     window.location.replace("login.php");
// 	      </script>';
// 	  }
if($employeeid==1120){
    	header("location:login.php");
}	  
?>

<!DOCTYPE html>
<html lang="en">
    <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
       <title>Heaven Pizza & Cafe</title>
        <!-- Bootstrap -->
        <link href="css/font-awesome.min.css" rel="stylesheet">
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link href="css/styles.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <link href="css/responsive.css" rel="stylesheet">
				 <link href='js/jquery-ui.min.css' type='text/css' rel='stylesheet' >
        <!-- Icon css link -->
       
    <style>
    .table{
        margin-bottom: unset;
    }
.table>tbody>tr>td, .table>tfoot>tr>td{
    vertical-align: middle;
}
@media screen and (max-width: 600px) {
    table#cart tbody td .form-control{
		width:20%;
		display: inline !important;
	}
	.actions .btn{
		width:36%;
		margin:1.5em 0;
	}
	
	.actions .btn-info{
		float:left;
	}
	.actions .btn-danger{
		float:right;
	}
	
	table#cart thead { display: none; }
	table#cart tbody td { display: block; padding: .6rem; min-width:320px;}
	table#cart tbody tr td:first-child { background: #333; color: #fff; }
	table#cart tbody td:before {
		content: attr(data-th); font-weight: bold;
		display: inline-block; width: 8rem;
	}
	table#cart tfoot td{display:block; }
	table#cart tfoot td .btn{display:block;}
	
}
table td input {
  display: block;
  top:0;
  left:0;
  margin: 0;
  height: 100%;
  width: 100%;
  border: none;
  box-sizing: border-box;
}
</style>

<style>
.modal {
   position: absolute;
   top: 10px;
   right: 0px;
   bottom: 0;
   left: -500px;
   z-index: 10040;
   overflow: auto;
   overflow-y: auto;
}

.modal-dialog1 {
   position:fixed;
   top:auto;
   right:auto;
   left:30%;
   bottom:0;
}  


</style>
	</head>
    <body>
     <input type="hidden" id="websocket_fid" value="<?php echo $fid ?>" />    
	
        <!--================End Our feature Area =================-->
    <section class="most_popular_item_area" style="padding: unset">
		<div class="container-fluid"style="background-color:#fff">
		    		<div class="row">
		<div class="col-md-4" style="padding-right: unset;">
		    <?php
		    $displayquery = "SELECT pending_amount FROM franchises WHERE fid='$fid' AND pending_amount > 0"; 
	$result = mysqli_query($con,$displayquery);
    if(mysqli_num_rows($result) > 0){
		$row = mysqli_fetch_array($result);
			$pending_amount=$row['pending_amount'];
			echo'
		    <center style="color:red">
		     <h3 >Software Pending Amount <i class="fa fa-inr"></i> '.$pending_amount.'</h3><h4>Pay above amount to continue service</h4><hr style="margin-bottom:0px; margin-top:0px">
		     </center>';
    }
		    
		     ?>
					<div class="col-md-12" id="home_delivery">
                </div>
					<div class="col-md-12" id="showbill">
			
			</div>
			<div class="col-md-12" id="cancelorderdisplay">
			
			</div>
			<div class="col-md-12" id="checkout">
			
			</div>
			<div class="col-md-12" id="placedorderdisplay">
			
			</div>
			<div class="col-md-12" id="completedorder">
			
			</div>
			
			<div class="col-md-12" id="completedorderdisplay" style="padding-bottom:10px">
			
			</div>
			<div class="col-md-12" id="kitchenorderdisplay">
			
			</div>
			</div>
		    
			<div class="col-md-8 wthree_banner_bottom_right" id="listdisplay">
				<div class="bs-example bs-example-tabs" role="tabpanel" data-example-id="togglable-tabs">
					<font face="Cantata One, serif" color="#000" size="4px"><ul id="myTab" class="nav nav-tabs" role="tablist">
						<li role="presentation" class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab" aria-controls="home">Pizza</a></li>
						<li role="presentation"><a href="#burger" role="tab" id="burger-tab" data-toggle="tab" aria-controls="burger">Burgers</a></li>
						<li role="presentation"><a href="#fries" role="tab" id="fries-tab" data-toggle="tab" aria-controls="fries">Fries</a></li>
						<li role="presentation"><a href="#nuggets" role="tab" id="nuggets-tab" data-toggle="tab" aria-controls="nuggets">Nuggets</a></li>
						<li role="presentation"><a href="#shakes" role="tab" id="shakes-tab" data-toggle="tab" aria-controls="shakes">Shakes</a></li>
						<li role="presentation"><a href="#coffee" role="tab" id="coffee-tab" data-toggle="tab" aria-controls="coffee">Coffee</a></li>
					<li role="presentation" style="display:none"><a href="#mojito" role="tab" id="mojito-tab" data-toggle="tab" aria-controls="mojito">Mojito</a></li>
					<li role="presentation" style="display:none"><a href="#ice_tea" role="tab" id="ice_tea-tab" data-toggle="tab" aria-controls="ice_tea">Ice Tea</a></li>
					<li role="presentation" style="display:none"><a href="#water" role="tab" id="water-tab" data-toggle="tab" aria-controls="water">Water</a></li>

					<!--<li role="presentation"><a href="#other" role="tab" id="other-tab" data-toggle="tab" aria-controls="other">Other</a></li>-->
						</ul></font>

					<div id="myTabContent" class="tab-content">
	<!--==================================================DIV FOR PIZZA==================================================--> 
					
					<div  class="tab-pane fade active in" id="home" aria-labelledby="home-tab">
						<div  id="pizza_list">
						
						</div>
					</div>
						
	<!--================================================END DIV FOR PIZZA===============================================--> 
	
	<!--================================================DIV FOR Burgers===============================================--> 
					<div  role="tabpanel" class="tab-pane fade" id="burger" aria-labelledby="burger-tab">
						<div  id="burger_list">
						
						</div>
					</div>
					
	<!--================================================END DIV FOR Burgers===============================================--> 
	
	<!--================================================DIV FOR Fries===============================================--> 
					<div  role="tabpanel" class="tab-pane fade" id="fries" aria-labelledby="fries-tab">
						<div  id="fries_list">
						
						</div>
					</div>
					
	<!--================================================END DIV FOR Fries===============================================--> 
	<!--================================================DIV FOR Nuggets===============================================--> 

					<div  role="tabpanel" class="tab-pane fade" id="nuggets" aria-labelledby="nuggets-tab">
						<div  id="nuggets_list">
						
						</div>
					</div>
	<!--================================================END DIV FOR Nuggets===============================================--> 
		<!--================================================DIV FOR Shakes===============================================--> 
			
					<div  role="tabpanel" class="tab-pane fade" id="shakes" aria-labelledby="shakes-tab">
						<div  id="shakes_list">
						
						</div>
					</div>
					
	<!--================================================END DIV FOR Shakes===============================================--> 
	<!--================================================DIV FOR Coffee===============================================--> 
				
					<div  role="tabpanel" class="tab-pane fade" id="coffee" aria-labelledby="coffee-tab">
						<div  id="coffee_list">
						
						</div>	
					</div>
					
	<!--================================================END DIV FOR Coffee===============================================--> 
		<!--================================================DIV FOR Cold Drink===============================================--> 
				
					<div  role="tabpanel" class="tab-pane fade" id="mojito" aria-labelledby="mojito-tab">
						<div  id="mojito">
						
						</div>	
					</div>
					
					
					
	<!--================================================END DIV FOR Cold Drink===============================================--> 
	<!--================================================DIV FOR ice_tea ===============================================--> 
				
					<div  role="tabpanel" class="tab-pane fade" id="ice_tea" aria-labelledby="ice_tea-tab">
						<div  id="ice_tea_list">
						
						</div>	
					</div>
					
	<div  role="tabpanel" class="tab-pane fade" id="water" aria-labelledby="water-tab">
						<div  id="water">
						
						</div>	
					</div>

					</div>
				</div> 
			</div>
			
	<!--================================================DIV FOR CART===============================================--> 


	</div>
		</div>
    </section>

  <div id="approve_reject">
			</div>
         <!--================================================= Logout  =====================================================-->
		<div class="row text-center" id="homelogout">
            <button class="btn btn-primary " onclick="location.href='index.php';" name="update" type="update"><font size="3px"><b><i class="fa fa-home" aria-hidden="true"></i> Home</b></font></button>
		    <button class="btn btn-danger " onclick="location.href='#';" data-toggle="modal" data-target="#logoutModal"  name="update" type="update"><font size="3px"><b><i class="fa fa-sign-out" aria-hidden="true"></i> Logout</b></font></button>
        </div>
        
<!-- Modal Start-->      
	<div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style="left:0">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
					<button class="close" type="button" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">×</span>
					</button>
				</div>
				<div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
				<div class="modal-footer">
					<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
					<a class="btn btn-primary" href="logout.php">Logout</a>
				</div>
			</div>
		</div>
	</div>
	
	<div class="modal fade" id="checkofferdisplay" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
    </div>
  </div>
	
<!--Reprint Modal	-->
<div class="modal fade" id="reprint" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content modal-lg"><div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Todays Bill Details</h4>
        </div>
        <div class="modal-body" id="reprintdisplay">
            
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div> </div>
      
    </div>
  </div>    

<!--ReOrder Modal	-->	
<div class="modal fade" id="reorder" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content modal-lg"><div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Place Reorder</h4>
        </div>
        <div class="modal-body" id="reorderdisplay">
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div> </div>
      
    </div>
  </div>
  
 <div class="modal fade" id="home_delivery_display" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content modal-lg">
          <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title text-center">New Online Order List</h4>
        </div>
        <div class="modal-body">
            <div id="frenchises">
            </div>
            </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div> </div>
      
    </div>
  </div> 
  
   <div class="modal fade" id="completedorder_mobile" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content modal-md">
          <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title text-center"></h4>
        </div>
        <div class="modal-body">
            <div id="completedorder_mobile_display">
            </div>
            </div>
        <div class="modal-footer">
        </div> </div>
      
    </div>
  </div>
  
  <div class="modal fade" id="software_offer" role="dialog">
    <div class="modal-dialog modal-dialog1">
      <!-- Modal content-->
      <div class="modal-content modal-md">
          
        <div class="modal-body" >
            <h4 style="padding:3px;color:white;background-color: #f10000;font-weight: 900;"><center>System Generated Offer</center></h4>
            <div id="software_offer_display"></div>
        </div>
         </div>
      
    </div>
  </div>
  
  <input type="hidden" value="" id="online_latitude">
  <input type="hidden" value="" id="online_longitude">
  <input type="hidden" value="" id="online_address">
  <input type="hidden" value="" id="online_order_type">
  
<!--============================================== END Logout  =========================================================-->        
      
		<script src="js/jquery-2.1.4.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
		<script src="js/jquery-ui.min.js" type="text/javascript"></script>

<script>
		
// Websocket 
var conn = new WebSocket('ws://162.241.130.143:8080');
conn.onopen = function(e) {
    console.log("Connection established!");
};		
		
$(document).ready(function(){
    home_delivery();
	pizza_list();
	burger_list();
	fries_list();
	nuggets_list();
	shakes_list();
	coffee_list();
	mojito();
	ice_tea_list();
	water();
	//placedorderdisplay();
	completedorderdisplay();
	showbill();
	kitchenorderdisplay();
});
// timer for checking connection with websocket
var timer=0;
var linkurl="audio/Loud1.mp3";
var audio = new Audio(linkurl);

setInterval(function(){
	timer=timer+1;
	if(timer>450){
	window.location.reload(); 
	}
},2000);

var session_check=0;

setInterval(function(){
	session_check=session_check+1;
	if(session_check>150){
	    session_check=0;
		$.ajax({
		url:"session.php",
		type:'post',
		data:{ 	
		    session_check:session_check,
			},
		success: function (data,status){
		}
	});
	}
},2000);


document.getElementById("online_latitude").value=sessionStorage.getItem("online_latitude");
document.getElementById("online_longitude").value=sessionStorage.getItem("online_longitude");
document.getElementById("online_address").value=sessionStorage.getItem("online_address");
document.getElementById("online_order_type").value=sessionStorage.getItem("online_order_type");

conn.onmessage = function(e) {
	var data = JSON.parse(e.data);
	var websocket_fid = $("#websocket_fid").val();
	timer=0;
	if(websocket_fid == data.websocket_fid && data.location == 'Display' )
	{
		completedorderdisplay();
		kitchenorderdisplay();
		reorderdisplay();
	}
	if(websocket_fid == data.fid && data.location == 'mobile_app' )
	{
	    var latitude = data.latitude; 
	    var longitude = data.longitude;
	    var address = data.address;
	    var order_type = data.order_type;;
	    var cid=data.cid;
            home_delivery();		
            audio.play();
        var location="mobile";  
        var status="cafeon";
       document.getElementById("online_latitude").value=latitude;
       document.getElementById("online_longitude").value=longitude;
       document.getElementById("online_address").value=address;
       document.getElementById("online_order_type").value=order_type;
       
        var reply_data={
            websocket_fid:websocket_fid,
            location:location,
            status:status,
            cid:cid,
        }        
	conn.send(JSON.stringify(reply_data));    
	}
	if(websocket_fid == data.fid && data.location == 'mobile_app_hd' )
	{
	    completedorderdisplay();
	}
		if(websocket_fid == data.fid && data.location == 'mobile_app_reject' )
	{
	    $('#home_delivery_display').modal('hide');
	    home_delivery();
	}
	
};

function websocket_connection(){
	var location="Kitchen";
	var websocket_fid = $("#websocket_fid").val();	
	var data = {
		websocket_fid:websocket_fid,
		location:location,
	};
	conn.send(JSON.stringify(data));
}

function websocket_connection_display(){
	var location="Displayonly";
	var websocket_fid = $("#websocket_fid").val();	
	var data = {
		websocket_fid:websocket_fid,
		location:location,
	};
	conn.send(JSON.stringify(data));
}

function websocket_connection_display_sound(billno){
	var billno=billno;
	var location="Display";
	var websocket_fid = $("#websocket_fid").val();	
	var data = {
		websocket_fid:websocket_fid,
		location:location,
		billno:billno,
	};
	conn.send(JSON.stringify(data));
}

function websocket_connection_kitchen(){
	var billno=billno;
	var location="Kitchenonly";
	var websocket_fid = $("#websocket_fid").val();	
	var data = {
		websocket_fid:websocket_fid,
		location:location,
	};
	conn.send(JSON.stringify(data));
}

function websocket_connection_customer_reply(cid,order_status){
	var location="mobile";
	var reject_reason="";
	if(order_status=="Rejected"){
	    reject_reason=document.getElementById("reject_reason").value;
	}
	var data = {
		cid:cid,
		order_status:order_status,
		location:location,
		reject_reason:reject_reason,
	};
	conn.send(JSON.stringify(data));
}

function closed()
{	
var closed="closed";
	$.ajax({
		url:"products_backend.php",
		type:'post',
		data:{ 	
				closed:closed,
			},
		success: function (data,status){
		home_delivery();
alert("Shop Open");

		}
	});
}
function opened()
{	
var opened="opened";
	$.ajax({
		url:"products_backend.php",
		type:'post',
		data:{ 	
		    opened:opened,
			},
		success: function (data,status){
		home_delivery();
alert("Shop Closed");
		  //audio.muted = true;
		}
	});
}

function home_delivery(){
    var home_delivery="home_delivery";
	$.ajax({
		 url:"without_gst_insert_oldmenu.php",

		type:'post',
		data:{
			home_delivery:home_delivery,		
		},
		success: function (data,status){
		$('#home_delivery').html(data);
		//frenchises();
		}		
	});	
}
function frenchises(){
	var frenchises="frenchises";
	$.ajax({
		 url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{
			frenchises:frenchises,		
		},
		success: function (data,status){
		$('#frenchises').html(data);
		audio.pause();
		var websocket_fid = $("#websocket_fid").val();
		var location="mobile";  
        var status="cafeon";
        var cid=sessionStorage.getItem("sessioncid");
		var reply_data={
            websocket_fid:websocket_fid,
            location:location,
            status:status,
            cid:cid,
        }        
	conn.send(JSON.stringify(reply_data)); 
		}		
	});	
}

function reject(cid,fid)
{
    var reject="reject";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	reject:reject,
				cid:cid,	
				fid:fid,
		},
		success: function (data,status){
		$('#approve_reject').html(data);
		var rejected="Rejected";
		websocket_connection_customer_reply(cid,rejected);
		home_delivery();
		}
		
	});
}
function approve(cid,fid)
{
    var approve="approve";
    var latitude=document.getElementById("online_latitude").value;
    var longitude=document.getElementById("online_longitude").value;
    var address=document.getElementById("online_address").value;
    var order_type=document.getElementById("online_order_type").value;
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	approve:approve,
				cid:cid,
				fid:fid,
				latitude:latitude,
				longitude:longitude,
				address:address,
				order_type:order_type,
		},
		success: function (data,status){
		$('#approve_reject').html(data);
		var approved="Approved";
		websocket_connection_customer_reply(cid,approved);
		home_delivery();
		kitchenorderdisplay();
		websocket_connection();
		}
		
	});
}
function completedorder_home_delivery(billno){
    var completedorder_home_delivery="completedorder_home_delivery";
	$.ajax({
		 url:"without_gst_insert_oldmenu.php",

		type:'post',
		data:{
			completedorder_home_delivery:completedorder_home_delivery,
			billno:billno,
		},
		success: function (data,status){
		$('#completedorder_mobile_display').html(data);
		}		
	});	
}

function completedorder_take_away(billno){
    var completedorder_take_away="completedorder_take_away";
	$.ajax({
		 url:"without_gst_insert_oldmenu.php",

		type:'post',
		data:{
			completedorder_take_away:completedorder_take_away,
			billno:billno,
		},
		success: function (data,status){
		$('#completedorder_mobile_display').html(data);
		}		
	});	
}

function dispatch(billno){
    var employee_id=document.getElementById("home_delivery_employeeid").value;
    var dispatch="dispatch";
	$.ajax({
		 url:"without_gst_insert_oldmenu.php",

		type:'post',
		data:{
			dispatch:dispatch,
			billno:billno,
			employee_id:employee_id,
		},
		success: function (data,status){
		    completedorderdisplay();
		}		
	});	
}

function take_away_payment(billno){
    var payment_mode = "Cash";
    var selected = $("input[type='radio'][name='payment_mode_take_away']:checked").val();
    var selected=document.querySelector('input[name="payment_mode_take_away"]:checked').value;
    payment_mode = selected;
    
    var take_away_payment="take_away_payment";
	$.ajax({
		 url:"without_gst_insert_oldmenu.php",

		type:'post',
		data:{
			take_away_payment:take_away_payment,
			billno:billno,
			payment_mode:payment_mode,
		},
		success: function (data,status){
		    completedorderdisplay();
		}		
	});	
}

function showpending(){
    var showpending="showpending";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	showpending:showpending,		
		},
		success: function (data,status){
		showbill();
		}
	});
}
function sendpending(){
    var sendpending="sendpending";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	sendpending:sendpending,		
		},
		success: function (data,status){
		showbill();
		}
	});
}
function showbill(){
	var showbill="showbill";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	showbill:showbill,		
		},
		success: function (data,status){
		$('#showbill').html(data);
		document.getElementById("printbackendbutton").style.display="block";
		}
		
	});
}

function cartadd(productid,productname,price,size,category)
{
    var cartadd="cartadd";
    document.getElementById("printbackendbutton").style.display="none";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	
		        cartadd:cartadd,
		        productid:productid,
				productname:productname,
				price:price,
				size:size,
				category:category,
				
		},
		success: function (data,status){
			// $('#showbill').html(data);
			showbill();
			sessionStorage.clear();
		}
		
	});
}
function plusone(productid,productname,price,quantity,plusone,category)
{
    document.getElementById("printbackendbutton").style.display="none";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	productid:productid,
				productname:productname,
				price:price,
				quantity:quantity,
				plusone:plusone,
				category:category,
		},
		success: function (data,status){
			showbill();
			sessionStorage.clear();
		}
		
	});
}

function minusone(productid,productname,price,quantity,minusone,category)
{
    document.getElementById("printbackendbutton").style.display="none";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	productid:productid,
				productname:productname,
				price:price,
				quantity:quantity,
				minusone:minusone,
				category:category,
		
		},
		success: function (data,status){
			showbill();
			sessionStorage.clear();
		}
		
	});
}
function addkeyup(productid){
	var addkeyup="addkeyup";
	var productid1="keyup"+productid;
	var quantity = document.getElementById(productid1).value;
	if(quantity!="" && quantity>=10){
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	addkeyup:addkeyup,
		        productid:productid,
				quantity:quantity,
		},
		success: function (data,status){
		showbill();
		sessionStorage.clear();
		}
	});
}
}

function addkeyup_parcel(productid){
	var addkeyup_parcel="addkeyup_parcel";
	var productid1="keyup"+productid;
	var parcel1="parcel"+productid;
	var quantity = document.getElementById(productid1).value;
	var parcel1 = document.getElementById(parcel1).checked;
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	addkeyup_parcel:addkeyup_parcel,
		        productid:productid,
				parcel1:parcel1,
		},
		success: function (data,status){
			showbill();
		}
	});
}

function addkeyup_extra(productid){
	var addkeyup_extra="addkeyup_extra";
	var extra1="extra"+productid;
	var extra1 = document.getElementById(extra1).value;
	// alert(lastChar);
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	addkeyup_extra:addkeyup_extra,
		        productid:productid,
				extra1:extra1,
		},
		success: function (data,status){
		showbill();
		}
	});

}

function software_offer(){
let amount=parseInt(document.getElementById('num1').value);
let software_offer="software_offer";
let display="";
if(amount>=100){
    let software_offer = sessionStorage.getItem('discount_id');
    let without_gst_amount=parseInt(document.getElementById('without_gst_amount').value);
    if (sessionStorage.getItem('discount_id') != null) {
        let discount_id=sessionStorage.getItem("discount_id");
 		let discount_productname=sessionStorage.getItem("discount_productname");
 		let discount_price=sessionStorage.getItem("discount_price");
 		let discount_before_price=sessionStorage.getItem("discount_before_price");
 		let discount_percentage=sessionStorage.getItem("discount_percentage");
 		let discount_size=sessionStorage.getItem("discount_size");
 		let diff=parseInt(discount_before_price-discount_price);
 		let after_offer_amount=parseInt(amount)+parseInt(discount_price);
 		let show_discount=discount_percentage +"%";
	    if(diff>discount_percentage){
	        show_discount="<i class='fa fa-inr'></i> "+diff;
	    }
        display="<div class='row'>"+
	    "<div class='col-md-12 text-center'>"+
	    "<b>Discount of <span style='float:right'><button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button></span></b>"+
	    "<h1 class='text-danger text-center' style='font-size: 50px;'><b >"+show_discount+"</b></h1>"+
	    "<h2 class='text-success text-center'><span style='font-size: 20px;'>on &nbsp;</span><b >"+discount_productname+" "+discount_size+" </b></h2><br>"+
	    "<div class='row'>"+
	    "<div class='col-md-6'><b class='text-center'>Without Offer</b><table class='table' style='border:black solid 1px'>"+
	    "<tr><td>Bill Amount</td><td>"+without_gst_amount+"</td></tr>"+
	    <?php 
	    if($gst=='Yes'){
	        echo'"<tr><td>GST(5%)</td><td>"+Math.round(without_gst_amount*5/100)+"</td></tr>"+';
	    }
	    ?>
	    "<tr><td>To Pay</td><td>"+amount+"</td></tr></table><button type='button' class='btn btn-success' style='margin-top: 5px' onclick='printbackend()' id='printbackend_no_discount'>Confirm & Print</button></div>"+
	    "<div class='col-md-6'><b class='text-center'>With Offer</b><table class='table' style='border:black solid 1px'>"+
	    "<tr><td>Bill Amount</td><td>"+without_gst_amount+"</td><tr>"+
	    "<tr><td>"+discount_productname+"<br>("+discount_before_price+")</td><td>"+discount_price+"</td>"+
	    <?php 
	    if($gst=='Yes'){
	        echo'"<tr><td>GST(5%)</td><td>"+Math.round(after_offer_amount*5/100)+"</td></tr><tr><td>To Pay</td><td>"+parseInt((after_offer_amount+Math.round(after_offer_amount*5/100))-Math.round(without_gst_amount*5/100))+"</td></tr>"+';
	    }else{
	        echo'"<tr><td>To Pay</td><td>"+parseInt(after_offer_amount)+"</td></tr>"+';
	    }
	    ?>
	    "</table><input type='number' id='mobile_number_discount' name='mobile_number_discount' autocomplete='off' placeholder='Mobile Number' class='form-control' style='margin-top: 5px' onkeyup='check_mobile_number()'><button type='button' class='btn btn-success' style='margin-top: 5px; display:none' onclick='printbackend_discount()' id='printbackend_discount'>Confirm & Print</button><button class='btn btn-secondary btn-block' id='printbackend_discount_disabled' title='Enter Mobile Number First' style='margin-top: 5px;'>Confirm & Print</button></div></div></div>"+
	    "</div>"+
	    "</div>";
  		$('#software_offer_display').html(display);
        $('#software_offer').modal('show');
        document.getElementById('software_offer').style.left = '0px';
    }else{
        $.ajax({		
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	
		        software_offer:software_offer,
				amount:amount,
		},
		success: function (data,status){
		    $('#software_offer_display').html(data);
		    $('#software_offer').modal('show');
		    document.getElementById('software_offer').style.left = '0px';
		    let discount_id=document.getElementById('discount_id').value;
		    let discount_category_id=document.getElementById('discount_category_id').value;
		    let discount_productname=document.getElementById('discount_productname').value;
		    let discount_price=parseInt(document.getElementById('discount_price').value);
		    let discount_before_price=parseInt(document.getElementById('discount_before_price').value);
		    let diff=parseInt(discount_before_price-discount_price);
		    let discount_percentage=parseInt(document.getElementById('discount_percentage').value);
		    let discount_size=document.getElementById('discount_size').value
		    discount_size=(discount_size!='Regular'?discount_size:'');
		    //$size=($row['size']!='Regular'? $row['size']: '');
		    let after_offer_amount=parseInt(amount)+parseInt(discount_price);
		    let show_discount=discount_percentage +"%";
		    
	    if(diff>discount_percentage){
	        show_discount="<i class='fa fa-inr'></i> "+diff;
	    }
		display="<div class='row'>"+
	    "<div class='col-md-12 text-center'>"+
	    "<b>Discount of <span style='float:right'><button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button></span></b>"+
	    "<h1 class='text-danger text-center' style='font-size: 50px;'><b >"+show_discount+"</b></h1>"+
	    "<h2 class='text-success text-center'><span style='font-size: 20px;'>on &nbsp;</span><b >"+discount_productname+" "+discount_size+" </b></h2><br>"+
	    "<div class='row'>"+
	    "<div class='col-md-6'><b class='text-center'>Without Offer</b><table class='table' style='border:black solid 1px'>"+
	    "<tr><td>Bill Amount</td><td>"+without_gst_amount+"</td></tr>"+
	    <?php 
	    if($gst=='Yes'){
	        echo'"<tr><td>GST(5%)</td><td>"+Math.round(without_gst_amount*5/100)+"</td></tr>"+';
	    }
	    ?>
	    "<tr><td>To Pay</td><td>"+amount+"</td></tr></table><button type='button' class='btn btn-success' style='margin-top: 5px' onclick='printbackend()' id='printbackend_no_discount'>Confirm & Print</button></div>"+
	    "<div class='col-md-6'><b class='text-center'>With Offer</b><table class='table' style='border:black solid 1px'>"+
	    "<tr><td>Bill Amount</td><td>"+without_gst_amount+"</td><tr>"+
	    "<tr><td>"+discount_productname+"<br>("+discount_before_price+")</td><td>"+discount_price+"</td>"+
	    <?php 
	    if($gst=='Yes'){
	        echo'"<tr><td>GST(5%)</td><td>"+Math.round(after_offer_amount*5/100)+"</td></tr><tr><td>To Pay</td><td>"+parseInt((after_offer_amount+Math.round(after_offer_amount*5/100))-Math.round(without_gst_amount*5/100))+"</td></tr>"+';
	    }else{
	        echo'"<tr><td>To Pay</td><td>"+parseInt(after_offer_amount)+"</td></tr>"+';
	    }
	    ?>
	    "</table><input type='number' id='mobile_number_discount' name='mobile_number_discount' autocomplete='off' placeholder='Mobile Number' class='form-control' style='margin-top: 5px' onkeyup='check_mobile_number()'><button type='button' class='btn btn-success' style='margin-top: 5px; display:none' onclick='printbackend_discount()' id='printbackend_discount'>Confirm & Print</button> <button class='btn btn-secondary btn-block' id='printbackend_discount_disabled' title='Enter Mobile Number First' style='margin-top: 5px;'>Confirm & Print</button></div></div></div>"+
	    "</div>"+
	    "</div>";
	    discount_size=document.getElementById('discount_size').value;
  		$('#software_offer_display').html(display);
 		sessionStorage.setItem("discount_id",discount_id);
 		sessionStorage.setItem("discount_productname",discount_productname);
 		sessionStorage.setItem("discount_price",discount_price);
 		sessionStorage.setItem("discount_before_price",discount_before_price);
 		sessionStorage.setItem("discount_percentage",discount_percentage);
 		sessionStorage.setItem("discount_size",discount_size);
 		sessionStorage.setItem("discount_category_id",discount_category_id);
		}
	});
    }
}else{
    let display="<button type='button' class='btn btn-success' style='margin-top: 5px' id='printbackend_no_discount'>Confirm & Print</button>";
    $('#software_offer_display').html(display);
    printbackend();
}
}
function check_mobile_number(){
    let mobile=document.getElementById("mobile_number_discount").value;
    let len=mobile.length;
    if(len==10){
        document.getElementById("printbackend_discount").style.display="block";
        document.getElementById("printbackend_discount_disabled").style.display="none";
        document.getElementById("mobile_number").value=mobile;
    }else{
        document.getElementById("printbackend_discount").style.display="none";
        document.getElementById("printbackend_discount_disabled").style.display="block";
    }
    console.log(len);
}

function printbackend_discount(){
    $('#printbackend_discount').remove();
    var printbackend_discount="printbackend_discount";
    let productid=sessionStorage.getItem("discount_id");
 	let productname=sessionStorage.getItem("discount_productname");
 	let price=sessionStorage.getItem("discount_price");
 	let category=sessionStorage.getItem("discount_category_id");
 	let discount_percentage=sessionStorage.getItem("discount_percentage");
 	let size=sessionStorage.getItem("discount_size");
 	let discount_before_price=sessionStorage.getItem("discount_before_price");
	$.ajax({		
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	
		        printbackend_discount:printbackend_discount,
				productid:productid,
				productname:productname,
				price:price,
				size:size,
				category:category,
				discount_percentage:discount_percentage,
				discount_before_price:discount_before_price,
		},
		success: function (data,status){
			    printbackend();
		}		
	});
}
function printbackend(){
    $('#printbackendbutton').remove();
    $('#printbackend_no_discount').remove();
    var printbackend="printbackend";
    var mobile_number = document.getElementById('mobile_number').value;
    var passcode = document.getElementById('passcode').value;
    var orderby="For Eat";
    orderby = document.getElementById('servicetype').value;
    var payment_mode = "Cash";
    var selected = $("input[type='radio'][name='payment_mode']:checked").val();
    var selected=document.querySelector('input[name="payment_mode"]:checked').value;
    payment_mode = selected;
    var amount=document.getElementById('num1').value;
	$.ajax({		
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	
		        printbackend:printbackend,
		        orderby:orderby,
				payment_mode:payment_mode,
				amount:amount,
				mobile_number:mobile_number,
				passcode:passcode,
		},
		success: function (data,status){
			    	websocket_connection();
window.location.replace("with_gst_bill.php");
		}		
	});
}

function reprint(billno,amount){
	var reprint="reprint";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	reprint:reprint,
		        billno:billno,
		        amount:amount
		},
		success: function (data,status){
		window.location.replace("with_gst_bill.php");
		}
	});
}

function reprintdisplay(){
	var reprintdisplay="reprintdisplay";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	reprintdisplay:reprintdisplay,		
		},
		success: function (data,status){
		$('#reprintdisplay').html(data);
		}
	});
}
function reorder(billno){
	var reorder="reorder";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	reorder:reorder,
		        billno:billno,
		},
		success: function (data,status){
		websocket_connection();
		websocket_connection_display();
		window.location.replace("without_gst_index.php");
		}
	});
}


function reorderdisplay(){
	var reorderdisplay="reorderdisplay";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	reorderdisplay:reorderdisplay,		
		},
		success: function (data,status){
		$('#reorderdisplay').html(data);
		}
	});
}

function completedorderdisplay(){
	var completedorderdisplay= "completedorderdisplay";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	completedorderdisplay:completedorderdisplay,
		},
		success: function (data,status){
		$('#completedorderdisplay').html(data);
		}
	});
}
function completedorder(billno){
	var completedorder="completedorder";
	// var billno=8;
	// var completedorder= document.getElementById('completedorder').value;
	$.ajax({
		
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	completedorder:completedorder,
				billno:billno,
		},
		success: function (data,status){
		$('#completedorder').html(data);
			completedorderdisplay();
			websocket_connection_display();
		}
	});
}

function kitchenorderdisplay(){
	var kitchenorderdisplay= "kitchenorderdisplay";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	kitchenorderdisplay:kitchenorderdisplay,
		},
		success: function (data,status){
		$('#kitchenorderdisplay').html(data);
		}
	});
}

function kitchenorder(billno){
	var kitchenorder="kitchenorder";
	$.ajax({
		
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	kitchenorder:kitchenorder,
				billno:billno,
		},
		success: function (data,status){
		$('#kitchenorder').html(data);
		completedorderdisplay();
		kitchenorderdisplay();
		websocket_connection_kitchen();
		websocket_connection_display_sound(billno);
		}
		
	});
}

function pizza_list(){
	var pizza_list="pizza_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	pizza_list:pizza_list,		
		},
		success: function (data,status){
		$('#pizza_list').html(data);
		}
		
	});
}

function burger_list(){
	var burger_list="burger_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	burger_list:burger_list,		
		},
		success: function (data,status){
		$('#burger_list').html(data);
		}
		
	});
}

function fries_list(){
	var fries_list="fries_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	fries_list:fries_list,		
		},
		success: function (data,status){
		$('#fries_list').html(data);
		}
		
	});
}

function nuggets_list(){
	var nuggets_list="nuggets_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	nuggets_list:nuggets_list,		
		},
		success: function (data,status){
		$('#nuggets_list').html(data);
		}
		
	});
}

function shakes_list(){
	var shakes_list="shakes_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	shakes_list:shakes_list,		
		},
		success: function (data,status){
		$('#shakes_list').html(data);
		}
		
	});
}

function coffee_list(){
	var coffee_list="coffee_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	coffee_list:coffee_list,		
		},
		success: function (data,status){
		$('#coffee_list').html(data);
		}
		
	});
}
function ice_tea_list(){
	var ice_tea_list="ice_tea_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	ice_tea_list:ice_tea_list,		
		},
		success: function (data,status){
		$('#ice_tea_list').html(data);
		}
		
	});
}
function other_list(){
	var other_list="other_list";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	other_list:other_list,		
		},
		success: function (data,status){
		$('#other_list').html(data);
		}
		
	});
}

function mojito(){
	var mojito="mojito";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	mojito:mojito,		
		},
		success: function (data,status){
		$('#mojito').html(data);
		}
		
	});
}
function water(){
	var water="water";
	$.ajax({
		url:"without_gst_insert_oldmenu.php",
		type:'post',
		data:{ 	water:water,		
		},
		success: function (data,status){
		$('#water').html(data);
		}
		
	});
}
</script>
<script>
function showDiv() {
   document.getElementById('welcomeDiv').style.display = "block";
}
</script>
   <script type="text/javascript">
    function disable(sender) { // sender here has all details of dropdown
        if (sender.value =="Swiggy" || sender.value =="Zomato") {
            document.getElementById("cash_disable").disabled = true;
            document.getElementById("card_disable").disabled = true;
			document.getElementById("bank_disable").disabled = true;
              document.getElementById("num2").disabled = true;
        }
		 else {
            document.getElementById("cash_disable").disabled = false;
            document.getElementById("card_disable").disabled = false;
            document.getElementById("bank_disable").disabled = false;
            document.getElementById("num2").disabled = false;

        }
    }
</script>
 <script type="text/javascript"></script>
<script type="text/javascript">
    function print1(){
    
    printbackend();
    }
</script>
 <script type="text/javascript">
    function sub(){
    var input1_ = document.getElementById('num1');
    var input2_ = document.getElementById('num2');
    var answer = document.getElementById('Answer');
        answer.innerHTML = (parseInt(input2_.value) - parseInt(input1_.value));
    }
    
   
</script>


    </body>
</html>