<?php
 
 include('db_con.php');
 include('function.php');
date_default_timezone_set('Asia/Karachi');
 $dated = date('d-m-Y h:i:s A');
 $count = 0;
 $stock = 0;
 $req_stock = 0;
 
 $tot_stock = 0;
 
  $type_id = $_GET['type_id'];
  
  //$stock = $_GET['stock'];
 
 //$store_id = $_GET['store_id'];
$sql = "SELECT ifnull(type_name,'ALL') from item_type where type_id='".$type_id."'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $type_name = $statement->fetchColumn();
  
  $statement = $connect->prepare("SELECT CONCAT(t.type_name, ' ',i.item_name)  as item_name,i.min_qty,i.stock from items i,item_type t where t.type_id=i.type_id 
  AND i.status = 'active' AND i.stock < i.min_qty and i.type_id LIKE '%".$type_id."%' order by item_name ASC");
 $statement->execute();
 
 $result = $statement->fetchAll(); 
 if($type_name==''){$type_name='ALL';}
 
  ?>
<!DOCTYPE html>
<html>
<head>
  <title>Less Than Minimum Stock Report</title>
  
   <style type="text/css">
    
   * {
  font-size: 15px;
  font-family: calibri;
  padding: 4px;

}
thead td{
border-bottom:1px solid black;
border-top:1px solid black;
font-weight: bold;
padding:2px;
}
tbody td{
border-bottom:1px solid black;

font-weight: normal;
padding:2px;
}

.rightside {
  text-align: right;
}


.table_header {
  font-weight: bold;
}

</style>
</head>
<body>
<table width="100%" class="header_table">
<tr>
<td colspan="2"><b>Minimum Stock Report as on : <?php echo $dated;?></b></td>
</tr>
<tr>
<td colspan="2"><?php echo '<b>Item Type : </b>'.$type_name  ; ?></td>
</tr>
</table>
  <table width="100%" class="data_table">
    <thead>
  <tr>
  <td width="7%">No</td>
  <td width="63%">Item Name</td>
  <td width="10%" class="rightside">Min-Stock</td>
  <td width="10%" class="rightside">Stock</td>
  <td width="10%" class="rightside">Required</td>
  </tr>
  </thead>
  <tbody>
  
<?php
foreach($result as $row)
 {
$count++;
  
  $stock = $row["stock"];
  $min_stock = $row["min_qty"];
  $req_stock = $min_stock - $stock;
echo '
  
  
  
<tr>
  <td width="7%">'.$count.'</td>
<td width="63%">'.$row["item_name"].'</td>
<td width="10%" class="rightside">'.number_format($min_stock, 2).'</td>
   <td width="10%" class="rightside">'.number_format($stock, 2).'</td>
   <td width="10%" class="rightside">'.number_format($req_stock, 2).'</td>
  
   
    
   </tr>
  ';
   
  }
  ?>
</tbody>
  </table>
</body>
</html>