<?
session_start();
include("../opendb.php");
include("../test.php");
print 'war:'.$war_no;
$brres=mysqli_query($db,"select brname from branch where brcode='$brcode'");
$brrow=mysqli_fetch_row($brres);

$chin=mysqli_query($db,"select * from sparetrinwar where frombr='$brrow[0]' and warno='$war_no'");
if(mysqli_num_rows($chin)>0)
{
  print "<script> alert('Cannot Cancel.\\nIt has been accepted by Branch');</script>";
  return;
}
else
 print "<script> alert('Ok, can be deleted');</script>";
$sq="select jvno from journal2 where partic='Spare transfer out (WAR)' and tr_no='$war_no' and brcode='$brcode'";

//print $sq."<br>";
$re=mysqli_query($db,$sq)or die('err1'.mysqli_error());

$jvrow=mysqli_fetch_array($re);
$sql="delete from journal2 where jvno='$jvrow[0]' and brcode='$brcode'";
mysqli_query($db,$sql) or die('err2'.mysqli_error());

//print $sql.'<br>';
$sql="delete from warsparetransout where warno='$war_no' and brcode='$brcode'";
mysqli_query($db,$sql) or die('err3'.mysqli_error());
//print $sql.'<br>';

$tbl="spareinvwar".$brcode;
mysqli_query($db,"update $tbl set trans='n' where warno='$war_no'");
//$sql="delete from $tbl where warno='$war_no'";
//mysqli_query($db,$sql) or die('err4'.mysqli_error());
//print $sql.'<br>';
print "<font color=green><b>Record has been cancelled</b></font>";
?>
