<?php
session_start();
require("php_con.php");
require("function.php");

if(isset($_GET['re-print'])){
	$_SESSION['bill_print']=1;
}

if(isset($_COOKIE['user_id'])){
	$current_user_qury=mysqli_query($connation,"SELECT * FROM user_details WHERE user_id='$_COOKIE[user_id]'");
	$current_user_resalt=mysqli_fetch_array($current_user_qury);
}
else{
	echo "<script>window.location='logout';</script>";
	exit();
}

if(isset($_POST['Start_balance_bt'])){
	$Start_balance_start_amount=mysqli_real_escape_string($connation,$_POST['Start_balance_start_amount']);
	mysqli_query($connation,"INSERT INTO start_balance_details(Start_balance_date, Start_balance_start_amount, Start_balance_start_user) VALUES ('$current_date','$Start_balance_start_amount','$_COOKIE[user_id]')");
	//mysqli_query($connation,"UPDATE setting SET setting_value='1' WHERE setting_text='bill_start_count'");
}

$start_balance_qury=mysqli_query($connation,"SELECT * FROM start_balance_details WHERE Start_balance_date='$current_date' AND Start_balance_start_user='$_COOKIE[user_id]'");
if(mysqli_num_rows($start_balance_qury)>0){
	//$start_balance_resalt=mysqli_fetch_array($start_balance_qury);
	$start_enter=1;
}
else{
	$start_enter=0;
}

if(isset($_GET['bill_id'])){
$bill_id=mysqli_real_escape_string($connation,$_GET['bill_id']);
}
else{
$bill_id=time();
	
$check_bil_id=mysqli_query($connation,"SELECT * FROM sale_details WHERE sale_details_billid='$bill_id'");
if(mysqli_num_rows($check_bil_id)>0){
echo "<script>window.location='poin-of-sale';</script>";
}
	
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title><?php echo $system_name; ?></title>
<link rel="stylesheet" href="cus_css.css">
	
<script src="data_table/js/jquery-3.5.1.js"></script>
<script src="data_table/js/jquery.dataTables.min.js"></script>
<script src="data_table/js/dataTables.bootstrap4.min.js"></script>
<link rel="stylesheet" href="data_table/css/bootstrap.css">
<link rel="stylesheet" href="data_table/css/dataTables.bootstrap4.min.css">
	
<link rel="stylesheet" href="alert/sweetalert2.min.css">
<script src="alert/sweetalert2.min.js"></script>
	
<link rel="stylesheet" href="icon/css/font-awesome.css">
<link rel="stylesheet" href="icon/css/font-awesome.min.css">
</head>

<body>
<script>
window.addEventListener("load",function(){
	var load_screen=document.getElementById('load_screen');
	document.body.removeChild(load_screen);
});
</script>

<div id="load_screen"><div id="loading"><img src="image/loading.gif" width="80px;"></div></div>
	
	

<?php if($start_enter==0){ ?>
<div style="width: 450px; margin: auto; margin-top: 5%; text-align: center; background-color: rgba(135,206,235,0.5); padding: 10px;">
<form method="post" autocomplete="off">
<h4>Enter Your Day Start Balance<br><br>
Valid User: <strong><?php echo $current_user_resalt['user_fname']; ?></strong><br>
Valid Date: <strong><?php echo $current_date; ?></strong>
</h4><br>
<table>
  <tbody>
    <tr>
      <td><input name="Start_balance_start_amount" type="text" class="form-control" placeholder="Amount" required></td>
      <td><button name="Start_balance_bt" type="submit" class="btn btn-success ml-2" style="white-space: nowrap;">Enter Amount</button></td>
	<td><a href="dashboard" class="btn btn-danger ml-2" style="white-space: nowrap;">Cancel</a></td>
		<td><a href="logout" class="btn btn-dark ml-2" style="white-space: nowrap;">Logout</a></td>
    </tr>
  </tbody>
</table>
</form>
</div>
<?php } ?>
	
<?php if($start_enter==1){ ?>

<!--pos start-->
<table style="width: 100%; margin: auto; height: 100vh;">
<tbody>
<tr>
<td valign="top" class="p-2" style="background-color: black; color: white;">
	
<table>
	<tbody>
		<tr>
			<td style="padding-right: 20px;"><img src="image/logo-sm.jpg" style="border-radius: 5px; height: 50px;"></td>
			<td>System ID<br><input name="bill_id" type="text" class="form-control form-control-sm" id="bill_id" value="<?php echo $bill_id; ?>" readonly>
			</td>
			<td class="pl-2">User<br><input type="text" class="form-control form-control-sm" readonly value="<?php if(isset($current_user_resalt)){ echo $current_user_resalt['user_fname']; } ?>">
			</td>
			<td class="pl-2">Start Time<br><input type="text" class="form-control form-control-sm" readonly value="<?php echo date_format(date_create($current_time)," h:i:s A ") ?>">
			</td>
			<td class="pl-2">&nbsp;<br><a href="logout" class="btn btn-sm btn-secondary" title="Exit POS"><i class="fa fa-sign-out"></i> Logout</a></td>
		</tr>
	</tbody>
</table>

</td>
<td rowspan="2" valign="top" class="p-2">
<div style="width: 100%; height: 100%; overflow-y: scroll;">

<div class="pos-main-btn">
<div class="pos-sub-btn btn-dark" onClick="item_list();"><i class="fa fa-lg fa-search"></i> Product List</div>
<div class="pos-sub-btn btn-dark" onClick="return_model();"><i class="fa fa-lg fa-refresh"></i> Return</div>
<div class="pos-sub-btn btn-dark" onClick="other_item();"><i class="fa fa-lg fa-question"></i> Other Item (F4)</div>
<label for="wholesale_btn" style="margin: 0px; padding: 0px;"><div class="pos-sub-btn btn-dark"><input name="wholesale_btn" type="checkbox" id="wholesale_btn" onChange="document.getElementById('special_btn').checked=false;"> Wholesale (F8)</div></label>
<label for="special_btn" style="margin: 0px; padding: 0px;"><div class="pos-sub-btn btn-dark"><input name="special_btn" type="checkbox" id="special_btn" onChange="document.getElementById('wholesale_btn').checked=false;"> Special (F9)</div></label>

<div class="pos-sub-btn btn-info" onClick="q_list_open();"><i class="fa fa-lg fa-list"></i> Quotation List</div>
<div class="pos-sub-btn btn-info" onClick="q_print();"><i class="fa fa-lg fa-print"></i> Print Quotation</div>
<div class="pos-sub-btn btn-primary" onClick="customer_balance();"><i class="fa fa-lg fa-user"></i> Customer Balance</div>
<div class="pos-sub-btn btn-primary" onClick="invoice_check_model();"><i class="fa fa-lg fa-newspaper-o"></i> Issue Bill Check</div>
<div class="pos-sub-btn btn-warning" onClick="my_expenses();"><i class="fa fa-lg fa-dollar"></i> My Expenses</div>

<div class="pos-sub-btn btn-warning" onClick="today_sale();"><i class="fa fa-lg fa-calendar-minus-o"></i> Today Sale</div>
<div class="pos-sub-btn btn-warning" onClick="month_sale();"><i class="fa fa-lg fa-calendar"></i> Monthly Sale</div>
<div class="pos-sub-btn btn-primary" onClick="hold_bill();"><i class="fa fa-lg fa-tasks"></i> Current Hold Bill</div>
<div class="pos-sub-btn btn-warning" onClick="today_end();"><i class="fa fa-lg fa-check"></i> Day End Summery Report</div>
</div>
	
<?php if($current_user_resalt['user_type']==1||$current_user_resalt['user_type']==2){ ?>

<table style="width: 100%; height: 59%;">
  <tbody>
    <tr>
      <td>
		
<div style="height: 100%; overflow-y: scroll;" id="item_load_div">

<div align="center" style="background-color: #CCCCCC; margin-bottom: 5px;">Please Select Category</div>
	
</div>
		
		</td>
      <td style="width: 35%;">
		  
<div style="height: 100%; overflow-y: scroll;">
<div align="center" style="background-color: #CCCCCC; margin-bottom: 5px;">Pin Category</div>
<?php
$c_qury=mysqli_query($connation,"SELECT * FROM catogary_list cl WHERE cl.catogary_pin_to_pos='1' ORDER BY cl.catogary_text ASC");
while($c_resalt=mysqli_fetch_assoc($c_qury)){
?>
<div class="pos_cat_btn" onClick="select_cat_wise_product('<?php echo $c_resalt['catogary_id']; ?>');"><?php echo $c_resalt['catogary_text']; ?></div>
<?php } ?>
	
</div>
	</td>		  
		  
    </tr>
  </tbody>
</table>

	
<?php } ?>
	
</div>
	
</td>
</tr>
<tr  style="background-color: #CCCCCC;">
<td valign="top" style="width: 60%; height: 100%;" class="p-2">
	
<table style="width: 100%; margin-bottom: 5px;">
  <tbody>
    <tr>
      <th scope="col"><input name="product_barcode" type="text" autofocus="autofocus" class="form-control form-control-sm" id="product_barcode" placeholder="Scan Barcode (Insert)" <?php if(setting_view("product_suggestions")==1){echo "list='product_list'";} ?> autocomplete="off" onFocus="this.select();" onKeyUp="JavaScript:select_qty(event);"></th>
      <th scope="col" style="width: 120px;"><input name="sale_qty" type="number" class="form-control form-control-sm" id="sale_qty" placeholder="QTY1" step="0.000001" autocomplete="off" onFocus="this.select();" onKeyUp="JavaScript:save_list(event);"></th>
    </tr>
  </tbody>
</table>
	
<datalist id="product_list">
	<?php 
	$sug_list_qury=mysqli_query($connation,"SELECT * FROM product_details ORDER BY product_name");
	while($sug_list_resalt=mysqli_fetch_array($sug_list_qury)){
	?>
	<option value="<?php echo $sug_list_resalt['product_barcode']; ?>"><?php echo $sug_list_resalt['product_productid']." - ".$sug_list_resalt['product_name']." | ".$sug_list_resalt['product_name_sinhala']; ?></option>
	<?php } ?>
</datalist>

	
<iframe src="sale_list.php?bill_id=<?php echo $bill_id; ?>" id="sale_list_load" style="height: 90%; width: 100%; border: none; background-color: white;"></iframe>
	
</td>
</tr>
<tr>
<td align="right" valign="middle" class="pb-4">

<div id="total_amount" style="background-color: black; color: gold; padding-right: 20px; padding-bottom: 5px;">
<span style="font-weight: bold; font-size: 36px;">0.00</span><br>
<span style="font-size: 16px; color: white;">0 Item(s)</span>
</div>

	
</td>
<td valign="middle" class="pr-2 pb-4" align="center">
	
<p class="text-secondary mb-2"><i>This bill hold and open new bill, Click here CTRL+New Bill</i></p>
	
  <button type="button" class="btn btn-success btn-lg" onClick="save_bt();"><i class="fa fa-check-circle"></i> Payment (+)</button>
	<a href="hold-bill-new?bill_id=<?php echo $bill_id; ?>" type="button" class="btn btn-dark btn-lg" onClick="return confirm('Are your sure?');">Hold</a>
  <a href="poin-of-sale" class="btn btn-dark btn-lg" onClick="return confirm('Are your sure?');">New Bill</a>
<button type="button" class="btn btn-danger btn-lg" onClick="if(confirm('Are you sure to close these windows?')){window.location='dashboard';}"><i class="fa fa-close"></i> Close</button> <script></script>

</td>
  </tr>
</tbody>
</table>

	
<?php } ?>	
<?php if(isset($_GET['print'])&&isset($_SESSION['bill_print'])){ if($_SESSION['bill_print']==1){ ?>
<iframe src="bill_print.php?print=<?php echo $_GET['print']; ?>" style="display: none; width: 0px; height: 0px;"></iframe>
<?php } } ?>
	
<?php if(isset($_GET['q_id'])&&isset($_SESSION['bill_print'])){ if($_SESSION['bill_print']==1){ ?>
<iframe src="quotation_print.php?q_id=<?php echo $_GET['q_id']; ?>" style="display: none; width: 0px; height: 0px;"></iframe>
<?php } } ?>
	
<div class="model model-hide" id="cus_model">
	<div class="model-contain">
		<div class="model-header">Search Product <span onClick="model_close();">&times;</span>
		</div>
		<div class="model-body">
			
<table style="width: 100%;">
  <tbody>
    <tr>
      <td style="width: 75%;"><input name="search_text" type="text" class="form-control" id="search_text" placeholder="Barcode, Product Name" autocomplete="off" onKeyUp="search_product(this.value,'product');"></td>
      <td><input name="search_price" type="text" class="form-control" id="search_price" placeholder="Sale Price" autocomplete="off" onKeyUp="search_product(this.value,'price');"></td>
    </tr>
  </tbody>
</table>

			
		<div style="width: 100%; height: 390px; overflow-y: scroll; margin-top: 10px;" id="search_product_dis"></div>

		</div>
	</div>
</div>
	
<div class="model model-hide" id="cus_balance_model">
	<div class="model-contain">
		<div class="model-header">Customer Balance <span onClick="model_close_cus_balance();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="cus_balance_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="q_list">
	<div class="model-contain" style="width: 70%;">
		<div class="model-header">Quotation List <span onClick="q_list_close();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="quotation_list_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="invoice_check">
	<div class="model-contain">
		<div class="model-header">Invoice Check <span onClick="model_close_invoice_check();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="invoice_check_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="calculart_dis">
	<div class="model-contain">
		<div class="model-header">Calculator <span onClick="model_close_calculater();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="calculater_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="today_sale_dis">
	<div class="model-contain" style="width: 70%;">
		<div class="model-header">Today My Sale <span onClick="model_close_today_my_sale();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="today_my_dale_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="month_sale_dis">
	<div class="model-contain" style="width: 70%;">
		<div class="model-header">My Monthly Sale <span onClick="model_close_month_my_sale();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="month_my_dale_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="my_expenses_model">
	<div class="model-contain">
		<div class="model-header">My Expenses <span onClick="my_expenses_model_close();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="my_expenses_model_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="retun_model_popup">
	<div class="model-contain" style="width: 40%;">
		<div class="model-header">Add Return Item <span onClick="return_model_close();">&times;</span>
		</div>
		<div class="model-body">
			
<table style="margin: auto; width: 100%;">
  <tbody class="table-sm">
    <tr>
      <td>Select Item</td>
      <td><input name="return_barcode" type="text" class="form-control form-control-sm" id="return_barcode" placeholder="Scan Barcode" autocomplete="off" onKeyUp="if(event.keyCode==13){document.getElementById('return_qty').select();}" <?php if(setting_view("product_suggestions")==1){echo "list='product_list'";} ?>></td>
    </tr>
    <tr>
      <td>Retun QTY</td>
      <td><input name="return_qty" type="text" class="form-control form-control-sm w-25" id="return_qty" pattern="[0-9]+([\.][0-9]{0,2})?" onKeyUp="if(event.keyCode==13){document.getElementById('return_reason').select();}"></td>
    </tr>
    <tr>
      <td>Return Reason</td>
      <td><input name="return_reason" type="text" class="form-control form-control-sm" id="return_reason" pattern="[0-9]+([\.][0-9]{0,2})?"  onKeyUp="if(event.keyCode==13){document.getElementById('return_add_btn').focus();}" value="Exchange Item"></td>
    </tr>
    <tr>
      <td colspan="2" align="right"><button type="button" class="btn btn-sm btn-dark" id="return_add_btn" onClick="add_return_btn();">Add to list</button></td>
    </tr>
  </tbody>
</table>

		</div>
	</div>
</div>
	
<div class="model model-hide" id="today_summery">
	<div class="model-contain" style="width: 40%;">
		<div class="model-header">Today Summery Report <span onClick="today_summery_close();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="today_summery_load"></iframe>
		</div>
	</div>
</div>
	
<div class="model model-hide" id="add_other_item">
	<div class="model-contain" style="width: 40%;">
		<div class="model-header">Add New Other Item <span onClick="other_item_close();">&times;</span>
		</div>
		<div class="model-body">
			
<table class="table-sm" style="margin: auto;">
  <tbody>
    <tr>
      <td>Product Name</td>
      <td><input name="sale_other_info" type="text" class="form-control form-control-sm" id="sale_other_info" style="background-color: rgba(255,255,0,0.1);" autocomplete="off" onKeyUp="if(event.keyCode==13){document.getElementById('sale_buy_price').select();}" value="<?php if(setting_view("bill_lan")==1){echo 'වෙනත් අයිතම';}else{echo 'Other Item';} ?>"></td>
    </tr>
    <tr>
      <td>Product Cost</td>
      <td><input name="sale_buy_price" type="tel" class="form-control form-control-sm" id="sale_buy_price" autocomplete="off" onKeyUp="if(event.keyCode==13){ document.getElementById('sale_saleprice').select(); }" style="background-color: rgba(0,128,0,0.1);"></td>
    </tr>
    <tr>
      <td>Product Sale</td>
      <td><input name="sale_saleprice" type="tel" class="form-control form-control-sm" id="sale_saleprice" autocomplete="off" onKeyUp="if(event.keyCode==13){ document.getElementById('sale_qty1').select(); }" style="background-color: rgba(0,128,0,0.1);"></td>
    </tr>
    <tr>
      <td>QTY</td>
      <td><input name="sale_qty1" type="tel" class="form-control form-control-sm" id="sale_qty1" autocomplete="off" onKeyUp="if(event.keyCode==13){ document.getElementById('other_add_btn').focus(); }" style="background-color: rgba(0,0,255,0.1);"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><button id="other_add_btn" type="button" class="btn btn-sm btn-dark" onClick="add_other_function();">Add to List</button></td>
    </tr>
  </tbody>
</table>

			
		</div>
	</div>
</div>
	
<div class="model model-hide" id="hold_bill_popup">
	<div class="model-contain" style="width: 80%;">
		<div class="model-header">Current Hold Bill <span onClick="model_close_hold_bill();">&times;</span>
		</div>
		<div class="model-body">
		<iframe style="width: 100%; height: 400px; border: none;" scrolling="auto" id="current_hold_load"></iframe>
		</div>
	</div>
</div>
	
<script src="select2/script.min.js"></script>
<script>
function hold_bill(){
document.getElementById('current_hold_load').src="ajax_current_hold_bill.php";
document.getElementById('hold_bill_popup').classList.remove("model-hide");
}
function model_close_hold_bill(){
document.getElementById('hold_bill_popup').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function other_item(){
document.getElementById('add_other_item').classList.remove("model-hide");
document.getElementById('sale_other_info').value="<?php if(setting_view("bill_lan")==1){echo 'වෙනත් අයිතම';}else{echo 'Other Item';} ?>";
document.getElementById('sale_other_info').select();
}
function other_item_close(){
document.getElementById('add_other_item').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function today_end(){
document.getElementById('today_summery').classList.remove("model-hide");
document.getElementById('today_summery_load').src="ajax_today_my_summery.php";
}
function today_summery_close(){
document.getElementById('today_summery').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function item_list(){
document.getElementById('search_text').value="";
document.getElementById('search_price').value="";
document.getElementById('search_product_dis').innerHTML="";
document.getElementById('cus_model').classList.remove("model-hide");
}
function model_close(){
document.getElementById('search_text').value="";
document.getElementById('search_price').value="";
document.getElementById('search_product_dis').innerHTML="";
document.getElementById('cus_model').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function customer_balance(){
document.getElementById('cus_balance_load').src="ajax_cus_balance.php";
document.getElementById('cus_balance_model').classList.remove("model-hide");
}
function model_close_cus_balance(){
document.getElementById('cus_balance_model').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function invoice_check_model(){
document.getElementById('invoice_check_load').src="ajax_invoice_check.php";
document.getElementById('invoice_check').classList.remove("model-hide");
}
function model_close_invoice_check(){
document.getElementById('invoice_check_load').src="ajax_invoice_check.php";	
document.getElementById('invoice_check').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function calculater(){
document.getElementById('calculater_load').src="ajax_calculater.php";
document.getElementById('calculart_dis').classList.remove("model-hide");
}
function model_close_calculater(){
document.getElementById('calculart_dis').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function today_sale(){
document.getElementById('today_my_dale_load').src="ajax_today_my_sale.php";
document.getElementById('today_sale_dis').classList.remove("model-hide");
}
function model_close_today_my_sale(){
document.getElementById('today_sale_dis').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function month_sale(){
document.getElementById('month_my_dale_load').src="ajax_month_my_sale.php";
document.getElementById('month_sale_dis').classList.remove("model-hide");
}
function model_close_month_my_sale(){
document.getElementById('month_sale_dis').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function my_expenses(){
document.getElementById('my_expenses_model_load').src="ajax_my_expenses.php";
document.getElementById('my_expenses_model').classList.remove("model-hide");
}
function my_expenses_model_close(){
document.getElementById('my_expenses_model').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function q_list_open(){
document.getElementById('quotation_list_load').src="quotation_list.php";
document.getElementById('q_list').classList.remove("model-hide");
}
function q_list_close(){
document.getElementById('q_list').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function return_model(){
document.getElementById('return_barcode').value="";
document.getElementById('return_qty').value="";
document.getElementById('retun_model_popup').classList.remove("model-hide");
document.getElementById('return_barcode').select();
}
function return_model_close(){
document.getElementById('retun_model_popup').classList.add("model-hide");
document.getElementById('product_barcode').select();
}
	
function add_other_function(){
	var bill_id=document.getElementById('bill_id').value;
	var sale_buy_price=document.getElementById('sale_buy_price').value;
	var sale_saleprice=document.getElementById('sale_saleprice').value;
	var sale_qty1=document.getElementById('sale_qty1').value;
	var sale_other_info=document.getElementById('sale_other_info').value;
	
	if(sale_buy_price==""||sale_other_info==""||sale_saleprice==""||sale_qty1==""||sale_saleprice<=0){
	alert("Please Enter Product Name, Cost Price, Sale Price and QTY");
	}
	else{
	document.getElementById('sale_list_load').src="sale_list.php?bill_id="+bill_id+"&sale_buy_price="+sale_buy_price+"&sale_saleprice="+sale_saleprice+"&sale_qty1="+sale_qty1+"&sale_other_info="+sale_other_info;
	
	document.getElementById('sale_buy_price').value="";
	document.getElementById('sale_saleprice').value="";
	document.getElementById('sale_qty1').value="";
	document.getElementById('sale_other_info').value="";
	other_item_close();
	}
}

window.addEventListener("keyup", function(event){
	//console.log(event.keyCode);
	if(event.keyCode==45){
		document.getElementById('product_barcode').vale="";
		document.getElementById('product_barcode').select();
	}
	if(event.keyCode==107){
		save_bt();
	}
	if(event.keyCode==27){
		document.querySelector(".model").classList.add("model-hide");
	}
	if(event.keyCode==115){
		other_item();
	}
	if(event.keyCode==120){
		if(document.getElementById('special_btn').checked){
		document.getElementById('special_btn').checked=false;
		}
		else{
		document.getElementById('special_btn').checked=true;
			document.getElementById('wholesale_btn').checked=false;
		}
	}
	if(event.keyCode==119){
		if(document.getElementById('wholesale_btn').checked){
		document.getElementById('wholesale_btn').checked=false;
		}
		else{
		document.getElementById('wholesale_btn').checked=true;
			document.getElementById('special_btn').checked=false;
		}
	}
});
	
<?php if(setting_view("auto_add_item_list")==1){ ?>
function select_qty(event){
	var product_barcode=document.getElementById('product_barcode').value;
	var bill_id=document.getElementById('bill_id').value;
	//console.log(event);
	if(event.keyCode==13){
		
	if(product_barcode==""){
	document.getElementById('product_barcode').select();
	}
	else{
		
	if(document.getElementById('wholesale_btn').checked){
	var wholesale_btn_val=1;
	}
	else if(document.getElementById('special_btn').checked){
	var wholesale_btn_val=2;
	}
	else{
	var wholesale_btn_val=0;
	}	
			document.getElementById('sale_list_load').src="sale_list.php?product_barcode="+product_barcode+"&bill_id="+bill_id+"&sale_qty=1&wholesale_btn_val="+wholesale_btn_val;
			document.getElementById('sale_qty').value="";
			document.getElementById('product_barcode').value="";
			document.getElementById('product_barcode').select();
			}
	}
	}
<?php } else{ ?>	
function select_qty(event){
	var product_barcode=document.getElementById('product_barcode').value;
	var bill_id=document.getElementById('bill_id').value;
	//console.log(event);
	if(event.keyCode==13){
		
	if(product_barcode==""){
	document.getElementById('product_barcode').select();
	}
	else{
		
	if(product_barcode.substr(0,1)=="0"){
	if(document.getElementById('wholesale_btn').checked){
	var wholesale_btn_val=1;
	}
	else if(document.getElementById('special_btn').checked){
	var wholesale_btn_val=2;
	}
	else{
	var wholesale_btn_val=0;
	}		
			document.getElementById('sale_list_load').src="sale_list.php?product_barcode="+product_barcode+"&bill_id="+bill_id+"&sale_qty=1&wholesale_btn_val="+wholesale_btn_val;
			document.getElementById('sale_qty').value="";
			document.getElementById('product_barcode').value="";
			document.getElementById('product_barcode').select();
		}
		else{
			document.getElementById('sale_qty').value="1";
			document.getElementById('sale_qty').select();
		}
	}
	}
}
<?php } ?>
	
function save_list(event){
	var product_barcode=document.getElementById('product_barcode').value;
	var bill_id=document.getElementById('bill_id').value;
	var sale_qty=document.getElementById('sale_qty').value;
	
	//console.log(sale_qty);
	if(event.keyCode==13){
	if(product_barcode==""||sale_qty<=0){
	alert("Please Enter Product Barcode and QTY");
	document.getElementById('product_barcode').select();
	document.getElementById('sale_qty').value="";
	}
	else{
		
	if(document.getElementById('wholesale_btn').checked){
	var wholesale_btn_val=1;
	}
	else if(document.getElementById('special_btn').checked){
	var wholesale_btn_val=2;
	}
	else{
	var wholesale_btn_val=0;
	}
		
	document.getElementById('sale_list_load').src="sale_list.php?product_barcode="+product_barcode+"&bill_id="+bill_id+"&sale_qty="+sale_qty+"&wholesale_btn_val="+wholesale_btn_val;
	document.getElementById('sale_qty').value="";
	document.getElementById('product_barcode').value="";
	document.getElementById('product_barcode').select();
	}
	}
}
	
function add_return_btn(){
	var product_barcode=document.getElementById('return_barcode').value;
	var bill_id=document.getElementById('bill_id').value;
	var sale_qty=document.getElementById('return_qty').value;
	var return_reason=document.getElementById('return_reason').value;
	
	if(document.getElementById('wholesale_btn').checked){
	var wholesale_btn_val=1;
	}
	else if(document.getElementById('special_btn').checked){
	var wholesale_btn_val=2;
	}
	else{
	var wholesale_btn_val=0;
	}
	
	if(return_reason==""||product_barcode==""||sale_qty<=0){
	alert("Please Enter Product Barcode and QTY");
	}
	else{
	document.getElementById('sale_list_load').src="sale_list.php?product_barcode="+product_barcode+"&bill_id="+bill_id+"&sale_qty=-"+sale_qty+"&wholesale_btn_val="+wholesale_btn_val+"&return_reason="+return_reason;
	
	document.getElementById('return_barcode').value="";
	document.getElementById('return_qty').value="";
	document.getElementById('return_reason').value="Exchange Item";
	return_model_close();
	}
}
	
function list_value_send(product_barcode){
	document.getElementById('product_barcode').value=product_barcode;
	document.getElementById('sale_qty').value="1";
	document.getElementById('sale_qty').select();
}
	
function save_bt(){
	let bill_id=document.getElementById('bill_id').value;
	window.location="bill-payment?bill_id="+bill_id;
}

setInterval(function(){
	
	let bill_id=document.getElementById('bill_id').value;

	const xhttp = new XMLHttpRequest();
	xhttp.onload = function() {
	document.getElementById("total_amount").innerHTML = this.responseText;
	}
	xhttp.open("GET", "ajax_total_cal_pos.php?bill_id="+bill_id, true);
	xhttp.send();
	
},
1000);	

	
function search_product(search_text,search_type){
	document.getElementById('search_product_dis').innerHTML=`<img src="image/loading_sm.gif"> Searching...`;
	
	const xhttp = new XMLHttpRequest();
	xhttp.onload = function() {
	document.getElementById("search_product_dis").innerHTML = this.responseText;
	}
	xhttp.open("GET", "ajax_pos_product_search.php?search_text="+search_text+"&search_type="+search_type, true);
	xhttp.send();
}
	
function q_print(){
	let q_id=document.getElementById('bill_id').value;
	if(confirm('Are your sure?')){
		window.location='quotation-create?q_id='+q_id;
	}
}
	
function select_cat_wise_product(catogary_id){
	document.getElementById('item_load_div').innerHTML=`<div align="center">Please Wait...</div>`;
  const xhttp = new XMLHttpRequest();
  xhttp.onload = function() {
    document.getElementById("item_load_div").innerHTML = this.responseText;
    }
  xhttp.open("GET", "ajax_pos_cat_wise_item_load.php?catogary_id="+catogary_id, true);
  xhttp.send();
}
	
function add_product_pos(product_barcode){
	document.getElementById('product_barcode').value=product_barcode;
	document.getElementById('sale_qty').value="1";
	document.getElementById('sale_qty').focus();
}
</script>

	
</body>
</html>

<?php unset($_SESSION['bill_print']); ?>
<?php @mysqli_close($connation); ?>