<!DOCTYPE html>
<html>
<head>
<title>Auto Print Page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
    h1{
        text-align:center;
        color:red;
    }
</style>
</head>
<body>

<h1>DO NOT CLOSE THIS WINDOW!</h1>
<p id="console">Fetching...</p>
<script>
    var mrefreshinterval = 5000;
    var check_printables = function() {
        $.ajax({
            url:"<?php echo base_url() ?>pos/check_printables",
            dataType:"JSON",
            method:"POST",
            data:{
                "cat_id":<?php echo $cat_id;?>
            },
            beforeSend:function(){
              $('#console').text("Fetching...");  
            },
            success:function(data){
                console.log(data.success);
                if(data.success){
                    $('#console').text("Data fetched!");
                    var sale_id = data.sale_id;
                    //var myWindow=window.open('<?php echo base_url() ?>pos/ap_kot','','width=200,height=100');
                    var myWindow=window.open('<?php echo base_url() ?>pos/ap_kot?sale_id='+sale_id+'&cat_id='+<?php echo $cat_id;?>,'_s'+sale_id,'width=600,height=800');
                        //myWindow.document.write("<p>This is 'myWindow'</p>");
                        //myWindow.document.close();
                        //myWindow.focus();
                        setTimeout(function(){
                            <?php
                            //echo $auto_print;
                            
                            //echo $auto_close;
                            ?>
                        },500);
                }else{
                    $('#console').text("No data found");
                }
            },error:function(data){
                $('#console').text(data.responseText);
                console.log(data);
            }
        });
    }
    setTimeout(function(){
        window.location.reload();
    }, 61000);
    setInterval(check_printables, mrefreshinterval);
</script>
</body>
</html>