<?php
include('db_con.php');
  include('header.php');
  include('function.php');
  
  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();
}
 stock_instore($connect);
  $item_no = $_GET['id'];
  $tot_stock = $_GET['stock'];
 //$store_id = $_Get['fitem_no'];
// $store_id = $_Get['titem_no'];
 
 $sql = "SELECT item_name FROM items WHERE item_id='".$item_no."'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
           $item_name = $statement->fetchColumn();
         
  $sql = "select store_id,sum(purchase-sale-pr+sr+qty_in-qty_out) as stock from stock_instore where
  item_no = '".$item_no."' group by store_id";
   $statement = $connect->prepare($sql);
 $statement->execute();
  
 
 $result = $statement->fetchAll();
 
  ?>
<!DOCTYPE html>
<html>
<head>
	<title>Item Detail</title>
	<style>
	#head_table{padding:5px;font-family: calibri;font-size: 18px;border:1px solid gray;}
	#items{font-family: calibri;font-weight: normal;}
	#head_table td{padding: 5px;}
	#items td, th{padding: 5px;font-size: 16px;font-family: calibri;}
	</style>
</head>
<body>
<table width="100%" border="1" id="head_table">
<tr>
<td colspan="2">Stock Report</td>
</tr>
<tr>
<td>Item No :</td><td><?php echo $item_no;?></td>
</tr>
<tr>
<td>Item Name :</td><td><?php echo $item_name;?></td>
</tr>
</table>
<br />
  <table width="100%" id="items" border="1">
  <tr>
  <th width="7%">Store_ID</th>
  
  
  <th width="14%" class="rightside">Stock</th>
  </tr>
  
  
<?php
foreach($result as $row)
 {
  
  $stock = $row["stock"];
echo '
  
  
  
<tr>
  <td width="7%">'.$row["store_id"].'</td>
   <td width="14%" class="rightside">'.number_format($stock, 2).'</td>
  
   
    
   </tr>
  ';
   
  }
  echo '
<tr>
  <td width="7%"><b>Total Stock :</b></td>
   <td width="14%" class="rightside"><b>'.number_format($tot_stock, 2).'</b></td>
  
   
    
   </tr>'
  ?>
  </table>
</body>
</html>
