<?php 
session_start();
require("php_con.php");
if(isset($_POST['close_popup'])){
$_SESSION['low_stock_popup']=true;
echo "<script>window.open('dashboard','_parent');</script>";
}
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="data_table/css/bootstrap.css" rel="stylesheet" type="text/css">
</head>

<body>
	
<div align="right" class="mb-2 bg-white" style="position: sticky; top: 0px;">
<form method="post">
<button type="submit" name="close_popup" class="btn btn-sm btn-danger">&times;</button>
</form>
</div>
	
<table class="table table-sm table-bordered" style="font-size: 14px;">
  <tbody>
    <tr class="table-active">
      <td>Barcode</td>
      <td>Item</td>
      <td>Alert</td>
      <td>Available</td>		  
      <td>Re-Order</td>
    </tr>
<?php 
$l_qury=mysqli_query($connation,"SELECT pd.product_barcode,pd.product_name,pd.product_alertqty,(SUM(if(sd.stock_type=1,sd.stock_qty,0)-if(sd.stock_type=0,sd.stock_qty,0))) AS av_qty
FROM product_details pd RIGHT JOIN stock_details sd ON pd.product_systemid=sd.stock_systemid
WHERE pd.product_systemid!=''
GROUP BY pd.product_barcode");
while($l_resalt=mysqli_fetch_assoc($l_qury)){
if($l_resalt['product_alertqty']>$l_resalt['av_qty']){
?>
    <tr>
      <td><?php echo $l_resalt['product_barcode']; ?></td>
      <td><?php echo $l_resalt['product_name']; ?></td>
      <td align="right"><?php echo number_format((float)$l_resalt['product_alertqty']); ?></td>
      <td align="right"><?php echo number_format((float)$l_resalt['av_qty']); ?></td>
      <td align="right"><strong><?php echo number_format((float)$l_resalt['product_alertqty']-$l_resalt['av_qty']); ?></strong></td>
    </tr>
<?php } } ?>
	  
  </tbody>
</table>

	
</body>
</html>