<?php
// Start output buffering and session
ob_start();
include('include/session.php');
// session_start();

// Set error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Include necessary files
include('include/navigation.php');
include('connection.php');
include('class.php');

// Establish database connection
$dbConnection = new DbConnection();
$connection = $dbConnection->connection;

// Redirect if user is already logged in
if (isset($_SESSION["id"])) {
    header("Location: _order_list.php");
    exit;
}

?>
<!-- Your HTML form goes here -->

<body>
<div class="container_main"><br>
      <div id="warantee_button">
                    <div class="item-right"><button class="reset-button"><a href="store.php"><i class="fa-solid fa-backward"></i></a></button></div>
                    <div class="item-left"><a href="_store_rejected_list.php" class="reset-button">Rejected List</a></div>
                     <div class="item-left"><a href="_store_approved_list.php" class="reset-button"> Stock Approved List</a></div>
                </div>
        <form action="arrival_form.php" method="POST">
            <div class="form-group" >
              
                <h1>Arrival Store</h1>
              <div class="box_button arrival_store" id="boxButton">
     <button type="button" class="btn btn-outline-success" style="width:50%">

        <select class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split category_one"  id ="category_one" name="category[]" style="width:100%" required>
                <option value=""> Select Category </option>
            <?php
                        $sql = "SELECT category FROM  procurement";

                        $result = $connection->query($sql);

                        // Check if there are rows in the result
                        if ($result->num_rows > 0) {
                            while ($row = $result->fetch_assoc()) {
                                echo '<option value="' . $row["category"] . '">' . $row["category"] . '</option>';
                            }
                        }
                    ?>
        </select>
    </button>
            <button type="button" class="btn btn-outline-success"style="width:50%">
                    <select class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split product_one" name="product[]" id="product_one" style="width:100%" required>
                    <option value=""> Select product</option>
                    <optgroup label="Product">
                        <!-- Options will be dynamically populated using JavaScript -->
                    </optgroup>
                   </select>
           </button>
        <button type="button" class="btn btn-outline-success" >
            <select class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split variation_one" name="variation[]" id="variation_one" required>
                <option value=""> Select variation</option>
                <optgroup label="variation">
                    <!-- Options will be dynamically populated using JavaScript -->
                </optgroup>
            </select>
        </button>
        
        <button type="button" class="btn btn-outline-success" style="width:180px">
        
           <input type="text" id="product_id" class="form-control product_id" placeholder="Product_id" aria-label="Product_id" name="product_id[]" value="" required>
            
        </button>

        <button type="button" class="btn btn-outline-success" style="width:140px">
        
           <input type="text" id="price_one" class="form-control price_one" placeholder="Price" aria-label="Price_one" name="price[]" value="" required>
            
        </button>

         <button type="button" class="btn btn-outline-success" style="width:140px;">
            <input type="text" class="form-control " placeholder="quantity" aria-label="Text input with segmented dropdown button" id="quantity" name="quantity[]" required>

        </button>
       

   

        <select class="btn btn-secondary btn-outline-success"id="dropdownMenuButton"  name="quality_check_pass[]" style="height:60px; width:140px;">
        <option value="">choose</option>
                        <option value="Yes">Yes</option>
                        <option value="No">No</option>
       </select>
             
                
        <button type="button" class="btn btn-outline-success" style="width:180px;">
             <input type="text" class="form-control " placeholder="quality_no" aria-label="Text input with segmented dropdown button" id="quantity" name="quality_check_no[]" >

        </button>               


 </div>
 <div id="clonedContainer"></div>
   <div class="button" id="add_button">
                    <button type="button" class="btn btn-info" id="addMore">Add More</button>
                </div>
                <div class="button">
                    <button type="submit" name="submit" class="reset-button">Submit</button>
                </div> 
            </div>
        </form>
    </div>
     <section class="footer">
     <?php include('include/footer_two.php');         ?>
     
 </section>
</body>
<?php 
 include("include/footer_link.php");
?>
<script src="assets/script/script.js"></script>

</html>
<?php
ob_end_flush();
?>