<?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="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.3.0/font/bootstrap-icons.css">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</head>
<body>
<style>
    body{
        width: 100%;
        height: 100%;
        background: #605e5f;
    }
    .pos-wrap{
        width: 100%;
        height: 100%;
       
    }
    .topbox i{
        color: #fff;
        font-size: 18px;
    }
    .pos-top{
        padding: 15px 0px;
		background-color:#000000;
    }
    .pos-top{
        border-bottom: 1px solid #ffffff;
    }
    .pos-middele{
        border: 4px solid #ffffff;
        padding-top: 5px;
        padding-bottom: 5px;
        padding-left: 5px;
        padding-right: 5px;
    }
    thead{
        border-bottom: 1px solid #eddfe1;
        
    }
    table{
       
    }
    th,td{
        color:#fff;
    }
    i{
        color: #fff !important;
    }
    .icon-text{
		font-weight:600;
        text-align: center;
        color: #fff;
        margin-top: 5px;
		font-size: 14px;
    }
    .icon-wrap{
        text-align: center;
    }
    .box-wrap{
        padding: 15px 0px;
        border: 2px solid gray; 
        border-radius: 3px;
        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: 50px;
    }
    .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: #000000;
        color: #ffffff;
        padding-left: 45px;
        border-color: #ffffff;
    }
    .searchwrap i{
        position: absolute;
        left: 25px;
        top: 5px;
    }
    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;
       
    }
    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(0 0 0) 0%, rgba(64, 59, 74, 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;
        }
        
</style>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>
<section class="pos-wrap">
    <div class="container-fluid">
        <div class="pos-top">
            <div class="row">
                <div class="col-lg-2 d-flex justify-content-around">
                        <div class="topbox">
                                <a href="home.php" class="logo mr-2" style="margin-right: 10px; padding-right:15px;">
				                    <img src="images/settings/999882.png" alt="#" width="40px">
			                    </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="color:#fff;">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="color:#fff;">Tax</label>
                            </div>
                        </div>
                </div>
                    <div class="col-lg-8 searchwrap">
                        <i class="bi bi-search"></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-2" style="color: #fff; display:flex; align-items:center; background:green; font-size:13px; ">
                            <i style="margin-right: 10px;" class="fa fa-user" aria-hidden="true"></i>
			                Cashier : <?php echo $userinfo['fullname']; ?> | Canadian Outlet
                    </div>
            </div>
        </div>
        <div class="pos-middele full-height">
            <div class="row g-1">
                <div class="col-lg-8" id="right_cart_panel">
                <table class="table table-borderless mb-0">
                    <thead>
                        <tr>
                        <th scope="col">Product Name</th>
                        <th scope="col">Quantty</th>
                        <th scope="col">Price</th>
                        <th scope="col">Discount</th>
                        <th scope="col">Tax</th>
                        <th scope="col">Amount</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                    <tfoot>
                        <tr>
                        </tr>
                        <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td>Sub Total</td>
                            <td style=" ">0.00</td>
                        </tr>
                        <tr>
                        <td></td>
                        <td></td>
                            <td></td>
                            <td>Discount</td>
                            <td style="">0.00</td>
                        </tr>
                        <tr>
                        <td></td>
                            <td></td>
                            <td></td>
                            <td class="heighlight">Total</td>
                            <td class="heighlight" style="">0.00</td>
                        </tr>
                    </tfoot>
                    </table>
                </div>
                <div class="col-lg-4 bg2">
                    <div class="row g-1">
                        <div class="col-lg-3 mt-1 pb-1 item">
                            <div class="wrap box-wrap" style="background-color:#ff004f;">
                                    <div class="icon-wrap" onclick="deletefocusitem();">
                                        <span class="key">F8</span>
                                        <i class="bi bi-x"></i>
                                    </div>
                                    <div class="icon-text">
                                        Delete
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="searchfocus();" style="background-color:#808080;">
                                    <span class="key">F2</span>
                                    <div class="icon-wrap">
                                    <i class="bi bi-search"></i>
                                    </div>
                                    <div class="icon-text">
                                        Search
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="qtyfocus();" style="background-color:#000000;">
                                    <span class="key">F4</span>
                                    <div class="icon-wrap">
                                        <i class="bi bi-basket3"></i>
                                    </div>
                                    <div class="icon-text">
                                        Quantity
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 mt-1 pb-1 item">
                            <div class="wrap box-wrap" 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>
                    <div class="row g-1">
                            <div class="col-lg-3 mt-1 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(1);" style="background-color:#008000;">
                                        <span class="key">Shift + C</span>
                                        <div class="icon-text">
                                            Cash
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(2);" style="background-color:#0000FF;">
                                        <span class="key">Shift + E</span>
                                        <div class="icon-text">
                                            Credit
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(3);" style="background-color:#A020F0;">
                                        <span class="key">Shift + R</span>
                                        <div class="icon-text">
                                        Debit Card
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1 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">
                                        Bank Transfer
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 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">
                                        Cheques
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-3 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">
                                        Mobile Payment
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-3 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">
                                        Gift Cards
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-3 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">
                                        Other Payment
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="transactions();" style="background-color:#32a852;">
                                        <span class="key">Shift + F</span>
                                        <div class="icon-text">
                                        Recent Transactions
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="pendingsales();" style="background-color:#a632a8;">
                                        <span class="key">Shift + G</span>
                                        <div class="icon-text">
                                        Pending Sales
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addNewProductById(148);" style="background-color:#3d5e38;">
                                        <span class="key"></span>
                                        <div class="icon-text">
                                        Genaral Item
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 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">
                                        Tax
                                        </div>
                                </div>
                            </div>
                            <!--<div class="col-lg-3 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>


                    <div class="row g-1 mt-5">
                        <div class="col-lg-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="disfocus();" style="background-color:#0014a8;">
                                        <span class="key">Shift + D</span>
                                        <div class="icon-wrap">
                                        <i class="bi bi-percent"></i>
                                        </div>
                                        <div class="icon-text">
                                            Discount
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="lottery();" style="background-color:#fe4eda;">
                                        <span class="key">F11</span>
                                        <div class="icon-wrap">
                                        <i class="bi bi-chat-left-text"></i>
                                        </div>
                                        <div class="icon-text">
                                            Lottery
                                        </div>
                                </div>
                            </div>

                            <div class="col-lg-6 mt-1  item">
                                <div class="wrap box-wrap" onclick="calculator();" style="background-color:#800080;">
                                        <span class="key">F12</span>
                                        <div class="icon-wrap">
                                            <i class="bi bi-box"></i>
                                        </div>
                                        <div class="icon-text">
                                            Keypad
                                        </div>
                                </div>
                            </div>

                            <div class="col-lg-3 mt-1  item">
                            <div class="wrap box-wrap" onclick="onlySave1Bill();" style="background-color:#01796f;">
                                        
                                        <div class="icon-wrap">
                                        <i>F9</i>
                                        </div>
                                        <div class="icon-text">
                                            Save Sale
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="redirectToReturn();" style="background-color:#ff9f00;">
                                        <span class="key">F7</span>
                                        <div class="icon-wrap">
                                        <i class="bi bi-folder-symlink"></i>
                                        </div>
                                        <div class="icon-text">
                                            Return
                                        </div>
                                </div>
                            </div>

                            <div class="col-lg-6 mt-1  item">
                                <div class="wrap box-wrap" 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">
                                           Hold
                                        </div>
                                </div>
                            </div>



                            <div class="col-lg-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="tax();" style="background-color:#000039;">
                                        <span class="key">F3</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-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="pricefocus();" style="background-color:#648c11;">
                                        <span class="key">Shift + I</span>
                                        <div class="icon-wrap">
                                        <i class="bi bi-cash"></i>
                                        </div>
                                        <div class="icon-text">
                                            Price
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1 item">
                                <div class="wrap box-wrap" onclick="namefocus();" style="background-color:#000000;height: 138px;">
                                    <span class="key">Shift + L</span> 
                                        <div class="icon-wrap">
                                        <i class="bi bi-card-text"></i>
                                        </div>
                                        <div class="icon-text">
                                            Product Name
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="deleteallproduct();" style="background-color:#ff0000;">
                                        <span class="key">F5</span>                      
                                        <div class="icon-wrap">
                                        <i class="bi bi-trash"></i>
                                        </div>
                                        <div class="icon-text">
                                            Void Order
                                        </div>
                                </div>
                            </div>
                            

                    </div>



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






<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>
   
    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();
    }
    
  }
 

  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);       






  $(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');
}

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

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

var inputTimeout;
function handleInput() {
  clearTimeout(inputTimeout);
  inputTimeout = setTimeout(filterProducts, 1000);
}
function filterProducts() {
  var searchbarcode = document.getElementById("searchinputbox").value;
  
    $.ajax({
      url: "search-filter-products.php",
      type: "POST",
      data: "searchbarcode=" + searchbarcode + "&",
      success: function (data) {
        loadCartItems();  
        if(data==1){
            document.getElementById("searchinputbox").value = "";
            $("#searchitems").html("");
            $("#searchitems").css("display","none");
        }
       
      },
      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');




}
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");
            }
            
            $("#paymodalcontent").html(data);
            $("#payModal").modal("show");

            var payModal = document.getElementById('payModal');
            if (payModal) { 
                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);
            }
            
           // 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(cash){

   var cashamounthidden =  document.getElementById('cashamounthidden').value;
   
    var balace = parseFloat(cash) - parseFloat(cashamounthidden);
    if (balace === null){
        balace = cashamounthidden;
    }
    document.getElementById('balance').value =  Math.abs(balace);

}



  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 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;
                $('#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 pname = item.querySelectorAll('td')[0].textContent.trim();
                document.getElementById('modalproductname3').innerText = pname;
                document.getElementById('priceproductid').value = dataId;
                $('#priceModal').modal('show');
                document.getElementById('priceinput').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 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");
}

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();
            }else{
                document.getElementById('modalproductname').innerText = data[2];
                document.getElementById('modalproductqty').innerText = data[1];
                document.getElementById('qtyproductid').value = data[0];
                $('#qtyModal').modal('show');
                document.getElementById('qtyinput').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);
        },
        });
    }
}

document.addEventListener("DOMContentLoaded", function() {
const qtyinput = document.getElementById('qtyinput');
qtyinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const qty = qtyinput.value; 
        const tempid = document.getElementById('qtyproductid').value;

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


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

      
        $.ajax({
            url: "modal-dis-change.php",
            type: "POST",
            data: { tempid: tempid, discount: dis }, 
            success: function (data) {
                loadCartItems();
                $("#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();
                $("#itemtaxModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }
});



const priceinput = document.getElementById('priceinput');
priceinput.addEventListener('keydown', function(event) {
    if (event.key === 'Enter' || event.keyCode === 13) {
        const price = priceinput.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');
            }
        });
    }
});






});








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(1)');
                        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');
   
       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 cashamount = document.getElementById("cashamount").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;
        

		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& 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();
					window.open("salesreciept.php?receiptno=" + data + '&paid_amount=' + cashamount, "_blank");
				} 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 cashamount = document.getElementById("cashamount").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;

		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& 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) {
                    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 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 + "& 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 = document.getElementById("cashat").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: "only-load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& 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 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 cashamount = document.getElementById("cashamount").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;

		$.ajax({
			url: "only-load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& 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 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 cashamount = document.getElementById("cashamount").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;

		$.ajax({
			url: "orderid-new-barcode.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& 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) {
					$('#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 tempid = $("#allproductid").val();

                     $.ajax({
                            url: "save-all-genaral-item.php",
                            type: "POST",
                            data: { name: name,qty:qty,discount:discount,tax:tax,tempid:tempid,price:price }, 
                            success: function (data) {
                                loadCartItems();
                               
                                $("#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');
                            }
                        });
        }
    });
    
});

</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</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">
                    <input type="number" class="form-control mt-3" id="qtyinput" step="0.01" min="0" value="1">
                 </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="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" onkeypress="handlegenaralkeypress(event,'genaralqtyinput')" id="genaralnameinput">
                    <label class="mt-3" style="color: #fff;">Quantity</label>
                    <input type="number" class="form-control mt-1 gall2" onkeypress="handlegenaralkeypress(event,'genaralpriceinput')" id="genaralqtyinput" step="0.01" min="0" value="1">
                    <label class="mt-3" style="color: #fff;">Price</label>
                    <input type="number" class="form-control mt-1 gall3" onkeypress="handlegenaralkeypress(event,'genaraldiscountinput')" id="genaralpriceinput" step="0.01" min="0" value="0">
                    <label class="mt-3" style="color: #fff;">Discount</label>
                    <input type="text" class="form-control mt-1 gall4" 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" onkeypress="handlegenaralkeypress(event,'allgenadd')" id="genaraltaxinput" value="0">
                    <button class="number ntext mt-3 gall" 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">
                    <input type="text" class="form-control mt-3" id="disinput">
                 </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="priceinput">
                 </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">
                 </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-3">
                        
                        <button id="pbtn1" class="number ntext pbtn" onclick="onlypayBill();" onkeydown="if(event.keyCode==13){ onlypayBill(); event.preventDefault(); }" style="background-color:#001d87; width:100%;"><span class="key">S</span>Pay</button>
                    </div>
                    <div class="col-3">
                       
                        <button class="number ntext pbtn" onclick="payBill();" onkeydown="if(event.keyCode==13){ payBill(); event.preventDefault(); }" style="background-color:#24870b;width:100%;"> <span class="key">T</span>Print</button>
                    </div>
                    <div class="col-3">
                        
                        <button class="number ntext pbtn" onclick="onlySaveBill();" onkeydown="if(event.keyCode==13){ onlySaveBill(); event.preventDefault(); }" style="background-color:#01796f; width:100%;"><span class="key">R</span>Save</button>
                    </div>
                    <div class="col-3">
                       
                        <button class="number ntext pbtn" onclick="onlySaveBillWithBarcode();" onkeydown="if(event.keyCode==13){ onlySaveBillWithBarcode(); event.preventDefault(); }" style="background-color:#000000; width:100%;"> <span class="key">V</span>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;
}
</style>










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


    });
</script>












</body>
</html>

