<?php 
include('include/session.php');
// session_start();

include('include/navigation.php');
include('connection.php');
$dbConnection = new DbConnection();
$connection = $dbConnection->connection;
?>
<html lang="en">
<head>
    <link rel="stylesheet" href="assets/css/style.css">
<?php
include('include/header_links.php');

?>
<body>
    <div class="container_main">
    <!-- <button class="reset-button"><a href="_new_order.php"><i class="fa-solid fa-backward"></i></a></button> -->
    <button class="reset-button"><a href="_add_stock.php">Add Stock</a></button>
    <!--<button class="reset-button"><a href="_order_list.php">Order List</a></button>-->
        <h1>--Stock List--</h1>
     
        <table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">S.no</th>
      
      <th scope="col">Category</th>
      <th scope="col">Product</th>
      <th scope="col">Product Id</th>
      <th scope="col">variation</th>
      <th scope="col">Price</th>
      <th scope="col">Edit</th>
      <th scope="col">Delete</th>
      <!-- <th scope="col">Total Amount</th> -->
     
    </tr>
  </thead>
  <tbody>
  <?php
                   
                   $query = "
                   SELECT 
                       pv.*, 
                       p.category 
                   FROM 
                       product_variation pv
                   JOIN 
                       product p 
                   ON 
                       pv.product = p.product
               ";
  
                    $result = mysqli_query($connection, $query);
                    $id = 1;

                    if ($result && mysqli_num_rows($result) > 0) {
                        while ($row = mysqli_fetch_assoc($result)) {

                            echo "<tr>";

                            // Output sales data
                            echo "<td>{$id}</td>";
                            echo "<td>{$row['category']}</td>";
                            echo "<td>{$row['product']}</td>";
                             echo "<td>{$row['product_id']}</td>";
                            echo "<td>{$row['variation']}</td>";
                            echo "<td>{$row['price']}</td>";
                            echo "<td><a href='_edit_stock.php?id={$row['id']}&product=" . urlencode($row['product']) . "' class='btn btn-primary' title='Edit'><i class='fas fa-edit'></i></a> ";
                             echo "<td><a href='delete_product.php?id={$row['id']}' class='btn btn-danger' onclick='return confirm(\"Are you sure you want to delete this item?\");'><i class='fas fa-trash'></i></a>";
                            echo "</td>";
                           
                            echo "<tr>";
                            $id++;
                        }
                    }
                    ?>
  </tbody>
</table>
</div>
<section class="footer">
    <?php
 include_once("include/footer_two.php");
  ?>
     </section>
  </body>
 
  <?php 
 include("include/footer_link.php");
  ?>

 
<script src="assets/script/script.js"></script>
</html>

<?php
// ob_end_flush(); // Send the buffered output
?>
</html>