<?php
 
 include('db_con.php');
 include('function.php');
require_once 'pdf.php';
 $html = '';
 if (isset($_SESSION['user_id'])) {
    $user_type = $_SESSION['user_type'];
    $user_id = $_SESSION['user_id'];
    $user_name = $_SESSION['user_name'];
    $branch_id = $_SESSION['branch_id'];
    $branch_name = $_SESSION['branch_name'];
    $store_id = $_SESSION['store_id'];
    $store_name = $_SESSION['store_name'];
}else{
  header('Location: login');
  die();
}
         
            
  date_default_timezone_set('Asia/Karachi');
$curstamp = date('Y-m-d h:i:s a');
 
 $store_id = $_GET['store_id'];
 $item_name = $_GET['item_name'];
 $color_id = $_GET['color_id'];
 $type_id = $_GET['type_id'];
 $brand_id = $_GET['brand_id'];
 
 //$store_id = $_Get['fitem_no'];
// $store_id = $_Get['titem_no'];
 
 $sql = "SELECT store_name FROM store WHERE store_id='".$store_id."'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
           $store_name = $statement->fetchColumn();

           $sql = "SELECT user_name FROM user_detail WHERE user_id='".$user_id."'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
           $user_name = $statement->fetchColumn();
         
  $sql = "select s.item_no,s.stock, CONCAT(i.item_name, ' ',t.type_name,' ', b.brand_name,' ',c.color_name) item_name,u.uom_name from stock_instore s, items i,item_color c,item_brand b,item_type t,item_uom u where i.type_id=t.type_id and i.color_id=c.color_id and b.brand_id=i.brand_id and u.uom_id=i.uom and
  i.item_id=s.item_no and i.status = 'Active' and i.item_name LIKE '%".$item_name."%' and i.type_id LIKE '%".$type_id."%' and  i.brand_id LIKE '%".$brand_id."%' and  i.color_id LIKE '%".$color_id."%' and s.store_id = '".$store_id."' and s.stock <> 0";
   $statement = $connect->prepare($sql);
 $statement->execute();
  
 
 $result = $statement->fetchAll();
 
  ?>
<!DOCTYPE html>
<html>
<head>
  <title></title>
  <style>
    .head_table td{
      border : 1px solid gray;
    }
</style>
</head>
<body>
<table class="head_table" width="100%" style="border:1px solid gray;">
<tr>
<td colspan="2">Stock Report <?php echo 'Printed at : '.$curstamp . ' --  Printed By : '.$user_name;?></td>
</tr>
<tr>
<td>Store Name :</td><td><?php echo $store_name;?></td>
</tr>
</table>
  <table width="100%" id="items" border="1">
  <tr>
  
  <th width="80%">Item Name</th>
  
<th width="10%" class="rightside">UOM</th>
  <th width="10%" class="rightside">Stock</th>
  </tr>
  
  
<?php
foreach($result as $row)
 {
  
  $stock = $row["stock"];
echo '
  
  
  
<tr>
  
<td width="80%">'.$row["item_name"].'</td>
<td width="10%">'.$row["uom_name"].'</td>
   <td width="10%" class="rightside">'.number_format($stock, 2).'</td>
  
   
    
   </tr>
  ';
   
  }
  ?>
  </table>
</body>
</html>