<?php
session_start();
if(!isset($_SESSION['aid']))
{
	echo '<script>location.href="../index.php"</script>';
}

include "../connection/config.php";
 $sid=$_GET['sid'];
 $iid=$_GET['iid'];

 $sqli=mysqli_query($con,"select * from stock_details where sid='$sid'");
 $feti=mysqli_fetch_assoc($sqli);
  $stockin = $feti['stockin'];
  $dead_stock = $feti['dead_stock'];

   // update stock
   $update_item_sql=mysqli_query($con,"select * from stock where iid='$iid'");
   $update_item_fet=mysqli_fetch_assoc($update_item_sql);

   $ugstock=$update_item_fet['good_stock']; 
   $udstock=$update_item_fet['dead_stock'];

   $update_goodstock = $ugstock - $stockin; 
   $update_deadstock = $udstock - $dead_stock;

   $sqli2="update stock set good_stock='$update_goodstock',dead_stock='$update_deadstock' where iid='$iid'";  
   $exee2=mysqli_query($con,$sqli2);

   $sql="delete from stock_details where sid='$sid'";
   $exe=mysqli_query($con,$sql);

echo '<script>location.href="stock_input.php"</script>';

?>