<?php
session_start();
if(!isset($_SESSION['user_id'])){
    echo "<script> window.location.href = '/'; </script>";
}
    include 'load.php';
    require_once 'db_connection.php'; 
    if (isset($_GET['order_id'])) {
        $_SESSION['order_id'] = $_GET['order_id'];
    } else {
        $_SESSION['order_id'] = 0;
    }
    
?>
<?php
	$UserID = $_SESSION['user_id'];
	$getEmpQuery = $conn->query("SELECT branch_id FROM tbl_user_branch WHERE user_id='$UserID' ");
	if ($emp = $getEmpQuery->fetch_array()) {
		$branch_id = $emp['0'];
	}
	$userinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileusers WHERE user_id='$UserID'"));
	?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' />
    <link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/animate.css">
    <link rel="stylesheet" href="assets/plugins/select2/css/select2.min.css">
    <link rel="stylesheet" href="assets/plugins/owlcarousel/owl.carousel.min.css">
    <link rel="stylesheet" href="assets/plugins/owlcarousel/owl.theme.default.min.css">
    <link rel="stylesheet" href="assets/alertify/alertify.core.css">
    <link rel="stylesheet" href="assets/alertify/alertify.default.css">
    <link rel="stylesheet" href="assets/plugins/select2/css/select2.min.css">
    <link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
    <link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
  
	<link rel="stylesheet" href="assets/css/bootstrap-icons.css">
    <script src="js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</head>
<body>
<style>
    body{
        width: 100%;
        height: 100%;
        background: #ffffff;
    }
    .pos-wrap{
        width: 100%;
        height: 100%;
        
    }
    .topbox i{
        color: #fff;
        font-size: 18px;
    }
    .pos-top{
        padding: 5px 0px;
		background-color:#000000;
    }
    .pos-top{
       
    }
    .pos-middele{
        border: 2px solid #000000;
        
    }
    thead{
        border-bottom: 1px solid #eddfe1;
		background-color: #ffffff;
    }
    table{
       
    }
    th,td{
        color:#fff;
    }
    i{
        color: #fff !important;
    }
    .icon-text{
		font-weight:600;
        text-align: center;
        color: #fff;
        margin-top: 10px;
		font-size: 12px;
    }
    .icon-wrap{
        text-align: center;
		margin-top: 11px;
    }
    .box-wrap{
        padding: 15px 0px;
        border: 2px solid #ffffff; 
        border-radius: 5px;
        position: relative;
    }
    .box-wrap:hover{
        background-color: gray !important;
        cursor: pointer;
    }
    .key{
        color: #fff;
        position: absolute;
        top: 1px;
        left: 8px;
		font-size: 11px;
    }
    .item i{
        font-size: 18px;
    }
    .full-height {
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    .top-row {
      flex: 0 0 auto;
    }
    .bottom-row {
      flex: 1 0 auto;
      align-self: flex-end;
    }
    .topbox i{
        font-size: 20px;
        cursor: pointer;
    }
    .searchwrap{
        position: relative;
    }
    .searchwrap input{
        background-color: #ffffff;
        color: #000000;
        padding-left: 45px;
        border-color: #000000;
    }
    .searchwrap i{
        position: absolute;
        left: 22px;
        top: 8px;
    }
    input::placeholder {
      color: #fff; 
      opacity: 0.8; 
    }
    .heighlight{
        font-size: 25px;
        font-weight: 700;
    }
    .table tfoot {
      
    }
    table{
        
    }
    .searchwrap{
        position: relative;
    }
    #searchitems{
        position: absolute;
        width: 98%;
        /* height: 100%; */
        max-height: 250px;
        /* overflow: hidden; */
        overflow-y: scroll;
        z-index: 2;
        background: #fff;
    }
    #searchitems ul li{
        list-style: none;
    }
    tbody tr{
        height: 10px;
        cursor: pointer;
        background-color: #422e2e;
        border-bottom: 2px solid #ffffff;
    }
    tbody tr:hover{
        background-color: #505273;
    }
    #searchitems ul li{
        padding: 5px 20px;
    }
    #searchitems ul li:hover{
        background-color: #402f32;
        color: #fff;
        cursor: pointer;
    }
    #searchitems ul{
        padding-left: 0;
        margin-bottom: 0;
    }
    #searchitems{
        display: none;
    }
    .bg2{
     background: linear-gradient(85deg, rgb(249 247 247) 0%, rgb(249 248 251 / 0%) 100%);
    }
    .close{
        background-color: transparent;
        border: none;
    }
    .modal-dialog2 {
        max-width: 400px;
        margin: 1.75rem auto;
    }
    .number{
        color: #fff;
        background: #0669ff;
        text-align: center;
        font-size: 25px;
        font-weight: 700;
        border: 1px solid #262a22;
        height: 60px;
        line-height: 51px;
    }
    .number:hover{
        background: #262a22;
        cursor: pointer;
    }
    tr.selectedrow {
            outline: none;
            background-color: #255fc9;
        }
        #searchitems li.selectedlirow{
            background-color: #255fc9;
            color: #fff;
        }
        .ntext{
            font-size: 15px;
        }
        .box-wrap{
            padding: 8px 0px;
        }
        .item i {
    font-size: 18px;
}
        
.select2-container .select2-selection--single{
    height: 40px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered{
    line-height: 35px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow{
    top: 7px;
}
</style>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>
<section class="pos-wrap">
    <div class="container-fluid p-0" style="overflow: hidden;">
        <div class="pos-top">
            <div class="row">
                <div class="col-lg-5 d-flex justify-content-around">
                        <div class="topbox">
                                <a href="home.php" class="logo mr-2" style="text-align:left;">
				                    <img src="images/poslogo.png" alt="#" width="50px" style="margin-top:0px;">
			                    </a>
                        </div>
                        
						<div class="topbox">
							<div class="form-check form-switch mt-2">
                                <?php $disrows = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM all_discount_tbl WHERE all_discount_tbl_id ='1' AND status='1'")); ?>
                                <input class="form-check-input" type="checkbox" role="switch" id="discheck" <?php if($disrows==1){ echo "checked"; }else { } ?> >
                                <label class="form-check-label" for="discheck" style="font-size: 10px;font-weight:700;color:#ffffff;">All Discount</label>
                            </div>
                        </div>
                        <div class="topbox">
                          <!--  <div class="form-check form-switch mt-2">
                            <?php// $taxrows = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM tax WHERE tax_id ='1' AND status='1'")); ?>
                                <input class="form-check-input" type="checkbox" role="switch" id="taxcheck" <?php// if($taxrows==1){ echo "checked"; }else { } ?>>
                                <label class="form-check-label" for="taxcheck" style="font-size: 11px;font-weight:700;color:#000000;">Tax <span style="font-size: 9px;">(Shift + 6)</span></label>
                            </div>-->
                            
                            <div class="select" style="display: flex;">
	<div class="selectBtn" data-type="firstOption">Pending Sales</div>
	<div class="selectDropdown">
        <?php $sales = mysqli_query($conn, "SELECT * FROM mobileorders WHERE status='0' AND order_id !='0' ORDER BY order_id DESC");  
        if ($sales->num_rows > 0) {
            while($row = $sales->fetch_assoc()) { ?>
		<div class="option" data-type="firstOption"><a style="text-decoration:none;color:#000000;" href="pos-panel.php?order_id=<?php echo $row['order_id']; ?>"><?php echo $row['orid']; ?></a></div>
		<?php 
            }
        }
        ?>
	</div>
    <a href="pos-panel.php"><button type="button" class="btn-close" aria-label="Close" style="padding: 10px;background-color:#ffffff;"></button></a>
</div>



<style>
    .select {
  position: relative;
 
  width: 250px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
.select .selectBtn {
  background: var(--bg1);
  padding: 6px;
  box-sizing: border-box;
  border-radius: 3px;
  width: 100%;
  cursor: pointer;
  position: relative;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  background: #fff;
}
.select .selectBtn:after {
  content: "";
  position: absolute;
  top: 45%;
  right: 15px;
  width: 6px;
  height: 6px;
  -webkit-transform: translateY(-50%) rotate(45deg);
          transform: translateY(-50%) rotate(45deg);
  border-right: 2px solid #666;
  border-bottom: 2px solid #666;
  transition: 0.2s ease;
}
.select .selectBtn.toggle {
  border-radius: 3px 3px 0 0;
}
.select .selectBtn.toggle:after {
  -webkit-transform: translateY(-50%) rotate(-135deg);
          transform: translateY(-50%) rotate(-135deg);
}
.select .selectDropdown {
  position: absolute;
  top: 100%;
  width: 100%;
  border-radius: 0 0 3px 3px;
  overflow: hidden;
  background: var(--bg1);
  border-top: 1px solid #eee;
  z-index: 1;
  background: #fff;
  -webkit-transform: scale(1, 0);
          transform: scale(1, 0);
  -webkit-transform-origin: top center;
          transform-origin: top center;
  visibility: hidden;
  transition: 0.2s ease;
  box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2);
}
.select .selectDropdown .option {
 
  box-sizing: border-box;
  cursor: pointer;
}
.select .selectDropdown .option a{
    width: 100%;
    display: block;
    padding: 10px;
}


.select .selectDropdown .option:hover {
  background: #f8f8f8;
}
.select .selectDropdown.toggle {
  visibility: visible;
  -webkit-transform: scale(1, 1);
          transform: scale(1, 1);
}
.topbox a{
    color: #fff;
}
</style>


                        </div>
                       
                </div>
                    <div class="col-lg-4 searchwrap">
                        <i class="fa fa-search" style="background-color:#000000;padding:5px 5px 5px 5px;"></i>
                        <input type="text" class="form-control"  id="searchinputbox" oninput="handleInput();" placeholder="Search product by name, code or barcode" onKeyDown="if(event.keyCode==32) searchbarcodeProduct();">
                       <div id="searchitems" style="display: none;">
                            
                        </div>
                    </div>
                    <div class="col-lg-3" style="color:#ffffff;display:flex;align-items:center;font-size:12px;height:38px;text-align:center;border-radius: 6px;">
                            <i style="margin-right: 10px;" class="fa fa-user" aria-hidden="true"></i>
			                Cashier : <?php echo $userinfo['fullname']; ?> | Eat More Resturant
                    </div>
            </div>
        </div>
        <div class="pos-middele full-height">
            <div class="row g-1">
                <div class="col-lg-5" id="right_cart_panel">
                <div class="table-responsive">    
                <table class="table table-borderless mb-0">
                    <thead style="background-color:#083fdb;">
                        <tr>
                        <th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Product Name</th>
                        <th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Quantity</th>
                        <th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Price</th>
                        <th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Discount</th>
                        <th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Tax</th>
                        <th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                    <tfoot>
                        <tr>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td></td>
							 <td></td>
                            <td style="background-color: #08a306;font-weight: bold;">Discount</td>
                            <td style="background-color: #08a306;font-weight: bold;">0.00</td>
                        </tr>
                        <tr>
                        <td></td>
                        <td></td>
                            <td></td>
							 <td></td>
                            <td style="background-color: #0910e7;font-weight: bold;">Tax</td>
                            <td style="background-color: #0910e7;font-weight: bold;">0.00</td>
                        </tr>
                        <tr>
                        <td></td>
                            <td></td>
                            <td></td>
							 <td></td>
                            <td class="heighlight" style="background-color: #f50404;font-weight: bold;font-size:16px;">Total</td>
                            <td class="heighlight" style="background-color: #f50404;font-weight: bold;font-size:16px;">0.00</td>
                        </tr>
                    </tfoot>
                    </table>
                    </div>
                </div>
                <div class="col-lg-2 bg2">
                    <div class="row g-1">
                    <div class="col-lg-6 col-6 item item1" >
                        <?php $order_type = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM order_type WHERE order_type_id ='1'")); ?>
                                        <div class="form-check">
                                        <span class="key">Shift + 6</span>
                                            <input class="form-check-input order_type" type="radio" name="exampleRadios" id="take_away" value="Take Away" <?php if($order_type['order_type']=="Take Away"){ echo "checked"; } ?>>
                                                <label class="form-check-label">
                                                    Take Away
                                                </label>
                                        </div>
                                    </div>
                               
                                <div class="col-lg-6 col-6 item item1">
                                    <div class="form-check">
                                    <span class="key">Shift + 7</span>
                                        <input class="form-check-input order_type" type="radio" name="exampleRadios" id="dine_in" value="Dine In" <?php if($order_type['order_type']=="Dine In"){ echo "checked"; } ?>>
                                            <label class="form-check-label">
                                               Dine In
                                            </label>
                                        </div>
                                </div>
                               
                                    <div class="col-lg-6 col-6  item item1" style="margin-top: 1px !important;">
                                    <div class="form-check">
                                    <span class="key">Shift + 8</span>
                                        <input class="form-check-input order_type" type="radio" name="exampleRadios" id="table" value="Table" <?php if($order_type['order_type']=="Table"){ echo "checked"; } ?>>
                                            <label class="form-check-label">
                                               Table
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-6  item item1" style="margin-top: 1px !important;">
                                        <div class="form-check">
                                        <span class="key">Shift + 9</span>
                                        <input class="form-check-input order_type" type="radio" name="exampleRadios" id="delivery" value="Delivery" <?php if($order_type['order_type']=="Delivery"){ echo "checked"; } ?>>
                                            <label class="form-check-label">
                                               Delivery
                                            </label>
                                        </div>
                                    </div>
                                     <div class="col-lg-6 col-6  item item1" style="margin-top: 1px !important;">
                                        <div class="form-check">
                                        <span class="key">Shift + 1</span>
                                        <input class="form-check-input order_type" type="radio" name="exampleRadios" id="room" value="Room" <?php if($order_type['order_type']=="Room"){ echo "checked"; } ?>>
                                            <label class="form-check-label">
                                               Room
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-lg-6 col-6  item item1" style="margin-top: 1px !important;">
                                        <div class="form-check">
                                        <span class="key">Shift + 0</span>
                                        <input class="form-check-input order_type" type="radio" name="exampleRadios" id="None" value="None" <?php if($order_type['order_type']=="None"){ echo "checked"; } ?>>
                                            <label class="form-check-label">
                                               None
                                            </label>
                                        </div>
                                    </div>
                                    


<style>
    .item .form-check{
        background-color: #083fdb;
        padding-left: 35px;
        padding-top: 6px;
        padding-bottom: 6px;
        position: relative;
        
    }
    .item .form-check label{ 
        color:#fff;
        font-size
    }
    .item .form-check span{
        text-align: right;
        padding-right: 10px;
        right: 0;
    }
</style>

                        <div class="col-lg-6 col-6 item item1">
                            <div class="wrap box-wrap" style="background-color:#ff004f;" onclick="deletefocusitem();">
                            <span class="key">F5</span>
                                    <!-- <div class="icon-wrap" >
                                        <span class="key">F8</span>
                                       <i class="fa fa-times"></i> 
                                    </div>-->
                                    <div class="icon-text" style="font-size:16px;">
                                        Delete
                                    </div>
                            </div>
                        </div>
                        <!--<div class="col-lg-6 col-6 item item1" style="margin-top: 1px;">
                            <div class="wrap box-wrap" onclick="searchfocus();" style="background-color:#4f1acb;">
                                    <span class="key">F2</span>
                                    <div class="icon-wrap">
                                    <i class="fa fa-search"></i>
                                    </div>
                                    <div class="icon-text">
                                        Search
                                    </div>
                            </div>
                        </div>-->
                        <div class="col-lg-6 col-6  item">
                            <div class="wrap box-wrap" onclick="qtyfocus();" style="background-color:#1a6a7c;">
                                    <span class="key">F4</span>
                                   <!-- <div class="icon-wrap">
                                        <i class="fa fa-shopping-cart"></i>
                                    </div>-->
                                    <div class="icon-text" style="font-size:16px;">
                                        Quantity
                                    </div>
                            </div>
                        </div>
                        
                        <div class="col-lg-6 col-6   item">
                                <div class="wrap box-wrap" onclick="pricefocus();" style="background-color:#648c11;">
                                        <span class="key">Shift + I</span>
                                       <!-- <div class="icon-wrap">
                                        <i class="fa fa-tags"></i>
                                        </div>-->
                                        <div class="icon-text" style="font-size:16px;">
                                            Price
                                        </div>
                                </div>
                            </div>

                            <div class="col-lg-6 col-6  item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(1);" style="background-color:#008000;">
                                        <span class="key">Shift + C</span>
                                        <div class="icon-text" style="font-size:16px;">
                                            Cash
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-6  item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(2);" style="background-color:#0000FF;">
                                        <span class="key">Shift + E</span>
                                        <div class="icon-text" style="font-size:16px;">
                                            Credit
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-6  item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(3);" style="background-color:#A020F0;">
                                        <span class="key">Shift + R</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Debit Card
                                        </div>
                                </div>
                            </div>              
                           <!-- <div class="col-lg-4 mt-0 col-6  pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(4);" style="background-color:#800000;">
                                        <span class="key">Shift + B</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Bank Transfer
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(5);" style="background-color:#fd5800;">
                                        <span class="key">Shift + Q</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Cheques
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(6);" style="background-color:#009698;">
                                        <span class="key">Shift + M</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Mobile Payment
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(7);" style="background-color:#ffdf00;">
                                        <span class="key">Shift + G</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Gift Cards
                                        </div>
                                </div>
                            </div>-->
							<!--<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(8);" style="background-color:#000080;">
                                        <span class="key">Shift + O</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Other Payment
                                        </div>
                                </div>
                            </div>-->
                            <div class="col-lg-6 col-6 mt-0  item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(9);" style="background-color:#fcba03;">
                                        <span class="key">Shift + W</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Cash & Card 
										</div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-6 mt-0  item item1">
                                <div class="wrap box-wrap" onclick="transactions();" style="background-color:#32a852;">
                                        <span class="key">Shift + F</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        All Transactions
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-6 mt-0  item item1">
                                <div class="wrap box-wrap" onclick="pendingsales();" style="background-color:#a632a8;">
                                        <span class="key">Shift + Y</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Pending Sales
                                        </div>
                                </div>
                            </div>
                           <!-- <div class="col-lg-4 col-6 mt-0  item item1">
                                <div class="wrap box-wrap" onclick="addNewProductById(148);" style="background-color:#3d5e38;">
                                        <span class="key">Shift + K</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Genaral Items
                                        </div>
                                </div>
                            </div>
                            
                            <div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="taxfocus();" style="background-color:#0703fc;">
                                        <span class="key">Shift + X</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Tax
                                        </div>
                                </div>
                            </div>-->
                            <!--<div class="col-lg-4 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="saleslist();" style="background-color:#2b212b;">
                                        <span class="key">Shift</span>
                                        <div class="icon-text">
                                         
                                        </div>
                                </div>
                            </div>-->
							<div class="col-lg-6 col-12 mt-0  item item1">
                                <div class="wrap box-wrap bigbox" onclick="redirectToReturn();" style="background-color:#ff9f00;">
                                        <span class="key">F7</span>
                                        <div class="icon-text" style="font-size:16px;">
                                            Return
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-12 mt-0  item item1">
                                <div class="wrap box-wrap" onclick="addNewProductById(148);" style="background-color:#3d5e38;">
                                        <span class="key">Shift + K</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Genaral Items
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-12 mt-0  item item1">
                               <!-- <div class="wrap box-wrap" onclick="printkot();" style="background-color:#3299a8;"> -->
                               <div class="wrap box-wrap" onclick="kotpopup();" style="background-color:#3299a8;">
                                        <span class="key">Shift + Z</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        KOT
                                        </div>
                                </div>
                            </div>
                            <!--<div class="col-lg-4 col-12 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addFreeItem();" style="background-color:#3299a8;">
                                        <span class="key">Shift + 6</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Free Items
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-12 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addMarketReturnItem();" style="background-color:#3486eb;">
                                        <span class="key">Shift + 9</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Market Return
                                        </div>
                                </div>
                            </div>-->
                            
                           <div class="col-lg-6 col-6   item">
                                <div class="wrap box-wrap bigbox" onclick="disfocus();" style="background-color:#0014a8;">
                                        <span class="key">Shift + D</span>
                                        <div class="icon-wrap">
                                        <i class="fa fa-percent"></i>
                                        </div>
                                        <div class="icon-text">
                                            Discount
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-6 col-6  item">
                            <div class="wrap box-wrap bigbox" onclick="addAlldiscount();" style="background-color:#00bfff;">
                                    <span class="key">Shift + A</span>
                                    <div class="icon-wrap">
                                        <i class="disval">
                                            <?php $dis = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM all_discount_tbl WHERE all_discount_tbl_id ='1'"));
                                            if($dis['discount_type']==0){ echo $dis['discount_val']; }else{ echo $dis['discount_val']."%"; } ?>    
                                        </i>
                                       
                                    </div>
                                    
                                    <div class="icon-text">
                                        All Discount
                                    </div>
                            </div>
                        </div>
                           <!-- <div class="col-lg-3 col-6 mt-1  item">
                                <div class="wrap box-wrap" onclick="lottery();" style="background-color:#fe4eda;height:120px;">
                                        <span class="key">Shift + 2</span>
                                        <div class="icon-wrap">
                                        <i class="fa fa-box"></i>
                                        </div>
                                        <div class="icon-text">
                                            Lottery
                                        </div>
                                </div>
                            </div>

                            <div class="col-lg-6 col-6 mt-1  item">
                                <div class="wrap box-wrap" onclick="calculator();" style="background-color:#800080;height:120px;">
                                        <span class="key">F12</span>
                                        <div class="icon-wrap">
                                            <i class="fa fa-calculator"></i>
                                        </div>
                                        <div class="icon-text">
                                            Keypad
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-3 col-6 mt-1  item">
                                <div class="wrap box-wrap" onclick="tax();" style="background-color:#44329f;height:120px;">
                                        <span class="key">Shift + 3</span>
                                        <div class="icon-wrap">
                                        <i class="taxval">
                                            <?php //$dis = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tax WHERE tax_id ='1'"));
                                           // if($dis['tax_type']==0){ echo $dis['tax']; }else{ echo $dis['tax']."%"; } ?>    
                                        </i>
                                        </div>
                                        <div class="icon-text">
                                            Tax
                                        </div>
                                </div>
                            </div>-->
							
							<div class="col-lg-6 col-6   item" style="margin-top: 1px;">
                                <div class="wrap box-wrap bigbox" onclick="onlySave1Bill();" style="background-color:#0bda51;">
                                <span class="key">Shift + H</span>
                                        <div class="icon-wrap">
                                        <i class="holdcount"><?php 
                                             echo mysqli_num_rows(mysqli_query($conn, "SELECT * FROM mobileorders WHERE status='0'"));
                                             
                                        
                                        
                                        ?></i>
                                        </div>
                                        <div class="icon-text">
                                           Print/Hold
                                        </div>
                                </div>
                            </div>
                            <!--<div class="col-lg-6 col-6   item" style="margin-top: 1px;">
                            <div class="wrap box-wrap bigbox" onclick="onlySave1Bill();" style="background-color:#01796f;height:120px;">
                                        
                                        <div class="icon-wrap">
                                        <i>F9</i>
                                        </div>
                                        <div class="icon-text">
                                            Save Sale
                                        </div>
                                </div>
                            </div>-->
							
							<!--<div class="col-lg-3 col-6 mt-1 item">
                                <div class="wrap box-wrap" onclick="namefocus();" style="background-color:#812906;height:120px;">
                                    <span class="key">Shift + L</span> 
                                        <div class="icon-wrap">
                                        <i class="fa fa-edit"></i>
                                        </div>
                                        <div class="icon-text">
                                            Product Name
                                        </div>
                                </div>
                            </div>-->

                            <div class="col-lg-6 col-6   item" style="margin-top: 1px;">
                                <div class="wrap box-wrap bigbox" onclick="deleteallproduct();" style="background-color:#ff0000;">
                                        <span class="key">F5</span>                      
                                        <div class="icon-wrap">
                                        <i class="fa fa-trash"></i>
                                        </div>
                                        <div class="icon-text">
                                            Void Order
                                        </div>
                                </div>
                            </div>

                    </div>

                    </div>
                    <div class="col-lg-5 bg2 mb-4">
                                  


                        <div class="subcategory-wrap row" style="padding-top: 8px;padding-left: 10px;padding-right: 10px; margin-bottom:10px;">
                                
                                        <?php $category = mysqli_query($conn, "SELECT * FROM mobilecategory WHERE status='1'"); 
                                            if ($category->num_rows > 0) {
                                                while($row = $category->fetch_assoc()) { ?>
                                                <div class="col-lg-2">
                                                        <a onclick="catproductload(<?php echo $row['ctid']; ?>); loadsubcat(<?php echo $row['ctid']; ?>);" style="cursor:pointer;">
                                                        <div class="item">
                                                        
                                                        <h6 style="text-align: center;color:#fff; background: #000000;font-size:9px;padding:7px;"><?php echo $row['catename']; ?></h6>
                                                        </div>
                                                        </a>
                                                        </div>
                                            <?php  }
                                            }
                                        ?>    
                                        
                                   

                        </div>




                        <div class="subcategory-wrap" id="subwrap2" style="background: #648c11;padding-top: 10px;padding-left: 10px;padding-right: 10px;">
                                <div class="owl-carousel owl-theme">
                                        <?php $subcategorylist = mysqli_query($conn, "SELECT * FROM mobilesubcategory WHERE status='1'"); 
                                            if ($subcategorylist->num_rows > 0) {
                                                while($row = $subcategorylist->fetch_assoc()) { ?>
                                                        <a onclick="subcatproductload(<?php echo $row['sbid']; ?>);" style="cursor:pointer;">
                                                        <div class="item">
                                                       
                                                        <h6 style="text-align: center;background: #000000;font-size:10px;color:#ffffff;padding:5px;"><?php echo $row['subname']; ?></h6>
                                                        </div>
                                                        </a>
                                            <?php  }
                                            }
                                        ?>    
                                        
                                    </div>

                        </div>





                        <div class="productlist" style="margin-top: 20px; padding-right:10px;">
                            <div class="row" id="productlist">
                            <?php $productlist = mysqli_query($conn, "SELECT * FROM mobileproducts WHERE status='1'"); 
                                if ($productlist->num_rows > 0) {
                                    while($row = $productlist->fetch_assoc()) { ?>
                                            <div class="product col-lg-3" onclick="addNewProductById(<?php echo $row['prid']; ?>);" style="cursor:pointer;">
                                                <div class="productwrap">
                                                    <h6 style="text-align: center;background:#08a306;font-weight:600;font-size:10px;color:#ffffff;padding:4px;margin-bottom:0rem;"><?php echo $row['itemcode']; ?></h6>
                                                    <h6 style="text-align: center;background:#000000;font-weight:600;font-size:11px;color:#ffffff;padding:4px;margin-bottom:0rem;"><?php echo $row['proname']; ?></h6>
													<img src="assets/img/empty.png"/ width="100%">
													<p style="text-align: center;background:#08a306;font-weight:600;font-size:12px;color:#ffffff;padding:4px;">Rs.<?php echo number_format((float)$row['sellprice'], 2); ?></p>
												</div>
                                            </div>
                                <?php  }
                                }
                            ?>    
                            </div>
                        </div>







                                </div>
              








                    </div>


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

<style>
    .number:focus{
        background-color: #1a6a7c;
    }
    input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
</style>




<script src="assets/js/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="assets/js/bootstrap.bundle.min.js"></script>
<script src="assets/plugins/select2/js/select2.min.js"></script>
<script src="assets/plugins/owlcarousel/owl.carousel.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

<script>

let index = 1;

const on = (listener, query, fn) => {
	document.querySelectorAll(query).forEach(item => {
		item.addEventListener(listener, el => {
			fn(el);
		})
	})
}

on('click', '.selectBtn', item => {
	const next = item.target.nextElementSibling;
	next.classList.toggle('toggle');
	next.style.zIndex = index++;
});
on('click', '.option', item => {
	item.target.parentElement.classList.remove('toggle');

	const parent = item.target.closest('.select').children[0];
	parent.setAttribute('data-type', item.target.getAttribute('data-type'));
	parent.innerText = item.target.innerText;
})



function catproductload(id){
                $.ajax({
                        url: "cat-product.php",
                        type: "POST",
                        data: { category: id, }, 
                        success: function (data) {
                            
                            document.getElementById('productlist').innerHTML = data;
                          
                           
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });
}

function loadsubcat(id){
                $.ajax({
                        url: "cat-product.php",
                        type: "POST",
                        data: { category2: id, }, 
                        success: function (data) {
                            
                            document.getElementById('subwrap2').innerHTML = data;
                          
                           
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });
}
function subcatproductload(id){
    $.ajax({
                        url: "cat-product.php",
                        type: "POST",
                        data: { subcat: id, }, 
                        success: function (data) {
                            
                            document.getElementById('productlist').innerHTML = data;
                          
                           
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });
}




$(function() {
 

    var owl = $(".owl-carousel");
owl.owlCarousel({
  items: 6,
  margin: 10,
  loop: true,
  nav: false,
  dots: false,
  autoplay: true,
  responsive: {
    0: {
      items: 1 
    },
    600: {
      items: 5 
    },
    1025: {
      items: 6 
    }
  }
});



});

   
    document.body.onload = function() {
        
        loadCartItems();    
    }
    loadCartItems();
  document.onkeyup = function(e) {
    if (e.code === 'F2') {
        searchfocus();
        
    }else if(e.code === 'F4'){
        qtyfocus();
    }else if(e.shiftKey && e.keyCode  === 68){
        disfocus();
    }else if(e.code === 'F8'){
        deletefocusitem();
    }else if(e.keyCode  === 84){
        var firstRow = document.querySelector('.table tbody tr:nth-child(1)');
        firstRow.classList.add('selectedrow');
    
     }else if(e.keyCode  === 27){
        $("#qtyModal").modal("hide");
        $("#disModal").modal("hide");
        
     }else if(e.shiftKey && e.keyCode  === 67){
        paymentmethod(1);
    }else if(e.shiftKey && e.keyCode  === 69){
        paymentmethod(2);
    }else if(e.shiftKey && e.keyCode  === 82){
        paymentmethod(3);
    }else if(e.shiftKey && e.keyCode  === 66){
        paymentmethod(4);
     }else if(e.shiftKey && e.keyCode  === 81){
        paymentmethod(5);
    }else if(e.shiftKey && e.keyCode  === 77){
        paymentmethod(6);
    }else if(e.shiftKey && e.keyCode  === 71){
        paymentmethod(7);
    }else if(e.shiftKey && e.keyCode  === 79){
        paymentmethod(8);
    }else if(e.keyCode  === 116){
        deleteallproduct();

    }else if(e.keyCode  === 112){
        onlypay1Bill();
    }else if(e.keyCode  === 120){
        onlySave1Bill();
    }else if(e.keyCode  === 118){
        redirectToReturn();
    }else if(e.keyCode  === 123){
        calculator();
    }else if(e.shiftKey && e.keyCode === 80){ //s
        onlypayBill();
    }else if(e.shiftKey && e.keyCode === 84){ //t
        payBill();
    }else if(e.shiftKey && e.keyCode === 83){  //r
        onlySaveBill();
    }else if(e.shiftKey && e.keyCode === 86){ // v
        onlySaveBillWithBarcode();
    }else if(e.shiftKey && e.keyCode === 65){ // A
        addAlldiscount();
    }else if(e.shiftKey && e.keyCode === 72){ // H
        onlySave1Bill();
    
    }else if(e.shiftKey && e.keyCode === 70){ // F
        transactions();
    }else if(e.shiftKey && e.keyCode === 73){ // G
        pricefocus();
    }else if(e.shiftKey && e.keyCode === 76){ // G
        namefocus();
    }else if(e.shiftKey && e.keyCode === 88){ // X
        taxfocus();
    }else if(e.shiftKey && e.keyCode === 87){ // W
        paymentmethod(9);
    }else if(e.shiftKey && e.keyCode === 89){ // Y
        pendingsales();
    }else if(e.shiftKey && e.keyCode === 75){ // K
        addNewProductById(148);
    }else if(e.shiftKey && e.keyCode === 50){ // 2
        lottery();
    }else if(e.shiftKey && e.keyCode === 51){ // 3
        tax();
    }else if(e.shiftKey && e.keyCode === 52){ // 4
        document.getElementById('discheck').click();
    }else if(e.shiftKey && e.keyCode === 54){ // 6
        document.getElementById("take_away").checked = true;
    }else if(e.shiftKey && e.keyCode === 55){ // 7
        document.getElementById("dine_in").checked = true;
    }else if(e.shiftKey && e.keyCode === 56){ // 8
        document.getElementById("table").checked = true;
    }else if(e.shiftKey && e.keyCode === 57){ // 9
        document.getElementById("delivery").checked = true;
    }else if(e.shiftKey && e.keyCode === 48){ // 0
        document.getElementById("None").checked = true;
    }else if(e.shiftKey && e.keyCode === 90){ //Z
        kotpopup();
    }

  }
 
  



  function checkLogin() {
                $.ajax({
                        url: "check-login.php",
                        type: "POST",
                       // data: { check: check, tax: "1" }, 
                        success: function (data) {
                            if(data==1){
                                window.location.href = '/';
                            }
                           
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });
  }
 // checkLogin(); 
//setInterval(checkLogin, 10000);       
$('.order_type').on('change', function() {
    var order_type = $(this).val();
                    $.ajax({
                        url: "order-type.php",
                        type: "POST",
                        data: { order_type: order_type }, 
                        success: function (data) {
                            loadCartItems();
                           
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });

});





  $(document).ready(function() {
            $('#taxcheck').on('change', function() {
           
                var check = 0;
                if ($(this).is(':checked')) {
                   check = 1;
                
                } else {
                    check = 0;
                    
                }
                
                    $.ajax({
                        url: "on-off.php",
                        type: "POST",
                        data: { check: check, tax: "1" }, 
                        success: function (data) {
                           
                            loadCartItems();    
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });



            });
            $('#discheck').on('change', function() {
                var check = 0;
                if ($(this).is(':checked')) {
                   check = 1;
                
                } else {
                    check = 0;
                    
                }

                    $.ajax({
                        url: "on-off.php",
                        type: "POST",
                        data: { check: check, dis: "1" }, 
                        success: function (data) {
                            
                            loadCartItems();    
                        },
                        error: function (jXHR, textStatus, errorThrown) {
                           
                        },
                    });



            });
});










  function holdCart(){
    $.ajax({
        url: "hold-cart.php",
        type: "POST",
        //data : "proid="+proid+"&",
        success: function (data) {
            if(data==1){
                $(".holdcount").html("1");
            }else{
                $(".holdcount").html("0");
            }
            loadCartItems();    
        },
        error: function (jXHR, textStatus, errorThrown) {
            // alert(jXHR.responseText);
        },
    });
  }


  function redirectToReturn(){
   // window.location.href ='/add-sales-return.php';
    window.open('/add-sales-return.php', '_blank');
  }
  function transactions(){
    //window.location.href ='/saleslist.php';
    window.open('/saleslist.php', '_blank');
  }
  function pendingsales(){
    //window.location.href ='/pedding-sales-bill.php';
    window.open('/pedding-sales-bill.php', '_blank');
  }
  
function addAlldiscount(){
    $("#alldisModal").modal('show');
    var alldisModal = document.getElementById('alldisModal');
    if (alldisModal) { 
        document.getElementById('all_discount').focus();
        
    }
}

function cloaseAllDisModal(){
    $("#alldisModal").modal('hide');
}

function tax(){
    $("#taxModal").modal('show');
    var lotteryModal = document.getElementById('lotteryModal');
    if (lotteryModal) { 
        document.getElementById('tax').focus();
        
        document.addEventListener('keydown', function(event) {
            if (event.key === 'Enter') {
                event.preventDefault();
                document.getElementById('taxadd').click();
               
            }
        });

    }
}
function cloaseTaxModal(){
    $("#taxModal").modal('hide');
}

var inputTimeout;
function handleInput() {
  clearTimeout(inputTimeout);
  inputTimeout = setTimeout(filterProducts, 1);
 
}
function filterProducts() {
  var searchbarcode = document.getElementById("searchinputbox").value;
  
    $.ajax({
      url: "search-filter-products.php",
      type: "POST",
      dataType: 'json',
      data: "searchbarcode=" + searchbarcode + "&",
      success: function (data) {
        loadCartItems();  
        if(data[0] > 0){
            document.getElementById("searchinputbox").value = "";
            $("#searchitems").html("");
            $("#searchitems").css("display","none");


            if(data[4]==148){
                document.getElementById('allmodalproductname').innerText = data[2];
                document.getElementById('allproductid').value = data[0];
                $('#allModal').modal('show');
                document.getElementById('genaralnameinput').focus();
                var allModal = document.getElementById('allModal');
                if (allModal) { 
                   


                    setTimeout(function() {
                    var allmodalinput = document.getElementsByClassName('allmodalinput');
                    if (allmodalinput.length > 0) {
                        allmodalinput[0].focus();
                        
                            document.addEventListener('keydown', function(event) {
                                var focusedElement = document.activeElement;
                                if (focusedElement && focusedElement.classList.contains('allmodalinput')) {
                                    var index = Array.prototype.indexOf.call(allmodalinput, focusedElement);
                                    
                                        if (event.key === 'ArrowDown') {
                                            if (index < allmodalinput.length - 1) {
                                                allmodalinput[index + 1].focus();
                                            }
                                        }else if (event.key === 'ArrowUp') {
                                            if (index > 0) {
                                                allmodalinput[index - 1].focus();
                                            }
                                        }
                                  

                                }
                            });
                       
                    }
                    
                    
                }, 100);




                }
            }else{
                
              
                document.getElementById('modalproductname').innerText = data[2];
                document.getElementById('modalproductqty').innerText = data[1];
                document.getElementById('qtyproductid').value = data[0];
                document.getElementById('priceinput').value = data[3];
                document.getElementById('discountinput').value = data[5];
                document.getElementById('costprice').innerText = "(Cost Price = "+data[6]+")";
                $('#qtyModal').modal('show');
                document.getElementById('qtyinput').focus();
                document.getElementById("qtyinput").select();


                var qtyModal = document.getElementById('qtyModal');
                if (qtyModal) { 
                    
                setTimeout(function() {
                    var qtyModalinput = document.getElementsByClassName('qtyModalinput');
                    if (qtyModalinput.length > 0) {
                        qtyModalinput[0].focus();
                        
                            document.addEventListener('keydown', function(event) {
                                var focusedElement = document.activeElement;
                                if (focusedElement && focusedElement.classList.contains('qtyModalinput')) {
                                    var index = Array.prototype.indexOf.call(qtyModalinput, focusedElement);
                                    
                                        if (event.key === 'ArrowDown') {
                                            if (index < qtyModalinput.length - 1) {
                                                qtyModalinput[index + 1].focus();
                                            }
                                        }else if (event.key === 'ArrowUp') {
                                            if (index > 0) {
                                                qtyModalinput[index - 1].focus();
                                            }
                                        }
                                  

                                }
                            });
                       
                    }
                    
                    
                }, 100);


            }




            }














        }
       
      },
      error: function (jXHR, textStatus, errorThrown) {
        
      },
    });
  
}
function customerchange(customer){
    if (customer != 0) {
        $.ajax({
            url: "load-credit-balance.php",
            type: "POST",
            data : "customer="+customer+"&",
            success: function (data) {
                if (data != '') {
                         // var totalbillvalue = document.getElementById("total_amount_view").innerHTML;

							//var totalbillvalue = parseInt(totalbillvalue, 10);
							//var data = parseInt(data, 10);

							//var balanceCreditvalue = data + totalbillvalue;
							//var balanceCreditvalue = totalbillvalue;

							document.getElementById("creditAmountvalue").value = data;
							//document.getElementById("totalAmountvalue").value = balanceCreditvalue;
							document.getElementById("totalAmountvalue").value = data;
							//document.getElementById("totalAmountvalue2").value = balanceCreditvalue;
                } 
            },
            error: function (jXHR, textStatus, errorThrown) {
                alert(jXHR.responseText);
            },
        });
    }
}


function calculator(){
    $("#calculatorModal").modal('show');


    var input = document.getElementById('input'), 
  number = document.querySelectorAll('.numbers div'), 
  operator = document.querySelectorAll('.operators div'), 
  result = document.getElementById('result'), 
  clear = document.getElementById('clear'), 
  resultDisplayed = false; 


for (var i = 0; i < number.length; i++) {
  number[i].addEventListener("click", function(e) {

    
    var currentString = input.innerHTML;
    var lastChar = currentString[currentString.length - 1];

    
    if (resultDisplayed === false) {
      input.innerHTML += e.target.innerHTML;
    } else if (resultDisplayed === true && lastChar === "+" || lastChar === "-" || lastChar === "×" || lastChar === "÷") {
     
      resultDisplayed = false;
      input.innerHTML += e.target.innerHTML;
    } else {
      
      resultDisplayed = false;
      input.innerHTML = "";
      input.innerHTML += e.target.innerHTML;
    }

  });
}


for (var i = 0; i < operator.length; i++) {
  operator[i].addEventListener("click", function(e) {

   
    var currentString = input.innerHTML;
    var lastChar = currentString[currentString.length - 1];

   
    if (lastChar === "+" || lastChar === "-" || lastChar === "×" || lastChar === "÷") {
      var newString = currentString.substring(0, currentString.length - 1) + e.target.innerHTML;
      input.innerHTML = newString;
    } else if (currentString.length == 0) {
      
      console.log("enter a number first");
    } else {
      
      input.innerHTML += e.target.innerHTML;
    }

  });
}


result.addEventListener("click", function() {

 
  var inputString = input.innerHTML;


  var numbers = inputString.split(/\+|\-|\×|\÷/g);


  var operators = inputString.replace(/[0-9]|\./g, "").split("");

  console.log(inputString);
  console.log(operators);
  console.log(numbers);
  console.log("----------------------------");

 

  var divide = operators.indexOf("÷");
  while (divide != -1) {
    numbers.splice(divide, 2, numbers[divide] / numbers[divide + 1]);
    operators.splice(divide, 1);
    divide = operators.indexOf("÷");
  }

  var multiply = operators.indexOf("×");
  while (multiply != -1) {
    numbers.splice(multiply, 2, numbers[multiply] * numbers[multiply + 1]);
    operators.splice(multiply, 1);
    multiply = operators.indexOf("×");
  }

  var subtract = operators.indexOf("-");
  while (subtract != -1) {
    numbers.splice(subtract, 2, numbers[subtract] - numbers[subtract + 1]);
    operators.splice(subtract, 1);
    subtract = operators.indexOf("-");
  }

  var add = operators.indexOf("+");
  while (add != -1) {
   
    numbers.splice(add, 2, parseFloat(numbers[add]) + parseFloat(numbers[add + 1]));
    operators.splice(add, 1);
    add = operators.indexOf("+");
  }

  input.innerHTML = numbers[0]; 

  resultDisplayed = true; 
});


clear.addEventListener("click", function() {
  input.innerHTML = "";
})
}

function cloasecalModal(){
    $("#calculatorModal").modal('hide');
}

function lottery(){
    $("#lotteryModal").modal('show');

    var lotteryModal = document.getElementById('lotteryModal');
    if (lotteryModal) { 
        document.getElementById('lottery_number').focus();
        
        document.addEventListener('keydown', function(event) {
            if (event.key === 'Enter') {
                document.getElementById('lotteryadd').click();
                document.getElementById('searchinputbox').focus();
            }else if (event.key === 'ArrowUp') {
                document.getElementById('lottery_number').focus();                      
            }else if (event.key === 'ArrowDown') {
                document.getElementById('lottery_win_amount').focus();
            }
        });

    }

}
function cloaselotteryModal(){
    $("#lotteryModal").modal('hide');
}

function cloaseitemTaxModal(){
    $("#itemtaxModal").modal('hide');
}
function paymentmethod(method){
    
    $.ajax({
        url: "payment-popup-genarate.php",
        type: "POST",
        data: { method: method }, 
        success: function (data) {
            if(method==1){
                $("#paytype").html("Cash Payment");
            }else if(method==2){
                $("#paytype").html("Credit Payment");
            }else if(method==3){
                $("#paytype").html("Card Payment");
            }else if(method==4){
                $("#paytype").html("Bank Transfer Payment");
            }else if(method==5){
                $("#paytype").html("Cheques Payment");
            }else if(method==6){
                $("#paytype").html("Mobile Payment");
            }else if(method==7){
                $("#paytype").html("Gift Cards");
            }else if(method==8){
                $("#paytype").html("Other Payment");
            }else if(method==9){
                $("#paytype").html("Cash & Card Payment");
            }
            
            $("#paymodalcontent").html(data);
            $("#payModal").modal("show");

            var payModal = document.getElementById('payModal');
            if (payModal) { 
                $(".select2").select2({
                    dropdownParent: $("#payModal .modal-content")
                });        
               /* setTimeout(function() {
                    var pbtn = document.getElementsByClassName('pbtn');
                    if (pbtn.length > 0) {
                            pbtn[0].focus();
                            document.addEventListener('keydown', function(event) {
                                var focusedElement = document.activeElement;
                                if (focusedElement && focusedElement.classList.contains('pbtn')) {
                                    var index = Array.prototype.indexOf.call(pbtn, focusedElement);
                                    if (event.key === 'ArrowRight') {
                                        if (index < pbtn.length - 1) {
                                            pbtn[index + 1].focus();
                                        }
                                    } else if (event.key === 'ArrowLeft') {
                                        if (index > 0) {
                                            pbtn[index - 1].focus();
                                        }
                                    }
                                }
                            });
                       
                    }
                    
                    
                }, 100);
                */
              /*  var cash_type = document.getElementById('cash_type').value;

                if(cash_type=="cash"){
                            document.getElementById("billcustomer").focus();
                            const billcustomer = document.getElementById('billcustomer');
                            billcustomer.addEventListener('keydown', function(event) {
                                    if (event.key === 'Enter') {
                                        document.getElementById("cashamount").focus();
                                   
   
                                    }
                                });
                                const cashamount = document.getElementById('cashamount');
                                cashamount.addEventListener('keydown', function(event) {
                                    if (event.key === 'ArrowDown') {
                                        document.getElementById("balance").focus();
                                   
   
                                    }
                                });


                }

            */
           


        /* setTimeout(function() {
                    var inputele = document.getElementsByClassName('inputele');
                    if (inputele.length > 0) {
                        inputele[0].focus();
                        
                            document.addEventListener('keydown', function(event) {
                                var focusedElement = document.activeElement;
                                if (focusedElement && focusedElement.classList.contains('inputele')) {
                                    var index = Array.prototype.indexOf.call(inputele, focusedElement);
                                    

                                    
                                        if (event.key === 'Enter') {
                                            if (focusedElement.tagName === 'SELECT'){
                                                inputele[index + 1].focus();
                                            }
                                        }else if (event.key === 'ArrowDown') {
                                            if (index < inputele.length - 1) {
                                                inputele[index + 1].focus();
                                            }
                                        }else if (event.key === 'ArrowUp') {
                                            if (index > 0) {
                                                inputele[index - 1].focus();
                                            }
                                        }
                                  

                                }
                            });
                       
                    }
                    
                    
                }, 100); */
                
                 
                setTimeout(function() {
                    var billcustomer = document.getElementById('billcustomer');
                    var billdate = document.getElementById('billdate');
                    var cardno = document.getElementById('cardno');
                    var cheque_date = document.getElementById('cheque_date');
                    var cheque_number = document.getElementById('cheque_number');
                    var mobile_payment_method = document.getElementById('mobile_payment_method');
                    var gift_number = document.getElementById('gift_number');
                   
                    var cardpayment = document.getElementById('cardpayment');
                    var cashamount = document.getElementById('cashamount');

                    var pbtn1 = document.getElementById('pbtn1');
                    var pbtn2 = document.getElementById('pbtn2');
                    var pbtn3 = document.getElementById('pbtn3');
                    var pbtn4 = document.getElementById('pbtn4');
                    
                    if(method==1 || method==2 || method==8){
                        document.getElementById('billcustomer').focus();
                        billcustomer.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('cashamount').focus();
                            }
                        });
                       

                        cashamount.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('billcustomer').focus();
                                       
                                   }
                        });
                        
                       /* pbtn1.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn2').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cashamount').focus();
                                       
                                   }
                        });

                        pbtn2.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn3').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn1').focus();
                                       
                                   }
                        });
                        pbtn3.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn4').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn2').focus();
                                       
                                   }
                        });

                        pbtn4.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn3').focus();
                                       
                                   }
                        });
                        */


                    }else if(method==3 || method==4){
                        document.getElementById('billcustomer').focus();
                        billcustomer.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('cardno').focus();
                            }
                        });
                        cardno.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cashamount').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('billcustomer').focus();
                                       
                                   }
                        });

                        cashamount.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cardno').focus();
                                       
                                   }
                        });

                     /*   pbtn1.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn2').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cashamount').focus();
                                       
                                   }
                        });

                        pbtn2.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn3').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn1').focus();
                                       
                                   }
                        });
                        pbtn3.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn4').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn2').focus();
                                       
                                   }
                        });

                        pbtn4.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn3').focus();
                                       
                                   }
                        });
                        */
                    }else if(method==5){
                        document.getElementById('billcustomer').focus();
                        billcustomer.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('cheque_date').focus();
                            }
                        });
                        cheque_date.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cheque_number').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('billcustomer').focus();
                                       
                                   }
                        });
                        cheque_number.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cashamount').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cheque_date').focus();
                                       
                                   }
                        });


                        cashamount.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cheque_number').focus();
                                       
                                   }
                        });

                       /* pbtn1.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn2').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cashamount').focus();
                                       
                                   }
                        });

                        pbtn2.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn3').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn1').focus();
                                       
                                   }
                        });
                        pbtn3.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn4').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn2').focus();
                                       
                                   }
                        });

                        pbtn4.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn3').focus();
                                       
                                   }
                        });
                        */
                    }else if(method==6){
                        document.getElementById('billcustomer').focus();
                        billcustomer.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('mobile_payment_method').focus();
                            }
                        });
                        mobile_payment_method.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('cashamount').focus();
                            }else if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cashamount').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('billcustomer').focus();
                                       
                                   }
                        });

                        cashamount.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('mobile_payment_method').focus();
                                       
                                   }
                        });
                        /*
                        pbtn1.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn2').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cashamount').focus();
                                       
                                   }
                        });

                        pbtn2.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn3').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn1').focus();
                                       
                                   }
                        });
                        pbtn3.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn4').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn2').focus();
                                       
                                   }
                        });

                        pbtn4.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn3').focus();
                                       
                                   }
                        });
                        */
                    }else if(method==7){
                        document.getElementById('billcustomer').focus();
                        billcustomer.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('gift_number').focus();
                            }
                        });
                        gift_number.addEventListener('keydown', function(event) {
                             if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cashamount').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('billcustomer').focus();
                                       
                                   }
                        });

                        cashamount.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('gift_number').focus();
                                       
                                   }
                        });
                        /*
                        pbtn1.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn2').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cashamount').focus();
                                       
                                   }
                        });

                        pbtn2.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn3').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn1').focus();
                                       
                                   }
                        });
                        pbtn3.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn4').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn2').focus();
                                       
                                   }
                        });

                        pbtn4.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn3').focus();
                                       
                                   }
                        });
                        */
                    }else if(method==9){
                        document.getElementById('billcustomer').focus();
                        billcustomer.addEventListener('keydown', function(event) {
                            if (event.key === 'Enter') {
                                document.getElementById('cardno').focus();
                            }
                        });
                        cardno.addEventListener('keydown', function(event) {
                             if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cardpayment').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('billcustomer').focus();
                                       
                                   }
                        });
                        cardpayment.addEventListener('keydown', function(event) {
                             if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('cashamount').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cardno').focus();
                                       
                                   }
                        });

                        cashamount.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();

                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cardno').focus();
                                       
                                   }
                        });
                        /*
                        pbtn1.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn2').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('cashamount').focus();
                                       
                                   }
                        });

                        pbtn2.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn3').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn1').focus();
                                       
                                   }
                        });
                        pbtn3.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('pbtn4').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn2').focus();
                                       
                                   }
                        });

                        pbtn4.addEventListener('keydown', function(event) {
                            if (event.key === 'ArrowDown') {
                                           
                                           document.getElementById('billcustomer').focus();
                                      
                                   }else if (event.key === 'ArrowUp') {
                                     
                                           document.getElementById('pbtn3').focus();
                                       
                                   }
                        });
                        */
                    }

                }, 100);
                 

















            }
            
           // loadCartItems();    
        },
        error: function () {
             
        },
    });
    


}






function clickpad(num){
    var cashamount = parseFloat(document.getElementById("cashamount").value);
    if(num==1 || num==2 || num==3 || num==4 || num==5 || num==6 || num==7 || num==8 || num==9 || num==0 ){
        cashamount = parseFloat(cashamount.toString() + num.toString());
        document.getElementById("cashamount").value = cashamount;

    }else if(num==10 || num==20 || num==30 || num==40){
        document.getElementById("cashamount").value = parseFloat(num);
    }else if(num=="-1"){
        cashamount = cashamount.toString();
       
        if(cashamount.length==1){
            document.getElementById("cashamount").value = 0;
        }else{
           
            var newStr = cashamount.substring(0, cashamount.length - 1);
        
            document.getElementById("cashamount").value = parseFloat(newStr);
        }
        
    }else if(num=="-2"){
        document.getElementById("cashamount").value = 0;
    }   


    
}










  var selectedTableRowIndex = 0;

  function updateSelectedRow() {
    var rows = document.querySelectorAll('.table tbody tr');
    
    rows.forEach(function(row) {
        row.classList.remove('selectedrow');
    });
    
    rows[selectedTableRowIndex].classList.add('selectedrow');
}

document.addEventListener('keydown', function(event) {
    var rows = document.querySelectorAll('.table tbody tr');
        var has = false;
      
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }

        if(has){
            switch(event.key) {
                case 'ArrowUp':
                    selectedTableRowIndex = Math.max(0, selectedTableRowIndex - 1);
                    updateSelectedRow();
                    break;
                case 'ArrowDown':
                    selectedTableRowIndex = Math.min(rows.length - 1, selectedTableRowIndex + 1);
                    updateSelectedRow();
                    break;
            }
        }
});

function getCash(){
    var cash =  document.getElementById('cashamount').value;
    var cardpayment =  document.getElementById('cardpayment').value;
   var cashamounthidden =  document.getElementById('cashamounthidden').value;
   cash = parseFloat(cash) + parseFloat(cardpayment);
    var balace = parseFloat(cash) - parseFloat(cashamounthidden);
    if (balace === null){
        balace = cashamounthidden;
    }
    document.getElementById('balance').value =  Math.abs(balace).toFixed(2);

}



  function searchfocus(){
        event.preventDefault();
        document.getElementById('searchinputbox').focus();
  }


  function searchbarcodeProduct() {
   
  var searchbarcode = document.getElementById("searchinputbox").value;
  var searchQty = 1; 
  if (searchbarcode && searchQty > 0) {
    $.ajax({
      url: "load-search-barcode-by-barcode-byproduct.php",
      type: "POST",
      data: "searchbarcode=" + searchbarcode + "& searchQty=" + searchQty + "&",
      success: function (data) {
        if (data > 0) {
          loadCartItems();
          document.getElementById("searchinputbox").value = "";
          
        } else {
          alertify.error(data);
          document.getElementById("searchinputbox").value = "";
          
        }
      },
      error: function (jXHR, textStatus, errorThrown) {
        alert(jXHR.responseText);
      },
    });
  }
}
function deleteallproduct(){
    $.ajax({
        url: "delete-all-products.php",
        type: "POST",
        //data : "proid="+proid+"&",
        success: function (data) {
            loadCartItems();    
        },
        error: function (jXHR, textStatus, errorThrown) {
             alert(jXHR.responseText);
        },
    });
}


document.getElementById('searchinputbox').addEventListener('keydown', function(event) {
      if (event.key === 'Enter') {
       // event.preventDefault(); 
        searchbarcodeProduct();
       
       
      }
    });

    

function loadCartItems() {
  $.ajax({
    url: "load-left-cart-panel.php",
    type: "POST",
    //data : "proid="+proid+"&",
    success: function (data) {
      $("#right_cart_panel").html(data);
    },
    error: function (jXHR, textStatus, errorThrown) {
      alert(jXHR.responseText);
    },
  });
  //showTotalAmount();
}

function qtyfocus(){
    var rows = document.querySelectorAll('.table tr');
        var has = false;
      /*  rows.forEach(function(row) {
            if (row.className.contains('selectedrow') > -1) {
                has = true;
                return;
            } else {   
                has = false;
            }
        }); */
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }
       if(has){
            var items = document.querySelectorAll('.selectedrow');
            items.forEach(function(item) {
                var dataId = item.getAttribute('data-id');
                var sqty = item.getAttribute('data-qty');
                var price = item.getAttribute('data-price');
                
                var qty = parseFloat(item.querySelectorAll('td')[1].textContent.trim());
                var pname = item.querySelectorAll('td')[0].textContent.trim();
                document.getElementById('modalproductname').innerText = pname;
                document.getElementById('modalproductqty').innerText = sqty;
                document.getElementById('qtyproductid').value = dataId;
                document.getElementById('priceinput').value = price;
                $('#qtyModal').modal('show');
                document.getElementById('qtyinput').focus();
            });
       }else{
            Swal.fire({
            title: 'Error!',
                text: 'Please select table row to change quntity',
                icon: 'warning',
                confirmButtonText: 'OK'
            });
        
       }
}
        
function disfocus(){
    var rows = document.querySelectorAll('.table tr');
        var has = false;
      /*  rows.forEach(function(row) {
            if (row.className.contains('selectedrow') > -1) {
                has = true;
                return;
            } else {   
                has = false;
            }
        }); */
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }
       if(has){
            var items = document.querySelectorAll('.selectedrow');
            items.forEach(function(item) {
                var dataId = item.getAttribute('data-id');
                var pname = item.querySelectorAll('td')[0].textContent.trim();
                document.getElementById('modalproductname2').innerText = pname;
                document.getElementById('disproductid').value = dataId;
                $('#disModal').modal('show');
                document.getElementById('disinput').focus();
            });
       }else{
            Swal.fire({
            title: 'Error!',
                text: 'Please select table row to change discount',
                icon: 'warning',
                confirmButtonText: 'OK'
            });
        
       }
}


function taxfocus(){
    var rows = document.querySelectorAll('.table tr');
        var has = false;
      /*  rows.forEach(function(row) {
            if (row.className.contains('selectedrow') > -1) {
                has = true;
                return;
            } else {   
                has = false;
            }
        }); */
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }
       if(has){
            var items = document.querySelectorAll('.selectedrow');
            items.forEach(function(item) {
                var dataId = item.getAttribute('data-id');
                var pname = item.querySelectorAll('td')[0].textContent.trim();
                document.getElementById('modalproductname6').innerText = pname;
                document.getElementById('taxproductid').value = dataId;
                $('#itemtaxModal').modal('show');
                document.getElementById('taxxinput').focus();
            });
       }else{
            Swal.fire({
            title: 'Error!',
                text: 'Please select table row to change tax',
                icon: 'warning',
                confirmButtonText: 'OK'
            });
        
       }
}
function pricefocus(){
    var rows = document.querySelectorAll('.table tr');
        var has = false;



        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }

        if(has){
            var items = document.querySelectorAll('.selectedrow');
            items.forEach(function(item) {
                var dataId = item.getAttribute('data-id');
                var price = item.getAttribute('data-price');
                var pname = item.querySelectorAll('td')[0].textContent.trim();
                document.getElementById('modalproductname3').innerText = pname;
                document.getElementById('priceproductid').value = dataId;
                $('#priceModal').modal('show');
                document.getElementById('priceinput3').value =  price;
                document.getElementById('priceinput3').focus();
            });
         }else{
            Swal.fire({
            title: 'Error!',
                text: 'Please select table row to change price',
                icon: 'warning',
                confirmButtonText: 'OK'
            });
         }
}


function namefocus(){
    var rows = document.querySelectorAll('.table tr');
        var has = false;



        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }

        if(has){
            var items = document.querySelectorAll('.selectedrow');
            items.forEach(function(item) {
                var dataId = item.getAttribute('data-id');
                var pname = item.querySelectorAll('td')[0].textContent.trim();
                document.getElementById('modalproductname5').innerText = pname;
                document.getElementById('nameproductid').value = dataId;
                $('#nameModal').modal('show');
                document.getElementById('nameinput').focus();
            });
         }else{
            Swal.fire({
            title: 'Error!',
                text: 'Please select table row to change product name',
                icon: 'warning',
                confirmButtonText: 'OK'
            });
         }
}
function addFreeItem(){
    $('#freeitemModal').modal('show');
    document.getElementById('freeproduct').focus();
    var freeitemModal = document.getElementById('freeitemModal');

            if (freeitemModal) { 
                $(".select3").select2({
                    dropdownParent: $("#freeitemModal .modal-content")
                });    
            }

}
function addMarketReturnItem(){
    $('#marketreturnModal').modal('show');
    document.getElementById('marketreturnproduct').focus();
    var marketreturnModal = document.getElementById('marketreturnModal');

            if (marketreturnModal) { 
                $(".select4").select2({
                    dropdownParent: $("#marketreturnModal .modal-content")
                });    
            }

}
function deletefocusitem(){
    var rows = document.querySelectorAll('.table tr');
        var has = false;
      /*  rows.forEach(function(row) {
            if (row.className.contains('selectedrow') > -1) {
                has = true;
                return;
            } else {   
                has = false;
            }
        }); */
        for (var i = 0; i < rows.length; i++) {
            if (rows[i].classList.contains('selectedrow')) {
                has = true;
                break; 
            }
        }
       if(has){
            var items = document.querySelectorAll('.selectedrow');
            items.forEach(function(item) {
                var dataId = item.getAttribute('data-id');
                var pname = item.querySelectorAll('td')[0].textContent.trim();

                    Swal.fire({
                        title: 'Are you sure?',
                        text: "You are going to delete product "+pname,
                        icon: 'warning',
                        showCancelButton: true,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Yes, delete it!'
                    }).then((result) => {
                        if (result.isConfirmed) {    
                            deleteCartItem(dataId);
                        } else {
                            
                           
                        }
                    });



            });
                }else{
                        Swal.fire({
                        title: 'Error!',
                            text: 'Please select table row to delete',
                            icon: 'warning',
                            confirmButtonText: 'OK'
                        });
                    
                }
}

function deleteCartItem(tempid) {
  $.ajax({
    url: "load-modal-cart-item-delete.php",
    type: "POST",
    data: "tempid=" + tempid + "&",
    success: function (data) {
      if (data > 0) {
        loadCartItems();
        document.getElementById("searchbarcode").value = "";
      } else {
       
      }
    },
    error: function () {
    
    },
  });
}
function goToCheckout() {


//showTotalAmount();
document.getElementById("cash_type").focus();
$('#myModal').modal('show');

var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
document.getElementById("totalview").innerHTML = "Total : Rs. " + totalbillvalue;
document.getElementById("cashamount").value = totalbillvalue.replace(/\s/g, '');
//showChangeAmount();
}

function cloasemyModal() {
  $("#myModal").modal("hide");
}

 
function cloaseqtyModal() {
  $("#qtyModal").modal("hide");
}
function cloasedisModal() {
  $("#disModal").modal("hide");
}
function cloasepriceModal() {
  $("#priceModal").modal("hide");
}
function cloasenameModal() {
  $("#nameModal").modal("hide");
}
function cloasepayModal() {
  $("#payModal").modal("hide");
}

function cloaseallModal() {
  $("#allModal").modal("hide");
}

function cloasefreeitemModal() {
  $("#freeitemModal").modal("hide");
}

function cloaseMarketReturnModal() {
  $("#marketreturnModal").modal("hide");
}

function cloaseKotModal() {
  $("#kotModal").modal("hide");
}

function kotpopup() {
    $('#kotModal').modal('show');
     $.ajax({
        url: "load-kot.php",
        type: "POST",
       
        success: function (data) {
            document.getElementById("kotinput").innerHTML = data;
        },
        error: function () {
        
        },
  });
}



document.addEventListener("DOMContentLoaded", function() {
    const searchInput = document.getElementById("searchinputbox");
    
    searchInput.addEventListener("input", function() {
        let input = searchInput.value;
        if(input.trim() === ""){
            $("#searchitems").html("");
            $("#searchitems").css("display","none");
        }else{
                $.ajax({
                    url: "live-search-item-load.php",
                    type: "POST",
                    data : "product="+input+"&", 
                    success: function (data) {
                        if(data == 0 || data === ""){
                            $("#searchitems").html("");
                            $("#searchitems").css("display","none");
                           
                        }else{
                            $("#searchitems").css("display","block");
                            $("#searchitems").html(data);
                        }
                        
                    },
                    error: function () {
                
                },
            });
        }
       
    });
});

//document.addEventListener("keydown", function(event) {
   // const searchInput = document.getElementById("searchinputbox");
   // if (event.key === "ArrowDown") {

           /// if (currentIndex < listItems.length - 1) {
             //   currentIndex++;
             //   updateSelection(currentIndex);
            //}
        //    searchInput.addEventListener("focus", function() {
          //      console.log("test");
         //   });
      //  } else if (event.key === "ArrowUp") {
            //if (currentIndex > 0) {
           //     currentIndex--;
           //     updateSelection(currentIndex);
           // }
     ///   }

//});
function addNewProductById(prid){
    var searchbarcode = prid; 
    var searchQty = 1; 
    if (searchbarcode && searchQty > 0) {
        $.ajax({
        url: "load-search-product-by-barcode.php",
        type: "POST",
        dataType: 'json',
        data: "searchbarcode=" + searchbarcode + "& searchQty=" + searchQty + "&",
        success: function (data) {
          //  if (data[0] > 0) {
            loadCartItems();
            $("#searchitems").html("");
            document.getElementById("searchinputbox").value = "";
            
            if(prid==148){
                document.getElementById('allmodalproductname').innerText = data[2];
                document.getElementById('allproductid').value = data[0];
                $('#allModal').modal('show');
                document.getElementById('genaralnameinput').focus();
                var allModal = document.getElementById('allModal');
                if (allModal) { 
                   


                    setTimeout(function() {
                    var allmodalinput = document.getElementsByClassName('allmodalinput');
                    if (allmodalinput.length > 0) {
                        allmodalinput[0].focus();
                        
                            document.addEventListener('keydown', function(event) {
                                var focusedElement = document.activeElement;
                                if (focusedElement && focusedElement.classList.contains('allmodalinput')) {
                                    var index = Array.prototype.indexOf.call(allmodalinput, focusedElement);
                                    
                                        if (event.key === 'ArrowDown') {
                                            if (index < allmodalinput.length - 1) {
                                                allmodalinput[index + 1].focus();
                                            }
                                        }else if (event.key === 'ArrowUp') {
                                            if (index > 0) {
                                                allmodalinput[index - 1].focus();
                                            }
                                        }
                                  

                                }
                            });
                       
                    }
                    
                    
                }, 100);




                }
            }else{
                
                
                document.getElementById('modalproductname').innerText = data[2];
                document.getElementById('modalproductqty').innerText = data[1];
                document.getElementById('qtyproductid').value = data[0];
                document.getElementById('priceinput').value = data[3];
                document.getElementById('discountinput').value = data[4];
                document.getElementById('costprice').innerText = "(Cost Price = "+data[5]+")";
                $('#qtyModal').modal('show');
                document.getElementById('qtyinput').focus();
                document.getElementById("qtyinput").select();

            
                var qtyModal = document.getElementById('qtyModal');
                if (qtyModal) { 
                    
              /*  setTimeout(function() {


                    var qtyModalinput = document.getElementsByClassName('qtyModalinput');
                    if (qtyModalinput.length > 0) {
                        alert(qtyModalinput.length);
                        qtyModalinput[0].focus();
                        
                            document.addEventListener('keydown', function(event) {
                                var focusedElement = document.activeElement;
                                if (focusedElement && focusedElement.classList.contains('qtyModalinput')) {
                                    var index = Array.prototype.indexOf.call(qtyModalinput, focusedElement);
                                    
                                        if (event.key === 'ArrowDown') {
                                            if (index < qtyModalinput.length - 1) {
                                                qtyModalinput[index + 1].focus();
                                            }
                                        }else if (event.key === 'ArrowUp') {
                                            if (index > 0) {
                                                qtyModalinput[index - 1].focus();
                                            }
                                        }
                                  

                                }
                            });
                       
                    }



                    
                    
                }, 100);
 */



 
 document.getElementById('qtyinput').focus(); 
    var qtyInput = document.getElementById('qtyinput');
    var priceInput = document.getElementById('priceinput');
    var discountInput = document.getElementById('discountinput');


    qtyInput.addEventListener('keydown', function(event) {
        if (event.key === 'ArrowDown') {
            priceInput.focus(); 
        }else if (event.key === 'ArrowUp') {
            discountInput.focus(); 
        }
    });

    priceInput.addEventListener('keydown', function(event) {
        if (event.key === 'ArrowDown') {
            discountInput.focus(); 
        }else if (event.key === 'ArrowUp') {
            qtyInput.focus(); 
        }
    });

    discountInput.addEventListener('keydown', function(event) {
        if (event.key === 'ArrowDown') {
            qtyInput.focus(); 
        }else if (event.key === 'ArrowUp') {
            priceInput.focus(); 
        }
    });


























           }




            }





            

            
           // } else {
               
			//		Swal.fire({
				//		title: 'Error!',
				//			text: 'This product does not have a quntity!',
					//		icon: 'warning',
					//		confirmButtonText: 'OK'
					//	});
				
           // }
        },
        error: function (jXHR, textStatus, errorThrown) {
            alert(jXHR.responseText);
        },
        });
    }
}


function manualArrowKeyNavigation() {
    
    var qtyInput = document.getElementById('qtyinput');
    var priceInput = document.getElementById('priceinput');
    var discountInput = document.getElementById('discountinput');
    
 
    document.addEventListener('keydown', function(event) {
        var focusedElement = document.activeElement; 

        if (event.key === 'ArrowDown') {
            event.preventDefault(); 

           
            if (focusedElement === qtyInput) {
                priceInput.focus();
            } else if (focusedElement === priceInput) {
                discountInput.focus();
            }
        } else if (event.key === 'ArrowUp') {
            event.preventDefault(); 

           
            if (focusedElement === discountInput) {
                priceInput.focus();
            } else if (focusedElement === priceInput) {
                qtyInput.focus();
            }
        }
    });
}















document.addEventListener("DOMContentLoaded", function() {
const qtyinput = document.getElementById('qtyinput');
const discountinput = document.getElementById('discountinput');
var priceinput2 = document.getElementById('priceinput');
var distype = document.getElementById('distype');

qtyinput.addEventListener('keydown', function(event) {

    if (event.key === 'Enter' || event.keyCode === 13) {
        const qty = qtyinput.value; 
        const dis = discountinput.value; 
        const price = priceinput2.value;
        const distypeval = distype.value;
        const tempid = document.getElementById('qtyproductid').value;

      
        $.ajax({
            url: "modal-qty-change.php",
            type: "POST",
            data: { tempid: tempid, qty: qty, dis:dis, price:price,distype:distypeval }, 
            success: function (data) {
                loadCartItems();
                qtyinput.value = 1;
                discountinput.value = 0;
                $("#qtyModal").modal("hide");
                document.getElementById('searchinputbox').focus();
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }//else if(event.key === 'ArrowDown'){
       // document.getElementById('discountinput').focus();
   // }
});


discountinput.addEventListener('keydown', function(event) {

if (event.key === 'Enter' || event.keyCode === 13) {
    const qty = qtyinput.value; 
    const dis = discountinput.value; 
    const price = priceinput2.value;
    const distypeval = distype.value;
    const tempid = document.getElementById('qtyproductid').value;

  
    $.ajax({
        url: "modal-qty-change.php",
        type: "POST",
        data: { tempid: tempid, qty: qty, dis:dis,price:price,distype:distypeval }, 
        success: function (data) {
            loadCartItems();
                qtyinput.value = 1;
                discountinput.value = 0;
            $("#qtyModal").modal("hide");
            document.getElementById('searchinputbox').focus();
        },
        error: function () {
            console.error('Error occurred during AJAX request');
        }
    });
    }//else if(event.key === 'ArrowUp'){
       // document.getElementById('qtyinput').focus();
    //}
});


priceinput2.addEventListener('keydown', function(event) {

if (event.key === 'Enter' || event.keyCode === 13) {
    const qty = qtyinput.value; 
    const dis = discountinput.value; 
    const price = priceinput2.value; 
    const distypeval = distype.value;
    
    const tempid = document.getElementById('qtyproductid').value;

  
    $.ajax({
        url: "modal-qty-change.php",
        type: "POST",
        data: { tempid: tempid, qty: qty, dis:dis,price:price,distype:distypeval }, 
        success: function (data) {
            loadCartItems();
            qtyinput.value = 1;
                discountinput.value = 0;
            $("#qtyModal").modal("hide");
            document.getElementById('searchinputbox').focus();
        },
        error: function () {
            console.error('Error occurred during AJAX request');
        }
    });
    }//else if(event.key === 'ArrowUp'){
       // document.getElementById('qtyinput').focus();
    //}
});

document.getElementById('saveqty1').addEventListener('click', function(event) {
    const qty = qtyinput.value; 
    const dis = discountinput.value; 
    const price = priceinput2.value; 
    const distypeval = distype.value;
    const tempid = document.getElementById('qtyproductid').value;

  
    $.ajax({
        url: "modal-qty-change.php",
        type: "POST",
        data: { tempid: tempid, qty: qty, dis:dis,price:price,distype:distypeval }, 
        success: function (data) {
            loadCartItems();
            qtyinput.value = 1;
                discountinput.value = 0;
            $("#qtyModal").modal("hide");
            document.getElementById('searchinputbox').focus();
        },
        error: function () {
            console.error('Error occurred during AJAX request');
        }
    });
});



const disinput = document.getElementById('disinput');
const distype1 = document.getElementById('distype2');
disinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const dis = disinput.value; 
        const distypeval1 = distype1.value; 
        const tempid = document.getElementById('disproductid').value;

      
        $.ajax({
            url: "modal-dis-change.php",
            type: "POST",
            data: { tempid: tempid, discount: dis,distype1:distypeval1 }, 
            success: function (data) {
                loadCartItems();
               
                disinput.value = 0;
                $("#disModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }
});

document.getElementById('savediscount').addEventListener('click', function(event) {

    const dis = disinput.value; 
    const distypeval1 = distype1.value; 
        const tempid = document.getElementById('disproductid').value;

      
        $.ajax({
            url: "modal-dis-change.php",
            type: "POST",
            data: { tempid: tempid, discount: dis,distype1:distypeval1 }, 
            success: function (data) {
                loadCartItems();
               
                disinput.value = 0;
                $("#disModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });

});




const taxxinput = document.getElementById('taxxinput');
taxxinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const tax = taxxinput.value; 
        const tempid = document.getElementById('taxproductid').value;

      
        $.ajax({
            url: "modal-taxx-change.php",
            type: "POST",
            data: { tempid: tempid, tax: tax }, 
            success: function (data) {
                loadCartItems();
                taxxinput.value = 0;
                $("#itemtaxModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }
});



const priceinput3 = document.getElementById('priceinput3');
priceinput3.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const price = priceinput3.value; 
        const tempid = document.getElementById('priceproductid').value;

      
        $.ajax({
            url: "modal-price-change.php",
            type: "POST",
            data: { tempid: tempid, price: price }, 
            success: function (data) {
                loadCartItems();
                
                $("#priceModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }
});


/*document.addEventListener("DOMContentLoaded", function() {
    var savefreeitem = document.getElementById('savefreeitem');
    savefreeitem.addEventListener("click", function() {
                savefreeitens();
            });
});

function savefreeitens(){       
    const freeqtyinput = document.getElementById('freeqtyinput');
    const freeproduct = document.getElementById('freeproduct');
    const qty = freeqtyinput.value; 
    const product = freeproduct.value;

    if (!product.length) {
            alert("Please select product");
        }else{

            $.ajax({
                url: "modal-freeitem-change.php",
                type: "POST",
                data: { product: product, qty: qty }, 
                success: function (data) {
                    if(data==1){
                        loadCartItems();
                        $("#freeitemModal").modal("hide");
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Product Added successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                    }
                },
                error: function () {
                    console.error('Error occurred during AJAX request');
                }
            });

        }
}
*/
const freeqtyinput = document.getElementById('freeqtyinput');
const freeproduct = document.getElementById('freeproduct');
freeqtyinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const qty = freeqtyinput.value; 
        const product = freeproduct.value;


        if (!product.length) {
            alert("Please select product");
        }else{

            $.ajax({
                url: "modal-freeitem-change.php",
                type: "POST",
                data: { product: product, qty: qty }, 
                success: function (data) {
                    if(data==1){
                        loadCartItems();
                        product.value = "";
                        freeqtyinput.value = 1;
                       
                        $("#freeitemModal").modal("hide");
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Product Added successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                    }
                },
                error: function () {
                    console.error('Error occurred during AJAX request');
                }
            });

        }

    }else if (event.key === 'ArrowUp') {
        document.getElementById('freeproduct').focus();
    }
});
freeproduct.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        document.getElementById('freeqtyinput').focus();
    }
});

document.getElementById('savefreeitem').addEventListener('click', function(event) {
    const freeqtyinput = document.getElementById('freeqtyinput');
const freeproduct = document.getElementById('freeproduct');
const qty = freeqtyinput.value; 
        const product = freeproduct.value;


        if (!product.length) {
            alert("Please select product");
        }else{

            $.ajax({
                url: "modal-freeitem-change.php",
                type: "POST",
                data: { product: product, qty: qty }, 
                success: function (data) {
                    if(data==1){
                        loadCartItems();
                        product.value = "";
                        freeqtyinput.value = 1;
                       
                        $("#freeitemModal").modal("hide");
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Product Added successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                    }
                },
                error: function () {
                    console.error('Error occurred during AJAX request');
                }
            });

        }
});





const marketreturnqtyinput = document.getElementById('marketreturnqtyinput');
const marketreturnproduct = document.getElementById('marketreturnproduct');
marketreturnqtyinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const qty = marketreturnqtyinput.value; 
        const product = marketreturnproduct.value;


        if (!product.length) {
            alert("Please select product");
        }else{

            $.ajax({
                url: "modal-marketreturn-change.php",
                type: "POST",
                data: { product: product, qty: qty }, 
                success: function (data) {
                    if(data==1){
                        loadCartItems();
                        product.value = "";
                        marketreturnqtyinput.value = 1;
                       
                        $("#marketreturnModal").modal("hide");
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Product Added successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                    }
                },
                error: function () {
                    console.error('Error occurred during AJAX request');
                }
            });

        }

    }else if (event.key === 'ArrowUp') {
        document.getElementById('marketreturnproduct').focus();
    }
});
marketreturnproduct.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        document.getElementById('marketreturnqtyinput').focus();
    }
});



















document.getElementById('savemarketitem').addEventListener('click', function(event) {
    const marketreturnqtyinput = document.getElementById('marketreturnqtyinput');
const marketreturnproduct = document.getElementById('marketreturnproduct');
const qty = marketreturnqtyinput.value; 
        const product = marketreturnproduct.value;


        if (!product.length) {
            alert("Please select product");
        }else{

            $.ajax({
                url: "modal-marketreturn-change.php",
                type: "POST",
                data: { product: product, qty: qty }, 
                success: function (data) {
                    if(data==1){
                        loadCartItems();
                        product.value = "";
                        freeqtyinput.value = 1;
                       
                        $("#marketreturnModal").modal("hide");
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Product Added successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                    }
                },
                error: function () {
                    console.error('Error occurred during AJAX request');
                }
            });

        }
});




document.getElementById('saveprice').addEventListener('click', function(event) {
    const price = priceinput3.value; 
        const tempid = document.getElementById('priceproductid').value;

      
        $.ajax({
            url: "modal-price-change.php",
            type: "POST",
            data: { tempid: tempid, price: price }, 
            success: function (data) {
                loadCartItems();
                
                $("#priceModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });

});
function saveproductprice(){
    const priceinput3 = document.getElementById('priceinput3');

    const price = priceinput3.value; 
        const tempid = document.getElementById('priceproductid').value;

      
        $.ajax({
            url: "modal-price-change.php",
            type: "POST",
            data: { tempid: tempid, price: price }, 
            success: function (data) {
                loadCartItems();
                
                $("#priceModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
}








const all_discount = document.getElementById('all_discount');
all_discount.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        event.preventDefault();
        document.getElementById("alldisadd").click();
     }
});



const nameinput = document.getElementById('nameinput');
nameinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const name = nameinput.value; 
        const tempid = document.getElementById('nameproductid').value;

      
        $.ajax({
            url: "modal-name-change.php",
            type: "POST",
            data: { tempid: tempid, name: name }, 
            success: function (data) {
                loadCartItems();
                $("#nameModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }
});

document.getElementById('saveproductname').addEventListener('click', function(event) {
    const name = nameinput.value; 
        const tempid = document.getElementById('nameproductid').value;

      
        $.ajax({
            url: "modal-name-change.php",
            type: "POST",
            data: { tempid: tempid, name: name }, 
            success: function (data) {
                loadCartItems();
                $("#nameModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
});


});








var currentIndex = 0;
document.addEventListener("DOMContentLoaded", function() {



    const listItems = document.querySelectorAll("#searchitems li"); 
   
      const searchInput = document.getElementById("searchinputbox");
 
    function isInputFocused() {
        return searchInput === document.activeElement;
    }
    

    searchInput.addEventListener("keydown", function(event) {
        
        if (event.key === "ArrowDown") {
            const listItems = document.querySelectorAll("#searchitems li");
            var itemhas = false;
            if (isInputFocused()) {
                    if(currentIndex==0){
                        
                        var firstRowli = document.querySelector('#searchitems li:nth-child(0)');
                        firstRowli.classList.add('selectedlirow');
                        document.getElementById('searchinputbox').blur();
                        firstRowli.focus();
                        currentIndex++;
                    }
                
                
            }
       
        }
        
           /* switch(event.key) {
                case 'ArrowUp':
                    currentIndex = Math.max(0, currentIndex - 1);
                    updateSelection();
                    break;
                case 'ArrowDown':
                    currentIndex = Math.min(listItems.length - 1, currentIndex + 1);
                    updateSelection();
                    break;
            }
           */
        
    });

    // Focus event listener on input to reset currentIndex
   // searchInput.addEventListener("focus", function() {
  //      currentIndex = -1; // Reset currentIndex when input is focused
   // });

    // Add focus and click event listeners to list items
   // listItems.forEach((item, index) => {
      //  item.addEventListener("click", function() {
       //     currentIndex = index;
       //     updateSelection(currentIndex);
      //  });
      //  item.addEventListener("focus", function() {
      //      currentIndex = index;
      //  });
    //});


});


function updateSelectedRowli() {
       
       var rows = document.querySelectorAll('#searchitems li');
      
if (rows.length !== 0) {


       rows.forEach(function(row) {
        var inputBox = row.querySelector('.selectedlirow');
           row.classList.remove('selectedlirow');
          
         
       });
      
     
             rows[currentIndex].classList.add('selectedlirow');
           
          
            var i = currentIndex +1;
            document.querySelector('#searchitems li:nth-child('+i+')').focus();
       
      // rows[currentIndex].querySelector('.selectedlirow').;

      console.log(currentIndex);

      if(currentIndex==0){
        document.querySelector('#searchinputbox').focus();
      }
}

}


  
    
   
    
    

document.addEventListener('keydown', function(event) {
    
    var lirows = document.querySelectorAll('#searchitems li');
        var hasli = false;  
      
        for (var i = 0; i < lirows.length; i++) {
            if (lirows[i].classList.contains('selectedlirow')) {
                hasli = true;
                break; 
            }
        }

        if(lirows){
            switch(event.key) {
                case 'ArrowUp':
                    currentIndex = Math.max(0, currentIndex - 1);
                    
                    updateSelectedRowli();
                    break;
                case 'ArrowDown':
                    
                    currentIndex = Math.min(lirows.length - 1, currentIndex + 1);
                    updateSelectedRowli();
                    break;
            }
        }


});

function handlegenaralkeypress(event,id){
    if (event.key === 'Enter') {
        event.preventDefault();
        const idd = document.getElementById(id);
        if (idd) {
            idd.focus();
        }
    }
}
function payBill() {
       //showTotalAmount();
		var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
		//var discount_display = document.getElementById("discount_display").innerHTML;
		//discount_display = parseInt(discount_display.replace('Rs.',''));
		//var discount = discount_display;
		//var discount = document.getElementById("discount_total").value;
		var customer = document.getElementById("billcustomer").value;
		var billdate = document.getElementById('billdate').value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = document.getElementById("totalAmountvalue").value;
		var tddiscount = document.getElementById("tddiscount").value;
		var cardno = document.getElementById("cardno").value;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = document.getElementById("cheque_date").value;
		var cheque_number = document.getElementById("cheque_number").value; 
		var pay_type = document.getElementById("cash_type").value;
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;
        
        var table = document.getElementById("tables").value;
        var room = document.getElementById("rooms").value;
        var order_type = document.getElementsByClassName("order_type").value;
        var servicechargetot = document.getElementById("servicechargetot").value;
		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& tddiscount=" + tddiscount + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& table=" + table + "& room=" + room + "& order_type" + order_type + "& servicechargetot=" + servicechargetot + "& billdate=" + billdate + "&",   
			success: function(data) {
				if (data > 0) {
					$('#payModal').modal('hide');
                    $('.disval').html('0');
					//var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
					loadCartItems();
					window.open("salesreciept.php?receiptno=" + data + '&paid_amount=' + cashamount, "_self");
				} else {
					
				}
			},
			error: function() {
				
			}
		})

	}

    function onlypayBill(){
        //showTotalAmount();
		var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
		//var discount_display = document.getElementById("discount_display").innerHTML;
		//discount_display = parseInt(discount_display.replace('Rs.',''));
		//var discount = discount_display;
		//var discount = document.getElementById("discount_total").value;
		var customer = document.getElementById("billcustomer").value;
		var billdate = document.getElementById('billdate').value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = document.getElementById("totalAmountvalue").value;

		var cardno = document.getElementById("cardno").value;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = document.getElementById("cheque_date").value;
		var cheque_number = document.getElementById("cheque_number").value; 
		var pay_type = document.getElementById("cash_type").value;
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;
        var table = document.getElementById("tables").value;
        var room = document.getElementById("rooms").value;
        var order_type = document.getElementsByClassName("order_type").value;
        var servicechargetot = document.getElementById("servicechargetot").value;

       
		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& table=" + table + "& room=" + room + "& order_type=" + order_type + "& servicechargetot=" + servicechargetot + "& billdate=" + billdate + "&",
			success: function(data) {
				if (data > 0) {
                    if(data==7){
                        Swal.fire({
                            title: 'Error!',
                                text: 'Enter cash amount!',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
                    }else if(data==8){
                        
                        Swal.fire({
                            title: 'Error!',
                                text: 'Select credit customer!',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
                            
                    }else if(data==9){
                        
                        Swal.fire({
                            title: 'Error!',
                                text: 'Customer credit limit is over!',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
                    }else{
                        $('#payModal').modal('hide');
                        $('.disval').html('0');
                        //var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
                        loadCartItems();

                        Swal.fire({
                            title: 'Success!',
                            text: 'Order saved successfuly.',
                            icon: 'success',
                            confirmButtonText: 'OK'
                        });
                    }
					
					//window.open("salesreciept.php?receiptno=" + data + '&paid_amount=' + cashamount, "_blank");
				} else {
					
				}
			},
			error: function() {
				
			}
		})
    }


    function onlypay1Bill(){
        var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
		//var discount_display = document.getElementById("discount_display").innerHTML;
		//discount_display = parseInt(discount_display.replace('Rs.',''));
		//var discount = discount_display;
		//var discount = document.getElementById("discount_total").value;
		var customer = 0;
		var cashamount = document.getElementById("cashat").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = cashamount;

		var cardno = 0;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = "";
		var cheque_number = 0; 
		var pay_type = "cash";
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = 0;
        var mobile_payment_method = "";

		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "&",
			success: function(data) {
				if (data > 0) {
					$('#payModal').modal('hide');
                    $('.disval').html('0');
					//var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
					loadCartItems();

                    Swal.fire({
                        title: 'Success!',
                        text: 'Order saved successfuly.',
                        icon: 'success',
                        confirmButtonText: 'OK'
                    });
					//window.open("salesreciept.php?receiptno=" + data + '&paid_amount=' + cashamount, "_blank");
				} else {
					
				}
			},
			error: function() {
				
			}
		})
    }


    function onlySave1Bill(){
        var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
    //var discount_display = document.getElementById("discount_display").innerHTML;
    //discount_display = parseInt(discount_display.replace('Rs.',''));
    //var discount = discount_display;
    //var discount = document.getElementById("discount_total").value;
    var customer = 0;
    var cashamount = 0;   
    var cashamounthidden = document.getElementById("cashat").value; 
    var servicechrge = document.getElementById("scharge").value; 
    var totalAmountvalue = 0;

    var cardno = 0;
    var cheque = ""; //document.getElementById("cheque").value;
    //var duedate = ""; //document.getElementById("duedate").value;
    var duedate = 0;
    var cheque_number = 0; 
    var pay_type = 0;
    var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
    var country = "0"; //document.getElementById("country").value;
    var city = "0"; //document.getElementById("city").value;
    //var branch_id = document.getElementById("branch_id").value;
    //var oid = document.getElementById("oid").value;
    var gift_number = 0;
    var mobile_payment_method = 0;
    var cardpayment = 0;
   
    $.ajax({
        url: "load-save-new-kot.php",
        type: "POST",
        data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& servicechrge=" + servicechrge + "&",
        success: function(data) {
            if (data > 0) {
                $('#kotModal').modal('hide');
               
                //var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
                loadCartItems();

              //  Swal.fire({
               //     title: 'Success!',
              //      text: 'Order saved successfuly.',
               //     icon: 'success',
               //     confirmButtonText: 'OK'
          //  });
                window.open("salesreciept3.php?receiptno=" + data, "_blank");
            } else {
                
            }
        },
        error: function() {
            
        }
    })
    }


    function onlySaveBill(){
    
        var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
		//var discount_display = document.getElementById("discount_display").innerHTML;
		//discount_display = parseInt(discount_display.replace('Rs.',''));
		//var discount = discount_display;
		//var discount = document.getElementById("discount_total").value;
		var customer = document.getElementById("billcustomer").value;
		var billdate = document.getElementById('billdate').value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = document.getElementById("totalAmountvalue").value;

		var cardno = document.getElementById("cardno").value;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = document.getElementById("cheque_date").value;
		var cheque_number = document.getElementById("cheque_number").value; 
		var pay_type = document.getElementById("cash_type").value;
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;
        var table = document.getElementById("tables").value;
        var room = document.getElementById("rooms").value;
        var order_type = document.getElementsByClassName("order_type").value;
        var servicechargetot = document.getElementById("servicechargetot").value;
		$.ajax({
			url: "only-load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& table=" + table + "& room=" + room + "& order_type=" + order_type + "& servicechargetot=" + servicechargetot + "& billdate=" + billdate + "&",
			success: function(data) {
				if (data > 0) {
					$('#payModal').modal('hide');
                    $('.disval').html('0');
					//var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
					loadCartItems();

                    Swal.fire({
                        title: 'Success!',
                        text: 'Order saved successfuly.',
                        icon: 'success',
                        confirmButtonText: 'OK'
                    });
					//window.open("salesreciept.php?receiptno=" + data + '&paid_amount=' + cashamount, "_blank");
				} else {
					
				}
			},
			error: function() {
				
			}
		})
    }

    function printkot(){
    
    var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
    //var discount_display = document.getElementById("discount_display").innerHTML;
    //discount_display = parseInt(discount_display.replace('Rs.',''));
    //var discount = discount_display;
    //var discount = document.getElementById("discount_total").value;
    var customer = 0;
    var cashamount = 0;   
    var cashamounthidden = 0; 
    var totalAmountvalue = 0;

    var cardno = 0;
    var cheque = ""; //document.getElementById("cheque").value;
    //var duedate = ""; //document.getElementById("duedate").value;
    var duedate = 0;
    var cheque_number = 0; 
    var pay_type = 0;
    var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
    var country = "0"; //document.getElementById("country").value;
    var city = "0"; //document.getElementById("city").value;
    //var branch_id = document.getElementById("branch_id").value;
    //var oid = document.getElementById("oid").value;
    var gift_number = 0;
    var mobile_payment_method = 0;
    var cardpayment = 0;
    var table = document.getElementById("tables").value;
    var room = document.getElementById("rooms").value;
    $.ajax({
        url: "load-save-new-kot.php",
        type: "POST",
        data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& table=" + table + "& room=" + room + "&",
        success: function(data) {
            if (data > 0) {
                $('#kotModal').modal('hide');
               
                //var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
                loadCartItems();

               // Swal.fire({
                //    title: 'Success!',
                //    text: 'Order saved successfuly.',
                //    icon: 'success',
                //    confirmButtonText: 'OK'
                //});
                window.open("kotreciept.php?receiptno=" + data, "_blank");
            } else {
                
            }
        },
        error: function() {
            
        }
    })
}

    function onlySaveBillWithBarcode(){
        //showTotalAmount();
		var totalbillvalue = document.getElementById("total_amount_view").innerHTML;
		//var discount_display = document.getElementById("discount_display").innerHTML;
		//discount_display = parseInt(discount_display.replace('Rs.',''));
		//var discount = discount_display;
		//var discount = document.getElementById("discount_total").value;
		var customer = document.getElementById("billcustomer").value;
		var billdate = document.getElementById('billdate').value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = document.getElementById("totalAmountvalue").value;

		var cardno = document.getElementById("cardno").value;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = document.getElementById("cheque_date").value;
		var cheque_number = document.getElementById("cheque_number").value; 
		var pay_type = document.getElementById("cash_type").value;
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;
        
var table = document.getElementById("tables").value;
        var room = document.getElementById("rooms").value;
        var order_type = document.getElementsByClassName("order_type").value;
        var servicechargetot = document.getElementById("servicechargetot").value;
		$.ajax({
			url: "orderid-new-barcode.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& table=" + table + "& room=" + room + "& order_type=" + order_type + "& servicechargetot=" + servicechargetot + "& billdate=" + billdate + "&",
			success: function(data) {
				if (data > 0) {
					$('#myModal').modal('hide');
                    $('.disval').html('0');
					window.location.replace("gen-orderid-barcode.php?order_id="+data);
					//var totalbillvalue = document.getElementById("total_amount_view").innerHTML = "Order has been saved<br>Order Number : " + data;
					loadCartItems();

                   // Swal.fire({
                    //    title: 'Success!',
                    //    text: 'Order saved successfuly.',
                    //    icon: 'success',
                    //    confirmButtonText: 'OK'
                   // });
					//window.open("salesreciept.php?receiptno=" + data + '&paid_amount=' + cashamount, "_blank");
				} else {
					
				}
			},
			error: function() {
				
			}
		})
    }

    function tbrowclick(event){
            var rows = document.querySelectorAll('.table tr');
            rows.forEach(function(row) {
                row.classList.remove('selectedrow');
            });
        event.currentTarget.classList.add('selectedrow');

    }
    
   


    $(document).ready(function(){
       
        $(".select2").select2({
        });

      

        $("#lotteryadd").click(function(){  
            var lottery_number = $("#lottery_number").val();
            var lottery_win_amount = $("#lottery_win_amount").val();
            if (lottery_number === "") {
                      Swal.fire({
						title: 'Error!',
							text: 'Please enter lottery number!',
							icon: 'warning',
							confirmButtonText: 'OK'
						});
            }else{
                if (lottery_win_amount === "") {
                           Swal.fire({
                            title: 'Error!',
                                text: 'Please enter lottery win amount!',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
                }else{
                        $.ajax({
                            url: "save-lottery.php",
                            type: "POST",
                            data: { lottery_number: lottery_number, lottery_win_amount: lottery_win_amount }, 
                            success: function (data) {
                                loadCartItems();
                                $("#lotteryModal").modal("hide");
                                if(data==1){
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Lottery saved successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                                }
                            },
                            error: function () {
                                console.error('Error occurred during AJAX request');
                            }
                        });
                }
            }


        });
   
    
    $("#alldisadd").click(function(){  
        var all_discount = $("#all_discount").val();
        if (all_discount === "") {
                        Swal.fire({
                            title: 'Error!',
                                text: 'Please enter discount!',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
        }else{
                $.ajax({
                            url: "save-all-discount.php",
                            type: "POST",
                            data: { all_discount: all_discount }, 
                            success: function (data) {
                                loadCartItems();
                                $(".disval").html(all_discount);
                                $("#alldisModal").modal("hide");
                                if(data==1){
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Discount saved successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                                }
                            },
                            error: function () {
                                console.error('Error occurred during AJAX request');
                            }
                        });
        }
    });


    $("#allgenadd").click(function(){  
        var name = $("#genaralnameinput").val();
        var qty = $("#genaralqtyinput").val();
        var discount = $("#genaraldiscountinput").val();
        var tax = $("#genaraltaxinput").val();
        var price = $("#genaralpriceinput").val();
        var marketprice = $("#genaralmarketpriceinput").val();
        var tempid = $("#allproductid").val();
        var distype3 = $("#distype3").val();

                     $.ajax({
                            url: "save-all-genaral-item.php",
                            type: "POST",
                            data: { name: name,qty:qty,discount:discount,tax:tax,tempid:tempid,price:price,marketprice:marketprice,distype:distype3 }, 
                            success: function (data) {
                                loadCartItems();
                               
                                
                                $("#genaralnameinput").val("");
                                $("#genaralqtyinput").val("");
                                $("#genaraldiscountinput").val("");
                                $("#genaraltaxinput").val("");
                                $("#genaralpriceinput").val("");
                                $("#genaralmarketpriceinput").val("");
                                $("#allproductid").val("");
                                $("#allModal").modal("hide");       
                                if(data==1){
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Genaral Item saved successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                                }
                            },
                            error: function () {
                                console.error('Error occurred during AJAX request');
                            }
                        });





    });







    $("#taxadd").click(function(){  
        var tax = $("#tax").val();
        if (tax === "") {
                        Swal.fire({
                            title: 'Error!',
                                text: 'Please enter tax!',
                                icon: 'warning',
                                confirmButtonText: 'OK'
                            });
        }else{
                $.ajax({
                            url: "save-tax.php",
                            type: "POST",
                            data: { tax: tax }, 
                            success: function (data) {
                                loadCartItems();
                                $(".taxval").html(tax);
                                $("#taxModal").modal("hide");
                                if(data==1){
                                    Swal.fire({
                                        title: 'Success!',
                                        text: 'Tax saved successfuly.',
                                        icon: 'success',
                                        confirmButtonText: 'OK'
                                    });
                                }
                            },
                            error: function () {
                                console.error('Error occurred during AJAX request');
                            }
                        });
        }
    });
    
});

function creditcustomerchange(){

    var customer = document.getElementById("billcustomer").value;
    var cash_type = document.getElementById("cash_type").value;
    var cashamount = document.getElementById("cashamount").value;
    var cashamounthidden = document.getElementById("cashamounthidden").value;
    

                if(customer!="dc" || customer!="0" && cash_type=='credit'){
                        $.ajax({
                            url: "change-credit-customer.php",
                            type: "POST",
                            dataType: 'json',
                            data: { customer: customer,cashamount:cashamount,cashamounthidden:cashamounthidden }, 
                            success: function (data) {
                               $("#creditAmountvalue").val(data[0]);
                               $("#totalAmountvalue").val(data[1]);
                            },
                            error: function () {
                                console.error('Error occurred during AJAX request');
                            }
                        });
                    }
}






</script>




<div class="modal" tabindex="-1" role="dialog" id="qtyModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseqtyModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Change Quantity & Discount</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Product : <span id="modalproductname"></span></p>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Default Quantity : <span id="modalproductqty"></span></p>
                 <div class="qtyinputwrap">
                    <input type="hidden" id="qtyproductid" value="0">
                    <label style="color:#fff;">Quantity</label>
                    <input type="text" class="form-control mb-3 qtyModalinput" id="qtyinput" step="0.01" min="0" value="1">
                    <label style="color:#fff;">Price <span id="costprice"></span></label>
                    <input type="text" class="form-control mb-3 qtyModalinput" id="priceinput" value="0">
                    <label style="color:#fff;">Discount Type</label>
                    <select id="distype"  class="form-control mb-3">
                        <option value="0">Normal</option>
                        <option value="1">%</option>
                    </select>
                    <label style="color:#fff;">Discount</label>
                    <input type="number" min="1" steps="0.01" class="form-control mb-3 qtyModalinput" id="discountinput" value="0">
                    <button style="width:100%;" type="text" class="btn btn-primary mb-3 qtyModalinput" id="saveqty1">Save</button>
                 </div>  
                 <!--<div class="row mt-3 g-1">
                    <div class="col-3">
                        <div class="number">1</div>
                    </div>
                    <div class="col-3">
                        <div class="number">2</div>
                    </div>
                    <div class="col-3">
                        <div class="number">3</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">4</div>
                    </div>
                    <div class="col-3">
                        <div class="number">5</div>
                    </div>
                    <div class="col-3">
                        <div class="number">6</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">7</div>
                    </div>
                    <div class="col-3">
                        <div class="number">8</div>
                    </div>
                    <div class="col-3">
                        <div class="number">9</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                 </div>    --> 
            </div>
        </div>
    </div>
</div>

<div class="modal" tabindex="-1" role="dialog" id="kotModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseKotModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">KOT</h5>
                
                
                 <div class="kotinputwrap">
                     <div id="kotinput">

                     </div>
                    <?php 
                   
                                ?>
                    <div class="col-3 mt-4">    
                        <button id="pbtn5" class="number ntext pbtn inputele" onclick="printkot();" onkeydown="if(event.keyCode==13){ printkot(); event.preventDefault(); }" style="background-color:#001d87; width:100%;">Print KOT</button>
                    </div>
                 </div>  
               
            </div>
        </div>
    </div>
</div>


<div class="modal" tabindex="-1" role="dialog" id="allModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseallModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Change Genaral Item</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Product : <span id="allmodalproductname"></span></p>
               
                 <div class="qtyinputwrap">
                    <input type="hidden" id="allproductid" value="0">
                    <label class="mt-3" style="color: #fff;">Product Name</label>
                    <input type="text" class="form-control mt-1 gall1 allmodalinput" onkeypress="handlegenaralkeypress(event,'genaralqtyinput')" id="genaralnameinput">
                    <label class="mt-3" style="color: #fff;">Quantity</label>
                    <input type="text" class="form-control mt-1 gall2 allmodalinput" onkeypress="handlegenaralkeypress(event,'genaralpriceinput')" id="genaralqtyinput" step="0.01" min="0" value="1">
                    <label class="mt-3" style="color: #fff;">Price</label>
                    <input type="text" class="form-control mt-1 gall3 allmodalinput" onkeypress="handlegenaralkeypress(event,'genaraldiscountinput')" id="genaralpriceinput" step="0.01" min="0" value="0">
                    <label class="mt-3" style="color:#fff;">Discount Type</label>
                    <select id="distype3"  class="form-control mb-3">
                        <option value="0">Normal</option>
                        <option value="1">%</option>
                    </select>
                    <label class="mt-3" style="color: #fff;">Discount</label>
                    <input type="text" class="form-control mt-1 gall4 allmodalinput" onkeypress="handlegenaralkeypress(event,'genaraltaxinput')" id="genaraldiscountinput" value="0">
                    <label class="mt-3" style="color: #fff;">Tax</label>
                    <input type="text" class="form-control mt-1 gall5 allmodalinput" onkeypress="handlegenaralkeypress(event,'genaralmarketpriceinput')" id="genaraltaxinput" value="0%">
                    <label class="mt-3" style="color: #fff;">Market Price</label>
                    <input type="text" class="form-control mt-1 gall5 allmodalinput" onkeypress="handlegenaralkeypress(event,'allgenadd')" id="genaralmarketpriceinput" value="0">
                    <button class="number ntext mt-3 gall allmodalinput" style="width: 100%;" id="allgenadd">Save</button>
                 </div>  
                 
                 </div>     
            </div>
        </div>
    </div>
</div>






<div class="modal" tabindex="-1" role="dialog" id="disModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloasedisModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Change Discount</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Product : <span id="modalproductname2"></span></p>
                
                 <div class="qtyinputwrap">
                    <input type="hidden" id="disproductid" value="0">
                    <label style="color:#fff;">Discount Type</label>
                    <select id="distype2"  class="form-control mb-3">
                        <option value="0">Normal</option>
                        <option value="1">%</option>
                    </select>
                    <label style="color:#fff;">Discount</label>
                    <input type="text" class="form-control mt-3" id="disinput">
                    <button class="btn btn-primary mt-3" style="width:100%;" id="savediscount">Save</button>
                 </div>  
                <!-- <div class="row mt-3 g-1">
                    <div class="col-3">
                        <div class="number">1</div>
                    </div>
                    <div class="col-3">
                        <div class="number">2</div>
                    </div>
                    <div class="col-3">
                        <div class="number">3</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">4</div>
                    </div>
                    <div class="col-3">
                        <div class="number">5</div>
                    </div>
                    <div class="col-3">
                        <div class="number">6</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">7</div>
                    </div>
                    <div class="col-3">
                        <div class="number">8</div>
                    </div>
                    <div class="col-3">
                        <div class="number">9</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                 </div>   -->  
            </div>
        </div>
    </div>
</div>

<div class="modal" tabindex="-1" role="dialog" id="itemtaxModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseitemTaxModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Change tax</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Product : <span id="modalproductname6"></span></p>
                
                 <div class="qtyinputwrap">
                    <input type="hidden" id="taxproductid" value="0">
                    <input type="text" class="form-control mt-3" id="taxxinput">
                 </div>  
                <!-- <div class="row mt-3 g-1">
                    <div class="col-3">
                        <div class="number">1</div>
                    </div>
                    <div class="col-3">
                        <div class="number">2</div>
                    </div>
                    <div class="col-3">
                        <div class="number">3</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">4</div>
                    </div>
                    <div class="col-3">
                        <div class="number">5</div>
                    </div>
                    <div class="col-3">
                        <div class="number">6</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">7</div>
                    </div>
                    <div class="col-3">
                        <div class="number">8</div>
                    </div>
                    <div class="col-3">
                        <div class="number">9</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                 </div>    --> 
            </div>
        </div>
    </div>
</div>










<div class="modal" tabindex="-1" role="dialog" id="priceModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloasepriceModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Change Price</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Product : <span id="modalproductname3"></span></p>
                
                 <div class="qtyinputwrap">
                    <input type="hidden" id="priceproductid" value="0">
                    <input type="text" class="form-control mt-3" id="priceinput3">
                    <button class="btn btn-primary mt-3" style="width:100%;" id="saveprice">Save</button>
                 </div>  
                <!-- <div class="row mt-3 g-1">
                    <div class="col-3">
                        <div class="number">1</div>
                    </div>
                    <div class="col-3">
                        <div class="number">2</div>
                    </div>
                    <div class="col-3">
                        <div class="number">3</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">4</div>
                    </div>
                    <div class="col-3">
                        <div class="number">5</div>
                    </div>
                    <div class="col-3">
                        <div class="number">6</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                    <div class="col-3">
                        <div class="number">7</div>
                    </div>
                    <div class="col-3">
                        <div class="number">8</div>
                    </div>
                    <div class="col-3">
                        <div class="number">9</div>
                    </div>
                    <div class="col-3">
                        <div class="number">.</div>
                    </div>
                 </div>    --> 
            </div>
        </div>
    </div>
</div>


<div class="modal" tabindex="-1" role="dialog" id="nameModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloasenameModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Change Name</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;">Product : <span id="modalproductname5"></span></p>
                
                 <div class="qtyinputwrap">
                    <input type="hidden" id="nameproductid" value="0">
                    <input type="text" class="form-control mt-3" id="nameinput">
                    <button class="btn btn-primary mt-3" style="width:100%;" id="saveproductname">Save</button>
                 </div>  
                 
            </div>
        </div>
    </div>
</div>


<div class="modal" tabindex="-1" role="dialog" id="freeitemModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloasefreeitemModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Free Item</h5>
                
                
                 <div class="qtyinputwrap">
                    <input type="hidden" id="nameproductid" value="0">
                    <label class="mt-3" style="color: #fff;">Product</label>
                    
                    <select class="form-control select3" id="freeproduct">
                        <option value="">Select Product</option>
                        <?php $products = mysqli_query($conn, "SELECT * FROM mobileproducts,tbl_stock WHERE mobileproducts.prid=tbl_stock.prid AND tbl_stock.qty > '0'");
                            if ($products->num_rows > 0) {
                                while($row = $products->fetch_assoc()) { ?>
                                <option value="<?php echo $row['prid']; ?>"><?php echo $row['itemcode']." | ".$row['proname']." | Qty-".$row['qty']; ?></option>
                               <?php }
                            }
                        
                        ?>
                    </select>
                    <label class="mt-3" style="color: #fff;">Qty</label>
                    <input type="text" class="form-control" id="freeqtyinput" value="1">

                    <button class="mt-3 btn btn-primary" style="width: 100%;" id="savefreeitem">Save</button>
                 </div>  
                 
            </div>
        </div>
    </div>
</div>


<div class="modal" tabindex="-1" role="dialog" id="marketreturnModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseMarketReturnModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Market Return</h5>
                
                
                 <div class="qtyinputwrap">
                   
                    <label class="mt-3" style="color: #fff;">Product</label>
                    
                    <select class="form-control select4" id="marketreturnproduct">
                        <option value="">Select Product</option>
                        <?php $products = mysqli_query($conn, "SELECT * FROM mobileproducts,tbl_stock WHERE mobileproducts.prid=tbl_stock.prid AND tbl_stock.qty > '0'");
                            if ($products->num_rows > 0) {
                                while($row = $products->fetch_assoc()) { ?>
                                <option value="<?php echo $row['prid']; ?>"><?php echo $row['itemcode']." | ".$row['proname']." | Qty-".$row['qty']; ?></option>
                               <?php }
                            }
                        
                        ?>
                    </select>
                    <label class="mt-3" style="color: #fff;">Qty</label>
                    <input type="text" class="form-control" id="marketreturnqtyinput" value="1">

                    <button class="mt-3 btn btn-primary" style="width: 100%;" id="savemarketitem">Save</button>
                 </div>  
                 
            </div>
        </div>
    </div>
</div>






<div class="modal" tabindex="-1" role="dialog" id="payModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloasepayModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Payment Panel</h5>
                <p style="color:#ffffff; text-align:center; margin-bottom:5px;"><span id="paytype"></span></p>
                <div class="row" id="paymodalcontent">

                </div>
                <div class="row mt-3 g-1 btnwrap">
                    <div class="col-6">
                        
                        <button id="pbtn1" class="number ntext pbtn inputele" onclick="onlypayBill();" onkeydown="if(event.keyCode==13){ onlypayBill(); event.preventDefault(); }" style="background-color:#001d87; width:100%;"><span class="key">S</span> <i class="fa fa-credit-card"></i>  Pay</button>
                    </div>
                    <div class="col-6">
                       
                        <button id="pbtn2" class="number ntext pbtn inputele" onclick="payBill();" onkeydown="if(event.keyCode==13){ payBill(); event.preventDefault(); }" style="background-color:#24870b;width:100%;"> <span class="key">T</span> <i class="fa fa-print"></i> Print</button>
                    </div>
                    <div class="col-6">
                        
                        <button id="pbtn3" class="number ntext pbtn inputele" onclick="onlySaveBill();" onkeydown="if(event.keyCode==13){ onlySaveBill(); event.preventDefault(); }" style="background-color:#01796f; width:100%;"><span class="key">R</span> <i class="fa fa-pause"></i> Hold</button>
                    </div>
                    <div class="col-6">
                       
                        <button id="pbtn4" class="number ntext pbtn inputele" onclick="onlySaveBillWithBarcode();" onkeydown="if(event.keyCode==13){ onlySaveBillWithBarcode(); event.preventDefault(); }" style="background-color:#000000; width:100%;"> <span class="key">V</span> <i class="fa fa-barcode"></i> Barcode</button>
                    </div>
                </div>
                   
            </div>
        </div>
    </div>
</div>
<style>
    .btnwrap .number{
        position:relative;
    }
    .btnwrap .number .key{
        top: -15px;
        font-size: 10px;
    }
</style>


<div class="modal" tabindex="-1" role="dialog" id="calculatorModal">
	<div class="modal-dialog modal-dialog2" role="document" style="max-width: 426px;">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloasecalModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Calculator</h5>
                
                
                <div class="row mt-3 g-1">
                    <div class="col-12">
                            <div class="calculator">
                                    <div class="input" id="input"></div>
                                    <div class="buttons">
                                        <div class="operators">
                                        <div>+</div>
                                        <div>-</div>
                                        <div>&times;</div>
                                        <div>&divide;</div>
                                        </div>
                                        <div class="leftPanel">
                                        <div class="numbers">
                                            <div>7</div>
                                            <div>8</div>
                                            <div>9</div>
                                        </div>
                                        <div class="numbers">
                                            <div>4</div>
                                            <div>5</div>
                                            <div>6</div>
                                        </div>
                                        <div class="numbers">
                                            <div>1</div>
                                            <div>2</div>
                                            <div>3</div>
                                        </div>
                                        <div class="numbers">
                                            <div>0</div>
                                            <div>.</div>
                                            <div id="clear">C</div>
                                        </div>
                                        </div>
                                        <div class="equal" id="result">=</div>
                                    </div>
                                    </div>
                            </div>

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





<div class="modal" tabindex="-1" role="dialog" id="lotteryModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaselotteryModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Lottery</h5>
                
                
                <div class="row mt-3 g-1">
                    <div class="col-12 mb-2">
                        <div class="form-group">
                            <input type="text" class="form-control" id="lottery_number" placeholder="Lottery Number">
                        </div>
                    </div>
                    <div class="col-12 mb-2">
                        <div class="form-group">
                            <input type="number" class="form-control" id="lottery_win_amount" step="0.01" placeholder="Lottery Win Amount">
                        </div>
                    </div>
                    <div class="col-12 mb-2">
                        <button type="submit" class="number ntext" style="width: 100%;" id="lotteryadd">Save</button>
                    </div>
            </div>
        </div>
    </div>
</div>
</div>






<div class="modal" tabindex="-1" role="dialog" id="alldisModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseAllDisModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">All Discount</h5>
                
                
                <div class="row mt-3 g-1">
                    <div class="col-12 mb-2">
                        <div class="form-group">
                            <input type="text" class="form-control" id="all_discount" value="<?php $dis = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM all_discount_tbl WHERE all_discount_tbl_id ='1'")); if($dis['discount_type']==0){ echo $dis['discount_val']; }else{ echo $dis['discount_val']."%"; } ?>" placeholder="All Discount">
                        </div>
                    </div>
                   
                    <div class="col-12 mb-2">
                        <button type="submit" class="number ntext" style="width: 100%;" id="alldisadd">Save</button>
                    </div>
            </div>
        </div>
    </div>
    </div>
</div>

    <div class="modal" tabindex="-1" role="dialog" id="taxModal">
	<div class="modal-dialog modal-dialog2" role="document">
		<div class="modal-content" style="background:#403b4a; border: 2px solid #373c32;">
			<!--<div class="modal-header" style="background:#403b4a;">
				
				
			</div>-->
			<div class="modal-body" id="myModalMsg"> 
                <button type="button" class="close" style="position: absolute; right: 8px; top: 7px;" data-dismiss="modal" aria-label="Close" onclick="cloaseTaxModal();">
					<span style="color:#fff;" aria-hidden="true">&times;</span>
				</button>
                <h5 class="modal-title" style="color:#ffffff; text-align:center;">Tax</h5>
                
                
                <div class="row mt-3 g-1">
                    <div class="col-12 mb-2">
                        <div class="form-group">
                            <input type="text" class="form-control" id="tax" value="<?php $tax = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM tax WHERE tax_id ='1'")); if($tax['tax_type']==0){ echo $tax['tax']; }else{ echo $tax['tax']."%"; } ?>" placeholder="Tax">
                        </div>
                    </div>
                   
                    <div class="col-12 mb-2">
                        <button type="submit" class="number ntext" style="width: 100%;" id="taxadd">Save</button>
                    </div>
            </div>
        </div>
    </div>
    </div>





<style>
    .calculator {
  padding: 20px;
  -webkit-box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  border-radius: 1px;
}

.calculator .input {
  border: 1px solid #ddd;
  border-radius: 1px;
  min-height: 60px;
  padding-right: 15px;
  padding-top: 10px;
  text-align: right;
  margin-right: 6px;
  font-size: 2.5rem;
  overflow-x: auto;
  transition: all .2s ease-in-out;
  color: #fff;
}

.calculator .input:hover {
  border: 1px solid #bbb;
  -webkit-box-shadow: inset 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  box-shadow: inset 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
}

.buttons {}

.operators {}

.operators div {
  display: inline-block;
  border: 1px solid #bbb;
  border-radius: 1px;
  width: 80px;
  text-align: center;
  padding: 10px;
  margin: 20px 4px 10px 0;
  cursor: pointer;
  background-color: #ddd;
  transition: border-color .2s ease-in-out, background-color .2s, box-shadow .2s;
}

.operators div:hover {
  background-color: #ddd;
  -webkit-box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  border-color: #aaa;
}

.operators div:active {
  font-weight: bold;
}

.leftPanel {
  display: inline-block;
}

.numbers div {
  display: inline-block;
  border: 1px solid #ddd;
  border-radius: 1px;
  width: 80px;
  text-align: center;
  padding: 10px;
  margin: 10px 4px 10px 0;
  cursor: pointer;
  background-color: #f9f9f9;
  transition: border-color .2s ease-in-out, background-color .2s, box-shadow .2s;
}

.numbers div:hover {
  background-color: #f1f1f1;
  -webkit-box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  border-color: #bbb;
}

.numbers div:active {
  font-weight: bold;
}

div.equal {
  display: inline-block;
  border: 1px solid #3079ED;
  border-radius: 1px;
  width: 23%;
  text-align: center;
  padding: 110px 10px;
  margin: 10px 0px 10px 0;
  vertical-align: top;
  cursor: pointer;
  color: #FFF;
  background-color: #4d90fe;
  transition: all .2s ease-in-out;
}

div.equal:hover {
  background-color: #307CF9;
  -webkit-box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  box-shadow: 0px 1px 4px 0px rgba(0, 0, 0, 0.2);
  border-color: #1857BB;
}

div.equal:active {
  font-weight: bold;
}


@media only screen and (max-width: 1366px) {
    .productwrap h6{
        font-size: 12px;
    }
    .item .form-check label {
        font-size: 13px;
    }
    .icon-text{
        font-size: 12px !important;
    }
}
@media only screen and (max-width: 1025px) {
    th{
        font-size: 12px !important;
    }
    td{
        font-size: 11px !important;
    }
    .icon-text {
        font-size: 10px !important;
    }
    .item i {
        font-size: 18px;
    }
    .wrap.box-wrap.bigbox{
        height: 85px !important;
    }
    .key{
        font-size: 7px;
    }
    .item .form-check label {
        font-size: 9px !important;
    }
    .select{
        width: 195px;
        height: 33px;
        font-size: 14px;
    }
    .productwrap h6 {
        font-size: 10px !important; 
    }
    .item h6{
        font-size: 8px !important;
    }
    .resbtn{
        font-size: 10px !important;
    }
    .searchwrap input{
        height: 35px;
        font-size: 14px;
    }
    .searchwrap i{
        top: 5px;
    }
    .item{
        padding-left: 1px;
        padding-right: 1px;
        padding-top: 1px !important;
        padding-bottom: 1px !important;
    }
    .item .form-check{
        margin-bottom: 1px !important;
    }
}
</style>










<script>
    $(document).ready(function() {
        const textInput = $('#qtyinput');
        textInput.on('input', function() {
           var qty = $(this).val();
           var productid = $("#qtyproductid").val();
           
        });


    });
</script>












</body>
</html>

