
<?php
include "config.php";

if (isset($_GET['order_id'])) {
    $order_id = intval($_GET['order_id']);

    $sql = "SELECT p.item_name,p.item_code, d.quantity,d.total, d.price, d.status, d.issued_qty, d.balance_qty
            FROM order_items d
            LEFT JOIN tbl_stock_items p ON d.product_id = p.id
            WHERE d.order_id = $order_id";
    $res = mysqli_query($con, $sql);

    if (mysqli_num_rows($res) > 0) {
        echo "<table style='width:100%; font-size:12px; border-collapse:collapse;' border='1'>";
        echo "<tr><th>Product</th><th>Item Code</th><th>Price</th><th>Qty</th><th>I.Qty</th><th>B.Qty</th><th>Total</th><th>Status</th></tr>";
        while ($item = mysqli_fetch_assoc($res)) {
            echo "<tr>
                    <td>{$item['item_name']}</td>
                    <td>{$item['item_code']}</td>
                    <td>{$item['price']}</td>
                    <td>{$item['quantity']}</td>
                    
                    <td>{$item['issued_qty']}</td>
                    <td>{$item['balance_qty']}</td>
                    <td>{$item['total']}</td>
                    <td>{$item['status']}</td>
                  </tr>";
        }
        echo "</table>";
    } else {
        echo "<p>No items found for this order.</p>";
    }
}
?>