
<?php include ("inc/config.php");
 
if(isset($_REQUEST["term"])){  $sql = "SELECT * FROM product_sales where time >= CURDATE() AND YEAR(time) = YEAR(CURRENT_DATE) AND  customer LIKE ?";
    
if($stmt = $mysqli->prepare($sql)){
 // Bind variables to the prepared statement as parameters
 $stmt->bind_param("s", $param_term);
 // Set parameters
 $param_term = $_REQUEST["term"] . '%' ;
 // Attempt to execute the prepared statement
 if($stmt->execute()){
   $result = $stmt->get_result();
   // Check number of rows in the result set
 if($result->num_rows > 0){

  echo "<table>";
  echo "<thead>";
  echo "<tr class='t2'>";
  echo "<th>Customer Name</th>";
  echo "<th>items released</th>";
  echo "<th>Item Size</th>";
  echo "<th>Quantity</th>";
  echo "<th>Unit price</th>";
  echo "<th>Total Price</th>";
  echo "<th>Receipt_No</th>";
  echo "<th>Served by</th>";
  echo "<th>Time</th>";
  echo "</tr>";
  echo "</thead>";
  echo "<tbody>";

 // Fetch result rows as an associative array
 while($row = $result->fetch_array(MYSQLI_ASSOC)){
  echo "<tr>";
  echo "<td>" . $row['customer'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['size'] . "</td>";
  echo "<td>" . $row['quantity'] . "</td>";
  echo "<td>" . $row['price'] . "</td>";
  echo "<td>" . $row['unit_totalprice'] . "</td>";
  echo "<td> 
         <form method ='post'> 
            <input type='hidden' name='receipt_no' value=".$row['receipt_no']." />
            <button class='receipt' type='submit' name='submit'  ><u> " . $row['receipt_no'] . " </u></button>
        </form>
  </td>";

  echo "<td>" . $row['session'] . "</td>";
  echo "<td  style='float: right; margin-right: 2%; color:orange; font-weight:bold; '  >" . date_format( new DateTime ($row['time'] ),"d M, Y H: m: s"). "</td>";

  echo "</tr>";
  
  }

  echo "</table>";
      } else{
                echo "<p class='no-results'>No matches found</p>";
            }
        } else{
            echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
        }
    }
     
    // Close statement
    $stmt->close();
}
 
// Close connection
$mysqli->close();
?>