<?
session_start();
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.html'; </script>";
 return;
}

include("../opendb.php");
include("../test.php")
?>
<center>
<form action='<?print $PHP_SELF?>' method='post'>
<input type=hidden name='purno' value='<?print $purno?>'>
<input type=hidden name='ttype' value='<?print $ttype?>'>

<table border=1>
<tr><td>Enter password </td><td><input type=password name='pswd'></td></tr>
<tr><td colspan=2 align=center><input type=submit value='Delete' name='del'></td></tr>
</table>
</form>
<?
if($del && $pswd=='del')
{
 $re1=mysqli_query($db,"select porderno,jvno,supqty,partcode from sparepurchase where purno='$purno' and taxtype='$ttype' and brcode='$brcode'");
 while($purrow=mysqli_fetch_array($re1))
  {
    $sql="update purorder_spare set sup_qty=(sup_qty-$purrow[supqty]),sup_purno='0', sup_date='0000-00-00' where orderno='$purrow[porderno]' and partcode='$purrow[partcode]' and brcode='$brcode'";
mysqli_query($db,$sql) or die(mysqli_error());
   }

$sql="select porderno,jvno from sparepurchase where purno='$purno' and taxtype='$ttype' and brcode='$brcode'";

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

mysqli_query($db,$sql);
$sql="delete from sparepurchase where purno='$purno' and taxtype='$ttype' and brcode='$brcode'";
mysqli_query($db,$sql);

print "<font color=red>Record has been deleted</font>";
print "<script> document.location='purrepo.php'; </script>";
}
?>

