<?
session_start();
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$code=$_REQUEST['code'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
//$sql="delete from brtransferout where invno='$code' and brcode='$brcode'";
//echo $sql;
$find_jv=mysqli_query($db,"select * from brtransferin where invno='$code' and brcode='$brcode'");
while($irow=mysqli_fetch_array($find_jv))
{
if($irow[22]=='D')
	{
		mysqli_query($db,"update sparestock set curstk_dam=(curstk_dam-'$irow[7]') where itemcode='$irow[5]' and brcode='$brcode'");
	}
elseif($irow[22]=='S')
	{
		mysqli_query($db,"update sparestock set curstk_soil=(curstk_soil-'$irow[7]') where itemcode='$irow[5]' and brcode='$brcode'");
	}
elseif($irow[22]=='C')
	{
		mysqli_query($db,"update sparestock set curstk_cut=(curstk_cut-'$irow[7]') where itemcode='$irow[5]' and brcode='$brcode'");
	}
else
	{
		mysqli_query($db,"update sparestock set curstk=(curstk-'$irow[7]') where itemcode='$irow[5]' and brcode='$brcode'");
	}
	$j_no=$irow[18];
}
//$f_j=mysqli_fetch_row($find_jv);

mysqli_query($db,"delete from brtransferin where invno='$code' and brcode='$brcode'");
if($j_no >0)
	{
		mysqli_query($db,"delete from journal2 where jvno='$j_no' and brcode='$brcode'");
  	}



print "<script> alert('Data Has been Deleted');document.location='branchreceipt.php'; </script>";

?>
