<?php 
session_start();
include 'db_connection.php';
if(isset($_GET['receiptno'])){
    $receiptno = $_GET['receiptno'];
   // $orderinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobile_kot WHERE order_id ='$receiptno'")); 
    $kot = $receiptno;

    $kotinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobile_kot WHERE kot_id ='$kot'")); 
  
    
   
   
    
   

}

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KOT</title>
    <style>
    @page {
        size: 10.4cm 10cm landscape;
        font-size: 15px;
    }

    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
    }

    .container {
        width: 80mm;
        margin: 0 auto;
        padding: 10px;
        box-sizing: border-box;
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    tbody{
        td{
            font-size: 15px;
        }
    }
    tfoot{
        td{
            font-size: 15px;
        }
    }
    th,
    td {
        padding: 5px;
        text-align: left;
        font-size: 10px;

    }

    img {
        width: 80px;
        height: auto;
        margin-right: 10px;
    }

    p {
        font-size: 12px;
        margin: 0;
    }

    .center {
        text-align: center;
    }
    </style>
</head>

<body>
    <div class="container">
        <div style="width:100%;">
            <div style="text-align: center;">
                <b>
                   
                    <p style="font-size:24px;">KOT: Kitchen</p>
                    <p style="font-size:14px;">Order Type: <?php echo $kotinfo['order_type']; ?></p>
                    <p style="font-size:14px;">Order No: <?php echo $receiptno; ?></p>
                    <p style="font-size:14px;">KOT Number: <?php echo $kot; ?></p>
                    <?php if($kotinfo['room_no']!=0){ ?>
                    <p style="font-size:14px;">Room No: <?php echo $kotinfo['room_no']; ?></p>
                    <?php } ?>
                    <?php if($kotinfo['table_no']!=0){ ?>
                    <p style="font-size:14px;">Table No: <?php echo $kotinfo['table_no']; ?></p>
                    <?php } ?>
                </b>
            </div>
        </div>
        <hr>
        <p>Date: <?php echo $kotinfo['added_date']; ?></p>
        <hr>
        <table>
            <thead>
                
                <tr>
                    <th><span style="text-align: center; font-size:16px;">Item Name</span></th>
                    <th style="text-align: right;"><span style="font-size:16px;">Quantity</span></th>
                </tr>
            </thead>
            <tbody>
                
                    <?php 
                   

                    $res = mysqli_query($conn, "SELECT * FROM mobiletemporarycart WHERE kot_id ='$kot' AND orderid!='0' AND print_kot='0'");
                        if ($res->num_rows > 0) { 
                            while($row = $res->fetch_assoc()) {
                               
                                $proid = $row['proid'];
                                $pro_qty = $row['pro_qty'];

                                $productinfo = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM mobileproducts WHERE prid ='$proid'")); ?>
                                <tr>
                                    <td><?php echo $productinfo['proname']; ?></td>
                                    <td style="text-align: right;"><?php echo $pro_qty; ?></td>
                                </tr>

                         <?php   }
                          $sql12 = "UPDATE mobiletemporarycart SET print_kot='1' WHERE kot_id='$kot'";
                          $conn->query($sql12);
                        }
                    
                       
                    ?>
                
            </tbody>
           
        </table>

       
    </div>
    <!-- JavaScript to trigger print functionality -->
    <script>
    window.onload = function() {
        window.print();
    };
    </script>
</body>

</html>

<?php
$conn->close();
?>
<script>
function redirectToPosPanel() {
    window.location.href = "/pos-panel.php";
}

window.onafterprint = redirectToPosPanel;
window.onload = function() {
    window.print();
    setTimeout(redirectToPosPanel, 2000);
};
</script>