<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include_once('opendb.php');
$code=$_REQUEST['code'];

$find_jv=mysqli_query($db,"select * from spareinvoice where invno='$code' and brcode='$brcode'");
while($irow=mysqli_fetch_array($find_jv))
{

		mysqli_query($db,"update sparestock set curstk=(curstk+'$irow[qty]') where itemcode='$irow[8]' and brcode='$brcode'");
	
	$j_no=$irow[jvno];
}



mysqli_query($db,"delete from spareinvoice 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='invoice_sale1.php'; </script>";

?>
