<?php 
require('../config/dbcon.php');
?>
<!doctype html>
<html>
 <body >
   <!-- CSS -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/js/bootstrap-datepicker.js"></script>
   

   <!-- Search filter -->
   <form method='post' action=''>
       <input type="text" class="date form-control" style="width : 150px; margin-left: 10px;" value="<?php date_default_timezone_set('Asia/Kolkata'); echo date( 'd/m/Y'); ?>" style="width: 200px" />
     Start Date <input type='text' class='dateFilter' name='fromDate' value='<?php if(isset($_POST['fromDate'])) echo $_POST['fromDate']; ?>'>
 
     End Date <input type='text' class='dateFilter' name='endDate' value='<?php if(isset($_POST['endDate'])) echo $_POST['endDate']; ?>'>

     <input type='submit' name='but_search' value='Search'>
   </form>

   <!-- Employees List -->
   <div style='height: 80%; overflow: auto;' >
 
     <table border='1' width='100%' style='border-collapse: collapse;margin-top: 20px;'>
       <tr>
         <th>partno</th>
         <th>description_one</th>
         <th>list</th>
         <th>moq</th>
       </tr>

       <?php
       $emp_query = "SELECT * FROM item_mst";

       // Date filter
       if(isset($_POST['but_search'])){
          $fromDate = $_POST['fromDate'];
          $endDate = $_POST['endDate'];

          if(!empty($fromDate) && !empty($endDate)){
             $emp_query .= " and description_one between '".$fromDate."' and '".$endDate."' ";
          }
        }

        // Sort
        $emp_query .= " ORDER BY description_one DESC limit 100";
        $employeesRecords = mysqli_query($connect,$emp_query);

        // Check records found or not
        if(mysqli_num_rows($employeesRecords) > 0){
          while($row = mysqli_fetch_assoc($employeesRecords)){
            $id = $row['id'];
            $partno = $row['partno'];
            $description_one = $row['description_one'];
            $list = $row['list'];
            $moq = $row['moq'];
            echo "<tr>";
            echo "<td>". $partno ."</td>";
            echo "<td>". $description_one ."</td>";
            echo "<td>". $list ."</td>";
            echo "<td>". $moq ."</td>";
            echo "</tr>";
          }
        }else{
          echo "<tr>";
          echo "<td colspan='4'>No record found.</td>";
          echo "</tr>";
        }
        ?>
      </table>
 
    </div>
 </body>
</html>
<script type="text/javascript">
      $(".date").datepicker({
        format: "dd/mm/yyyy",
      });
    </script>