<?php
session_start();
if(!isset($_SESSION['user_id'])){
    echo "<script> window.location.href = '/'; </script>";
}
    include 'load.php';
    require_once 'db_connection.php'; 
    if (isset($_GET['order_id'])) {
        $_SESSION['order_id'] = $_GET['order_id'];
    } else {
        $_SESSION['order_id'] = 0;
    }
    
?>
<?php
	$UserID = $_SESSION['user_id'];
	$getEmpQuery = $conn->query("SELECT branch_id FROM tbl_user_branch WHERE user_id='$UserID' ");
	if ($emp = $getEmpQuery->fetch_array()) {
		$branch_id = $emp['0'];
	}
	$userinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileusers WHERE user_id='$UserID'"));
	?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' />
    <link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">
    <link rel="stylesheet" href="assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/css/animate.css">
    <link rel="stylesheet" href="assets/plugins/select2/css/select2.min.css">
    <link rel="stylesheet" href="assets/plugins/owlcarousel/owl.carousel.min.css">
    <link rel="stylesheet" href="assets/plugins/owlcarousel/owl.theme.default.min.css">
    <link rel="stylesheet" href="assets/alertify/alertify.core.css">
    <link rel="stylesheet" href="assets/alertify/alertify.default.css">
    <link rel="stylesheet" href="assets/plugins/select2/css/select2.min.css">
    <link rel="stylesheet" href="assets/plugins/fontawesome/css/fontawesome.min.css">
    <link rel="stylesheet" href="assets/plugins/fontawesome/css/all.min.css">
  
	<link rel="stylesheet" href="assets/css/bootstrap-icons.css">
    <script src="js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</head>
<body>
<style>
    body{
        width: 100%;
        height: 100%;
        background: #ffffff;
    }
    .pos-wrap{
        width: 100%;
        height: 100%;
        
    }
    .topbox i{
        color: #fff;
        font-size: 18px;
    }
    .pos-top{
        padding: 5px 0px;
		background-color:#ffffff;
    }
    .pos-top{
       
    }
    .pos-middele{
        border: 2px solid #000000;
        padding-top: 5px;
        padding-bottom: 5px;
        padding-left: 5px;
        padding-right: 5px;
    }
    thead{
        border-bottom: 1px solid #eddfe1;
		background-color: #ffffff;
    }
    table{
       
    }
    th,td{
        color:#fff;
    }
    i{
        color: #fff !important;
    }
    .icon-text{
		font-weight:600;
        text-align: center;
        color: #fff;
        margin-top: 11px;
		font-size: 14px;
    }
    .icon-wrap{
        text-align: center;
		margin-top: 11px;
    }
    .box-wrap{
        padding: 15px 0px;
        border: 2px solid #ffffff; 
        border-radius: 5px;
        position: relative;
    }
    .box-wrap:hover{
        background-color: gray !important;
        cursor: pointer;
    }
    .key{
        color: #fff;
        position: absolute;
        top: 1px;
        left: 8px;
		font-size: 11px;
    }
    .item i{
        font-size: 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: #ffffff;
        color: #000000;
        padding-left: 45px;
        border-color: #000000;
    }
    .searchwrap i{
        position: absolute;
        left: 22px;
        top: 8px;
    }
    input::placeholder {
      color: #fff; 
      opacity: 0.8; 
    }
    .heighlight{
        font-size: 25px;
        font-weight: 700;
    }
    .table tfoot {
      
    }
    table{
        
    }
    .searchwrap{
        position: relative;
    }
    #searchitems{
        position: absolute;
        width: 98%;
        /* height: 100%; */
        max-height: 250px;
        /* overflow: hidden; */
        overflow-y: scroll;
        z-index: 2;
        background: #fff;
    }
    #searchitems ul li{
        list-style: none;
    }
    tbody tr{
        height: 10px;
        cursor: pointer;
        background-color: #422e2e;
        border-bottom: 2px solid #ffffff;
    }
    tbody tr:hover{
        background-color: #505273;
    }
    #searchitems ul li{
        padding: 5px 20px;
    }
    #searchitems ul li:hover{
        background-color: #402f32;
        color: #fff;
        cursor: pointer;
    }
    #searchitems ul{
        padding-left: 0;
        margin-bottom: 0;
    }
    #searchitems{
        display: none;
    }
    .bg2{
     background: linear-gradient(85deg, rgb(249 247 247) 0%, rgb(249 248 251 / 0%) 100%);
    }
    .close{
        background-color: transparent;
        border: none;
    }
    .modal-dialog2 {
        max-width: 400px;
        margin: 1.75rem auto;
    }
    .number{
        color: #fff;
        background: #0669ff;
        text-align: center;
        font-size: 25px;
        font-weight: 700;
        border: 1px solid #262a22;
        height: 60px;
        line-height: 51px;
    }
    .number:hover{
        background: #262a22;
        cursor: pointer;
    }
    tr.selectedrow {
            outline: none;
            background-color: #255fc9;
        }
        #searchitems li.selectedlirow{
            background-color: #255fc9;
            color: #fff;
        }
        .ntext{
            font-size: 15px;
        }
        .box-wrap{
            padding: 8px 0px;
        }
        .item i {
    font-size: 35px;
}
        
.select2-container .select2-selection--single{
    height: 40px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered{
    line-height: 35px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow{
    top: 7px;
}
td{
    font-size: 10px;
}
th{
    font-size: 12px;
}
label{
    font-size: 11px;
}
#pbtn1,#pbtn2,#pbtn3,#pbtn4,#pbtn5{
    height: 40px;
    line-height: 35px;
}

</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-4 d-flex justify-content-around">
                        <div class="topbox">
                                <a href="home.php" class="logo mr-2" style="text-align:left;">
				                    <img src="images/poslogo.png" alt="#" width="50px">
			                    </a>
                        </div>
                        
						<div class="topbox">
							<div class="form-check form-switch mt-1">
                                <?php $disrows = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM all_discount_tbl WHERE all_discount_tbl_id ='1' AND status='1'")); ?>
                                <input class="form-check-input" type="checkbox" role="switch" id="discheck" <?php if($disrows==1){ echo "checked"; }else { } ?> >
                                <label class="form-check-label" for="discheck" style="font-size: 10px;font-weight:700;color:#000000;">All Discount</label>
                            </div>
                        </div>
                       <!-- <div class="topbox">
                            <div class="form-check form-switch mt-1">
                            <?php //$taxrows = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM tax WHERE tax_id ='1' AND status='1'")); ?>
                                <input class="form-check-input" type="checkbox" role="switch" id="taxcheck" <?php if($taxrows==1){ echo "checked"; }else { } ?>>
                                <label class="form-check-label" for="taxcheck" style="font-size: 11px;font-weight:700;color:#000000;">Tax <span style="font-size: 9px;">(Shift + 6)</span></label>
                            </div>
                        </div>-->
                        <div class="topbox">
                        <div class="form-check form-switch mt-1" style="font-size: 11px;margin-top:9px !important;">
                            <i style="color:#000 !important;  margin-right: 10px;font-size: 10px;" class="fa fa-user" aria-hidden="true"></i>
                            Cashier : <?php echo $userinfo['fullname']; ?> 
                        </div>
                        </div>
                </div>
                    
                    <div class="col-lg-5 searchwrap">
                        <i class="fa fa-search" style="background-color:#000000;padding:5px 5px 5px 5px;"></i>
                        <input type="text" class="form-control"  id="searchinputbox" oninput="handleInput();" placeholder="Search product by name, code or barcode" onKeyDown="if(event.keyCode==32) searchbarcodeProduct();">
                       <div id="searchitems" style="display: none;">
                            
                        </div>
                    </div>
                    
            </div>
        </div>
        <div class="pos-middele full-height">
            <div class="row g-1">
                <div class="col-lg-6" id="right_cart_panel">
                <div class="table-responsive">    
                <table class="table table-borderless mb-0">
                    <thead style="background-color:#083fdb;">
                        <tr>
                        <th scope="col" style="font-weight:bold;font-size:12px;color:#ffffff;">Name / Price</th>
                        <th scope="col" style="font-weight:bold;font-size:12px;color:#ffffff;">Qty</th>
                       
                        <th scope="col" style="font-weight:bold;font-size:12px;color:#ffffff;">Dis</th>
                        <!--<th scope="col" style="font-weight:bold;font-size:16px;color:#ffffff;">Tax</th>-->
                        <th scope="col" style="font-weight:bold;font-size:12px;color:#ffffff;">Total</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                    <tfoot>
                        <tr>
                        </tr>
                        <tr>
                            <td style="background-color: #08a306;font-weight: bold;">Discount</td>
                            <td style="background-color: #08a306;font-weight: bold;">0.00</td>
                       
                       <!-- <tr>
                        <td></td>
                        <td></td>
                            <td></td>
							 <td></td>
                            <td style="background-color: #0910e7;font-weight: bold;">Tax</td>
                            <td style="background-color: #0910e7;font-weight: bold;">0.00</td>
                        </tr>-->
                       
                        
                            <td class="heighlight" style="background-color: #f50404;font-weight: bold;font-size:16px;">Total</td>
                            <td class="heighlight" style="background-color: #f50404;font-weight: bold;font-size:16px;">0.00</td>
                        </tr>
                    </tfoot>
                    </table> 
                    </div>
                </div>
                <div class="col-lg-3" style="background-color: #000000;padding:20px;">
                    <div class="row">
                    <div class="col-12 mb-1">
                        <label style="color:#fff; margin-bottom:3px;">Route</label>
                        <select class="form-control inputele" id="route">
                            <option value="0" selected>Select Route</option>
                            <?php $cus2 = "SELECT * FROM mobileroute WHERE status=1";
                                $result = $conn->query($cus2);
                                if ($result->num_rows > 0) {
                                    while ($row = $result->fetch_assoc()) {
                                        $rtid = $row["rtid"];
                                        $routename = $row["routename"];
                                        echo '<option value="' . $rtid . '">' . $routename . '</option>';
                                    }
                                } ?>
                            </select>
                        </div>
                <div class="col-12 mb-1">
                        <label style="color:#fff; margin-bottom:3px;">Customer</label>
                        <select class="form-control inputele" id="billcustomer" onchange="creditcustomerchange(this.value);">
                           <!-- <option value="0">Walk-in Customer</option>
                            <option value="dc">Delivery Customer</option>'; -->
                            
                            </select>
                        </div>
                <div class="col-4 mb-1">
                            <label style="color:#ffff; margin-bottom:3px;">Payment Method</label>
                            <select class="form-select" id="paymethod" onchange="paymethodchaneg(this.value)">
                                <option value="Cash">Cash</option>
                                <option value="Credit">Credit</option>
                                <option value="Debit-Card">Debit Card</option>
                                <option value="Bank-Transfer">Bank Transfer</option>
                                <option value="Cheques">Cheques</option>
                                <option value="Mobile-Payment">Mobile Payment</option>
                                <option value="Gift-Cards">Gift Cards</option>
                                <option value="Other-Payment">Other Payment</option>
                                <option value="Cash-Card">Cash & Card</option>
                            </select>
                        </div>
                        
                        <div class="col-4 mb-1 methodCredit method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Credit Amount</label>
                            <input type="text" class="form-control" readonly="" id="creditAmountvalue" placeholder="Credit Amount">
                        </div>
                        <div class="col-4 mb-1 methodCredit method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Credit Left</label>
                            <input type="text" class="form-control" readonly="" id="totalAmountvalue" placeholder="Credit Amount Left">
                        </div>
                        <div class="col-4 mb-1 methodDebit-Card method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Card Number</label>
                            <input type="number" class="form-control inputele" id="cardno" name="payment_option_number" placeholder="Card Number">
                        </div>
                        <div class="col-4 mb-1 methodBank-Transfer method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Ref Number</label>
                             <input type="number" class="form-control inputele" id="cardno" name="payment_option_number" placeholder="Referece Number">
                        </div>
                        <div class="col-4 mb-1 methodCheques method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Cheque Date</label>
                            <input type="text" class="form-control inputele" id="cheque_date" value="" placeholder="Cheque Date">
                        </div>
                        <div class="col-4 mb-1 methodCheques method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Cheque Num</label>
                            <input type="text" class="form-control inputele" id="cheque_number" value="" placeholder="Cheque Number">
                        </div>
                        <div class="col-4 mb-1 methodMobile-Payment method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Pay Method</label>
                            <select name="m-pay" id="mobile_payment_method" class="form-control inputele">
                                <option value="google">Google Pay</option>
                                <option value="apple">Apple Pay</option>
        
                            </select>
                        </div>
                        <div class="col-4 mb-1 methodGift-Cards method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Gift Number</label>
                            <input type="text" class="form-control inputele" id="gift_number" value="" placeholder="Gift Card Number">
                        </div>
                        <div class="col-4 mb-1 methodCash-Card method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Card Number</label>
                            <input type="number" class="form-control inputele" id="cardno" name="cardno" placeholder="Card Number">
                        </div>
                        <div class="col-4 mb-1 methodCash-Card method" style="display: none;">
                            <label style="color:#fff; margin-bottom:3px;">Card Payment</label>
                            <input type="number" class="form-control inputele" id="cardpayment" name="cardpayment" placeholder="Card Payment">
                        </div>
                        <div class="col-4 mb-1">
                            <label style="color:#fff; margin-bottom:3px;">Cash</label>
                            <input type="text" class="form-control inputele" id="cashamount"  onkeyup="getCash(this.value); creditcustomerchange();" placeholder="Cash Amount" value="">
                        </div>
                        <div class="col-4 mb-1">
                            <label style="color:#fff; margin-bottom:3px;">Balance</label>
                            <input type="text" class="form-control" id="balance"  placeholder="Balance" value="0" readonly>
                            <input type="hidden" class="form-control" id="cashamounthidden"  placeholder="Cash Amount" value="">
                        </div>
                        <div class="col-12 mb-1">
                            <div class="row mt-3 g-1 btnwrap">
                                <div class="col-3">
                                    
                                    <button id="pbtn1" class="number ntext pbtn inputele" onclick="onlypayBill();" onkeydown="if(event.keyCode==13){ onlypayBill(); event.preventDefault(); }" style="background-color:#001d87; width:100%;">Pay</button>
                                </div>
                                <div class="col-3">
                                
                                    <button id="pbtn2" class="number ntext pbtn inputele" onclick="payBill();" onkeydown="if(event.keyCode==13){ payBill(); event.preventDefault(); }" style="background-color:#24870b;width:100%;">Print</button>
                                </div>
                                <div class="col-3">
                                    
                                    <button id="pbtn3" class="number ntext pbtn inputele" onclick="onlySaveBill();" onkeydown="if(event.keyCode==13){ onlySaveBill(); event.preventDefault(); }" style="background-color:#01796f; width:100%;">Hold</button>
                                </div>
                               <!-- <div class="col-6">
                                
                                    <button id="pbtn4" class="number ntext pbtn inputele" onclick="onlySaveBillWithBarcode();" onkeydown="if(event.keyCode==13){ onlySaveBillWithBarcode(); event.preventDefault(); }" style="background-color:#000000; width:100%;"> <span class="key">Shift + V</span>Barcode</button>
                                </div>-->
                                <div class="col-3">
                                
                                    <button id="pbtn5" class="number ntext pbtn inputele" onclick="a4print();" onkeydown="if(event.keyCode==13){ a4print(); event.preventDefault(); }" style="background-color:#812906; width:100%;">A4 Print</button>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
                <style>
                    .icon-text{
                        margin-top: 0px;
                        font-size: 10px;
                    }
                </style>
                <div class="col-lg-3 bg2">
                    
                    <div class="row g-1">
                            <div class="col-lg-3 col-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="disfocus();" style="background-color:#0014a8;">
                                       

                                        <div class="icon-text">
                                          Line  Discount
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-3 mt-1  item">
                                <div class="wrap box-wrap" onclick="pricefocus();" style="background-color:#648c11;">
                                       
                                        <div class="icon-text">
                                            Price
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-3 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="addAlldiscount();" style="background-color:#00bfff;">
                                    
                                    
                                    <div class="icon-text">
                                        All Discount (<?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']."%"; } ?>    )
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-3 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="qtyfocus();" style="background-color:#1a6a7c;">
                                    
                                    <div class="icon-text">
                                        Quantity
                                    </div>
                           </div>
                           </div>
						   <div class="col-lg-3 col-3 mt-1 item">
                                <div class="wrap box-wrap" onclick="deletefocusitem();" style="background-color:#ff0000;">
                                        
                                        <div class="icon-text">
                                        Delete
                                        </div>
                                </div>
                            </div>
                           
                            <div class="col-lg-3 col-3 mt-1 item item1">
                                <div class="wrap box-wrap" onclick="addNewProductById(148);" style="background-color:#3d5e38;">
                                       
                                        <div class="icon-text" style="font-size:10px;">
                                        Genaral Items
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-3 col-3 mt-1 item item1">
                                <div class="wrap box-wrap" onclick="addFreeItem();" style="background-color:#3299a8;">
                                       
                                        <div class="icon-text" style="font-size:10px;">
                                        Free Items
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-3 col-3 mt-1 item item1">
                                <div class="wrap box-wrap" onclick="deleteallproduct();" style="background-color:#ff0000;">
                                        
                                        <div class="icon-text">
                                            Void Order
                                        </div>
                                </div>
                            </div>
                        <!--<div class="col-lg-3 col-6 mt-1 pb-1 item">
                            <div class="wrap box-wrap" style="background-color:#ff004f;height:120px;">
                                    <div class="icon-wrap" onclick="deletefocusitem();">
                                        <span class="key">F8</span>
                                        <i class="fa fa-times"></i>
                                    </div>
                                    <div class="icon-text">
                                        Delete
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-6 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="searchfocus();" style="background-color:#4f1acb;height:120px;">
                                    <span class="key">F2</span>
                                    <div class="icon-wrap">
                                    <i class="fa fa-search"></i>
                                    </div>
                                    <div class="icon-text">
                                        Search
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-6 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="qtyfocus();" style="background-color:#1a6a7c;height:120px;">
                                    <span class="key">F4</span>
                                    <div class="icon-wrap">
                                        <i class="fa fa-shopping-cart"></i>
                                    </div>
                                    <div class="icon-text">
                                        Quantity
                                    </div>
                            </div>
                        </div>
                        <div class="col-lg-3 col-6 mt-1 pb-1 item">
                            <div class="wrap box-wrap" onclick="addAlldiscount();" style="background-color:#00bfff;height:120px;">
                                    <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-4 col-6 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" style="font-size:16px;">
                                            Cash
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-6 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" style="font-size:16px;">
                                            Credit
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-6 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" style="font-size:16px;">
                                        Debit Card
                                        </div>
                                </div>
                            </div>              
                            <div class="col-lg-4 mt-0 col-6  pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(4);" style="background-color:#800000;">
                                        <span class="key">Shift + B</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Bank Transfer
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(5);" style="background-color:#fd5800;">
                                        <span class="key">Shift + Q</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Cheques
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(6);" style="background-color:#009698;">
                                        <span class="key">Shift + M</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Mobile Payment
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(7);" style="background-color:#ffdf00;">
                                        <span class="key">Shift + G</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Gift Cards
                                        </div>
                                </div>
                            </div>
							<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(8);" style="background-color:#000080;">
                                        <span class="key">Shift + O</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Other Payment
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="paymentmethod(9);" style="background-color:#fcba03;">
                                        <span class="key">Shift + W</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Cash & Card                                        </div>
                                </div>
                            </div>-->
                           <!-- <div class="col-lg-4 col-6 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" style="font-size:16px;">
                                        All Transactions
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="pendingsales();" style="background-color:#a632a8;">
                                        <span class="key">Shift + Y</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Pending Sales
                                        </div>
                                </div>
                            </div>-->
                           <!-- <div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addNewProductById(148);" style="background-color:#3d5e38;">
                                        <span class="key">Shift + K</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Genaral Items
                                        </div>
                                </div>
                            </div>-->
                            
                            <!--<div class="col-lg-4 col-6 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="taxfocus();" style="background-color:#0703fc;">
                                        <span class="key">Shift + X</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Tax
                                        </div>
                                </div>
                            </div>-->
                            <!--<div class="col-lg-4 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="saleslist();" style="background-color:#2b212b;">
                                        <span class="key">Shift</span>
                                        <div class="icon-text">
                                         
                                        </div>
                                </div>
                            </div>-->
                           <!-- <div class="col-lg-4 col-12 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addNewProductById(148);" style="background-color:#3d5e38;">
                                        <span class="key">Shift + K</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Genaral Items
                                        </div>
                                </div>
                            </div>
                            <div class="col-lg-4 col-12 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addFreeItem();" style="background-color:#3299a8;">
                                        <span class="key">Shift + 6</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Free Items
                                        </div>
                                </div>
                            </div>-->
                            <!--<div class="col-lg-4 col-12 mt-0 pb-1 item item1">
                                <div class="wrap box-wrap" onclick="addMarketReturnItem();" style="background-color:#3486eb;">
                                        <span class="key">Shift + 9</span>
                                        <div class="icon-text" style="font-size:16px;">
                                        Market Return
                                        </div>
                                </div>
                            </div>-->
                    </div>


                    <div class="row g-1">
                            
                          <!-- <div class="col-lg-3 col-6 mt-1  item">
                                <div class="wrap box-wrap" onclick="disfocus();" style="background-color:#0014a8;height:120px;">
                                        <span class="key">Shift + D</span>
                                        <div class="icon-wrap">
                                        <i class="fa fa-percent"></i>
                                        </div>
                                        <div class="icon-text">
                                            Discount
                                        </div>
                                </div>
                            </div>-->
                           <!-- <div class="col-lg-3 col-6 mt-1  item">
                                <div class="wrap box-wrap" onclick="lottery();" style="background-color:#fe4eda;height:120px;">
                                        <span class="key">Shift + 2</span>
                                        <div class="icon-wrap">
                                        <i class="fa fa-box"></i>
                                        </div>
                                        <div class="icon-text">
                                            Lottery
                                        </div>
                                </div>
                            </div>

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

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



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

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




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

<script>
   
    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 === 67){ //C
        payBill();
    }else if(e.shiftKey && e.keyCode === 69){  //E
        onlySaveBill();
    }else if(e.shiftKey && e.keyCode === 86){ // v
        onlySaveBillWithBarcode();
    }else if(e.shiftKey && e.keyCode === 85){ // U
        a4print();
    }else if(e.shiftKey && e.keyCode === 65){ // A
        addAlldiscount();
    }else if(e.shiftKey && e.keyCode === 72){ // H
        onlySave1Bill();
    
    }else if(e.shiftKey && e.keyCode === 70){ // F
        transactions();
    }else if(e.shiftKey && e.keyCode === 73){ // G
        pricefocus();
    }else if(e.shiftKey && e.keyCode === 76){ // G
        namefocus();
    }else if(e.shiftKey && e.keyCode === 88){ // X
        taxfocus();
    //}else if(e.shiftKey && e.keyCode === 87){ // W
    //    paymentmethod(9);
    }else if(e.shiftKey && e.keyCode === 89){ // Y
        pendingsales();
    }else if(e.shiftKey && e.keyCode === 75){ // K
        addNewProductById(148);
    }else if(e.shiftKey && e.keyCode === 50){ // 2
        lottery();
    }else if(e.shiftKey && e.keyCode === 51){ // 3
        tax();
    }else if(e.shiftKey && e.keyCode === 52){ // 4
        document.getElementById('discheck').click();
    }else if(e.shiftKey && e.keyCode === 54){ // 6
        document.getElementById('taxcheck').click();
    }else if(e.shiftKey && e.keyCode === 87){ // W
        document.getElementById('searchinputbox').blur(); 
        document.getElementById('paymethod').focus(); 
        document.getElementById('paymethod').classList.add('focus-background');     
    }
  }
 
 function paymethodchaneg(method){
    $(".method").css("display", "none");
    $(".method"+method).css("display", "block");
 }

function loadpaymentpanel(){
    $.ajax({
        url: "genarate-payment-panel.php",
        type: "POST",
        // data: { check: check, tax: "1" }, 
        dataType: "json",
        success: function (data) {
            $("#cashamount").val(data[0]); 
            $("#cashamounthidden").val(data[0]);                      
                           
        },
        error: function (jXHR, textStatus, errorThrown) {    
        },
    });
}

  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');
    var alldisModal = document.getElementById('alldisModal');
    if (alldisModal) { 
        document.getElementById('all_discount').focus();
        
    }
}

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

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

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

var inputTimeout;
function handleInput() {
  clearTimeout(inputTimeout);
  inputTimeout = setTimeout(filterProducts, 1);
 
}

function onChangeQuantity(val,id){
    $.ajax({
        url: "chnage-qty.php",
        type: "POST",
        data: "id=" + id + "&val=" + val,
        success: function (data) { 
            loadCartItems();    
        },
        error: function (jXHR, textStatus, errorThrown) {
           
        },
    });
}
function filterProducts() {
  var searchbarcode = document.getElementById("searchinputbox").value;
  
    $.ajax({
      url: "search-filter-products.php",
      type: "POST",
      dataType: 'json',
      data: "searchbarcode=" + searchbarcode + "&",
      success: function (data) {
        loadCartItems();  
        if(data[0] > 0){
            document.getElementById("searchinputbox").value = "";
            $("#searchitems").html("");
            $("#searchitems").css("display","none");


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


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

                                }
                            });
                       
                    }
                    
                    
                }, 100);




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


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

                                }
                            });
                       
                    }
                    
                    
                }, 100);


            }




            }














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

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

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

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


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


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


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

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

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

  });
}


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

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

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

  });
}


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

 
  var inputString = input.innerHTML;


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


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

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

 

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

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

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

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

  input.innerHTML = numbers[0]; 

  resultDisplayed = true; 
});


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

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

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

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

    }

}



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

function cloaseitemTaxModal(){
    $("#itemtaxModal").modal('hide');
}
document.addEventListener('DOMContentLoaded', arrowkeyfunction);
document.getElementById('paymethod').addEventListener('change', arrowkeyfunction);

function arrowkeyfunction() {
    var paymethod = document.getElementById('paymethod').value;
    var currentId = document.activeElement.id;
    if(paymethod=="Cash" || paymethod=="Credit" || paymethod=="Other-Payment"){
        document.addEventListener('keydown', function(event) {
            
    if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
        event.preventDefault();

      
        const focusOrder = [
            'paymethod', 'billcustomer', 'cashamount', 'pbtn1', 'pbtn2', 'pbtn3', 'pbtn4', 'pbtn5'
        ];

        
        const currentId = document.activeElement.id;
        const currentIndex = focusOrder.indexOf(currentId);

       
        function setFocusWithDelay(targetId) {
            setTimeout(() => {
              
                const previouslyFocusedElement = document.querySelector('.focus-background');
                if (previouslyFocusedElement) {
                    previouslyFocusedElement.classList.remove('focus-background');
                }

               
                const targetElement = document.getElementById(targetId);
                targetElement.focus();
                targetElement.classList.add('focus-background');
            }, 50);  
        }

        if (currentIndex !== -1) {
           
            if (event.key === 'ArrowDown' || event.key === 'Enter') {
                const nextIndex = currentIndex + 1;
                if (nextIndex < focusOrder.length) {
                    setFocusWithDelay(focusOrder[nextIndex]);
                }
            }
            
            else if (event.key === 'ArrowUp') {
                const prevIndex = currentIndex - 1;
                if (prevIndex >= 0) {
                    setFocusWithDelay(focusOrder[prevIndex]);
                }
            }
        }
    }
});
        
    }else if(paymethod=="Debit-Card" || paymethod=="Bank-Transfer"){
        document.addEventListener('keydown', function(event) {
            
            if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
                event.preventDefault();
        
              
                const focusOrder = [
                    'paymethod', 'billcustomer', 'cardno' , 'cashamount', 'pbtn1', 'pbtn2', 'pbtn3', 'pbtn4', 'pbtn5'
                ];
        
                
                const currentId = document.activeElement.id;
                const currentIndex = focusOrder.indexOf(currentId);
        
               
                function setFocusWithDelay(targetId) {
                    setTimeout(() => {
                        //document.getElementById(targetId).focus();
                        const previouslyFocusedElement = document.querySelector('.focus-background');
                        if (previouslyFocusedElement) {
                            previouslyFocusedElement.classList.remove('focus-background');
                        }

                    
                        const targetElement = document.getElementById(targetId);
                        targetElement.focus();
                        targetElement.classList.add('focus-background');
                    }, 50);  
                }
        
                if (currentIndex !== -1) {
                   
                    if (event.key === 'ArrowDown' || event.key === 'Enter') {
                        const nextIndex = currentIndex + 1;
                        if (nextIndex < focusOrder.length) {
                            setFocusWithDelay(focusOrder[nextIndex]);
                        }
                    }
                    
                    else if (event.key === 'ArrowUp') {
                        const prevIndex = currentIndex - 1;
                        if (prevIndex >= 0) {
                            setFocusWithDelay(focusOrder[prevIndex]);
                        }
                    }
                }
            }
        });
    }else if(paymethod=="Cheques"){
        document.addEventListener('keydown', function(event) {
            
            if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
                event.preventDefault();
        
              
                const focusOrder = [
                    'paymethod', 'billcustomer', 'cheque_date', 'cheque_number' , 'cashamount', 'pbtn1', 'pbtn2', 'pbtn3', 'pbtn4', 'pbtn5'
                ];
        
                
                const currentId = document.activeElement.id;
                const currentIndex = focusOrder.indexOf(currentId);
        
               
                function setFocusWithDelay(targetId) {
                    setTimeout(() => {
                       // document.getElementById(targetId).focus();
                       const previouslyFocusedElement = document.querySelector('.focus-background');
                        if (previouslyFocusedElement) {
                            previouslyFocusedElement.classList.remove('focus-background');
                        }

                    
                        const targetElement = document.getElementById(targetId);
                        targetElement.focus();
                        targetElement.classList.add('focus-background');
                    }, 50);  
                }
        
                if (currentIndex !== -1) {
                   
                    if (event.key === 'ArrowDown' || event.key === 'Enter') {
                        const nextIndex = currentIndex + 1;
                        if (nextIndex < focusOrder.length) {
                            setFocusWithDelay(focusOrder[nextIndex]);
                        }
                    }
                    
                    else if (event.key === 'ArrowUp') {
                        const prevIndex = currentIndex - 1;
                        if (prevIndex >= 0) {
                            setFocusWithDelay(focusOrder[prevIndex]);
                        }
                    }
                }
            }
        });
        }else if(paymethod=="Mobile-Payment"){
            document.addEventListener('keydown', function(event) {
            
            if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
                event.preventDefault();
        
              
                const focusOrder = [
                    'paymethod', 'billcustomer', 'mobile_payment_method', 'cashamount', 'pbtn1', 'pbtn2', 'pbtn3', 'pbtn4', 'pbtn5'
                ];
        
                
                const currentId = document.activeElement.id;
                const currentIndex = focusOrder.indexOf(currentId);
        
               
                function setFocusWithDelay(targetId) {
                    setTimeout(() => {
                       // document.getElementById(targetId).focus();  
                       const previouslyFocusedElement = document.querySelector('.focus-background');
                            if (previouslyFocusedElement) {
                                previouslyFocusedElement.classList.remove('focus-background');
                            }

                        
                            const targetElement = document.getElementById(targetId);
                            targetElement.focus();
                            targetElement.classList.add('focus-background');
                    }, 50);  
                }
        
                if (currentIndex !== -1) {
                   
                    if (event.key === 'ArrowDown' || event.key === 'Enter') {
                        const nextIndex = currentIndex + 1;
                        if (nextIndex < focusOrder.length) {
                            setFocusWithDelay(focusOrder[nextIndex]);
                        }
                    }
                    
                    else if (event.key === 'ArrowUp') {
                        const prevIndex = currentIndex - 1;
                        if (prevIndex >= 0) {
                            setFocusWithDelay(focusOrder[prevIndex]);
                        }
                    }
                }
            }
        });

    }else if(paymethod=="Gift-Cards"){
        document.addEventListener('keydown', function(event) {
            
            if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
                event.preventDefault();
        
              
                const focusOrder = [
                    'paymethod', 'billcustomer', 'gift_number', 'cashamount', 'pbtn1', 'pbtn2', 'pbtn3', 'pbtn4', 'pbtn5'
                ];
        
                
                const currentId = document.activeElement.id;
                const currentIndex = focusOrder.indexOf(currentId);
        
               
                function setFocusWithDelay(targetId) {
                    setTimeout(() => {
                        //document.getElementById(targetId).focus();
                        const previouslyFocusedElement = document.querySelector('.focus-background');
                            if (previouslyFocusedElement) {
                                previouslyFocusedElement.classList.remove('focus-background');
                            }

                        
                            const targetElement = document.getElementById(targetId);
                            targetElement.focus();
                            targetElement.classList.add('focus-background');
                    }, 50);  
                }
        
                if (currentIndex !== -1) {
                   
                    if (event.key === 'ArrowDown' || event.key === 'Enter') {
                        const nextIndex = currentIndex + 1;
                        if (nextIndex < focusOrder.length) {
                            setFocusWithDelay(focusOrder[nextIndex]);
                        }
                    }
                    
                    else if (event.key === 'ArrowUp') {
                        const prevIndex = currentIndex - 1;
                        if (prevIndex >= 0) {
                            setFocusWithDelay(focusOrder[prevIndex]);
                        }
                    }
                }
            }
        });


    }else if(paymethod=="Cash-Card"){
        document.addEventListener('keydown', function(event) {
            
            if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter') {
                event.preventDefault();
        
              
                const focusOrder = [
                    'paymethod', 'billcustomer', 'cardno', 'cardpayment' , 'cashamount', 'pbtn1', 'pbtn2', 'pbtn3', 'pbtn4', 'pbtn5'
                ];
        
                
                const currentId = document.activeElement.id;
                const currentIndex = focusOrder.indexOf(currentId);
        
               
                function setFocusWithDelay(targetId) {
                    setTimeout(() => {
                      //  document.getElementById(targetId).focus();

                      const previouslyFocusedElement = document.querySelector('.focus-background');
                        if (previouslyFocusedElement) {
                            previouslyFocusedElement.classList.remove('focus-background');
                        }

                    
                        const targetElement = document.getElementById(targetId);
                        targetElement.focus();
                        targetElement.classList.add('focus-background');
                    }, 50);  
                }
        
                if (currentIndex !== -1) {
                   
                    if (event.key === 'ArrowDown' || event.key === 'Enter') {
                        const nextIndex = currentIndex + 1;
                        if (nextIndex < focusOrder.length) {
                            setFocusWithDelay(focusOrder[nextIndex]);
                        }
                    }
                    
                    else if (event.key === 'ArrowUp') {
                        const prevIndex = currentIndex - 1;
                        if (prevIndex >= 0) {
                            setFocusWithDelay(focusOrder[prevIndex]);
                        }
                    }
                }
            }
        });
    }
}

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

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

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


                }

            */
           


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

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

                                }
                            });
                       
                    }
                    
                    
                }, 100); */
                
                 
               // setTimeout(function() {
                  

               // }, 100);
                 

               if (method == 1 || method==2 || method==8) {
   
    document.getElementById('billcustomer').focus();

    document.addEventListener('keydown', function(event) {
       
        if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
            event.preventDefault();

           
            const currentId = document.activeElement.id;

          
            if (event.key === 'ArrowDown') {
               
                if (currentId === '') {
                    document.getElementById('cashamount').focus();
                } else if (currentId === 'cashamount') {
                    document.getElementById('pbtn1').focus();
                } else if (currentId === 'pbtn1') {
                    document.getElementById('pbtn2').focus();
                } else if (currentId === 'pbtn2') {
                    document.getElementById('pbtn3').focus();
                } else if (currentId === 'pbtn3') {
                    document.getElementById('pbtn4').focus();
                }
            }

            
            if (event.key === 'ArrowUp') {
                if (currentId === 'pbtn4') {
                    document.getElementById('pbtn3').focus();
                } else if (currentId === 'pbtn3') {
                    document.getElementById('pbtn2').focus();
                } else if (currentId === 'pbtn2') {
                    document.getElementById('pbtn1').focus();
                } else if (currentId === 'pbtn1') {
                    document.getElementById('cashamount').focus();
                } else if (currentId === 'cashamount') {
                    document.getElementById('billcustomer').focus();
                }
            }
        }
    });
}else if(method==3 || method==4){
    document.getElementById('billcustomer').focus();
    document.addEventListener('keydown', function(event) {
       
       if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
           event.preventDefault();    
           const currentId = document.activeElement.id;

            
           if (event.key === 'ArrowDown') {
               
               if (currentId === '') {
                   document.getElementById('cardno').focus();
               } else if (currentId === 'cardno') {
                   document.getElementById('cashamount').focus();
                } else if (currentId === 'cashamount') {
                   document.getElementById('pbtn1').focus();
               } else if (currentId === 'pbtn1') {
                   document.getElementById('pbtn2').focus();
               } else if (currentId === 'pbtn2') {
                   document.getElementById('pbtn3').focus();
               } else if (currentId === 'pbtn3') {
                   document.getElementById('pbtn4').focus();
               }
           }

           
           if (event.key === 'ArrowUp') {
               if (currentId === 'pbtn4') {
                   document.getElementById('pbtn3').focus();
               } else if (currentId === 'pbtn3') {
                   document.getElementById('pbtn2').focus();
               } else if (currentId === 'pbtn2') {
                   document.getElementById('pbtn1').focus();
               } else if (currentId === 'pbtn1') {
                   document.getElementById('cashamount').focus();
               } else if (currentId === 'cashamount') {
                   document.getElementById('cardno').focus();
                } else if (currentId === 'cardno') {
                   document.getElementById('billcustomer').focus();
               }
           }
       }

    });
}else if(method==5){
    document.getElementById('billcustomer').focus();
    document.addEventListener('keydown', function(event) {
       
       if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
           event.preventDefault();    
           const currentId = document.activeElement.id;

            
           if (event.key === 'ArrowDown') {
               
               if (currentId === '') {
                   document.getElementById('cheque_date').focus();
               } else if (currentId === 'cheque_date') {
                   document.getElementById('cheque_number').focus();
                } else if (currentId === 'cheque_number') {
                   document.getElementById('cashamount').focus();
                } else if (currentId === 'cashamount') {
                   document.getElementById('pbtn1').focus();
               } else if (currentId === 'pbtn1') {
                   document.getElementById('pbtn2').focus();
               } else if (currentId === 'pbtn2') {
                   document.getElementById('pbtn3').focus();
               } else if (currentId === 'pbtn3') {
                   document.getElementById('pbtn4').focus();
               }
           }

           
           if (event.key === 'ArrowUp') {
                if (currentId === 'pbtn4') {
                    document.getElementById('pbtn3').focus();
                } else if (currentId === 'pbtn3') {
                    document.getElementById('pbtn2').focus();
                } else if (currentId === 'pbtn2') {
                    document.getElementById('pbtn1').focus();
                } else if (currentId === 'pbtn1') {
                    document.getElementById('cashamount').focus();
                } else if (currentId === 'cashamount') {
                    document.getElementById('cheque_number').focus();
                } else if (currentId === 'cheque_number') {
                    document.getElementById('cheque_date').focus();
                } else if (currentId === 'cheque_date') {
                    document.getElementById('billcustomer').focus();
                }
            }
       }

    });

}else if(method==6){
    document.getElementById('billcustomer').focus();

document.addEventListener('keydown', function(event) {
   
    if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
        event.preventDefault();

       
        const currentId = document.activeElement.id;

      
        if (event.key === 'ArrowDown') {
           
            if (currentId === '') {
                document.getElementById('mobile_payment_method').focus();
            } else if (currentId === 'mobile_payment_method') {
                document.getElementById('cashamount').focus();
            } else if (currentId === 'cashamount') {
                document.getElementById('pbtn1').focus();
            } else if (currentId === 'pbtn1') {
                document.getElementById('pbtn2').focus();
            } else if (currentId === 'pbtn2') {
                document.getElementById('pbtn3').focus();
            } else if (currentId === 'pbtn3') {
                document.getElementById('pbtn4').focus();
            }
        }

        
        if (event.key === 'ArrowUp') {
            if (currentId === 'pbtn4') {
                document.getElementById('pbtn3').focus();
            } else if (currentId === 'pbtn3') {
                document.getElementById('pbtn2').focus();
            } else if (currentId === 'pbtn2') {
                document.getElementById('pbtn1').focus();
            } else if (currentId === 'pbtn1') {
                document.getElementById('cashamount').focus();
            } else if (currentId === 'cashamount') {
                document.getElementById('mobile_payment_method').focus();
            } else if (currentId === 'mobile_payment_method') {
                document.getElementById('billcustomer').focus();
            }
        }
    }
});

}else if(method==7){
    document.getElementById('billcustomer').focus();

document.addEventListener('keydown', function(event) {
   
    if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
        event.preventDefault();

       
        const currentId = document.activeElement.id;

      
        if (event.key === 'ArrowDown') {
           
            if (currentId === '') {
                document.getElementById('gift_number').focus();
            } else if (currentId === 'gift_number') {
                document.getElementById('cashamount').focus();
            } else if (currentId === 'cashamount') {
                document.getElementById('pbtn1').focus();
            } else if (currentId === 'pbtn1') {
                document.getElementById('pbtn2').focus();
            } else if (currentId === 'pbtn2') {
                document.getElementById('pbtn3').focus();
            } else if (currentId === 'pbtn3') {
                document.getElementById('pbtn4').focus();
            }
        }

        
        if (event.key === 'ArrowUp') {
            if (currentId === 'pbtn4') {
                document.getElementById('pbtn3').focus();
            } else if (currentId === 'pbtn3') {
                document.getElementById('pbtn2').focus();
            } else if (currentId === 'pbtn2') {
                document.getElementById('pbtn1').focus();
            } else if (currentId === 'pbtn1') {
                document.getElementById('cashamount').focus();
            } else if (currentId === 'cashamount') {
                document.getElementById('gift_number').focus();
            } else if (currentId === 'gift_number') {
                document.getElementById('billcustomer').focus();
            }
        }
    }
});
}else if(method==9){
    document.getElementById('billcustomer').focus();

document.addEventListener('keydown', function(event) {
   
    if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
        event.preventDefault();

       
        const currentId = document.activeElement.id;

      
        if (event.key === 'ArrowDown') {
           
            if (currentId === '') {
                document.getElementById('cardno').focus();
            } else if (currentId === 'cardno') {
                document.getElementById('cardpayment').focus();
            } else if (currentId === 'cardpayment') {
                document.getElementById('cashamount').focus();
            } else if (currentId === 'cashamount') {
                document.getElementById('pbtn1').focus();
            } else if (currentId === 'pbtn1') {
                document.getElementById('pbtn2').focus();
            } else if (currentId === 'pbtn2') {
                document.getElementById('pbtn3').focus();
            } else if (currentId === 'pbtn3') {
                document.getElementById('pbtn4').focus();
            }
        }

        
        if (event.key === 'ArrowUp') {
            if (currentId === 'pbtn4') {
                document.getElementById('pbtn3').focus();
            } else if (currentId === 'pbtn3') {
                document.getElementById('pbtn2').focus();
            } else if (currentId === 'pbtn2') {
                document.getElementById('pbtn1').focus();
            } else if (currentId === 'pbtn1') {
                document.getElementById('cashamount').focus();
            } else if (currentId === 'cashamount') {
                document.getElementById('cardpayment').focus();
            } else if (currentId === 'cardpayment') {
                document.getElementById('cardno').focus();
            } else if (currentId === 'cardno') {
                document.getElementById('billcustomer').focus();
            }
        }
    }
});
}













            }
            
           // 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).toFixed(2);

}



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


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


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

    

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

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


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



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

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


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



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

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

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

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

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

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

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



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

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


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

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

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

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

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

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

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

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

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

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


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

                                }
                            });
                       
                    }
                    
                    
                }, 100);




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

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


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

                                }
                            });
                       
                    }



                    
                    
                }, 100);
 */



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


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

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

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


























           }




            }





            

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


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

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

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

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















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

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

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

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


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

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

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


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

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

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

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

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



const disinput = document.getElementById('disinput');
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();
               
                disinput.value = 0;
                $("#disModal").modal("hide");
            },
            error: function () {
                console.error('Error occurred during AJAX request');
            }
        });
    }
});

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

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

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

});




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

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



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

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


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

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

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

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

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


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

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

        }

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

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


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

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

        }
});





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


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

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

        }

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



















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


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

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

        }
});




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

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

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

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

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








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



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

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

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

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


});








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



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

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

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

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


});


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


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

      console.log(currentIndex);

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

}


  
    
   
    
    

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

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


});

function handlegenaralkeypress(event,id){
    if (event.key === 'Enter') {
        event.preventDefault();
        const idd = document.getElementById(id);
        if (idd) {
            idd.focus();
        }
    }
}
function payBill() {
       //showTotalAmount();
		var totalbillvalue = 0;
		//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 route = document.getElementById("route").value;
		var customer = document.getElementById("billcustomer").value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = cashamount;
		var tddiscount = document.getElementById("tddiscount").value;
		var cardno = document.getElementById("cardno").value;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = document.getElementById("cheque_date").value;
		var cheque_number = document.getElementById("cheque_number").value; 
		var pay_type = document.getElementById("paymethod").value;
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;

		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& tddiscount=" + tddiscount + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& route=" + route + "&",   
			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("salesrecieptmobilenew.php?receiptno=" + data + '&paid_amount=' + cashamount, "_self");
				} else {
					
				}
			},
			error: function() {
				
			}
		})

	}


    function a4print() {
       //showTotalAmount();
		var totalbillvalue = 0;
		//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 route = document.getElementById("route").value;
		var customer = document.getElementById("billcustomer").value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = cashamount;
		var tddiscount = document.getElementById("tddiscount").value;
		var cardno = document.getElementById("cardno").value;
		var cheque = ""; //document.getElementById("cheque").value;
		//var duedate = ""; //document.getElementById("duedate").value;
		var duedate = document.getElementById("cheque_date").value;
		var cheque_number = document.getElementById("cheque_number").value; 
		var pay_type = document.getElementById("paymethod").value;
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;

		$.ajax({
			url: "load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& tddiscount=" + tddiscount + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& route=" + route + "&",   
			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("salesreciepta4.php?receiptno=" + data + '&paid_amount=' + cashamount, "_self");
				} else {
					
				}
			},
			error: function() {
				
			}
		})

	}

    function onlypayBill(){
        //showTotalAmount();
		var totalbillvalue = 0;
		//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 route = document.getElementById("route").value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = cashamount;

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

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


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

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

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

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


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

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

		$.ajax({
			url: "only-load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "&",
			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 = 0;
		//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 route = document.getElementById("route").value;
		var customer = document.getElementById("billcustomer").value;
		var cashamount = document.getElementById("cashamount").value;   
        var cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = cashamount;

		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("paymethod").value;      
		var deliveryCost = "0.00"; //document.getElementById("deliveryCostview").innerHTML;
		var country = "0"; //document.getElementById("country").value;
		var city = "0"; //document.getElementById("city").value;
		//var branch_id = document.getElementById("branch_id").value;
		//var oid = document.getElementById("oid").value;
        var gift_number = document.getElementById("gift_number").value;
        var mobile_payment_method = document.getElementById("mobile_payment_method").value;
        var cardpayment = document.getElementById("cardpayment").value;
		$.ajax({
			url: "only-load-save-new-bill.php",
			type: "POST",
			data: "country=" + country + "& city=" + city + "& deliveryCost=" + deliveryCost + "& totalbillvalue=" + totalbillvalue + "& cashamounthidden=" + cashamounthidden + "& cashamount=" + cashamount + "& customer=" + customer + "& cardno=" + cardno + "&  cheque=" + cheque + "&  duedate=" + duedate + "& pay_type=" + pay_type + "& totalAmountvalue=" + totalAmountvalue + "& cheque_number=" + cheque_number + "& gift_number=" + gift_number + "& mobile_payment_method=" + mobile_payment_method + "& cardpayment=" + cardpayment + "& route=" + route + "&",
			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 = 0;
		//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 cashamounthidden = document.getElementById("cashamounthidden").value; 
		var totalAmountvalue = cashamount;

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

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

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

    }
    
   


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

      

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


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


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

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





    });







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

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

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






</script>




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




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






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

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










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


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


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

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


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

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






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

                </div>
                <div class="row mt-3 g-1 btnwrap">
                    <div class="col-3">
                        
                        <button id="pbtn1" class="number ntext pbtn inputele" onclick="onlypayBill();" onkeydown="if(event.keyCode==13){ onlypayBill(); event.preventDefault(); }" style="background-color:#001d87; width:100%;"><span class="key">S</span>Pay</button>
                    </div>
                    <div class="col-3">
                       
                        <button id="pbtn2" class="number ntext pbtn inputele" onclick="payBill();" onkeydown="if(event.keyCode==13){ payBill(); event.preventDefault(); }" style="background-color:#24870b;width:100%;"> <span class="key">T</span>Print</button>
                    </div>
                    <div class="col-3">
                        
                        <button id="pbtn3" class="number ntext pbtn inputele" onclick="onlySaveBill();" onkeydown="if(event.keyCode==13){ onlySaveBill(); event.preventDefault(); }" style="background-color:#01796f; width:100%;"><span class="key">R</span>Hold</button>
                    </div>
                    <div class="col-3">
                       
                        <button id="pbtn4" class="number ntext pbtn inputele" onclick="onlySaveBillWithBarcode();" onkeydown="if(event.keyCode==13){ onlySaveBillWithBarcode(); event.preventDefault(); }" style="background-color:#000000; width:100%;"> <span class="key">V</span>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>


<script>
		$(document).ready(function() {
          
			$('#route').change(function() {
				var route = $(this).val();
				$.ajax({
					type: "POST",
					data: {
						route: route
					},
					url: "route-change.php",
					success: function(data) {
						$("#billcustomer").html(data);
					}
				});
			});
		});
	</script>












</body>
</html>

